Skip to content

Commit

Permalink
dynamically get the version number within python
Browse files Browse the repository at this point in the history
  • Loading branch information
adraismawur committed Dec 12, 2024
1 parent b320b48 commit bbe9ad1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
33 changes: 31 additions & 2 deletions big_scape/run_bigscape.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import psutil
import signal
import logging
import toml
from datetime import datetime
from pathlib import Path

Expand Down Expand Up @@ -40,14 +41,42 @@
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.
"""
# starting information
# TODO: add automatic updating of version number
# this is, lightly and delicately put, *not a great way to get the version*
# but after some research, it seems no one had the idea to make this easy

bigscape_version = get_bigscape_version()

logging.info(
"Starting BiG-SCAPE 2.0.0 %s run on %s level with %s alignment and %s weights",
"Starting BiG-SCAPE %s %s run on %s level with %s alignment and %s weights",
bigscape_version,
run["mode"],
run["record_type"].value,
run["alignment_mode"].value,
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ dependencies:
- pip:
- click==8.1.7
- PyYAML==6.0.1
- importlib-metadata==8.5.0

0 comments on commit bbe9ad1

Please sign in to comment.