diff --git a/poetry.lock b/poetry.lock index 2fb215fe..7e71f6cb 100644 --- a/poetry.lock +++ b/poetry.lock @@ -3131,4 +3131,4 @@ testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more [metadata] lock-version = "2.0" python-versions = ">=3.7,<3.12" -content-hash = "211348130ff5674b03a24fe52822c7985ffa25bafe62ea7579eb17224b718b25" +content-hash = "a357c428fa8c73c70766bfe27c52d6ea53713a3f71dc83134a61fc2180a6104e" diff --git a/pyproject.toml b/pyproject.toml index 19e1f9b5..320ee8b5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,6 +52,7 @@ boutiques = "^0.5.25" more-itertools = ">=8,<10" cached-property = "^1.5.2" pvandyken-deprecated = "0.0.3" +importlib_metadata = [ { version = "^6.6.0", python = "<3.8" } ] # Below are non-direct dependencies (i.e. dependencies of other depenencies) # specified to ensure a version with a pre-built wheel is installed depending diff --git a/snakebids/app.py b/snakebids/app.py index 518c73e0..c9d9ac1b 100644 --- a/snakebids/app.py +++ b/snakebids/app.py @@ -13,6 +13,11 @@ import snakemake from snakemake.io import load_configfile +if sys.version_info >= (3, 8): + from importlib import metadata +else: + import importlib_metadata as metadata + from snakebids.cli import ( SnakebidsArgs, add_dynamic_args, @@ -207,7 +212,12 @@ def run_snakemake(self) -> None: # Write the config file write_config_file( config_file=new_config_file, - data=app.config, + data=dict( + app.config, + snakemake_version=metadata.version("snakemake"), + snakebids_version=metadata.version("snakebids"), + app_version=app.get_app_version() or "unknown", + ), force_overwrite=True, ) @@ -240,6 +250,13 @@ def create_descriptor(self, out_file: PathLike[str] | str) -> None: ) new_descriptor.save(out_file) # type: ignore + def get_app_version(self) -> str | None: + """Attempt to get the app version, returning None if we can't.""" + try: + return metadata.version(self.snakemake_dir.name) + except metadata.PackageNotFoundError: + return None + def update_config(config: dict[str, Any], snakebids_args: SnakebidsArgs) -> None: """Add snakebids arguments to config in-place."""