From 4dac8e1b572aabdda575d93af9455b64b7f9a0dd Mon Sep 17 00:00:00 2001 From: Arjan Draisma Date: Thu, 12 Dec 2024 15:27:33 +0100 Subject: [PATCH] fix location of getting version to utils --- big_scape/__main__.py | 4 +++- big_scape/run_bigscape.py | 25 +------------------------ big_scape/utility/version.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 25 deletions(-) create mode 100644 big_scape/utility/version.py diff --git a/big_scape/__main__.py b/big_scape/__main__.py index b1fb718f..fc3ae8ab 100644 --- a/big_scape/__main__.py +++ b/big_scape/__main__.py @@ -9,12 +9,14 @@ from big_scape.cli import query_cli as query from big_scape.cli import benchmark_cli as benchmark from big_scape.cli.cli_config import CommandOrder +from big_scape.utility.version import get_bigscape_version def print_version(ctx, param, value): if not value or ctx.resilient_parsing: return - click.echo("BiG-SCAPE 2.0 beta") + bigscape_version = get_bigscape_version() + click.echo(f"BiG-SCAPE {bigscape_version}") ctx.exit() diff --git a/big_scape/run_bigscape.py b/big_scape/run_bigscape.py index e0d9aecc..944c4032 100644 --- a/big_scape/run_bigscape.py +++ b/big_scape/run_bigscape.py @@ -8,7 +8,6 @@ import psutil import signal import logging -import toml from datetime import datetime from pathlib import Path @@ -30,6 +29,7 @@ import big_scape.file_input as bs_files # import big_scape.genbank as bs_gbk +from big_scape.utility.version import get_bigscape_version import big_scape.data as bs_data import big_scape.enums as bs_enums import big_scape.comparison as bs_comparison @@ -41,29 +41,6 @@ import big_scape.distances.query as bs_query -def get_bigscape_version() -> str: - """Get the version of BiG-SCAPE. - The way we retrieve the version is different depending on whether the package is - installed or not. - - We need a dedicated library for this because the python community has not figured - out that version numbers are pretty core to software development and there is no - single place to put them. We want it to only be in the pyproject.toml file and not - anywhere else, but this file is not available when installed as a package - """ - # can we get to the pyproject.toml file? - pyproject_toml = Path(__file__).parent.parent / "pyproject.toml" - - if pyproject_toml.exists(): - return toml.load(pyproject_toml)["project"]["version"] - - # if not, we're probably running as a package. get the version of the currently - # installed big-scape package - import importlib.metadata - - return importlib.metadata.version("big-scape") - - def run_bigscape(run: dict) -> None: """Run a bigscape cluster analysis. This is the main function of the program that parses the command line arguments, loads the data, runs the analysis and saves the output. diff --git a/big_scape/utility/version.py b/big_scape/utility/version.py new file mode 100644 index 00000000..b19a1e5c --- /dev/null +++ b/big_scape/utility/version.py @@ -0,0 +1,30 @@ +"""Module that contains helper functions specifically related to the bigscape version +""" + +import toml + +from importlib import metadata +from pathlib import Path + + +def get_bigscape_version() -> str: + """Get the version of BiG-SCAPE. + The way we retrieve the version is different depending on whether the package is + installed or not. + + We need a dedicated library for this because the python community has not figured + out that version numbers are pretty core to software development and there is no + single place to put them. We want it to only be in the pyproject.toml file and not + anywhere else, but this file is not available when installed as a package + """ + # can we get to the pyproject.toml file? + print(__file__) + pyproject_toml = Path(__file__).parent.parent.parent / "pyproject.toml" + + if pyproject_toml.exists(): + return toml.load(pyproject_toml)["project"]["version"] + + # if not, we're probably running as a package. get the version of the currently + # installed big-scape package + + return metadata.version("big-scape")