Skip to content

Commit

Permalink
fix location of getting version to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
adraismawur committed Dec 12, 2024
1 parent 3acf7a0 commit 4dac8e1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
4 changes: 3 additions & 1 deletion big_scape/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down
25 changes: 1 addition & 24 deletions big_scape/run_bigscape.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import psutil
import signal
import logging
import toml
from datetime import datetime
from pathlib import Path

Expand All @@ -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
Expand All @@ -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.
Expand Down
30 changes: 30 additions & 0 deletions big_scape/utility/version.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 4dac8e1

Please sign in to comment.