Skip to content

chore(devcontainer): allow pypi for pre-commit hook bootstrap - #250

Merged
alpergundogdu merged 1 commit into
mainfrom
chore/devcontainer-allow-pypi-for-pre-commit
Apr 15, 2026
Merged

alpergundogdu merged 1 commit into
mainfrom
chore/devcontainer-allow-pypi-for-pre-commit

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Summary

Add pypi.org and files.pythonhosted.org to the devcontainer firewall's CRITICAL_DOMAINS so pre-commit can install the Python hook envs it needs on first run.

Why

The .pre-commit-config.yaml includes the upstream pre-commit/pre-commit-hooks repo (Python). pre-commit clones that repo (github.com — already allowed) and then runs pip install . inside the clone to build the hook environment. pip needs two sets of packages from PyPI:

  1. PEP 517 build toolchain — setuptools>=40.8.0, which pip fetches into an isolated build env before compiling the wheel.
  2. Runtime deps declared in the hook's setup.cfg — ruamel.yaml>=0.15, tomli>=1.1.0 for Python < 3.11.

Both come from pypi.org and files.pythonhosted.org. Neither host was in the allowlist, so the very first pre-commit run aborted with:

ERROR: Could not find a version that satisfies the requirement setuptools>=40.8.0
ERROR: No matching distribution found for setuptools>=40.8.0

…and every subsequent commit failed the same way. The local cargo hooks (cargo fmt, cargo clippy, cargo deny) were unaffected because they don't need any bootstrap.

markdownlint-cli is Node-based and already works via registry.npmjs.org (allowlisted), but pre-commit processes hooks sequentially and aborted on the first Python failure before reaching it.

Why CRITICAL and not OPTIONAL

Matches crates.io and registry.npmjs.org: package-index unavailability should fail loudly at container boot rather than silently break every commit later.

Rollout

Takes effect on the next devcontainer rebuild. Running containers keep using the image-baked copy at /usr/local/bin/init-firewall.sh (Dockerfile line 100). No runtime migration path.

Test plan

  • Rebuild devcontainer
  • pre-commit run --all-files completes without the setuptools error
  • Subsequent git commit in the container passes hooks without --no-verify

🤖 Generated with Claude Code

Add pypi.org and files.pythonhosted.org to the firewall's
CRITICAL_DOMAINS so pre-commit can install the Python hook envs it
needs on first run. Without this, `pip install .` inside the cached
`pre-commit-hooks` clone fails trying to fetch PEP 517 build deps
(`setuptools>=40.8.0`) plus the hook's declared runtime deps
(`ruamel.yaml`, `tomli`), and the `pre-commit-hooks` environment never
initializes — blocking every commit that would otherwise pass the
local cargo hooks.

Classifying as CRITICAL (abort-on-DNS-failure) matches `crates.io` and
`registry.npmjs.org`: package-index unavailability should fail loudly
at container boot, not silently break commits later.

Takes effect on next devcontainer rebuild (the running container uses
the image-baked copy at /usr/local/bin/init-firewall.sh).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds pypi.org and files.pythonhosted.org to the CRITICAL_DOMAINS list in the firewall initialization script to allow pre-commit to bootstrap Python environments. A review comment suggests updating the script's verification loop to include reachability checks for these new domains, ensuring the firewall configuration is correctly applied.

Comment on lines +31 to +32
"pypi.org"
"files.pythonhosted.org"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When adding new domains to CRITICAL_DOMAINS, it is recommended to also update the verification loop at the end of the script (lines 236-244) to include a reachability check for these services. This ensures that the firewall rules are correctly applied and that the package indices are actually accessible before the initialization script completes. For example, you could add a PyPI metadata URL like https://pypi.org/pypi/pip/json to the verify_url list.

@alpergundogdu
alpergundogdu merged commit 6572ad5 into main Apr 15, 2026
22 of 28 checks passed
@alpergundogdu
alpergundogdu deleted the chore/devcontainer-allow-pypi-for-pre-commit branch April 15, 2026 12:16
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