Skip to content

Remove pyscf/nac and pyscf/pbc/lo __init__.py files that shadow core's (#219) - #223

Open
MatthewRHermes wants to merge 1 commit into
pyscf:masterfrom
MatthewRHermes:fix-219-init-shadowing
Open

MatthewRHermes wants to merge 1 commit into
pyscf:masterfrom
MatthewRHermes:fix-219-init-shadowing

Conversation

@MatthewRHermes

Copy link
Copy Markdown
Collaborator

Fixes #219.

pyscf/nac/__init__.py and pyscf/pbc/lo/__init__.py both have counterparts in PySCF core (pbc/lo since pyscf/pyscf#3127, released in 2.14.0). A regular pip install pyscf-forge overwrites core's files, and pip uninstall pyscf-forge deletes them. With forge's pbc/lo/__init__.py installed, for example, from pyscf.pbc.lo import KPM stops working.

Changes

  • Delete both files. Every forge import of these packages is an explicit submodule import (from pyscf.nac import tduks_sf, from pyscf.pbc.lo import mlwf, from pyscf.pbc.lo.mlwf.<module> import ...). These still resolve once forge's modules sit next to core's __init__.py. pbc/lo/mlwf/__init__.py stays, since core has no mlwf subpackage.
  • run_ci.sh: before pip install ., install pyscf and fail if any forge __init__.py has a counterpart in it. Core's location comes from importlib.util.find_spec, so core isn't imported. The check runs against the latest core release, so a clash created later on core's side (as happened with pbc/lo) gets caught at the next CI run after that release.
  • README "Path Conflicts": one line noting that CI now enforces the rule.

Testing

  • I ran the new check locally against pyscf 2.14.0. On master it reports exactly pyscf/pbc/lo/__init__.py and pyscf/nac/__init__.py and exits 1. On this branch it exits 0.
  • pytest pyscf/nac pyscf/pbc/lo on this branch: all passing except test_tduks_sf.py::KnownValues::test_against_cache_refs (max abs diff 2.6e-6 vs. rtol 1e-7). That test fails the same way on master in my environment, so it's unrelated to this change.

Code changes and this description were drafted with the assistance of Claude Opus 5.5.

🤖 Generated with Claude Code

pyscf#219)

Both directories also exist in PySCF core with their own __init__.py, so a
regular install of pyscf-forge overwrites core's file, and uninstalling
pyscf-forge deletes it. All forge imports of these packages are explicit
submodule imports (pyscf.nac.tduks_sf, pyscf.pbc.lo.mlwf), which keep
working without forge's __init__.py.

Add a step to run_ci.sh that fails when a forge __init__.py has a
counterpart in the installed pyscf, before forge is installed on top of it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@MatthewRHermes MatthewRHermes added the housekeeping Enforcement of code rules, technical maintenance, and similar tedium label Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

housekeeping Enforcement of code rules, technical maintenance, and similar tedium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pyscf/nac/__init__.py and pyscf/pbc/lo/__init__.py shadow PySCF core's __init__.py

1 participant