diff --git a/.chasten/checks.yml b/.chasten/checks.yml index 91c7ce1a..e28eeff3 100644 --- a/.chasten/checks.yml +++ b/.chasten/checks.yml @@ -33,4 +33,4 @@ checks: pattern: './/FunctionDef/body//If[ancestor::If and not(parent::orelse)]' count: min: 1 - max: 15 + max: 15 \ No newline at end of file diff --git a/chasten/database.py b/chasten/database.py index 401333ad..bc0a144f 100644 --- a/chasten/database.py +++ b/chasten/database.py @@ -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 @@ -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 ) @@ -163,7 +174,7 @@ 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, ) @@ -171,7 +182,7 @@ def start_datasette_server( # noqa: PLR0912 # 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 diff --git a/chasten/main.py b/chasten/main.py index 7f5cbae6..2c24365a 100644 --- a/chasten/main.py +++ b/chasten/main.py @@ -822,6 +822,7 @@ def datasette_serve( # noqa: PLR0913 datasette_port=port, datasette_metadata=metadata, publish=False, + OpSystem=util.get_OS(), ) diff --git a/chasten/util.py b/chasten/util.py index 859cb42d..ec03cf92 100644 --- a/chasten/util.py +++ b/chasten/util.py @@ -1,6 +1,7 @@ """Utilities for use within chasten.""" import importlib.metadata +import platform from chasten import constants @@ -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: diff --git a/tests/test_database.py b/tests/test_database.py new file mode 100644 index 00000000..dd1ad2c3 --- /dev/null +++ b/tests/test_database.py @@ -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()) + )