Skip to content

Import a __version__ attribute into top-level namespace#102

Merged
skoudoro merged 10 commits intotee-ar-ex:masterfrom
arokem:dunder_version
Feb 5, 2026
Merged

Import a __version__ attribute into top-level namespace#102
skoudoro merged 10 commits intotee-ar-ex:masterfrom
arokem:dunder_version

Conversation

@arokem
Copy link
Collaborator

@arokem arokem commented Feb 4, 2026

Small fix so that the library has a trx.__version__ attribute

@codecov
Copy link

codecov bot commented Feb 4, 2026

Codecov Report

❌ Patch coverage is 25.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.95%. Comparing base (9b6a77d) to head (1483be2).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
trx/__init__.py 25.00% 6 Missing ⚠️
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     
Flag Coverage Δ
unittests 59.95% <25.00%> (-0.12%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Expose the package version at the top-level (trx.__version__) and validate it in CI/publish workflows.

Changes:

  • Re-export __version__ from trx/__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
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

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).

Suggested change
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"

Copilot uses AI. Check for mistakes.
Comment on lines 35 to 37
python -c "import trx; print(trx.__version__)"
python -m pip install --upgrade pip
python -m pip install -e .[dev,test]
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

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).

Suggested change
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__)"

Copilot uses AI. Check for mistakes.
@arokem arokem changed the title Import a __version__ attribute into top-level namespace WIP: Import a __version__ attribute into top-level namespace Feb 4, 2026
@arokem
Copy link
Collaborator Author

arokem commented Feb 4, 2026

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.

@arokem arokem changed the title WIP: Import a __version__ attribute into top-level namespace Import a __version__ attribute into top-level namespace Feb 4, 2026
@arokem
Copy link
Collaborator Author

arokem commented Feb 4, 2026

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 __init__

@skoudoro
Copy link
Collaborator

skoudoro commented Feb 4, 2026

Thanks, this is useful ! I can not try locally now, but I will do it tonight and go ahead to merge it

@skoudoro skoudoro merged commit 6b4a53d into tee-ar-ex:master Feb 5, 2026
14 of 16 checks passed
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.

2 participants