interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / .github / scripts / check-no-python.sh

49 lines · 2570 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0
3# Copyright 2026 Drake Stapleton (AIEN / aien-dev)
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# No-Python guard (Drake's rule, 2026-10-15: no Python anywhere in AIEN).
18# Fails when git tracks any Python source, notebook, Python packaging or
19# environment file, or any file whose first line is a python shebang.
20# POSIX sh, git, grep and head only.
21# Usage: sh .github/scripts/check-no-python.sh (from anywhere inside the repository)
22set -eu
23top=$(git rev-parse --show-toplevel) || { echo "no-python guard: FAIL. Not inside a git repository." >&2; exit 2; }
24cd "$top"
25[ -n "$(git ls-files | head -n 1)" ] || { echo "no-python guard: FAIL. No tracked files; refusing to pass an empty check." >&2; exit 2; }
26
27# File names are matched case-insensitively (Foo.PY counts).
28names='(^|/)(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)$'
29# Tracked paths that match the name rule but are not Python (one ERE, empty for none).
30exempt=''
31
32# -z keeps non-ASCII names unquoted so the patterns see the real name.
33found=$(git ls-files -z | tr '\0' '\n' | grep -i -E "$names" || true)
34if [ -n "$exempt" ] && [ -n "$found" ]; then
35 found=$(printf '%s\n' "$found" | grep -v -E "$exempt" || true)
36fi
37# Candidates contain a python shebang line anywhere; keep those where it is line 1.
38shebang=$(git grep -I -l -z -i -E '^#!.*python' -- . 2>/dev/null | tr '\0' '\n' |
39 while IFS= read -r f; do
40 if head -n 1 -- "$f" | grep -q -i -E '^#!.*python'; then printf '%s\n' "$f"; fi
41 done || true)
42
43if [ -n "$found" ] || [ -n "$shebang" ]; then
44 echo "no-python guard: FAIL. Python is not allowed in this repository. Offending tracked files:" >&2
45 [ -n "$found" ] && printf '%s\n' "$found" | sed 's/^/ /' >&2
46 [ -n "$shebang" ] && printf '%s\n' "$shebang" | sed 's/$/ (python shebang)/; s/^/ /' >&2
47 exit 1
48fi
49echo "no-python guard: PASS ($(git ls-files | wc -l | tr -d ' ') tracked files, none is Python)"