interplane.Get Omega
Read in your language

atlas

aien-dev/atlas

Brought by drakestapleton

branch master Branches Tags History

atlas / scripts / check-no-python.sh

32 lines · 1700 bytes Raw Blame History
1#!/bin/sh
2# No-Python guard (Drake's rule, 2026-10-15: no Python anywhere in AIEN).
3# Fails when git tracks any Python source, notebook, Python packaging or
4# environment file, or any file whose first line is a python shebang.
5# POSIX sh, git, grep and head only.
6# Usage: sh scripts/check-no-python.sh (from anywhere inside the repository)
7set -eu
8cd "$(git rev-parse --show-toplevel)"
9
10# File names are matched case-insensitively (Foo.PY counts).
11names='(^|/)(setup\.py|setup\.cfg|pyproject\.toml|pipfile|pipfile\.lock|poetry\.lock|uv\.lock|\.python-version|requirements[^/]*\.txt|requirements[^/]*\.in)$|\.(py|pyi|pyw|pyx|pyc|ipynb)$'
12# Tracked paths that match the name rule but are not Python (one ERE, empty for none).
13exempt=''
14
15# -z keeps non-ASCII names unquoted so the patterns see the real name.
16found=$(git ls-files -z | tr '\0' '\n' | grep -i -E "$names" || true)
17if [ -n "$exempt" ] && [ -n "$found" ]; then
18 found=$(printf '%s\n' "$found" | grep -v -E "$exempt" || true)
19fi
20# Candidates contain a python shebang line anywhere; keep those where it is line 1.
21shebang=$(git grep -I -l -z -i -E '^#!.*python' -- . 2>/dev/null | tr '\0' '\n' |
22 while IFS= read -r f; do
23 if head -n 1 -- "$f" | grep -q -i -E '^#!.*python'; then printf '%s\n' "$f"; fi
24 done || true)
25
26if [ -n "$found" ] || [ -n "$shebang" ]; then
27 echo "no-python guard: FAIL. Python is not allowed in this repository. Offending tracked files:" >&2
28 [ -n "$found" ] && printf '%s\n' "$found" | sed 's/^/ /' >&2
29 [ -n "$shebang" ] && printf '%s\n' "$shebang" | sed 's/$/ (python shebang)/; s/^/ /' >&2
30 exit 1
31fi
32echo "no-python guard: PASS ($(git ls-files | wc -l | tr -d ' ') tracked files, none is Python)"