Scm based plugin version#25
Conversation
lukaspie
left a comment
There was a problem hiding this comment.
I think the initiative is good and I agree we should store this information.
However, this seems unnecessarily complicated. Why not infer the version of both pynxtools version and the version of the plugin at runtime using importlib.metadata?
Using importlib.metadata is preferable to the git describe solution given here because it reports the version of the actually installed distribution independent of the presence of a git repository or build environment.
My suggestion would be the following:
We can put this into pynxtools/src/pynxtools/__init__.py:
from importlib.metadata import version, PackageNotFoundError
def get_package_version(dist_name: str) -> str | None:
"""Return the installed version of a distribution.
Args:
dist_name: Distribution name as used in package metadata.
Returns:
Installed version string, or ``"unknown version"`` if not found.
"""
try:
return version(dist_name)
except PackageNotFoundError:
return "unknown version"
Then, in pynxtools.dataconverter.helpers:
from pynxtools import get_package_version
def add_default_root_attributes(data, filename):
[...]
update_and_warn("/@creator", "pynxtools")
update_and_warn("/@creator_version", get_package_version("pynxtools"))
Then, in the pynxtools-plugin(-template) itself, we just do (in the read function)
from pynxtools import get_package_version
{{cookiecutter.__module_name}}_version = get_package_version("{{cookiecutter.__package_name}}")
similar to what you already did.
The one question then is where to place this version of the plugin (as /@creator in NXroot can only be filled once). We could put it to /NXentry/program_name-field,
but better yet would be to place a generic NXprogram into NXroot or NXentry eventually.
What do you think of this solution?
|
Feature-complete |
lukaspie
left a comment
There was a problem hiding this comment.
Just a bit of cleanup, conceptually fine.
Code and example how to store the plugin version during "dataconverting" NeXus/HDF5 files