-
Notifications
You must be signed in to change notification settings - Fork 16
Save more provenance information #308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
18d23ba
ac6cf4c
c272bee
8d25cfa
b2f34cf
e285826
b263e54
d19c80f
03c2c4c
f08dee1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,21 @@ def create_descriptor(self, out_file: PathLike[str] | str) -> None: | |
| ) | ||
| new_descriptor.save(out_file) # type: ignore | ||
|
|
||
| def get_app_version(self) -> str | None: | ||
|
tkkuehn marked this conversation as resolved.
Outdated
|
||
| """Attempt to get the app version, returning None if we can't. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're moving in this direction, I wonder if we should allow (and encourage) the passing of explicit modules (or string names of modules) to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not necessarily a goal for this PR, but maybe something to think about for the future
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't address this for now, but is probably worth a separate issue for discussion. |
||
|
|
||
| This will succeed only if the following conditions are true: | ||
|
|
||
| 1. The Snakebids app is a distribution package installed in the current | ||
| environment. | ||
| 2. The app's distribution package has the same name as this | ||
| SnakeBidsApp's snakemake_dir | ||
| """ | ||
| 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.""" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| def version(distribution_name: str) -> str: | ||
| """Get the version string for the named package. | ||
|
|
||
| :param distribution_name: The name of the distribution package to query. | ||
| :return: The version string for the package as defined in the package's | ||
| "Version" metadata key. | ||
| """ | ||
| ... | ||
|
|
||
| class PackageNotFoundError(ModuleNotFoundError): | ||
| """The package was not found.""" | ||
|
|
||
| def __str__(self) -> str: ... | ||
| @property | ||
| def name(self) -> str: ... |
Uh oh!
There was an error while loading. Please reload this page.