Skip to content

Use importlib.util to locate fork specs, dropping pkg_resources#11

Merged
lucasccordeiro merged 2 commits into
masterfrom
fix/pkg-resources-removed-setuptools81
Jun 30, 2026
Merged

Use importlib.util to locate fork specs, dropping pkg_resources#11
lucasccordeiro merged 2 commits into
masterfrom
fix/pkg-resources-removed-setuptools81

Conversation

@lucasccordeiro

Copy link
Copy Markdown
Contributor

Problem

ethcheck crashes at startup on environments with setuptools >= 81:

ModuleNotFoundError: No module named 'pkg_resources'
  File ".../ethcheck/ethcheck.py", line 15, in <module>
    import pkg_resources

pkg_resources was deprecated and is no longer bundled with setuptools
(removed in 81+). ethcheck.py imported it at module load and used
pkg_resources.resource_filename in get_file_path, so every entry point
(--help, --list-forks, --fork, ...) failed immediately.

Fix

Replace pkg_resources.resource_filename with the stdlib
importlib.util.find_spec (Python 3.9+). It resolves the fork's spec source
path from the package directory without importing the fork body, which
also decouples the core verification path from eth2spec's heavy runtime
dependencies.

spec = importlib.util.find_spec(module_name)
pkg_dir = spec.submodule_search_locations[0]
resource_path = os.path.join(pkg_dir, 'mainnet.py')  # falls back to spec.py

Verification

  • ethcheck --help and --list-forks run (6 forks listed).
  • get_file_path resolves the correct mainnet.py for all 6 forks
    (phase0, altair, bellatrix, capella, deneb, electra).
  • Existing test suite: 9 passed.
  • No new lint findings on the changed lines.

🤖 Generated with Claude Code

@lucasccordeiro lucasccordeiro added the bug Something isn't working label Jun 30, 2026
setuptools >= 81 no longer ships pkg_resources, so importing ethcheck
crashed at startup with ModuleNotFoundError. Replace the removed
pkg_resources.resource_filename in get_file_path with
importlib.util.find_spec, which resolves the fork's spec source path
without importing the fork body (also decoupling the verification path
from eth2spec's heavy runtime dependencies).
The stubbed ESBMC never wrote testcase.xml, but verify_function deletes
any stale one on entry, so the pytest-confirmation branch was never
reached -- the two failing tests saw a printed counterexample instead.
Model --generate-testcase in the stub, and assert the confirmed-bug case
returns 'failed' (the exit code 3 is exit_code_for's job, not an
in-function sys.exit), which also makes the ValueError test exercise its
branch.
@lucasccordeiro lucasccordeiro force-pushed the fix/pkg-resources-removed-setuptools81 branch from 4b5ebde to 1faafc2 Compare June 30, 2026 15:55
@lucasccordeiro lucasccordeiro merged commit c489259 into master Jun 30, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant