Skip to content

Make scipy optional again and declare packaging - #123

Closed
Kayvan-Zahiri wants to merge 1 commit into
materialscloud-org:mainfrom
Kayvan-Zahiri:lazy-scipy-import
Closed

Kayvan-Zahiri wants to merge 1 commit into
materialscloud-org:mainfrom
Kayvan-Zahiri:lazy-scipy-import

Conversation

@Kayvan-Zahiri

@Kayvan-Zahiri Kayvan-Zahiri commented Sep 25, 2026 •

Copy link
Copy Markdown

On a clean install of seekpath 2.2.1 (no bz extra), import seekpath fails:

$ pip install seekpath
$ python -c "import seekpath"
ModuleNotFoundError: No module named 'scipy'

scipy is listed only under the bz extra, and the tests already skip the Brillouin zone tests when it's missing, but seekpath/__init__.py has imported brillouinzone since cffa9d5 (March 2024), and that module imports scipy.spatial at the top.

Two changes:

  • brillouinzone.py imports scipy.spatial inside BZ._initialize_BZ, the only place it's used at runtime. The return annotations on hull and delaunay stay as they are through from __future__ import annotations and a TYPE_CHECKING import. Building a BZ without scipy still raises ModuleNotFoundError: No module named 'scipy'.
  • With that fixed, get_path hit a second missing dependency: hpkot/tools.py imports packaging, which isn't declared. I added it to dependencies.

Tested: in a clean Python 3.12 venv with a plain install (no scipy), import seekpath and seekpath.get_path(...) work on this branch; on 2.2.1 the import fails. With .[bz] installed, the full test suite passes (77 tests, including the new tests/test_import_without_scipy.py, which blocks scipy in a subprocess and imports seekpath; it fails without this change). The trailing-whitespace, end-of-file, quote-fixer, flynt and ruff hooks pass on the changed files.

Written with AI assistance. The runs above are real.

Since seekpath/__init__.py started importing brillouinzone (2024), scipy,
which is only the `bz` extra, became required for `import seekpath`.
Import scipy inside BZ._initialize_BZ instead. hpkot/tools.py also imports
packaging, which was never declared, so get_path failed on a clean
install.
@t-reents

Copy link
Copy Markdown
Collaborator

Thanks!
However, while working on #124, I noticed this issue myself and fixed it locally. I now opened a PR #125, which will supersede this one, so I'll close it.
Nonetheless, thank you for your contribution.

@t-reents t-reents closed this Sep 25, 2026
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