File size: 7,864 Bytes
d086025 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | #!/bin/bash
# programgen forward pre-cleanup: closed-book repo
# (keep build config + provisioned deps; strip target-repo source/tests).
set -euo pipefail
ROOT="${1:-/workspace/repo}"
cd "$ROOT"
# 0. Remove the target distribution installed while provisioning deps. Both
# editable and wheel installs can otherwise copy the answer into site-packages.
TARGET_DIST=dy-sql
for PROGRAMGEN_UNINSTALL_ATTEMPT in 1 2 3; do
python3 - "$ROOT" "$TARGET_DIST" <<'PY' > /tmp/programgen-target-dists.txt
import importlib.metadata
import json
import re
import sys
from pathlib import Path
from urllib.parse import unquote, urlparse
root = Path(sys.argv[1]).resolve()
target = re.sub(r'[-_.]+', '-', sys.argv[2]).lower()
for dist in importlib.metadata.distributions():
name = str(dist.metadata.get('Name') or '').strip()
try:
metadata_root = Path(dist.locate_file('')).resolve()
metadata_is_local = metadata_root == root or root in metadata_root.parents
except Exception:
metadata_is_local = False
try:
direct = json.loads(dist.read_text('direct_url.json') or '{}')
url = str(direct.get('url') or '')
source = Path(unquote(urlparse(url).path)).resolve() if url.startswith('file:') else None
except Exception:
source = None
normalized = re.sub(r'[-_.]+', '-', name).lower()
if name and not metadata_is_local and (source == root or (target and normalized == target)):
print(name)
PY
sort -fu /tmp/programgen-target-dists.txt -o /tmp/programgen-target-dists.txt
if [ ! -s /tmp/programgen-target-dists.txt ]; then break; fi
xargs -r python3 -m pip uninstall -y < /tmp/programgen-target-dists.txt
done
# Fail closed if a local-project distribution survived uninstall.
python3 - "$ROOT" "$TARGET_DIST" <<'PY'
import importlib.metadata
import json
import re
import sys
from pathlib import Path
from urllib.parse import unquote, urlparse
root = Path(sys.argv[1]).resolve()
target = re.sub(r'[-_.]+', '-', sys.argv[2]).lower()
leaks = []
for dist in importlib.metadata.distributions():
name = str(dist.metadata.get('Name') or '').strip()
try:
metadata_root = Path(dist.locate_file('')).resolve()
metadata_is_local = metadata_root == root or root in metadata_root.parents
except Exception:
metadata_is_local = False
try:
direct = json.loads(dist.read_text('direct_url.json') or '{}')
url = str(direct.get('url') or '')
source = Path(unquote(urlparse(url).path)).resolve() if url.startswith('file:') else None
except Exception:
source = None
normalized = re.sub(r'[-_.]+', '-', name).lower()
if not metadata_is_local and (source == root or (target and normalized == target)):
leaks.append(name or str(dist))
if leaks:
raise SystemExit('target distributions remain installed: ' + ', '.join(leaks))
PY
# 1. strip target-repo source + test files (build config kept)
find . -type f \( -name '*.c' -o -name '*.c++' -o -name '*.cc' -o -name '*.cjs' -o -name '*.cpp' -o -name '*.cts' -o -name '*.cu' -o -name '*.cuh' -o -name '*.cxx' -o -name '*.go' -o -name '*.h' -o -name '*.h++' -o -name '*.hh' -o -name '*.hpp' -o -name '*.hxx' -o -name '*.inl' -o -name '*.ipp' -o -name '*.java' -o -name '*.js' -o -name '*.jsx' -o -name '*.kt' -o -name '*.kts' -o -name '*.mjs' -o -name '*.mts' -o -name '*.pxd' -o -name '*.pxi' -o -name '*.py' -o -name '*.pyi' -o -name '*.pyx' -o -name '*.rs' -o -name '*.tpp' -o -name '*.ts' -o -name '*.tsx' \) -not -path './setup.py' -not -path './vendor/*' -not -path './node_modules/*' -delete || true
rm -rf -- dysql/test/__init__.py dysql/test/conftest.py dysql/test/test_annotations.py dysql/test/test_database_initialization.py dysql/test/test_mappers.py dysql/test/test_mariadbmap_tojson.py dysql/test/test_pydantic_mappers.py dysql/test/test_sql_decorator.py dysql/test/test_sql_exists_decorator.py dysql/test/test_sql_in_list_templates.py dysql/test/test_sql_insert_templates.py dysql/test/test_template_generators.py dysql/test/test_test_managers.py dysql/test_managers.py 2>/dev/null || true
rm -rf tests test spec specs __tests__ 2>/dev/null || true
# 2. strip build caches + editor/CI metadata (deps in ~/.cargo etc. kept)
rm -rf target build dist .programgen-build .pytest_cache __pycache__ *.egg-info .github .idea 2>/dev/null || true
# 2a. programgen closed-book artifact sweep v2: provisioning leftovers reproduce the stripped
# implementation (bytecode, in-place compiled extensions) or its layout
# (egg-info/dist-info); remove them everywhere except vendored deps.
find . \( -path './vendor' -o -path './node_modules' \) -prune -o -type d \( -name '__pycache__' -o -name '*.egg-info' -o -name '*.dist-info' -o -name '.eggs' -o -name '.pytest_cache' -o -name '.mypy_cache' -o -name '.ruff_cache' -o -name '.hypothesis' -o -name '.tox' -o -name '.nox' -o -name 'htmlcov' \) -print0 2>/dev/null | xargs -0 -r rm -rf || true
find . \( -path './vendor' -o -path './node_modules' \) -prune -o -type d \( -name .venv -o -name venv \) -exec test -f '{}/pyvenv.cfg' \; -print0 2>/dev/null | xargs -0 -r rm -rf || true
find . \( -path './vendor' -o -path './node_modules' \) -prune -o -type d \( -path '*/build/lib.*' -o -path '*/build/temp.*' -o -path '*/build/bdist.*' -o -path '*/build/lib' \) -print0 2>/dev/null | xargs -0 -r rm -rf || true
find . \( -path './vendor' -o -path './node_modules' \) -prune -o -type f \( -name '*.pyc' -o -name '*.pyo' -o -name '*.pyd' -o -name '*.cpython-*.so' -o -name '*.abi3.so' -o -name '*.cpython-*.dylib' -o -name '*.whl' -o -name '*.egg' -o -name '*.orig' -o -name '*.rej' -o -name '.coverage' -o -name '.coverage.*' \) -print0 2>/dev/null | xargs -0 -r rm -f || true
# 2b. strip editable-install residue that leaks the target package name/layout
# (`pip/pdm install -e .`): repo-local .pdm-build/*.egg-*, and the editable
# .pth pointers in site-packages that resolve back to this repo. Third-party
# dependency packages have their own dist-info and are untouched.
rm -rf .pdm-build .pdm-python *.egg-link 2>/dev/null || true
for SP in $(python3 -c "import site,sys;print(\"\\n\".join(set(site.getsitepackages()+[site.getusersitepackages()])))" 2>/dev/null); do
[ -d "$SP" ] || continue
find "$SP" -maxdepth 1 -name "__editable__*.pth" -delete 2>/dev/null || true
grep -rl "$ROOT" "$SP"/*.pth 2>/dev/null | xargs -r rm -f || true
done
# 2c. strip docs/examples + leftover EMPTY dirs (align with DeNovoSWE clean.sh):
# docs/*.rst can leak API usage; an empty package dir leaks the package
# name+layout. Build config (setup.py / pyproject / lockfiles / LICENSE)
# is kept; provisioned deps live outside $ROOT and are untouched.
find . -type f \( -name '*.md' -o -name '*.rst' \) -delete 2>/dev/null || true
find . -type d \( -name docs -o -name doc -o -name examples -o -name example \) -not -path './vendor/*' -not -path './node_modules/*' -exec rm -rf {} + 2>/dev/null || true
find . -type d -empty -delete 2>/dev/null || true
# 2z. programgen closed-book artifact check v2: fail closed before the baseline commit
PROGRAMGEN_LEFTOVERS=$(find . \( -path './vendor' -o -path './node_modules' \) -prune -o \( -type d \( -name '__pycache__' -o -name '*.egg-info' -o -name '*.dist-info' \) -o -type f \( -name '*.pyc' -o -name '*.pyo' -o -name '*.pyd' -o -name '*.cpython-*.so' -o -name '*.abi3.so' -o -name '*.whl' -o -name '*.egg' \) \) -print 2>/dev/null | head -20 || true)
if [ -n "$PROGRAMGEN_LEFTOVERS" ]; then
echo "programgen closed-book leftovers remain under $ROOT:" >&2
echo "$PROGRAMGEN_LEFTOVERS" >&2
exit 1
fi
# 3. git history sanitization (fresh repo, no history to mine)
rm -rf .git
git init -q
git config user.email closed-book@programgen.local
git config user.name programgen
git add -f -A
git commit --allow-empty -qm 'programgen forward closed-book baseline'
|