chore(dev): move the dev tools from .venv to .venv-dev #519

Merged
Defame1297 merged 1 commits from chore/516-venv-dev into main 2026-12-04 21:16:59 +00:00
12 changed files with 51 additions and 23 deletions

No files matched your search

+1
View File
@@ -6,6 +6,7 @@ profile: production
exclude_paths:
- .gitea
- .venv
- .venv-dev
- apm_modules
- apm.lock.yaml
- changelogs
+3 -3
View File
@@ -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"
+1
View File
@@ -1,6 +1,7 @@
# Built collection archives and local tooling
*.tar.gz
/.venv/
/.venv-dev/
/venv/
__pycache__/
*.pyc
+1
View File
@@ -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
+1 -1
View File
@@ -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`.
+1
View File
@@ -46,6 +46,7 @@ build_ignore:
- .python-version
- .ruff_cache
- .venv
- .venv-dev
- .yamllint
- docs
- .ansible-lint
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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.
+9 -9
View File
@@ -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."
+1 -1
View File
@@ -11,7 +11,7 @@
# Needs the network (PyPI) and the Python of .python-version (python<MINOR>; 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
+1 -1
View File
@@ -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"
+30 -6
View File
@@ -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)