copier-python 0.7.1__tar.gz → 0.9.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. copier_python-0.9.0/AGENTS.md +8 -0
  2. {copier_python-0.7.1 → copier_python-0.9.0}/PKG-INFO +3 -1
  3. copier_python-0.9.0/copier_python/__main__.py +140 -0
  4. copier_python-0.9.0/copier_python/repo.py +156 -0
  5. copier_python-0.9.0/copier_python/update.py +80 -0
  6. {copier_python-0.7.1 → copier_python-0.9.0}/docs/development/updates.md +2 -2
  7. {copier_python-0.7.1 → copier_python-0.9.0}/docs/development/workflow.md +3 -1
  8. {copier_python-0.7.1 → copier_python-0.9.0}/docs/project-development.md +3 -1
  9. {copier_python-0.7.1 → copier_python-0.9.0}/docs/project-setup.md +0 -6
  10. {copier_python-0.7.1 → copier_python-0.9.0}/docs/project-updates.md +2 -2
  11. {copier_python-0.7.1 → copier_python-0.9.0}/docs/setup.md +0 -1
  12. {copier_python-0.7.1 → copier_python-0.9.0}/pyproject.toml +21 -7
  13. copier_python-0.9.0/tests/conftest.py +78 -0
  14. copier_python-0.9.0/tests/template/__init__.py +0 -0
  15. copier_python-0.9.0/tests/template/__snapshots__/test_agents.ambr +14 -0
  16. {copier_python-0.7.1/tests → copier_python-0.9.0/tests/template}/__snapshots__/test_contributing.ambr +11 -2
  17. {copier_python-0.7.1/tests → copier_python-0.9.0/tests/template}/__snapshots__/test_docs.ambr +522 -28
  18. copier_python-0.9.0/tests/template/__snapshots__/test_pyproject.ambr +8109 -0
  19. {copier_python-0.7.1/tests → copier_python-0.9.0/tests/template}/__snapshots__/test_workflows.ambr +20 -20
  20. copier_python-0.9.0/tests/template/test_agents.py +13 -0
  21. {copier_python-0.7.1/tests → copier_python-0.9.0/tests/template}/test_docs.py +6 -0
  22. {copier_python-0.7.1/tests → copier_python-0.9.0/tests/template}/test_pyproject.py +14 -0
  23. {copier_python-0.7.1/tests → copier_python-0.9.0/tests/template}/test_template.py +4 -4
  24. copier_python-0.9.0/tests/test_update.py +429 -0
  25. copier_python-0.9.0/tests/utils.py +63 -0
  26. copier_python-0.7.1/tests/__snapshots__/test_pyproject.ambr +0 -2945
  27. copier_python-0.7.1/tests/conftest.py +0 -48
  28. {copier_python-0.7.1 → copier_python-0.9.0}/.gitignore +0 -0
  29. {copier_python-0.7.1 → copier_python-0.9.0}/CONTRIBUTING.md +0 -0
  30. {copier_python-0.7.1 → copier_python-0.9.0}/LICENSE +0 -0
  31. {copier_python-0.7.1 → copier_python-0.9.0}/README.md +0 -0
  32. {copier_python-0.7.1 → copier_python-0.9.0}/copier_python/__init__.py +0 -0
  33. {copier_python-0.7.1 → copier_python-0.9.0}/copier_python/py.typed +0 -0
  34. {copier_python-0.7.1 → copier_python-0.9.0}/docs/contributing.md +0 -0
  35. {copier_python-0.7.1 → copier_python-0.9.0}/docs/development/requirements.md +0 -0
  36. {copier_python-0.7.1 → copier_python-0.9.0}/docs/index.md +0 -0
  37. {copier_python-0.7.1 → copier_python-0.9.0}/docs/license.md +0 -0
  38. {copier_python-0.7.1 → copier_python-0.9.0}/docs/project-creation.md +0 -0
  39. {copier_python-0.7.1 → copier_python-0.9.0}/docs/project-release.md +0 -0
  40. {copier_python-0.7.1 → copier_python-0.9.0}/docs/releasing.md +0 -0
  41. {copier_python-0.7.1 → copier_python-0.9.0}/docs/requirements.md +0 -0
  42. {copier_python-0.7.1 → copier_python-0.9.0}/tests/__init__.py +0 -0
  43. {copier_python-0.7.1/tests → copier_python-0.9.0/tests/template}/__snapshots__/test_compose.ambr +0 -0
  44. {copier_python-0.7.1/tests → copier_python-0.9.0/tests/template}/__snapshots__/test_dockerfile.ambr +0 -0
  45. {copier_python-0.7.1/tests → copier_python-0.9.0/tests/template}/__snapshots__/test_license.ambr +0 -0
  46. {copier_python-0.7.1/tests → copier_python-0.9.0/tests/template}/__snapshots__/test_readme.ambr +0 -0
  47. {copier_python-0.7.1/tests → copier_python-0.9.0/tests/template}/__snapshots__/test_zensical.ambr +0 -0
  48. {copier_python-0.7.1/tests → copier_python-0.9.0/tests/template}/test_compose.py +0 -0
  49. {copier_python-0.7.1/tests → copier_python-0.9.0/tests/template}/test_contributing.py +0 -0
  50. {copier_python-0.7.1/tests → copier_python-0.9.0/tests/template}/test_dockerfile.py +0 -0
  51. {copier_python-0.7.1/tests → copier_python-0.9.0/tests/template}/test_license.py +0 -0
  52. {copier_python-0.7.1/tests → copier_python-0.9.0/tests/template}/test_readme.py +0 -0
  53. {copier_python-0.7.1/tests → copier_python-0.9.0/tests/template}/test_structure.py +0 -0
  54. {copier_python-0.7.1/tests → copier_python-0.9.0/tests/template}/test_version.py +0 -0
  55. {copier_python-0.7.1/tests → copier_python-0.9.0/tests/template}/test_workflows.py +0 -0
  56. {copier_python-0.7.1/tests → copier_python-0.9.0/tests/template}/test_zensical.py +0 -0
