Run flake8 as a module of the running interpreter - #10
Conversation
extract_codeblocks.py shelled out to a bare 'flake8', so it only worked when flake8 happened to be on PATH. Run it as '<sys.executable> -m flake8' instead, which resolves flake8 from whichever interpreter runs the script -- a virtualenv python now works with no PATH setup. --flake8 EXE still overrides, so an explicitly chosen binary is unaffected. CI is unaffected either way: it pip-installs flake8 into the same interpreter it then runs the script with.
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
MiniMax Code ReviewThe user wants me to review a pull request that modifies the file `.github/scripts/extract_codeblocks.py`. Let me analyze the changes:
Let me review this for potential issues: Positive aspects:
Potential issues:
One thing I notice is that this is a relatively minor change that makes the script work better in virtualenv environments. The code looks correct to me. Let me double-check the logic: flake8_cmd = [args.flake8] if args.flake8 else [sys.executable, '-m', 'flake8']This means:
This seems correct. The original code would have just used Code Review SummaryThis change improves the script to work better in virtual environments by invoking Changes Made
Potential IssuesMinor: Empty string handling If a user explicitly passes flake8_cmd = [args.flake8] if args.flake8 else [sys.executable, '-m', 'flake8']Consider using Verdict✅ Approved - The change is clean, well-documented, and solves the intended problem (running flake8 in virtualenvs without PATH setup). The only suggestion would be to clarify whether empty string for |
There was a problem hiding this comment.
🟢 Ready to approve
The change is small, localized, and correct, and it removes a concrete failure mode in virtualenv usage without altering the script’s core behavior.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Pull request overview
This PR hardens the doc code-block linting script by invoking flake8 via the same Python interpreter that is running extract_codeblocks.py (i.e., sys.executable -m flake8) instead of relying on a flake8 binary being present on PATH. This aligns the script with typical virtualenv usage while preserving an explicit override via --flake8.
Changes:
- Switch flake8 invocation from a bare executable name to a command list that defaults to
[sys.executable, '-m', 'flake8']. - Preserve the ability to override flake8 via
--flake8, now treated as an optional explicit executable.
File summaries
| File | Description |
|---|---|
| .github/scripts/extract_codeblocks.py | Builds flake8_cmd and uses it for subprocess.run, avoiding failures when flake8 isn’t on PATH but is installed in the running interpreter’s environment. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
extract_codeblocks.pyinvoked a bareflake8, so the doc-codeblock check only ran where flake8 happened to be onPATH. Running it from a virtualenv python — the normal local case — died withFileNotFoundError: [Errno 2] No such file or directory: 'flake8'before linting a single block.It now runs flake8 as a module of whichever interpreter executes the script (
[sys.executable, '-m', 'flake8']), so a venv python finds its own flake8 with noPATHsetup.--flake8 EXEstill overrides for an explicitly chosen binary.CI behaviour is unchanged:
doc-codeblock-flake8.ymlpip-installs flake8 into the same interpreter it then runs the script with, so both the old and new invocation resolve there.This mirrors the canonical template in nelson2005/config#63; this repo's
SKIP_DIRScustomization is deliberate and untouched.Verified against a seeded fixture pair with flake8 removed from
PATH:FileNotFoundError)docs/dirty.rst:6:1:1: F401--flake8 EXENo module named flake8This repo's own docs pass unchanged.