From 86392866b868ebab8c3f87bdf17ad18ac9da8134 Mon Sep 17 00:00:00 2001 From: Ariel Rokem Date: Wed, 4 Feb 2026 10:09:19 -0800 Subject: [PATCH 01/10] Import a __version__ attribute into top-level namespace --- .github/workflows/publish-to-test-pypi.yml | 2 +- .github/workflows/test.yml | 1 + trx/__init__.py | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish-to-test-pypi.yml b/.github/workflows/publish-to-test-pypi.yml index fe05a51..b341925 100644 --- a/.github/workflows/publish-to-test-pypi.yml +++ b/.github/workflows/publish-to-test-pypi.yml @@ -41,7 +41,7 @@ jobs: run: python -c "import sys; print(sys.version)" - name: Install sdist without optional dependencies run: pip install dist/*.tar.gz - - run: python -c 'import trx.version; print(trx.version.__version__)' + - run: python -c 'import trx; print(trx.__version__)' - name: Install pytest run: pip install pytest psutil pytest-console-scripts pytest-cov - name: Run tests diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e9f231e..7ec253f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,6 +32,7 @@ jobs: - name: Install dependencies run: | + python -c "import trx; print(trx.__version__)" python -m pip install --upgrade pip python -m pip install -e .[dev,test] diff --git a/trx/__init__.py b/trx/__init__.py index 047e068..b15f581 100644 --- a/trx/__init__.py +++ b/trx/__init__.py @@ -1 +1,2 @@ """TRX file format for brain tractography data.""" +from ._version import __version__ # noqa: F401 From 4ddbb712b2c431c224a02cfd2d3422ca2218f477 Mon Sep 17 00:00:00 2001 From: Ariel Rokem Date: Wed, 4 Feb 2026 10:13:14 -0800 Subject: [PATCH 02/10] The version file does not have a leading underscore. --- trx/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/trx/__init__.py b/trx/__init__.py index b15f581..a3345a8 100644 --- a/trx/__init__.py +++ b/trx/__init__.py @@ -1,2 +1,3 @@ """TRX file format for brain tractography data.""" -from ._version import __version__ # noqa: F401 + +from .version import __version__ # noqa: F401 From 4c6e666b12b8dbc9652a55d3b8448a6f1b0a9171 Mon Sep 17 00:00:00 2001 From: Ariel Rokem Date: Wed, 4 Feb 2026 10:19:19 -0800 Subject: [PATCH 03/10] Change order of build and import in test workflow (duh). --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7ec253f..40e83d1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,9 +32,9 @@ jobs: - name: Install dependencies run: | - python -c "import trx; print(trx.__version__)" python -m pip install --upgrade pip python -m pip install -e .[dev,test] + python -c "import trx; print(trx.__version__)" - name: Test run: spin test From 87891dc37e58291698bf0072bcb73df71e292899 Mon Sep 17 00:00:00 2001 From: Ariel Rokem Date: Wed, 4 Feb 2026 10:21:09 -0800 Subject: [PATCH 04/10] Use _version with a leading underscore after all. --- pyproject.toml | 2 +- trx/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 18de8f9..2f6f606 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -86,7 +86,7 @@ packages = ["trx"] include-package-data = true [tool.setuptools_scm] -write_to = "trx/version.py" +write_to = "trx/_version.py" fallback_version = "0.0" local_scheme = "no-local-version" diff --git a/trx/__init__.py b/trx/__init__.py index a3345a8..322a88e 100644 --- a/trx/__init__.py +++ b/trx/__init__.py @@ -1,3 +1,3 @@ """TRX file format for brain tractography data.""" -from .version import __version__ # noqa: F401 +from ._version import __version__ # noqa: F401 From 5ccbfb3cb5a027bde81bd742910b871edaf79f79 Mon Sep 17 00:00:00 2001 From: Ariel Rokem Date: Wed, 4 Feb 2026 10:41:32 -0800 Subject: [PATCH 05/10] Address warnings in doc build. 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. --- docs/source/conf.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/source/conf.py b/docs/source/conf.py index 27eaff0..fe3fde1 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -132,6 +132,11 @@ autoapi_dirs = ['../../trx'] autoapi_ignore = ['*test*', '*version*'] +# Added to suppress warnings from autoapi about import of _version +# within __init__.py: +suppress_warnings = ['autoapi.python_import_resolution'] + + # Sphinx gallery configuration sphinx_gallery_conf = { 'examples_dirs': '../../examples', From 6a2782918afb00a9e708cbbc5be613d4a3975a1b Mon Sep 17 00:00:00 2001 From: Ariel Rokem Date: Wed, 4 Feb 2026 10:50:31 -0800 Subject: [PATCH 06/10] Use a more elaborate init file instead of suppressing warnings. --- docs/source/conf.py | 5 ----- trx/__init__.py | 13 ++++++++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index fe3fde1..27eaff0 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -132,11 +132,6 @@ autoapi_dirs = ['../../trx'] autoapi_ignore = ['*test*', '*version*'] -# Added to suppress warnings from autoapi about import of _version -# within __init__.py: -suppress_warnings = ['autoapi.python_import_resolution'] - - # Sphinx gallery configuration sphinx_gallery_conf = { 'examples_dirs': '../../examples', diff --git a/trx/__init__.py b/trx/__init__.py index 322a88e..c0d3406 100644 --- a/trx/__init__.py +++ b/trx/__init__.py @@ -1,3 +1,14 @@ """TRX file format for brain tractography data.""" -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" From c0fe7d133c53a598c3cdce95ce8bccbec97fca0a Mon Sep 17 00:00:00 2001 From: Ariel Rokem Date: Wed, 4 Feb 2026 10:53:34 -0800 Subject: [PATCH 07/10] Fixes typo: "_version" instead of "version" --- trx/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trx/__init__.py b/trx/__init__.py index c0d3406..aac21b4 100644 --- a/trx/__init__.py +++ b/trx/__init__.py @@ -1,7 +1,7 @@ """TRX file format for brain tractography data.""" try: - from .version import __version__ # noqa: F401 + from ._version import __version__ # noqa: F401 except ImportError: try: from importlib.metadata import PackageNotFoundError, version From baf2ebeee17c7e2da96d8927dae4b13b5b69bdcd Mon Sep 17 00:00:00 2001 From: Ariel Rokem Date: Wed, 4 Feb 2026 10:54:33 -0800 Subject: [PATCH 08/10] Simplify by a lot. Don't need to cover some exotic cases. --- trx/__init__.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/trx/__init__.py b/trx/__init__.py index aac21b4..42db642 100644 --- a/trx/__init__.py +++ b/trx/__init__.py @@ -3,12 +3,4 @@ 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" + __version__ = "unknown" From 6b15d45ea55fbe63a45741d17c9856b00e05d661 Mon Sep 17 00:00:00 2001 From: Ariel Rokem Date: Wed, 4 Feb 2026 11:05:23 -0800 Subject: [PATCH 09/10] Include the case where version needs to be read from metadata. --- trx/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/trx/__init__.py b/trx/__init__.py index 42db642..33f8f02 100644 --- a/trx/__init__.py +++ b/trx/__init__.py @@ -3,4 +3,9 @@ try: from ._version import __version__ # noqa: F401 except ImportError: - __version__ = "unknown" + try: + from importlib.metadata import version + + __version__ = version("trx-python") + except Exception: + __version__ = "unknown" From 1483be2a74f9e5098fce61a26f9654a061edb3ed Mon Sep 17 00:00:00 2001 From: Ariel Rokem Date: Wed, 4 Feb 2026 11:07:55 -0800 Subject: [PATCH 10/10] Specify this a bit more. --- trx/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/trx/__init__.py b/trx/__init__.py index 33f8f02..1559ad5 100644 --- a/trx/__init__.py +++ b/trx/__init__.py @@ -4,8 +4,8 @@ from ._version import __version__ # noqa: F401 except ImportError: try: - from importlib.metadata import version + from importlib.metadata import PackageNotFoundError, version __version__ = version("trx-python") - except Exception: + except (ImportError, PackageNotFoundError): __version__ = "unknown"