@@ -0,0 +1,8 @@
1
+ # Environment/Tools
2
+
3
+ * Python project with `uv`, use `uv add`/`uv run python` instead of bare `pip`/`python`
4
+ * `poe setup`: One-time after-clone setup (dependencies, install pre-commit hooks).
5
+ * `poe lint`: Pre-commit hooks (via `pre-commit`-compatible `prek`) including lint, format, type check (ruff, ty)
6
+ * `poe test`: Run tests (accepts pytest arguments)
7
+ * `poe lt`: Lint+test (no arguments)
8
+ * `poe snapup`: Update test snapshots (syrupy, accepts pytest arguments)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: copier-python
3
- Version: 0.7.1
3
+ Version: 0.9.0
4
4
  Summary: Copier template for Python projects with modern tooling
5
5
  Project-URL: Homepage, https://smkent.github.io/copier-python
6
6
  Project-URL: Repository, https://github.com/smkent/copier-python
@@ -22,6 +22,8 @@ Classifier: Topic :: Software Development
22
22
  Classifier: Topic :: Utilities
23
23
  Classifier: Typing :: Typed
24
24
  Requires-Python: >=3.10
25
+ Requires-Dist: pyyaml>=6
26
+ Requires-Dist: typer>=0.9
25
27
  Description-Content-Type: text/markdown
26
28
 
27
29
  # copier-python
