Import a __version__ attribute into top-level namespace#102
Import a __version__ attribute into top-level namespace#102skoudoro merged 10 commits intotee-ar-ex:masterfrom
Conversation
8cb9a4a to
8639286
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #102 +/- ##
==========================================
- Coverage 60.06% 59.95% -0.12%
==========================================
Files 12 13 +1
Lines 2454 2462 +8
==========================================
+ Hits 1474 1476 +2
- Misses 980 986 +6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Expose the package version at the top-level (trx.__version__) and validate it in CI/publish workflows.
Changes:
- Re-export
__version__fromtrx/__init__.py. - Add a CI sanity-check to print
trx.__version__. - Update the TestPyPI publish workflow to check
trx.__version__from the installed sdist.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
trx/__init__.py |
Re-exports __version__ into the trx top-level namespace. |
.github/workflows/test.yml |
Adds a step intended to confirm trx.__version__ during tests. |
.github/workflows/publish-to-test-pypi.yml |
Updates version check to use the top-level trx.__version__. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
trx/__init__.py
Outdated
| @@ -1 +1,3 @@ | |||
| """TRX file format for brain tractography data.""" | |||
|
|
|||
| from .version import __version__ # noqa: F401 | |||
There was a problem hiding this comment.
Importing __version__ from .version will raise ImportError in a source checkout because trx/version.py is generated by setuptools_scm (and is gitignored) and therefore doesn't exist until after an install/build step. To avoid breaking import trx (and CI steps that import before installation), add a safe fallback (e.g., try/except around the import and compute the version via importlib.metadata.version('trx-python'), with a PackageNotFoundError fallback).
| from .version import __version__ # noqa: F401 | |
| try: | |
| from .version import __version__ # noqa: F401 | |
| except ImportError: | |
| try: | |
| from importlib.metadata import PackageNotFoundError, version | |
| except ImportError: # pragma: no cover | |
| __version__ = "0+unknown" | |
| else: | |
| try: | |
| __version__ = version("trx-python") | |
| except PackageNotFoundError: | |
| __version__ = "0+unknown" |
.github/workflows/test.yml
Outdated
| python -c "import trx; print(trx.__version__)" | ||
| python -m pip install --upgrade pip | ||
| python -m pip install -e .[dev,test] |
There was a problem hiding this comment.
This step imports trx before the package is installed (pip install -e .[...]). Since trx/version.py is generated during the build/install process, this will fail in CI. Move the version check to after the install, or change it to a command that doesn't require importing trx from the source tree (e.g., use python -m pip install ... first, then import).
| python -c "import trx; print(trx.__version__)" | |
| python -m pip install --upgrade pip | |
| python -m pip install -e .[dev,test] | |
| python -m pip install --upgrade pip | |
| python -m pip install -e .[dev,test] | |
| python -c "import trx; print(trx.__version__)" |
autoapi raises a warning when it can't resolve the import of _version within the __init__.py file, so we are going to suppress that kind of warning so we can continue to consider other warnings as errors.
|
This is more work than I was originally expecting 😅 I want to make sure that I have that init file set up correctly before we merge this, so I labeled this as "WIP" for now. |
|
OK - I think this might be OK now. CI is failing because of codecov, but I don't think that can be satisfied with the changes to |
|
Thanks, this is useful ! I can not try locally now, but I will do it tonight and go ahead to merge it |
Small fix so that the library has a
trx.__version__attribute