Skip to content

Make dev pass its own pre-commit again, and stop installing tests/ as a package - #174

Open
cshenry wants to merge 4 commits into
ModelSEED:devfrom
cshenry:fix/packaging-and-shebang-hook
Open

cshenry wants to merge 4 commits into
ModelSEED:devfrom
cshenry:fix/packaging-and-shebang-hook

Conversation

@cshenry

@cshenry cshenry commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

This fixes three small configuration defects on dev. One of them is ours: #173 added a test file without the encoding pragma, and the pre-commit job has been red on dev since 67e8284.

1. Pre-commit on dev: the missing pragma (1ded9c8)
tests/fbapkg/test_package_manager_exports.py (from #173) lacks # -*- coding: utf-8 -*-, so fix-encoding-pragma fails. This is a one-line addition, and every other test module already has the line. Sorry for letting that one through.

2. check-executables-have-shebangs only passes in CI (613aa63)
In .pre-commit-config.yaml, types: [python] on this hook replaces the manifest's types: [text, executable]; it does not narrow it. The hook is therefore handed every .py file. On a normal clone, where core.fileMode is true (the default), pre-commit-hooks v4.3.0 then flags 97 modules as "marked executable but has no shebang". None of them is executable. CI hides this only because pre-commit.yml sets core.filemode false first. Removing the override restores the manifest's filter, and the hook passes under either setting.

3. pip install modelseedpy installs a top-level tests package (4212e95 + 1cb833a, which must land together)
find_packages(exclude=("docs")) passes a string, not a tuple, so nothing is excluded. Every install therefore adds tests and tests.test_data to site-packages. The exclude now names docs and tests together with their subpackages.

That change alone stops test collection. Three test modules import tests.test_data.mock_data absolutely, and under tox (changedir = tests) that name resolved only through the copy installed by mistake. Adding __init__.py to tests/biochem, tests/community, tests/core and tests/fbapkg makes the repo root pytest's basedir for every test module, so the import resolves from the checkout.

Tests. I measured the way tox runs them: a non-editable install, with pytest run from tests/.

tree result
dev 67e8284 96 passed
packaging fix without the __init__.py files 3 collection errors, run interrupted
this branch 96 passed

Pre-commit on this branch: every hook passes, with core.fileMode both true and false.

One side effect is worth knowing about. With the repo root on sys.path, the tests import modelseedpy from the checkout rather than from the installed copy, so pytest's warning count rises from 5 to 39. The extra warnings are existing invalid-escape DeprecationWarnings (for example core/fbahelper.py:101) that surface when the checkout is compiled. None of them is new.

Alternatives, if you'd prefer them:

  • I can split out the pragma fix (item 1) as a standalone one-line PR, so dev goes green before the rest is reviewed.
  • I can move the package to a src/ layout, so the tests run against the installed copy. That is a larger change, which is why I haven't proposed it here.

🤖 Generated with Claude Code

Christopher Henry and others added 4 commits November 24, 2026 23:19
ModelSEED#173 added this file without the `# -*- coding: utf-8 -*-` line that the
`fix-encoding-pragma` hook in .pre-commit-config.yaml requires, so the
pre-commit job has failed on `dev` since 67e8284 (and failed on ModelSEED#173 itself).
Every other test module already carries the pragma.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`types: [python]` on this hook REPLACES the manifest's
`types: [text, executable]` rather than narrowing it, so the executable filter
is dropped and the hook is handed every .py file in the tree.

pre-commit-hooks v4.3.0 then consults file modes only when `git config
core.fileMode` is literally `false`; otherwise its whole check is "does this
file start with #!". On a normal clone (fileMode true, the default) that flags
every module that is not a script. Measured on a fresh worktree of dev 67e8284:

    97 files "marked executable but has no (or invalid) shebang!"

None of them is executable. CI does not see this only because
.github/workflows/pre-commit.yml runs `git config core.filemode false` first,
which routes the hook into its `git ls-files --stage` branch. Run locally, or
as an installed git hook, it fails on every commit.

Dropping the override restores the manifest's filter: only executable text
files are checked. After this change the hook passes with fileMode true and
with fileMode false.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`find_packages(exclude=("docs"))` passes a STRING, not a tuple, so setuptools
iterates its characters and the exclude matches nothing. `pip install
modelseedpy` therefore installs two extra top-level packages into
site-packages,

    tests, tests.test_data

squatting the generic name `tests` in every environment that installs this
library, where it can shadow a consumer's own test package.

The exclude now names docs and tests and their subpackages. No module under
modelseedpy/ imports from `tests`.

This change alone breaks test collection: three test modules import
`tests.test_data.mock_data` absolutely, and until now that only resolved
through the copy in site-packages. The next commit fixes that, and the two
must land together.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…solve

Three test modules import the suite absolutely:

    tests/core/test_msbuilder.py            from tests.test_data.mock_data import ...
    tests/core/test_mseditorapi.py          from tests.test_data.mock_data import ...
    tests/fbapkg/test_revbin_core_model.py  from tests.test_data.mock_data import ...

tox runs pytest with `changedir = tests`, so the repo root is never on
sys.path, and `tests` resolved only through the copy that setup.py was
installing by mistake. With that copy gone (previous commit), collection
stops with three `ModuleNotFoundError: No module named 'tests'`.

pytest's default prepend import mode walks up from each test file while the
directory has an `__init__.py` and inserts the first directory that does not.
tests/ and tests/test_data/ have one; tests/biochem, tests/community,
tests/core and tests/fbapkg did not, so their modules got their own directory
as basedir and no route to `tests`. Adding the four files makes the repo root
the basedir for every test module.

Measured the way tox runs it (non-editable install, pytest from tests/):

    dev 67e8284                     96 passed
    previous commit alone           3 errors during collection, interrupted
    previous commit + this commit   96 passed

One consequence: with the repo root on sys.path, the tests import modelseedpy
from the checkout rather than from the installed copy. That is inherent to a
flat layout; a src/ layout would avoid it but is a larger change. It is also
why the warning count rises from 5 to 39: the extra ones are invalid-escape
DeprecationWarnings (e.g. modelseedpy/core/fbahelper.py:101) raised when the
checkout's modules are compiled, which the precompiled installed copy did not
report. They are not new.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant