Skip to content

Commit

Permalink
Merge pull request #89 from AstuteSource/master
Browse files Browse the repository at this point in the history
Update to master
  • Loading branch information
hayleepierce authored Oct 16, 2023
2 parents 33e5de9 + e102e45 commit 095a428
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .chasten/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ checks:
pattern: './/FunctionDef/body//If[ancestor::If and not(parent::orelse)]'
count:
min: 1
max: 15
max: 15
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 @@ -822,6 +822,7 @@ def datasette_serve( # noqa: PLR0913
datasette_port=port,
datasette_metadata=metadata,
publish=False,
OpSystem=util.get_OS(),
)


Expand Down Expand Up @@ -911,6 +912,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 095a428

Please sign in to comment.