From bcc955d1650a2ad697f18dc095eeb276abeaf30d Mon Sep 17 00:00:00 2001 From: Jon Zeolla Date: Thu, 3 Jul 2025 17:19:54 -0400 Subject: [PATCH 1/3] fix(template): auto update task rendering --- tests/test_cookiecutter.py | 45 +++++++++++++++++-- .../README.md" | 2 + .../Taskfile.yml" | 2 +- 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/tests/test_cookiecutter.py b/tests/test_cookiecutter.py index d5637fc..d7ddfa0 100755 --- a/tests/test_cookiecutter.py +++ b/tests/test_cookiecutter.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 """ -Test cookiecutter-python +Test ai-native-python """ import copy @@ -109,7 +109,7 @@ def check_files(files): ) def test_supported_options(cookies, context_override): """ - Test all supported cookiecutter-python answer combinations + Test all supported answer combinations """ # Turn off the post generation hooks os.environ["RUN_POST_HOOK"] = "false" @@ -126,10 +126,47 @@ def test_supported_options(cookies, context_override): check_files(files) +@pytest.mark.integration +def test_update(cookies): + """ + Test task update + """ + # Turn on the post generation hooks but skip git push + os.environ["RUN_POST_HOOK"] = "true" + os.environ["SKIP_GIT_PUSH"] = "true" + + result = cookies.bake() + project = result.project_path + + try: + # First init the project just in case + # Clean environment to avoid VIRTUAL_ENV conflicts + env = os.environ.copy() + env.pop("VIRTUAL_ENV", None) + subprocess.run( + ["task", "init"], + capture_output=True, + check=True, + cwd=project, + env=env, + ) + + # And then run a task update + subprocess.run( + ["task", "update"], + capture_output=True, + check=True, + cwd=project, + env=env, + ) + except subprocess.CalledProcessError as error: + pytest.fail(f"stdout: {error.stdout.decode('utf-8')}, stderr: {error.stderr.decode('utf-8')}") + + @pytest.mark.integration def test_autofix_hook(cookies, context): """ - Test the post-generation pre-commit autofix hook of cookiecutter-python + Test the post-generation pre-commit autofix hook """ # Turn on the post generation hooks but skip git push os.environ["RUN_POST_HOOK"] = "true" @@ -177,7 +214,7 @@ def test_autofix_hook(cookies, context): @pytest.mark.integration def test_default_project(cookies): """ - Test a default cookiecutter-python project thoroughly + Test a default project thoroughly """ # Turn on the post generation hooks but skip git push os.environ["RUN_POST_HOOK"] = "true" diff --git "a/{{cookiecutter.project_name|replace(\" \", \"\")}}/README.md" "b/{{cookiecutter.project_name|replace(\" \", \"\")}}/README.md" index 623a704..b0ebfde 100644 --- "a/{{cookiecutter.project_name|replace(\" \", \"\")}}/README.md" +++ "b/{{cookiecutter.project_name|replace(\" \", \"\")}}/README.md" @@ -49,3 +49,5 @@ Both tools are pre-configured and will start working once the repository is push ## FAQs For frequently asked questions including release workflow troubleshooting, see our [FAQ documentation](./FAQ.md). + +_This project was generated with 🤟 by [Zenable](https://zenable.io)_ diff --git "a/{{cookiecutter.project_name|replace(\" \", \"\")}}/Taskfile.yml" "b/{{cookiecutter.project_name|replace(\" \", \"\")}}/Taskfile.yml" index ba60abb..e480097 100644 --- "a/{{cookiecutter.project_name|replace(\" \", \"\")}}/Taskfile.yml" +++ "b/{{cookiecutter.project_name|replace(\" \", \"\")}}/Taskfile.yml" @@ -172,7 +172,7 @@ tasks: - pre-commit autoupdate --freeze --jobs 4 - uv lock --upgrade # This can take a while but it's required for the following step to update BuildKit in the docker driver - - '{{ "{{" }}if eq .CLI_ARGS "all"{{ "}}" }}docker buildx rm multiplatform || true{{ "}}" }}end {{ "}}" }}' + - '{{ "{{" }}if eq .CLI_ARGS "all"{{ "}}" }}docker buildx rm multiplatform || true{{ "{{" }}end{{ "}}" }}' # If we just destroyed the "multiplatform" builder instance, this will configure a new one. The next time the host runs a `docker buildx build` it will # rebuild the builder instance, updating its BuildKit. There's no harm in running this even if we didn't do the `docker buildx rm` previously - task: init-docker-multiplatform From 49b14009f5fa4b6c0ad531c90d7a26328fd3aabd Mon Sep 17 00:00:00 2001 From: Jon Zeolla Date: Thu, 3 Jul 2025 17:40:53 -0400 Subject: [PATCH 2/3] Install and manage pre-commit --- Taskfile.yml | 6 ++++-- .../Taskfile.yml" | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 1322800..b5c5c1b 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -29,15 +29,16 @@ tasks: - uv sync --frozen init-pre-commit: - desc: Install the pre-commit hooks + desc: Setup pre-commit internal: true sources: - .pre-commit-config.yaml status: - # Don't install the pre-commit hooks if you aren't in a git repository; quote to avoid yaml intrepretering the ! as a node tag + # Don't do any of this if you aren't in a git repository; quote to avoid yaml intrepretering the ! as a node tag # https://yaml.org/spec/1.2.2/#691-node-tags - '! test -d .git' cmds: + - uv tool install pre-commit # Don't run this in pipelines - '{{if ne .GITHUB_ACTIONS "true"}}{{.RUN_SCRIPT}} pre-commit install{{else}}echo "Detected a github actions pipeline; skipping the pre-commit install"{{end}}' @@ -88,6 +89,7 @@ tasks: cmds: # This currently assumes uv was installed via uv (locally); we will want to make it more flexible in the future - '{{if ne .GITHUB_ACTIONS "true"}}brew upgrade uv{{end}}' + - uv tool upgrade --all - pre-commit autoupdate --freeze --jobs 4 # Copy the newly updated config into the project template, excluding the exclude line - cat .pre-commit-config.yaml | grep -v ^exclude > '{{`{{cookiecutter.project_name|replace(" ", "")}}`}}/.pre-commit-config.yaml' diff --git "a/{{cookiecutter.project_name|replace(\" \", \"\")}}/Taskfile.yml" "b/{{cookiecutter.project_name|replace(\" \", \"\")}}/Taskfile.yml" index e480097..356b20f 100644 --- "a/{{cookiecutter.project_name|replace(\" \", \"\")}}/Taskfile.yml" +++ "b/{{cookiecutter.project_name|replace(\" \", \"\")}}/Taskfile.yml" @@ -47,10 +47,11 @@ tasks: sources: - .pre-commit-config.yaml status: - # Only install the pre-commit hooks if you are in a git repository; quote to avoid yaml intrepretering the ! as a node tag + # Don't do any of this if you aren't in a git repository; quote to avoid yaml intrepretering the ! as a node tag # https://yaml.org/spec/1.2.2/#691-node-tags - '! test -d .git' cmds: + - uv tool install pre-commit # Don't run this in pipelines - '{{ "{{" }}if ne .GITHUB_ACTIONS "true"{{ "}}{{.RUN_SCRIPT}} pre-commit install{{else}}echo \"Detected a github actions pipeline; skipping the pre-commit install\"{{end}}" }}' @@ -169,10 +170,11 @@ tasks: cmds: # This currently assumes uv was installed via uv (locally); we will want to make it more flexible in the future - '{{ "{{" }}if ne .GITHUB_ACTIONS "true"{{ "}}" }}brew upgrade uv{{ "{{" }}end{{ "}}" }}' + - uv tool upgrade --all - pre-commit autoupdate --freeze --jobs 4 - uv lock --upgrade # This can take a while but it's required for the following step to update BuildKit in the docker driver - - '{{ "{{" }}if eq .CLI_ARGS "all"{{ "}}" }}docker buildx rm multiplatform || true{{ "{{" }}end{{ "}}" }}' + - '{{ "{{" }}if eq .CLI_ARGS "all"{{ "}}" }}docker buildx rm multiplatform || true{{ "}}" }}end {{ "}}" }}' # If we just destroyed the "multiplatform" builder instance, this will configure a new one. The next time the host runs a `docker buildx build` it will # rebuild the builder instance, updating its BuildKit. There's no harm in running this even if we didn't do the `docker buildx rm` previously - task: init-docker-multiplatform From c5114442b9ada3f52ecd17b79572b5ba3f166e2e Mon Sep 17 00:00:00 2001 From: Jon Zeolla Date: Thu, 3 Jul 2025 17:43:28 -0400 Subject: [PATCH 3/3] Fix --- .../Taskfile.yml" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/{{cookiecutter.project_name|replace(\" \", \"\")}}/Taskfile.yml" "b/{{cookiecutter.project_name|replace(\" \", \"\")}}/Taskfile.yml" index 356b20f..6da9061 100644 --- "a/{{cookiecutter.project_name|replace(\" \", \"\")}}/Taskfile.yml" +++ "b/{{cookiecutter.project_name|replace(\" \", \"\")}}/Taskfile.yml" @@ -174,7 +174,7 @@ tasks: - pre-commit autoupdate --freeze --jobs 4 - uv lock --upgrade # This can take a while but it's required for the following step to update BuildKit in the docker driver - - '{{ "{{" }}if eq .CLI_ARGS "all"{{ "}}" }}docker buildx rm multiplatform || true{{ "}}" }}end {{ "}}" }}' + - '{{ "{{" }}if eq .CLI_ARGS "all"{{ "}}" }}docker buildx rm multiplatform || true{{ "{{" }}end{{ "}}" }}' # If we just destroyed the "multiplatform" builder instance, this will configure a new one. The next time the host runs a `docker buildx build` it will # rebuild the builder instance, updating its BuildKit. There's no harm in running this even if we didn't do the `docker buildx rm` previously - task: init-docker-multiplatform