Skip to content

Commit d93a822

Browse files
authored
fix(template): auto updates (#11)
1 parent 74c1efa commit d93a822

4 files changed

Lines changed: 51 additions & 8 deletions

File tree

Taskfile.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@ tasks:
2929
- uv sync --frozen
3030

3131
init-pre-commit:
32-
desc: Install the pre-commit hooks
32+
desc: Setup pre-commit
3333
internal: true
3434
sources:
3535
- .pre-commit-config.yaml
3636
status:
37-
# 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
37+
# Don't do any of this if you aren't in a git repository; quote to avoid yaml intrepretering the ! as a node tag
3838
# https://yaml.org/spec/1.2.2/#691-node-tags
3939
- '! test -d .git'
4040
cmds:
41+
- uv tool install pre-commit
4142
# Don't run this in pipelines
4243
- '{{if ne .GITHUB_ACTIONS "true"}}{{.RUN_SCRIPT}} pre-commit install{{else}}echo "Detected a github actions pipeline; skipping the pre-commit install"{{end}}'
4344

@@ -88,6 +89,7 @@ tasks:
8889
cmds:
8990
# This currently assumes uv was installed via uv (locally); we will want to make it more flexible in the future
9091
- '{{if ne .GITHUB_ACTIONS "true"}}brew upgrade uv{{end}}'
92+
- uv tool upgrade --all
9193
- pre-commit autoupdate --freeze --jobs 4
9294
# Copy the newly updated config into the project template, excluding the exclude line
9395
- cat .pre-commit-config.yaml | grep -v ^exclude > '{{`{{cookiecutter.project_name|replace(" ", "")}}`}}/.pre-commit-config.yaml'

tests/test_cookiecutter.py

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22
"""
3-
Test cookiecutter-python
3+
Test ai-native-python
44
"""
55

66
import copy
@@ -109,7 +109,7 @@ def check_files(files):
109109
)
110110
def test_supported_options(cookies, context_override):
111111
"""
112-
Test all supported cookiecutter-python answer combinations
112+
Test all supported answer combinations
113113
"""
114114
# Turn off the post generation hooks
115115
os.environ["RUN_POST_HOOK"] = "false"
@@ -126,10 +126,47 @@ def test_supported_options(cookies, context_override):
126126
check_files(files)
127127

128128

129+
@pytest.mark.integration
130+
def test_update(cookies):
131+
"""
132+
Test task update
133+
"""
134+
# Turn on the post generation hooks but skip git push
135+
os.environ["RUN_POST_HOOK"] = "true"
136+
os.environ["SKIP_GIT_PUSH"] = "true"
137+
138+
result = cookies.bake()
139+
project = result.project_path
140+
141+
try:
142+
# First init the project just in case
143+
# Clean environment to avoid VIRTUAL_ENV conflicts
144+
env = os.environ.copy()
145+
env.pop("VIRTUAL_ENV", None)
146+
subprocess.run(
147+
["task", "init"],
148+
capture_output=True,
149+
check=True,
150+
cwd=project,
151+
env=env,
152+
)
153+
154+
# And then run a task update
155+
subprocess.run(
156+
["task", "update"],
157+
capture_output=True,
158+
check=True,
159+
cwd=project,
160+
env=env,
161+
)
162+
except subprocess.CalledProcessError as error:
163+
pytest.fail(f"stdout: {error.stdout.decode('utf-8')}, stderr: {error.stderr.decode('utf-8')}")
164+
165+
129166
@pytest.mark.integration
130167
def test_autofix_hook(cookies, context):
131168
"""
132-
Test the post-generation pre-commit autofix hook of cookiecutter-python
169+
Test the post-generation pre-commit autofix hook
133170
"""
134171
# Turn on the post generation hooks but skip git push
135172
os.environ["RUN_POST_HOOK"] = "true"
@@ -177,7 +214,7 @@ def test_autofix_hook(cookies, context):
177214
@pytest.mark.integration
178215
def test_default_project(cookies):
179216
"""
180-
Test a default cookiecutter-python project thoroughly
217+
Test a default project thoroughly
181218
"""
182219
# Turn on the post generation hooks but skip git push
183220
os.environ["RUN_POST_HOOK"] = "true"

{{cookiecutter.project_name|replace(" ", "")}}/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,5 @@ Both tools are pre-configured and will start working once the repository is push
4949
## FAQs
5050

5151
For frequently asked questions including release workflow troubleshooting, see our [FAQ documentation](./FAQ.md).
52+
53+
_This project was generated with 🤟 by [Zenable](https://zenable.io)_

{{cookiecutter.project_name|replace(" ", "")}}/Taskfile.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ tasks:
4747
sources:
4848
- .pre-commit-config.yaml
4949
status:
50-
# Only install the pre-commit hooks if you are in a git repository; quote to avoid yaml intrepretering the ! as a node tag
50+
# Don't do any of this if you aren't in a git repository; quote to avoid yaml intrepretering the ! as a node tag
5151
# https://yaml.org/spec/1.2.2/#691-node-tags
5252
- '! test -d .git'
5353
cmds:
54+
- uv tool install pre-commit
5455
# Don't run this in pipelines
5556
- '{{ "{{" }}if ne .GITHUB_ACTIONS "true"{{ "}}{{.RUN_SCRIPT}} pre-commit install{{else}}echo \"Detected a github actions pipeline; skipping the pre-commit install\"{{end}}" }}'
5657

@@ -169,10 +170,11 @@ tasks:
169170
cmds:
170171
# This currently assumes uv was installed via uv (locally); we will want to make it more flexible in the future
171172
- '{{ "{{" }}if ne .GITHUB_ACTIONS "true"{{ "}}" }}brew upgrade uv{{ "{{" }}end{{ "}}" }}'
173+
- uv tool upgrade --all
172174
- pre-commit autoupdate --freeze --jobs 4
173175
- uv lock --upgrade
174176
# This can take a while but it's required for the following step to update BuildKit in the docker driver
175-
- '{{ "{{" }}if eq .CLI_ARGS "all"{{ "}}" }}docker buildx rm multiplatform || true{{ "}}" }}end {{ "}}" }}'
177+
- '{{ "{{" }}if eq .CLI_ARGS "all"{{ "}}" }}docker buildx rm multiplatform || true{{ "{{" }}end{{ "}}" }}'
176178
# 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
177179
# 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
178180
- task: init-docker-multiplatform

0 commit comments

Comments
 (0)