@@ -0,0 +1,140 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ import shutil
5
+ from dataclasses import dataclass
6
+ from enum import Enum
7
+ from typing import TYPE_CHECKING, Annotated
8
+
9
+ from rich import print # noqa: A004
10
+ from rich.console import Console
11
+ from rich.panel import Panel
12
+ from rich.table import Table
13
+ from rich.text import Text
14
+ from typer import Argument, Context, Exit, Option, Typer
15
+
16
+ from .repo import RepoTarget
17
+ from .update import UpdateAction
18
+
19
+ if TYPE_CHECKING:
20
+ from collections.abc import Sequence
21
+
22
+
23
+ console = Console()
24
+
25
+
26
+ class Args:
27
+ Repos = Annotated[
28
+ list[str],
29
+ Argument(
30
+ help=(
31
+ "Repositories to update. Accepts gh:user/repo"
32
+ " or github.com/user/repo."
33
+ )
34
+ ),
35
+ ]
36
+ DryRun = Annotated[
37
+ bool, Option("--dry-run", "-n", help="Skip push and PR creation.")
38
+ ]
39
+
40
+
41
+ cli = Typer(
42
+ help="copier-python utilities",
43
+ add_completion=False,
44
+ no_args_is_help=True,
45
+ pretty_exceptions_enable=False,
46
+ )
47
+
48
+
49
+ @cli.callback()
50
+ def setup(ctx: Context) -> None:
51
+ pass
52
+
53
+
54
+ class UpdateStatus(Enum):
55
+ UPDATED = "bold green"
56
+ CURRENT = "bold blue"
57
+ FAILED = "bold red"
58
+
59
+ @property
60
+ def formatted_name(self) -> Text:
61
+ return Text(f"{self.name:<7}", style=self.value)
62
+
63
+
64
+ @dataclass
65
+ class UpdateResult:
66
+ repo: RepoTarget
67
+ status: UpdateStatus
68
+ exception: Exception | None = None
69
+ pr_url: str | None = None
70
+
71
+
72
+ @cli.command()
73
+ def update(
74
+ repos: Args.Repos,
75
+ *,
76
+ dry_run: Args.DryRun = False,
77
+ branch: Annotated[str, Option(help="Branch name to create.")] = "updates",
78
+ ) -> None:
79
+ """Apply copier-python template updates to one or more downstream repos."""
80
+ results = []
81
+
82
+ repo_targets = {(target := RepoTarget(repo)).url: target for repo in repos}
83
+ for target in repo_targets.values():
84
+ try:
85
+ pr_url = UpdateAction(target, branch=branch, dry_run=dry_run)()
86
+ if pr_url:
87
+ results.append(
88
+ UpdateResult(target, UpdateStatus.UPDATED, pr_url=pr_url)
89
+ )
90
+ else:
91
+ results.append(UpdateResult(target, UpdateStatus.CURRENT))
92
+ except Exception as exc: # noqa: BLE001, PERF203
93
+ console.print_exception()
94
+ results.append(
95
+ UpdateResult(target, status=UpdateStatus.FAILED, exception=exc)
96
+ )
97
+
98
+ _print_summary(results, dry_run=dry_run)
99
+ if any(r.status == UpdateStatus.FAILED for r in results):
100
+ raise Exit(1)
101
+
102
+
103
+ def _print_summary(results: Sequence[UpdateResult], *, dry_run: bool) -> None:
104
+ if not results:
105
+ return
106
+ grid = Table.grid(padding=(0, 1), expand=True)
107
+ grid.add_column()
108
+ grid.add_column()
109
+ grid.add_column()
110
+ for result in sorted(results, key=lambda r: r.repo.github_repo):
111
+ grid.add_row(
112
+ result.status.formatted_name,
113
+ Text.from_markup(
114
+ f"[link={result.repo.url}]{result.repo.github_repo}[/link]",
115
+ style="bold",
116
+ ),
117
+ Text(str(result.pr_url or result.exception)),
118
+ )
119
+ title = Text("Update Results", style="bold")
120
+ if dry_run:
121
+ title += Text(" (dry run)", style="green")
122
+ print(
123
+ Panel(grid, title=title, title_align="left", expand=False, padding=1)
124
+ )
125
+
126
+
127
+ def setup_env() -> None:
128
+ os.environ.pop("VIRTUAL_ENV", default=None)
129
+ os.environ["TERMINAL_WIDTH"] = str(
130
+ min(shutil.get_terminal_size().columns, 100)
131
+ )
132
+
133
+
134
+ def main() -> None:
135
+ setup_env()
136
+ cli()
137
+
138
+
139
+ if __name__ == "__main__":
140
+ main()
@@ -0,0 +1,156 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ import re
5
+ import subprocess
6
+ import tempfile
7
+ from contextlib import contextmanager, suppress
8
+ from dataclasses import InitVar, dataclass, field
9
+ from functools import cached_property
10
+ from pathlib import Path
11
+ from typing import TYPE_CHECKING, Any, ClassVar
12
+
13
+ import yaml
14
+ from rich import print # noqa: A004
15
+ from rich.panel import Panel
16
+ from rich.text import Text
17
+ from typing_extensions import Self
18
+
19
+ if TYPE_CHECKING:
20
+ from collections.abc import Generator, Sequence
21
+
22
+
23
+ @dataclass(unsafe_hash=True)
24
+ class RepoTarget:
25
+ arg: InitVar[str | Path]
26
+ github_repo: str = field(init=False)
27
+
28
+ _GITHUB_REGEXES: ClassVar[Sequence[str]] = [
29
+ r"(\.git)?/?$",
30
+ r"^gh\:",
31
+ r"^(https?://)?github.com/",
32
+ r"^((git\+)?ssh://)?([a-zA-Z0-9]+)@github.com:",
33
+ ]
34
+
35
+ def __post_init__(self, arg: str | Path) -> None:
36
+ arg = str(arg).strip()
37
+ if ((path := Path(arg)).is_dir()) and (root := self.repo_root(path)):
38
+ arg = root
39
+ for regex in self._GITHUB_REGEXES:
40
+ arg = re.sub(regex, "", arg)
41
+ if not re.fullmatch(r"[\w-]+\/[\w-]+", arg):
42
+ raise ValueError(arg)
43
+ self.github_repo = arg
44
+
45
+ def repo_root(self, path: Path) -> str | None:
46
+ with suppress(subprocess.CalledProcessError):
47
+ return subprocess.check_output(
48
+ ["git", "config", "--local", "remote.origin.url"],
49
+ text=True,
50
+ cwd=path,
51
+ ).strip()
52
+ return None
53
+
54
+ @cached_property
55
+ def name(self) -> str:
56
+ return self.github_repo.split("/")[-1]
57
+
58
+ @property
59
+ def url(self) -> str:
60
+ return f"https://github.com/{self.github_repo}"
61
+
62
+ @cached_property
63
+ def push_url(self) -> str:
64
+ return f"git@github.com:{self.github_repo}.git"
65
+
66
+
67
+ @dataclass
68
+ class RepoWorktree:
69
+ path: Path
70
+ repo: RepoTarget
71
+ branch: str
72
+
73
+ @classmethod
74
+ @contextmanager
75
+ def clone(
76
+ cls, repo: RepoTarget, branch: str
77
+ ) -> Generator[Self, None, None]:
78
+ with tempfile.TemporaryDirectory() as td:
79
+ repo_dir = Path(td) / "worktree"
80
+ cls.run_in(["git", "clone", repo.url, str(repo_dir)], repo=repo)
81
+ for cmd in (
82
+ [
83
+ *["git", "remote", "set-url", "--push", "origin"],
84
+ repo.push_url,
85
+ ],
86
+ ["poe", "setup"],
87
+ ["git", "checkout", "-b", branch],
88
+ ):
89
+ cls.run_in(cmd, repo=repo, cwd=repo_dir)
90
+ yield cls(path=repo_dir, repo=repo, branch=branch)
91
+
92
+ @classmethod
93
+ def run_in(
94
+ cls, cmd: list[str], *, repo: RepoTarget, **kwargs: Any
95
+ ) -> subprocess.CompletedProcess[str]:
96
+ kwargs.setdefault("check", True)
97
+ kwargs.setdefault("text", True)
98
+ cmd_text = Text(" ".join(cmd), style="color(153)")
99
+ txt = Text.assemble(
100
+ Text(f"{repo.github_repo} => ", style="bold"),
101
+ cmd_text,
102
+ )
103
+ print(Panel(txt, expand=False, border_style="white dim"))
104
+ return subprocess.run(cmd, **kwargs) # noqa: S603 PLW1510
105
+
106
+ def run(
107
+ self, cmd: list[str], **kwargs: Any
108
+ ) -> subprocess.CompletedProcess[str]:
109
+ kwargs.setdefault("cwd", self.path)
110
+ return self.run_in(cmd, repo=self.repo, **kwargs)
111
+
112
+ def git_status(self) -> list[str]:
113
+ return self.run(
114
+ ["git", "status", "--porcelain"], capture_output=True
115
+ ).stdout.splitlines()
116
+
117
+ @staticmethod
118
+ def has_conflicts(status: list[str]) -> bool:
119
+ conflict_codes = {"UU", "AA", "DD", "AU", "UA", "DU", "UD"}
120
+ return any(line[:2] in conflict_codes for line in status)
121
+
122
+ @property
123
+ def template_ref(self) -> str:
124
+ return yaml.safe_load( # type: ignore[no-any-return]
125
+ (self.path / ".copier-answers.yml").read_text()
126
+ ).get("_commit")
127
+
128
+ def shell(self) -> None:
129
+ self.run([os.environ.get("SHELL", "/bin/bash")], check=False)
130
+
131
+ def open_pr(self, title: str, body: str) -> str:
132
+ result = self.run(
133
+ [
134
+ "gh",
135
+ "pr",
136
+ "create",
137
+ "--title",
138
+ title,
139
+ "--body",
140
+ body,
141
+ "--head",
142
+ self.branch,
143
+ ],
144
+ capture_output=True,
145
+ check=False,
146
+ )
147
+ if result.returncode == 0:
148
+ return result.stdout.strip()
149
+ view = self.run(
150
+ ["gh", "pr", "view", "--json", "url", "--jq", ".url"],
151
+ capture_output=True,
152
+ check=False,
153
+ )
154
+ if view.returncode == 0:
155
+ return view.stdout.strip()
156
+ raise RuntimeError(f"gh pr create failed: {result.stderr.strip()}")
@@ -0,0 +1,80 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import os
5
+ import subprocess
6
+ from dataclasses import dataclass
7
+ from typing import TYPE_CHECKING
8
+
9
+ from .repo import RepoWorktree
10
+
11
+ if TYPE_CHECKING:
12
+ from .repo import RepoTarget
13
+
14
+
15
+ @dataclass
16
+ class UpdateAction:
17
+ repo: RepoTarget
18
+ branch: str
19
+ dry_run: bool = False
20
+
21
+ def __call__(self) -> str | None:
22
+ with RepoWorktree.clone(self.repo, branch=self.branch) as worktree:
23
+ return self._run(worktree)
24
+
25
+ def _run(self, repo: RepoWorktree) -> str | None:
26
+ """Run copier update in the repo worktree."""
27
+ copier_status = json.loads(
28
+ repo.run(
29
+ ["copier", "check-update", "--output-format", "json"],
30
+ capture_output=True,
31
+ ).stdout.strip()
32
+ )
33
+ start_ref = "v" + copier_status["current_version"]
34
+ end_ref = "v" + copier_status["latest_version"]
35
+ if not copier_status.get("update_available", False):
36
+ return None
37
+ repo.run(["copier", "update", "-l"])
38
+
39
+ status = repo.git_status()
40
+ if not status:
41
+ return None
42
+
43
+ if repo.has_conflicts(status):
44
+ print( # noqa: T201
45
+ "Conflicts detected."
46
+ " Resolve them and exit the shell to continue."
47
+ )
48
+ repo.shell()
49
+ status = repo.git_status()
50
+ if repo.has_conflicts(status):
51
+ raise RuntimeError("Conflicts remain, aborting")
52
+
53
+ try:
54
+ repo.run(["uv", "run", "poe", "lt"])
55
+ except subprocess.CalledProcessError:
56
+ print( # noqa: T201
57
+ "Lint/test failed. Fix errors and exit the shell to continue."
58
+ )
59
+ repo.shell()
60
+
61
+ title = "Apply template updates"
62
+ body = ""
63
+ if start_ref and end_ref and start_ref != end_ref:
64
+ ref_range = f"{start_ref}...{end_ref}"
65
+ body = os.linesep.join(
66
+ (
67
+ f"Applied updates from template: {ref_range}",
68
+ f"{repo.repo.url}/compare/{ref_range}",
69
+ )
70
+ )
71
+ repo.run(["git", "add", "-A"])
72
+ repo.run(["git", "commit", "-m", f"{title}\n\n{body}".strip()])
73
+
74
+ if self.dry_run:
75
+ return None
76
+
77
+ repo.run(
78
+ ["git", "push", "-u", "origin", repo.branch, "--force-with-lease"]
79
+ )
80
+ return repo.open_pr(title, body)
@@ -21,7 +21,7 @@ To apply updates without being prompted (reusing all previous answers), run:
21
21
  copier update -l
