From f62097a7484ab906d3d70c15cc8d1a02384109bf Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Fri, 4 Dec 2026 20:45:49 +0000 Subject: [PATCH] chore(dev): move the dev tools from .venv to .venv-dev uv uses .venv as its project environment, and `uv sync --frozen` removes every package that is not in uv.lock. The tools the git hooks need would go with it, so they get a directory of their own. Re-running scripts/dev-setup.sh switches the hooks of an older clone and leaves its .venv alone. Ignore rules and prunes cover both directories. Refs: #516 Assisted-by: Claude Code --- .ansible-lint | 1 + .gitea/workflows/build.yml | 6 ++--- .gitignore | 1 + .yamllint | 1 + docs/contributing/setup.md | 2 +- galaxy.yml | 1 + scripts/ansible-test-sanity.sh | 2 +- scripts/check_tarball.py | 2 +- scripts/dev-setup.sh | 18 +++++++-------- scripts/lock-requirements.sh | 2 +- tests/scripts/test_check_tarball.py | 2 +- tests/scripts/test_dev_setup.py | 36 ++++++++++++++++++++++++----- 12 files changed, 51 insertions(+), 23 deletions(-) diff --git a/.ansible-lint b/.ansible-lint index 1bae4dc..9774b7d 100644 --- a/.ansible-lint +++ b/.ansible-lint @@ -6,6 +6,7 @@ profile: production exclude_paths: - .gitea - .venv + - .venv-dev - apm_modules - apm.lock.yaml - changelogs diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 06ea15f..4ead791 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -94,13 +94,13 @@ jobs: # ansible-galaxy dereferences symlinks when it builds, so a symlink in the source tree # reaches the archive as a regular file with the target's content, where # scripts/check_tarball.py cannot see it. Refuse them in the tree instead: this step - # is the only guard against a file symlink. The two -prune paths below (./.venv, - # ./.git) are skipped only because the build skips them too (galaxy.yml build_ignore, + # is the only guard against a file symlink. The -prune paths below (./.git, ./.venv, + # ./.venv-dev) are skipped only because the build skips them too (galaxy.yml build_ignore, # and ansible-galaxy's own .git exclusion): the two lists must stay in step, and # tests/scripts/test_check_tarball.py fails when a pruned directory is not ignored. - name: Refuse symlinks in the source tree run: | - links="$(find . -path ./.git -prune -o -path ./.venv -prune -o -type l -print)" + links="$(find . -path ./.git -prune -o -path ./.venv -prune -o -path ./.venv-dev -prune -o -type l -print)" if [ -n "$links" ]; then echo "::error::symlinks in the source tree would be dereferenced into the Collection archive:" echo "$links" diff --git a/.gitignore b/.gitignore index 5816f21..8cee017 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Built collection archives and local tooling *.tar.gz /.venv/ +/.venv-dev/ /venv/ __pycache__/ *.pyc diff --git a/.yamllint b/.yamllint index 78da8c6..09e9046 100644 --- a/.yamllint +++ b/.yamllint @@ -3,6 +3,7 @@ extends: default ignore: | .venv/** + .venv-dev/** apm_modules/** # Generated by apm install; its list indentation fails the rules below. apm.lock.yaml diff --git a/docs/contributing/setup.md b/docs/contributing/setup.md index 7f023ac..588ad75 100644 --- a/docs/contributing/setup.md +++ b/docs/contributing/setup.md @@ -9,7 +9,7 @@ held by review until an offline link check exists. ## The clone - **Run `scripts/dev-setup.sh` once per clone, and again after a change to `requirements-dev.txt`, its - lock `requirements-dev.lock`, `requirements.yml` or the hook types.** It creates `.venv` with the + lock `requirements-dev.lock`, `requirements.yml` or the hook types.** It creates `.venv-dev` with the pinned tools on the Python named in `.python-version`, installs the collections of `requirements.yml` into `.ansible/collections`, and installs the git hooks (pre-commit, commit-msg, pre-push) with the virtualenv first on their `PATH`. diff --git a/galaxy.yml b/galaxy.yml index 839a517..dd52f58 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -46,6 +46,7 @@ build_ignore: - .python-version - .ruff_cache - .venv + - .venv-dev - .yamllint - docs - .ansible-lint diff --git a/scripts/ansible-test-sanity.sh b/scripts/ansible-test-sanity.sh index d3bc0b1..00af089 100755 --- a/scripts/ansible-test-sanity.sh +++ b/scripts/ansible-test-sanity.sh @@ -19,7 +19,7 @@ cd "$root" for tool in ansible ansible-test; do if ! command -v "$tool" >/dev/null 2>&1; then - echo "error: $tool is not on PATH; run scripts/dev-setup.sh and use its virtualenv (.venv/bin)" >&2 + echo "error: $tool is not on PATH; run scripts/dev-setup.sh and use its virtualenv (.venv-dev/bin)" >&2 exit 1 fi done diff --git a/scripts/check_tarball.py b/scripts/check_tarball.py index a5a7686..6a25cd6 100644 --- a/scripts/check_tarball.py +++ b/scripts/check_tarball.py @@ -27,7 +27,7 @@ allow list. It fails the build for: ansible-galaxy dereferences FILE symlinks while building, so a symlink to a file reaches the archive as a regular file with the target's content and this check cannot see it. The `Refuse symlinks in the source tree` step of .gitea/workflows/build.yml is the only guard -against that. Its `find` prunes ./.venv and ./.git only because both are in galaxy.yml +against that. Its `find` prunes ./.git, ./.venv and ./.venv-dev only because they are in galaxy.yml `build_ignore` (or excluded by ansible-galaxy itself, as .git is): the two lists must stay in step, and tests/scripts/test_check_tarball.py fails when a pruned directory is not ignored by the build. diff --git a/scripts/dev-setup.sh b/scripts/dev-setup.sh index a59cede..923230c 100755 --- a/scripts/dev-setup.sh +++ b/scripts/dev-setup.sh @@ -26,7 +26,7 @@ set -euo pipefail # The repository is derived from this script's own location (symlinks resolved), never # from the caller's working directory: running it from another repository must not -# create or remove that repository's .venv. +# create or remove that repository's .venv-dev. script="$(readlink -f "${BASH_SOURCE[0]}")" root="$(git -C "$(dirname "$script")/.." rev-parse --show-toplevel)" cd "$root" @@ -122,19 +122,19 @@ if still="$(git -C "$root" config --get core.hooksPath)" && [ -n "$still" ]; the fi # A virtualenv made by an older Python is rebuilt rather than reused. -if [ -x .venv/bin/python ] && ! .venv/bin/python -c "$py_ok" 2>/dev/null; then - rm -rf "$root/.venv" +if [ -x .venv-dev/bin/python ] && ! .venv-dev/bin/python -c "$py_ok" 2>/dev/null; then + rm -rf "$root/.venv-dev" fi -[ -x .venv/bin/python ] || "$python" -m venv .venv -.venv/bin/pip install --quiet --disable-pip-version-check --require-hashes -r requirements-dev.lock -r requirements-dev.txt -.venv/bin/pre-commit install --install-hooks +[ -x .venv-dev/bin/python ] || "$python" -m venv .venv-dev +.venv-dev/bin/pip install --quiet --disable-pip-version-check --require-hashes -r requirements-dev.lock -r requirements-dev.txt +.venv-dev/bin/pre-commit install --install-hooks # The collections of requirements.yml, exactly as pinned, into this clone (.ansible/ is ignored by # git and by the Collection build). ANSIBLE_COLLECTIONS_PATH is set to the target for the install: # a copy found elsewhere (~/.ansible/collections) would be skipped as already installed. collections="$root/.ansible/collections" mkdir -p "$collections" -ANSIBLE_COLLECTIONS_PATH="$collections" .venv/bin/ansible-galaxy collection install \ +ANSIBLE_COLLECTIONS_PATH="$collections" .venv-dev/bin/ansible-galaxy collection install \ -r requirements.yml -p "$collections" marker="# kamino-dev-setup: virtualenv first on PATH" @@ -150,7 +150,7 @@ for hook in pre-commit commit-msg pre-push; do { head -n 1 "$file" # %q shell-quotes the path: a repository path with spaces, quotes or $(...) is data. - printf '%s\n' "$marker" "export PATH=$(printf '%q' "$root/.venv/bin"):\"\$PATH\"" + printf '%s\n' "$marker" "export PATH=$(printf '%q' "$root/.venv-dev/bin"):\"\$PATH\"" tail -n +2 "$file" } > "$tmp" cat "$tmp" > "$file" # keeps the file mode of the hook @@ -179,4 +179,4 @@ else fi fi -echo "Done: git commit now runs the hooks with the tools in $root/.venv/bin and the collections in $collections." +echo "Done: git commit now runs the hooks with the tools in $root/.venv-dev/bin and the collections in $collections." diff --git a/scripts/lock-requirements.sh b/scripts/lock-requirements.sh index 8f702f8..fdad25a 100755 --- a/scripts/lock-requirements.sh +++ b/scripts/lock-requirements.sh @@ -11,7 +11,7 @@ # Needs the network (PyPI) and the Python of .python-version (python; KAMINO_PYTHON overrides it): the # header of the lock records it, and check_image_versions.py pins fails when it differs. # pip and pip-tools are installed, at the pinned versions below, into a throwaway virtualenv, never -# into the project's .venv. pip is pinned too: pip-tools breaks on newer pip releases (7.5.2 on pip 26). Commit +# into the project's .venv-dev. pip is pinned too: pip-tools breaks on newer pip releases (7.5.2 on pip 26). Commit # the lock with its requirements file; pip refuses an install of the two when they disagree # (`pip install --require-hashes -r requirements-dev.lock -r requirements-dev.txt`). # The pins are not hash-checked themselves: they come from PyPI over TLS, like the pip that diff --git a/tests/scripts/test_check_tarball.py b/tests/scripts/test_check_tarball.py index 1486a05..1120f4b 100644 --- a/tests/scripts/test_check_tarball.py +++ b/tests/scripts/test_check_tarball.py @@ -267,7 +267,7 @@ class CraftedTarballTest(unittest.TestCase): REPO, src, ignore=shutil.ignore_patterns( - ".git", ".venv", "__pycache__", "output", "*.tar.gz" + ".git", ".venv", ".venv-dev", "__pycache__", "output", "*.tar.gz" ), ) out = pathlib.Path(self.tmp.name) / "dist" diff --git a/tests/scripts/test_dev_setup.py b/tests/scripts/test_dev_setup.py index ec22fb2..7827a01 100644 --- a/tests/scripts/test_dev_setup.py +++ b/tests/scripts/test_dev_setup.py @@ -192,7 +192,7 @@ class DevSetupTest(unittest.TestCase): proc = self.run_setup(repo, KAMINO_PYTHON=str(wrong)) self.assertNotEqual(proc.returncode, 0) self.assertIn("is not Python 3.13 (.python-version)", proc.stderr) - self.assertFalse((repo / ".venv").exists()) + self.assertFalse((repo / ".venv-dev").exists()) def test_an_interpreter_of_another_minor_is_refused_and_the_pinned_one_accepted( self, @@ -201,10 +201,10 @@ class DevSetupTest(unittest.TestCase): proc = self.run_setup(repo, STUB_PY_MINOR="3.12") self.assertNotEqual(proc.returncode, 0) self.assertIn("is not Python 3.13 (.python-version)", proc.stderr) - self.assertFalse((repo / ".venv").exists()) + self.assertFalse((repo / ".venv-dev").exists()) proc = self.run_setup(repo, STUB_PY_MINOR="3.13") self.assertEqual(proc.returncode, 0, proc.stderr) - self.assertTrue((repo / ".venv").is_dir()) + self.assertTrue((repo / ".venv-dev").is_dir()) def test_a_missing_pin_file_is_refused_with_a_message(self) -> None: repo = self.make_repo() @@ -228,6 +228,30 @@ class DevSetupTest(unittest.TestCase): text = self.hook(repo, name).read_text() self.assertIn("# kamino-dev-setup: virtualenv first on PATH", text) self.assertEqual(self.hooks_z(repo), b"") + self.assertFalse((repo / ".venv").exists()) + + def test_a_rerun_moves_the_hooks_of_an_older_setup_to_venv_dev(self) -> None: + repo = self.make_repo() + kept = repo / ".venv" / "kept" + kept.parent.mkdir() + kept.write_text("") + names = ("pre-commit", "commit-msg", "pre-push") + for name in names: + hook = self.hook(repo, name) + hook.parent.mkdir(exist_ok=True) + hook.write_text( + "#!/usr/bin/env bash\n" + "# kamino-dev-setup: virtualenv first on PATH\n" + f'export PATH={repo}/.venv/bin:"$PATH"\n' + ) + hook.chmod(0o755) + result = self.run_setup(repo) + self.assertEqual(result.returncode, 0, result.stderr) + for name in names: + text = self.hook(repo, name).read_text() + self.assertIn(f'export PATH={repo}/.venv-dev/bin:"$PATH"\n', text) + self.assertNotIn("/.venv/bin", text) + self.assertTrue(kept.exists()) def test_a_missing_tea_warns_and_setup_succeeds(self) -> None: repo = self.make_repo() @@ -403,12 +427,12 @@ class DevSetupTest(unittest.TestCase): self.git(other, "init", "--quiet") result = self.run_setup(repo, cwd=other) self.assertEqual(result.returncode, 0, result.stderr) - self.assertFalse((other / ".venv").exists()) + self.assertFalse((other / ".venv-dev").exists()) self.assertEqual( os.listdir(other / ".git" / "hooks"), [n for n in os.listdir(other / ".git" / "hooks") if n.endswith(".sample")], ) - self.assertTrue((repo / ".venv").is_dir()) + self.assertTrue((repo / ".venv-dev").is_dir()) self.assertTrue(self.hook(repo).exists()) def test_crafted_repository_path_is_not_executed(self) -> None: @@ -428,7 +452,7 @@ class DevSetupTest(unittest.TestCase): self.assertEqual(hook.returncode, 0, hook.stderr) lines = hook.stdout.splitlines() self.assertEqual(lines[0], "hook-ran") - self.assertTrue(lines[1].startswith(f"{repo}/.venv/bin:"), lines[1]) + self.assertTrue(lines[1].startswith(f"{repo}/.venv-dev/bin:"), lines[1]) for place in (workdir, repo, self.tmp, Path.cwd()): self.assertFalse((place / "PWNED").exists(), place) self.assertFalse((place / "PWNED2").exists(), place) -- 2.43.0