Skip to content

Accept Python interpreters selected by nix-shell (EXE003) - #95

Open
LisaScheers wants to merge 2 commits into
xuhdev:masterfrom
LisaScheers:fix/nix-shell-python-shebang
Open

LisaScheers wants to merge 2 commits into
xuhdev:masterfrom
LisaScheers:fix/nix-shell-python-shebang

Conversation

@LisaScheers

Copy link
Copy Markdown

Summary

Python scripts launched through nix-shell currently trigger EXE003 even when a subsequent #! nix-shell -i python3 directive selects Python. This is documented usage in the Nix reference manual:

#!/usr/bin/env nix-shell
#! nix-shell -i python3
#! nix-shell --packages python3
print("Hello world")

Recognize the Python interpreter selected by these directives when the initial shebang invokes nix-shell, either directly or through env. Options can span multiple directive lines and include quoted arguments. A Python package alone does not qualify, and the last -i determines the interpreter. Missing, malformed, or non-Python interpreter options retain EXE003; executable permission and shebang placement checks remain active.

For context, Linux execve(2) describes the first-line interpreter directive and explicitly notes that POSIX does not specify shebang behavior. Python's lexical specification permits the subsequent lines as comments, which Nix reads as options. EXE005 already ignores those subsequent lines upstream; this fixes the separate EXE003 rejection.

Test plan

  • Confirmed the new positive cases fail against the original implementation.
  • Full test suite: 47 passed, 2 skipped (Windows-only tests skipped on macOS), using Python 3.11 in a temporary nix-shell environment.
  • Flake8 passes for both changed Python files.
  • Regression coverage includes multiple option lines, quoted expressions, direct and env invocation, non-Python/missing/malformed interpreters, lookalike commands, misplaced shebangs, and executable permissions.

Assisted by an LLM using GPT-6 in Codex.

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