Skip to content

Commit

Permalink
Merge pull request #52 from AstuteSource/Datasette-serve-fix
Browse files Browse the repository at this point in the history
fix: Datasette-serve command not running correctly on Windows
  • Loading branch information
Poiuy7312 committed Oct 13, 2023
2 parents 5180d49 + 7d413f0 commit dcc5e78
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 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
1 change: 1 addition & 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
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 dcc5e78

Please sign in to comment.