Skip to content

Commit

Permalink
Merge branch 'master' into createchecks
Browse files Browse the repository at this point in the history
  • Loading branch information
Poiuy7312 authored Oct 17, 2023
2 parents 0932363 + d6631d9 commit cb9ee47
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .chasten/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
pattern: './/FunctionDef/body//If[ancestor::If and not(parent::orelse)]'
count:
min: 1
max: 300
max: 300
13 changes: 0 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,3 @@ jobs:
echo "### Total coverage: ${TOTAL}%" >> $GITHUB_STEP_SUMMARY
CURRENT_GITHUB_STEP_SUMMARY="\`\`\`\n$(cat coverage.txt)\n\`\`\`"
echo "$CURRENT_GITHUB_STEP_SUMMARY" >> $GITHUB_STEP_SUMMARY
# Create the Coverage Badge
- name: Make Badge
uses: schneegans/[email protected]
with:
# GIST_TOKEN is a GitHub personal access token with scope "gist".
auth: ${{ secrets.GIST_TOKEN }}
gistID: 5300aa276fa9261b2b21b96c3141b3ad
filename: covbadge.json
label: Coverage
message: ${{ env.total }}%
minColorRange: 50
maxColorRange: 90
valColorRange: ${{ env.total }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,6 @@ coverage.txt

# coverage report
coverage.json

# bash command history
.bash_history
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM ubuntu

RUN apt-get update -y \
&& apt-get upgrade -y \
&& apt-get install software-properties-common -y \
&& add-apt-repository ppa:deadsnakes/ppa -y \
&& DEBIAN_FRONTEND=noninteractive apt-get install python3.11 -y \
&& update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1 \
&& update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 2 \
&& apt-get install python-is-python3 -y

RUN apt-get install -y curl \
&& curl -sSL https://install.python-poetry.org | python - \
&& apt install -y python3.11 python3.11-distutils \
&& curl -sSl https://bootstrap.pypa.io/get-pip.py | python -

RUN apt-get install -y libsqlite3-dev \
&& apt-get install python3.11-dev -y \
&& apt-get install -y libgmp-dev \
portaudio19-dev \
libssl-dev \
libpcap-dev \
libffi-dev \
libxml2-dev \
libxslt1-dev \
libblas-dev \
libatlas-base-dev \
&& apt-get install -y gcc-x86-64-linux-gnu

CMD cd root \
&& mkdir src

ENTRYPOINT export PATH="/root/.local/bin:$PATH" && cd root/src && /bin/bash
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,25 @@ Follow these steps to install the `chasten` program:
- Type `pipx list` and confirm that Chasten is installed
- Type `chasten --help` to learn how to use the tool

## 🐋 Docker

There is also the option to use [Docker](https://www.docker.com/) to use `chasten`

Follow these steps to utilize Docker:

- Install [Docker Desktop](https://docs.docker.com/get-docker/) for your operating system
- Ensure Docker Desktop is running
- `cd` into the chasten directory where the `Dockerfile` is located
- Type `docker build -t chasten .` to build the container
- Type one of the following commands to run the container:
- Windows (Command Prompt) -> `docker run --rm -v "%cd%":/root/src -it chasten`
- Windows (Powershell) -> `docker run --rm -v ${pwd}:/root/src -it chasten`
- Mac/Ubuntu -> `docker run --rm -v $(pwd):/root/src -it chasten`
- Inside the container type `poetry install`
- Outside of the container type `docker ps` to view running container information
- Outside of the container type `docker commit <your-container-id> <your-image-name>` to save the dependecy installation
- Now you can use Docker for all of your `chasten` needs!

## 🪂 Configuration

You can configure `chasten` with two YAML files, normally called `config.yml`
Expand Down
23 changes: 17 additions & 6 deletions chasten/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,28 @@ def display_datasette_details(
output.console.print()


def start_datasette_server( # noqa: PLR0912
def executable_name(OpSystem: str = "Linux") -> str:
"""Get the executable directory depending on OS"""
exe_directory = "/bin/"
executable_name = constants.datasette.Datasette_Executable
# Checks if the OS is windows and changed where to search if true
if OpSystem == "Windows":
exe_directory = "/Scripts/"
executable_name += ".exe"
virtual_env_location = sys.prefix
return virtual_env_location + exe_directory + executable_name


def start_datasette_server( # noqa: PLR0912, PLR0913
database_path: Path,
datasette_metadata: Path,
datasette_platform: str = enumerations.DatasettePublicationPlatform.FLY.value,
datasette_port: int = 8001,
publish: bool = False,
OpSystem: str = "Linux",
) -> None:
"""Start a local datasette server."""
# define the name of the executable needed to run the server
executable_name = constants.datasette.Datasette_Executable
# define the name of the file that contains datasette metadata;
# note that by default the metadata could be None and thus it
# will not be passed as a -m argument to the datasette program
Expand All @@ -148,8 +160,7 @@ def start_datasette_server( # noqa: PLR0912
# chasten will exist in a bin directory. For instance, the "datasette"
# executable that is a dependency of chasten can be found by starting
# the search from this location for the virtual environment.
virtual_env_location = sys.prefix
full_executable_name = virtual_env_location + "/bin/" + executable_name
full_executable_name = executable_name(OpSystem)
(found_executable, executable_path) = filesystem.can_find_executable(
full_executable_name
)
Expand All @@ -163,15 +174,15 @@ def start_datasette_server( # noqa: PLR0912
label = ":sparkles: Details for datasette startup:"
display_datasette_details(
label,
virtual_env_location,
sys.prefix,
str(executable_path),
full_executable_name,
)
# since it was not possible to find the executable for datasette, display and
# error message and then exit this function since no further steps are possible
if not found_executable:
output.console.print(
":person_shrugging: Was not able to find '{executable_name}'"
f":person_shrugging: Was not able to find {constants.datasette.Datasette_Executable}"
)
return None
# run the localhost server because the
Expand Down
6 changes: 5 additions & 1 deletion chasten/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ def write_chasten_results(
results_path_with_file = results_path / complete_results_file_name
results_json = results_content.model_dump_json(indent=2)
# use the built-in method with pathlib Path to write the JSON contents
results_path_with_file.write_text(results_json)
try:
results_path_with_file.write_text(results_json)
except: # noqa: E722
results_path_with_file.write_text(results_json, "utf-8")

# return the name of the created file for diagnostic purposes
return complete_results_file_name
# saving was not enabled and thus this function cannot
Expand Down
10 changes: 10 additions & 0 deletions chasten/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ def datasette_serve( # noqa: PLR0913
datasette_port=port,
datasette_metadata=metadata,
publish=False,
OpSystem=util.get_OS(),
)


Expand Down Expand Up @@ -955,6 +956,15 @@ def log() -> None:
server.start_syslog_server()


@cli.command()
def version():
"""🖥️ Display the version of Chasten."""
# Get Chasten version from util file
version_string = util.get_chasten_version()
# output chasten version
typer.echo(f"chasten {version_string}")


# ---
# End region: Command-line interface functions }}}
# ---
7 changes: 7 additions & 0 deletions chasten/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Utilities for use within chasten."""

import importlib.metadata
import platform

from chasten import constants

Expand All @@ -18,6 +19,12 @@ def get_human_readable_boolean(answer: bool) -> str:
return constants.humanreadable.No


def get_OS() -> str:
"""Gets the Operating system of the user."""
OpSystem = platform.system()
return OpSystem


def get_symbol_boolean(answer: bool) -> str:
"""Produce a symbol-formatted version of a boolean value of True or False."""
if answer:
Expand Down
9 changes: 9 additions & 0 deletions tests/test_database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""Pytest test suite for the database module."""

from chasten import database, filesystem, util


def test_executable_name() -> None:
assert filesystem.can_find_executable(
database.executable_name(OpSystem=util.get_OS())
)

0 comments on commit cb9ee47

Please sign in to comment.