22
22
  ```
23
23
 
24
- When `copier update` is finished, view changes with `git status` and `git diff`.
25
- Resolve any conflicts, and then commit the result.
24
+ When [`copier update`][copier-update] is finished, view changes with
25
+ `git status` and `git diff`. Resolve any conflicts, and then commit the result.
26
26
 
27
27
  [copier-update]: https://copier.readthedocs.io/en/stable/updating/
@@ -57,6 +57,8 @@ Start the development server with:
57
57
  poe docs
58
58
  ```
59
59
 
60
- The documentation site will be served at **<http://localhost:8000>**.
60
+ The documentation site will be served at:
61
+
62
+ [**http://localhost:8000**](http://localhost:8000){ .md-button .md-button--primary target="_blank" }
61
63
 
62
64
  To use a different bind host/port, run `poe --help docs` for arguments info.
@@ -34,6 +34,8 @@ Start the development server with:
34
34
  poe docs
35
35
  ```
36
36
 
37
- The documentation site will be served at **<http://localhost:8000>**.
37
+ The documentation site will be served at:
38
+
39
+ [**http://localhost:8000**](http://localhost:8000){ .md-button .md-button--primary target="_blank" }
38
40
 
39
41
  To use a different bind host/port, run `poe --help docs` for arguments info.
@@ -75,13 +75,7 @@ Repository Settings → Actions → General → Workflow permissions
75
75
 
76
76
  Repository Settings → Pages → Source → GitHub Actions
77
77
 
78
- [copier]: https://copier.readthedocs.io
79
- [github-new]: https://github.com/new
80
78
  [github-settings-docs]: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features
81
79
  [pypi-publishing-settings]: https://pypi.org/manage/account/publishing/
82
80
  [pypi-trusted-publishing]: https://docs.pypi.org/trusted-publishers/
83
- [pypi]: https://pypi.org
84
- [pypi-login]: https://pypi.org/account/login/
85
- [pyproject-name]: https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#name
86
81
  [renovate]: https://github.com/apps/renovate
87
- [uv]: https://docs.astral.sh/uv/
@@ -27,7 +27,7 @@ To apply updates without being prompted (reusing all previous answers), run:
27
27
  copier update -l
28
28
  ```
29
29
 
30
- When `copier update` is finished, view changes with `git status` and `git diff`.
31
- Resolve any conflicts, and then commit the result.
30
+ When [`copier update`][copier-update] is finished, view changes with
31
+ `git status` and `git diff`. Resolve any conflicts, and then commit the result.
32
32
 
33
33
  [copier-update]: https://copier.readthedocs.io/en/stable/updating/
@@ -57,7 +57,6 @@ need to be stored as secrets.
57
57
  [pypi-publishing-settings]: https://pypi.org/manage/account/publishing/
58
58
  [pypi-trusted-publishing]: https://docs.pypi.org/trusted-publishers/
59
59
  [renovate]: https://github.com/apps/renovate
60
- [repo-releases]: https://github.com/smkent/copier-python/releases
61
60
  [repo-settings]: https://github.com/smkent/copier-python/settings
62
61
  [repo-settings-envs]: https://github.com/smkent/copier-python/settings/environments
63
62
  [repo-settings-branches]: https://github.com/smkent/copier-python/settings/branches
@@ -29,7 +29,13 @@ classifiers = [
29
29
  "Typing :: Typed",
30
30
  ]
31
31
  keywords = []
32
- dependencies = []
32
+ dependencies = [
33
+ "pyyaml>=6",
34
+ "typer>=0.9",
35
+ ]
36
+
37
+ [project.scripts]
38
+ copier-python = "copier_python.__main__:main"
33
39
 
34
40
  [project.urls]
35
41
  Homepage = "https://smkent.github.io/copier-python"
@@ -41,17 +47,19 @@ dev = [
41
47
  "bump-my-version>=1.3.0",
42
48
  "copier>=9",
43
49
  "poethepoet>=0.42",
44
- "prek>=0.3",
50
+ "prek>=0.4",
45
51
  "pysentry-rs>=0.4",
46
52
  "pytest>=9",
47
53
  "pytest-cov>=7",
48
54
  "pytest-sugar>=1",
49
- "syrupy>=5",
55
+ "pytest-xdist>=3",
50
56
  "ruff>=0.15",
51
- "ty>=0.0.31",
57
+ "syrupy>=5",
58
+ "ty>=0.0.38",
59
+ "typing-extensions>=4",
52
60
  ]
53
61
  docs = [
54
- "zensical>=0.0.33",
62
+ "zensical>=0.0.43",
55
63
  ]
56
64
 
57
65
  [tool.bumpversion]
@@ -131,7 +139,7 @@ sequence = [
131
139
  help = "Install project dependencies and git hooks"
132
140
 
133
141
  [tool.poe.tasks.snapup]
134
- cmd = "pytest --snapshot-update"
142
+ cmd = "pytest --snapshot-update --numprocesses 0"
135
143
  help = "Update test snapshots"
136
144
 
137
145
  [tool.poe.tasks.test]
@@ -167,12 +175,18 @@ cmd = "pytest"
167
175
  executor = {isolated = true, python = "3.14"}
168
176
  help = "Run tests using Python 3.14"
169
177
 
178
+ [tool.poe.tasks.ti]
179
+ cmd = "pytest --numprocesses 0 --no-cov -vv"
180
+ help = "Run tests with debug friendly options"
181
+
170
182
  [tool.pytest]
171
183
  addopts = [
172
184
  "-ra",
173
- "--cov",
185
+ "--cov=copier_python",
174
186
  "--strict-config",
175
187
  "--strict-markers",
188
+ "--numprocesses",
189
+ "auto",
176
190
  ]
177
191
  testpaths = ["tests"]
178
192
 
@@ -0,0 +1,78 @@
1
+ from __future__ import annotations
2
+
3
+ import subprocess
4
+ import warnings
5
+ from pathlib import Path
6
+ from typing import TYPE_CHECKING, Any
7
+
8
+ import copier
9
+ import pytest
10
+
11
+ from copier_python.__main__ import setup_env
12
+
13
+ from .utils import DisallowCallable
14
+
15
+ if TYPE_CHECKING:
16
+ from collections.abc import Callable, Iterator
17
+
18
+ TEMPLATE_ROOT = Path(__file__).parent.parent
19
+
20
+ DEFAULT_DATA: dict[str, Any] = {
21
+ "project_name": "PKFire",
22
+ "project_description": "Onett Little League",
23
+ "project_type": "library",
24
+ "project_visibility": "public",
25
+ "python_version_minimum": "3.10",
26
+ "user_name": "Ness",
27
+ "user_email": "ness@onett.example.com",
28
+ "github_user": "ness",
29
+ "copyright_holder": "Ness",
30
+ "copyright_holder_email": "ness@onett.example.com",
31
+ "copyright_year": "1995",
32
+ "copyright_license": "MIT",
33
+ }
34
+
35
+
36
+ @pytest.fixture(scope="session", autouse=True)
37
+ def ensure_env() -> None:
38
+ setup_env()
39
+
40
+
41
+ @pytest.fixture(autouse=True)
42
+ def disallow_subprocess(
43
+ request: pytest.FixtureRequest,
44
+ ) -> Iterator[DisallowCallable]:
45
+ with DisallowCallable(request, subprocess.Popen, "__init__")() as mock:
46
+ yield mock
47
+
48
+
49
+ @pytest.fixture
50
+ def allow_subprocess(disallow_subprocess: DisallowCallable) -> Iterator[None]:
51
+ with disallow_subprocess.pause():
52
+ yield
53
+
54
+
55
+ @pytest.fixture
56
+ def render_template(
57
+ tmp_path: Path, disallow_subprocess: DisallowCallable
58
+ ) -> Callable[..., Path]:
59
+ def _render(*, vcs_ref: str = "HEAD", **kwargs: Any) -> Path:
60
+ worktree = tmp_path / "project"
61
+ with warnings.catch_warnings():
62
+ warnings.filterwarnings(
63
+ "ignore",
64
+ category=copier.errors.DirtyLocalWarning,
65
+ )
66
+ with disallow_subprocess.pause():
67
+ copier.run_copy(
68
+ src_path=str(TEMPLATE_ROOT),
69
+ dst_path=str(worktree),
70
+ data={**DEFAULT_DATA, **(kwargs or {})},
71
+ vcs_ref=vcs_ref,
72
+ defaults=True,
73
+ overwrite=True,
74
+ unsafe=False,
75
+ )
76
+ return worktree
77
+
78
+ return _render
File without changes
@@ -0,0 +1,14 @@
1
+ # serializer version: 1
2
+ # name: test_agents
3
+ '''
4
+ # Environment/Tools
5
+
6
+ * Python project with `uv`, use `uv add`/`uv run python` instead of bare `pip`/`python`
7
+ * `poe setup`: One-time after-clone setup (dependencies, install pre-commit hooks).
8
+ * `poe lint`: Pre-commit hooks (via `pre-commit`-compatible `prek`) including lint, format, type check (ruff, ty)
9
+ * `poe test`: Run tests (accepts pytest arguments)
10
+ * `poe lt`: Lint+test (no arguments)
11
+ * `poe snapup`: Update test snapshots (syrupy, accepts pytest arguments)
12
+
13
+ '''
14
+ # ---
@@ -83,6 +83,15 @@
83
83
  poe lt
84
84
  ```
85
85
 
86
+ ### Test snapshots
87
+
88
+ Some tests compare test results with saved snapshots. Test snapshots can be
89
+ updated by running:
90
+
91
+ ```sh
92
+ poe snapup
93
+ ```
94
+
86
95
  ### Applying copier-python template updates
87
96
 
88
97
  Copier can update your project with template changes that have occurred since
@@ -107,8 +116,8 @@
107
116
  copier update -l
108
117
  ```
109
118
 
110
- When `copier update` is finished, view changes with `git status` and `git diff`.
111
- Resolve any conflicts, and then commit the result.
119
+ When [`copier update`][copier-update] is finished, view changes with
120
+ `git status` and `git diff`. Resolve any conflicts, and then commit the result.
112
121
 
113
122
  [copier-update]: https://copier.readthedocs.io/en/stable/updating/
114
123