Skip to content

Commit

Permalink
Take a stab at saving version info
Browse files Browse the repository at this point in the history
  • Loading branch information
tkkuehn committed Jun 14, 2023
1 parent 05f1d9d commit 18d23ba
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion snakebids/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit 18d23ba

Please sign in to comment.