Skip to content

Scm based plugin version#25

Merged
mkuehbach merged 14 commits into
mainfrom
scm_based_plugin_version
Mar 18, 2026
Merged

Scm based plugin version#25
mkuehbach merged 14 commits into
mainfrom
scm_based_plugin_version

Conversation

@mkuehbach
Copy link
Copy Markdown
Contributor

Code and example how to store the plugin version during "dataconverting" NeXus/HDF5 files

Copy link
Copy Markdown
Contributor

@lukaspie lukaspie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@mkuehbach
Copy link
Copy Markdown
Contributor Author

Feature-complete

@mkuehbach mkuehbach requested a review from lukaspie February 13, 2026 15:43
Copy link
Copy Markdown
Contributor

@lukaspie lukaspie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a bit of cleanup, conceptually fine.

Comment thread pynxtools-{{cookiecutter.reader_name}}/docs/learn/versioning.md Outdated
Comment thread pynxtools-{{cookiecutter.reader_name}}/tests/test_utils_versioning.py Outdated
Comment thread pynxtools-{{cookiecutter.reader_name}}/tests/test_utils_versioning.py Outdated
Comment thread pynxtools-{{cookiecutter.reader_name}}/tests/test_utils_versioning.py Outdated
Copy link
Copy Markdown
Contributor

@lukaspie lukaspie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mkuehbach mkuehbach requested a review from lukaspie March 18, 2026 11:23
@mkuehbach mkuehbach merged commit 345a5b3 into main Mar 18, 2026
3 checks passed
@mkuehbach mkuehbach deleted the scm_based_plugin_version branch April 7, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants