Repository navigation
Conversation
Some tract_math operations import SciPy (ndimage, interpolate) or scikit-learn (BallTree), which were not declared anywhere, so users only found out from a bare ImportError. Declare them as the optional `tract_math` extra and make those operations raise an ImportError naming the extra when the package is missing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
Some
tract_mathoperations import packages that are not declared anywhere: SciPy (scipy.ndimageintract_map_image,tract_deform,tract_generate_population_probability_map;scipy.interpolateintract_prototype_mean) and scikit-learn (sklearn.neighbors.BallTreeintract_smooth). Without them, users get a bareModuleNotFoundError: No module named 'scipy'at run time.The change
pyproject.toml: new optional extratract_math = ["scipy", "scikit-learn"](4 added lines, nothing else changed).operations.py: a small_import_optional(module_name)helper (not a registered operation) used by the four operations above; when the module is missing it raisesImportError: This operation needs scipy: install it, or install tract_querier with the tract_math extra, e.g. pip install '.[tract_math]' from the source tree(chained to the original error).tract_prototype_meankeeps its existing behaviour (warns and skips the smoothing without SciPy); only its warning now names the extra.doc/installation_instructions.rst: one sentence after the requirements list.The message suggests
pip install '.[tract_math]'rather thantract_querier[tract_math]because the package is not on PyPI (the docs install from GitHub or a source tree).tensor_operations.tract_expand_tensor_metricsalso imports SciPy, but it is dead code (undefined name, no callers) and is removed in the #107 PR, so it is left alone here.tract_label_indices.pyimports SciPy too, outsidetract_math(handled by #135).Testing
test_tract_math_missing_optional_dependency: hidesscipy/sklearnviasys.modulesand checks thattract_map_image,tract_deformandtract_smoothraise anImportErrornaming thetract_mathextra. Passes here.python -m pytest -q -p no:cacheprovider tract_querier: 45 passed, 1 skipped (pre-existing unconditional skip).Maintainer decision: CI installs
.[test]only, so SciPy-dependent tests (e.g. those in #143, which usepytest.importorskip) are skipped there; installing.[test,tract_math]in.github/workflows/test_package.yamlwould run them. Not changed here.Merge order
pyproject.tomlis also edited by #98 (moves VTK to an optional extra in the same[project.optional-dependencies]table, so it will conflict textually next to this one), #120 and #121 (other tables; probably merge cleanly).doc/installation_instructions.rstis also edited by #98 (requirements list, adjacent lines).operations.pyis also edited by #143 and #145 (different lines).Closes #112
🤖 Generated with Claude Code