Merge pull request 'chore(dev): move the dev tools from .venv to .venv-dev' (#519) from chore/516-venv-dev into main
Reviewed-on: #519 Reviewed-by: Defame1297 <[email protected]>
This commit was merged in pull request #519.
This commit is contained in:
commit
d732ac0a71
12 files changed
+51
-23
No files matched your search
@@ -6,6 +6,7 @@ profile: production
|
|||||||
exclude_paths:
|
exclude_paths:
|
||||||
- .gitea
|
- .gitea
|
||||||
- .venv
|
- .venv
|
||||||
|
- .venv-dev
|
||||||
- apm_modules
|
- apm_modules
|
||||||
- apm.lock.yaml
|
- apm.lock.yaml
|
||||||
- changelogs
|
- changelogs
|
||||||
|
|||||||
@@ -94,13 +94,13 @@ jobs:
|
|||||||
# ansible-galaxy dereferences symlinks when it builds, so a symlink in the source tree
|
# 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
|
# 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
|
# 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,
|
# is the only guard against a file symlink. The -prune paths below (./.git, ./.venv,
|
||||||
# ./.git) are skipped only because the build skips them too (galaxy.yml build_ignore,
|
# ./.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
|
# 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.
|
# tests/scripts/test_check_tarball.py fails when a pruned directory is not ignored.
|
||||||
- name: Refuse symlinks in the source tree
|
- name: Refuse symlinks in the source tree
|
||||||
run: |
|
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
|
if [ -n "$links" ]; then
|
||||||
echo "::error::symlinks in the source tree would be dereferenced into the Collection archive:"
|
echo "::error::symlinks in the source tree would be dereferenced into the Collection archive:"
|
||||||
echo "$links"
|
echo "$links"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# Built collection archives and local tooling
|
# Built collection archives and local tooling
|
||||||
*.tar.gz
|
*.tar.gz
|
||||||
/.venv/
|
/.venv/
|
||||||
|
/.venv-dev/
|
||||||
/venv/
|
/venv/
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.pyc
|
*.pyc
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ extends: default
|
|||||||
|
|
||||||
ignore: |
|
ignore: |
|
||||||
.venv/**
|
.venv/**
|
||||||
|
.venv-dev/**
|
||||||
apm_modules/**
|
apm_modules/**
|
||||||
# Generated by apm install; its list indentation fails the rules below.
|
# Generated by apm install; its list indentation fails the rules below.
|
||||||
apm.lock.yaml
|
apm.lock.yaml
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ held by review until an offline link check exists.
|
|||||||
## The clone
|
## The clone
|
||||||
|
|
||||||
- **Run `scripts/dev-setup.sh` once per clone, and again after a change to `requirements-dev.txt`, its
|
- **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`
|
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
|
into `.ansible/collections`, and installs the git hooks (pre-commit, commit-msg, pre-push) with the
|
||||||
virtualenv first on their `PATH`.
|
virtualenv first on their `PATH`.
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ build_ignore:
|
|||||||
- .python-version
|
- .python-version
|
||||||
- .ruff_cache
|
- .ruff_cache
|
||||||
- .venv
|
- .venv
|
||||||
|
- .venv-dev
|
||||||
- .yamllint
|
- .yamllint
|
||||||
- docs
|
- docs
|
||||||
- .ansible-lint
|
- .ansible-lint
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ cd "$root"
|
|||||||
|
|
||||||
for tool in ansible ansible-test; do
|
for tool in ansible ansible-test; do
|
||||||
if ! command -v "$tool" >/dev/null 2>&1; then
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -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
|
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
|
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
|
`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
|
`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
|
in step, and tests/scripts/test_check_tarball.py fails when a pruned directory is not
|
||||||
ignored by the build.
|
ignored by the build.
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ set -euo pipefail
|
|||||||
|
|
||||||
# The repository is derived from this script's own location (symlinks resolved), never
|
# 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
|
# 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]}")"
|
script="$(readlink -f "${BASH_SOURCE[0]}")"
|
||||||
root="$(git -C "$(dirname "$script")/.." rev-parse --show-toplevel)"
|
root="$(git -C "$(dirname "$script")/.." rev-parse --show-toplevel)"
|
||||||
cd "$root"
|
cd "$root"
|
||||||
@@ -122,19 +122,19 @@ if still="$(git -C "$root" config --get core.hooksPath)" && [ -n "$still" ]; the
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# A virtualenv made by an older Python is rebuilt rather than reused.
|
# 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
|
if [ -x .venv-dev/bin/python ] && ! .venv-dev/bin/python -c "$py_ok" 2>/dev/null; then
|
||||||
rm -rf "$root/.venv"
|
rm -rf "$root/.venv-dev"
|
||||||
fi
|
fi
|
||||||
[ -x .venv/bin/python ] || "$python" -m venv .venv
|
[ -x .venv-dev/bin/python ] || "$python" -m venv .venv-dev
|
||||||
.venv/bin/pip install --quiet --disable-pip-version-check --require-hashes -r requirements-dev.lock -r requirements-dev.txt
|
.venv-dev/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
|
.venv-dev/bin/pre-commit install --install-hooks
|
||||||
|
|
||||||
# The collections of requirements.yml, exactly as pinned, into this clone (.ansible/ is ignored by
|
# 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:
|
# 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.
|
# a copy found elsewhere (~/.ansible/collections) would be skipped as already installed.
|
||||||
collections="$root/.ansible/collections"
|
collections="$root/.ansible/collections"
|
||||||
mkdir -p "$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"
|
-r requirements.yml -p "$collections"
|
||||||
|
|
||||||
marker="# kamino-dev-setup: virtualenv first on PATH"
|
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"
|
head -n 1 "$file"
|
||||||
# %q shell-quotes the path: a repository path with spaces, quotes or $(...) is data.
|
# %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"
|
tail -n +2 "$file"
|
||||||
} > "$tmp"
|
} > "$tmp"
|
||||||
cat "$tmp" > "$file" # keeps the file mode of the hook
|
cat "$tmp" > "$file" # keeps the file mode of the hook
|
||||||
@@ -179,4 +179,4 @@ else
|
|||||||
fi
|
fi
|
||||||
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."
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
# Needs the network (PyPI) and the Python of .python-version (python<MINOR>; KAMINO_PYTHON overrides it): the
|
# 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.
|
# 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
|
# 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
|
# 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`).
|
# (`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
|
# The pins are not hash-checked themselves: they come from PyPI over TLS, like the pip that
|
||||||
|
|||||||
@@ -267,7 +267,7 @@ class CraftedTarballTest(unittest.TestCase):
|
|||||||
REPO,
|
REPO,
|
||||||
src,
|
src,
|
||||||
ignore=shutil.ignore_patterns(
|
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"
|
out = pathlib.Path(self.tmp.name) / "dist"
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ class DevSetupTest(unittest.TestCase):
|
|||||||
proc = self.run_setup(repo, KAMINO_PYTHON=str(wrong))
|
proc = self.run_setup(repo, KAMINO_PYTHON=str(wrong))
|
||||||
self.assertNotEqual(proc.returncode, 0)
|
self.assertNotEqual(proc.returncode, 0)
|
||||||
self.assertIn("is not Python 3.13 (.python-version)", proc.stderr)
|
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(
|
def test_an_interpreter_of_another_minor_is_refused_and_the_pinned_one_accepted(
|
||||||
self,
|
self,
|
||||||
@@ -201,10 +201,10 @@ class DevSetupTest(unittest.TestCase):
|
|||||||
proc = self.run_setup(repo, STUB_PY_MINOR="3.12")
|
proc = self.run_setup(repo, STUB_PY_MINOR="3.12")
|
||||||
self.assertNotEqual(proc.returncode, 0)
|
self.assertNotEqual(proc.returncode, 0)
|
||||||
self.assertIn("is not Python 3.13 (.python-version)", proc.stderr)
|
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")
|
proc = self.run_setup(repo, STUB_PY_MINOR="3.13")
|
||||||
self.assertEqual(proc.returncode, 0, proc.stderr)
|
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:
|
def test_a_missing_pin_file_is_refused_with_a_message(self) -> None:
|
||||||
repo = self.make_repo()
|
repo = self.make_repo()
|
||||||
@@ -228,6 +228,30 @@ class DevSetupTest(unittest.TestCase):
|
|||||||
text = self.hook(repo, name).read_text()
|
text = self.hook(repo, name).read_text()
|
||||||
self.assertIn("# kamino-dev-setup: virtualenv first on PATH", text)
|
self.assertIn("# kamino-dev-setup: virtualenv first on PATH", text)
|
||||||
self.assertEqual(self.hooks_z(repo), b"")
|
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:
|
def test_a_missing_tea_warns_and_setup_succeeds(self) -> None:
|
||||||
repo = self.make_repo()
|
repo = self.make_repo()
|
||||||
@@ -403,12 +427,12 @@ class DevSetupTest(unittest.TestCase):
|
|||||||
self.git(other, "init", "--quiet")
|
self.git(other, "init", "--quiet")
|
||||||
result = self.run_setup(repo, cwd=other)
|
result = self.run_setup(repo, cwd=other)
|
||||||
self.assertEqual(result.returncode, 0, result.stderr)
|
self.assertEqual(result.returncode, 0, result.stderr)
|
||||||
self.assertFalse((other / ".venv").exists())
|
self.assertFalse((other / ".venv-dev").exists())
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
os.listdir(other / ".git" / "hooks"),
|
os.listdir(other / ".git" / "hooks"),
|
||||||
[n for n in os.listdir(other / ".git" / "hooks") if n.endswith(".sample")],
|
[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())
|
self.assertTrue(self.hook(repo).exists())
|
||||||
|
|
||||||
def test_crafted_repository_path_is_not_executed(self) -> None:
|
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)
|
self.assertEqual(hook.returncode, 0, hook.stderr)
|
||||||
lines = hook.stdout.splitlines()
|
lines = hook.stdout.splitlines()
|
||||||
self.assertEqual(lines[0], "hook-ran")
|
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()):
|
for place in (workdir, repo, self.tmp, Path.cwd()):
|
||||||
self.assertFalse((place / "PWNED").exists(), place)
|
self.assertFalse((place / "PWNED").exists(), place)
|
||||||
self.assertFalse((place / "PWNED2").exists(), place)
|
self.assertFalse((place / "PWNED2").exists(), place)
|
||||||
|
|||||||
Reference in new issue
Block a user