create-pyproj 1.3.4__tar.gz → 2.1.1__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 (102) hide show
  1. create-pyproj-1.3.4/src/create_pyproj/templates/package/MANIFEST.in.tmpl → create_pyproj-2.1.1/MANIFEST.in +3 -2
  2. create_pyproj-2.1.1/PKG-INFO +111 -0
  3. create_pyproj-2.1.1/pyproject.toml +76 -0
  4. create_pyproj-2.1.1/readme.md +101 -0
  5. create_pyproj-2.1.1/src/create_pyproj/__init__.py +5 -0
  6. create_pyproj-2.1.1/src/create_pyproj/main.py +132 -0
  7. create_pyproj-2.1.1/src/create_pyproj/scaffold.py +174 -0
  8. create_pyproj-2.1.1/src/create_pyproj/templater.py +99 -0
  9. create_pyproj-2.1.1/src/create_pyproj/templates/base/.env.example.tmpl +1 -0
  10. create_pyproj-2.1.1/src/create_pyproj/templates/base/.gitignore.tmpl +17 -0
  11. create_pyproj-2.1.1/src/create_pyproj/templates/base/.pre-commit-config.yaml.tmpl +20 -0
  12. create_pyproj-2.1.1/src/create_pyproj/templates/base/.python-version.tmpl +1 -0
  13. create_pyproj-2.1.1/src/create_pyproj/templates/base/.vscode/extensions.json.tmpl +7 -0
  14. create_pyproj-2.1.1/src/create_pyproj/templates/base/.vscode/settings.json.tmpl +22 -0
  15. create_pyproj-2.1.1/src/create_pyproj/templates/base/AGENTS.md.tmpl +41 -0
  16. create_pyproj-2.1.1/src/create_pyproj/templates/base/README.md.tmpl +155 -0
  17. create_pyproj-2.1.1/src/create_pyproj/templates/base/docs/api.md.tmpl +35 -0
  18. create_pyproj-2.1.1/src/create_pyproj/templates/base/docs/approach.md.tmpl +97 -0
  19. create_pyproj-2.1.1/src/create_pyproj/templates/base/docs/data-models.md.tmpl +6 -0
  20. create_pyproj-2.1.1/src/create_pyproj/templates/base/docs/domain-map.yml.tmpl +8 -0
  21. create_pyproj-2.1.1/src/create_pyproj/templates/base/docs/domain-model.md.tmpl +8 -0
  22. create_pyproj-2.1.1/src/create_pyproj/templates/base/docs/implementation.md.tmpl +27 -0
  23. create_pyproj-2.1.1/src/create_pyproj/templates/base/docs/index.md.tmpl +21 -0
  24. create_pyproj-2.1.1/src/create_pyproj/templates/base/docs/references.md.tmpl +6 -0
  25. create_pyproj-2.1.1/src/create_pyproj/templates/base/docs/topology.md.tmpl +24 -0
  26. create_pyproj-2.1.1/src/create_pyproj/templates/base/docs/use-cases.md.tmpl +6 -0
  27. create_pyproj-2.1.1/src/create_pyproj/templates/base/mise.toml.tmpl +63 -0
  28. create_pyproj-2.1.1/src/create_pyproj/templates/base/mkdocs.yml.tmpl +14 -0
  29. create_pyproj-2.1.1/src/create_pyproj/templates/base/pyproject.toml.tmpl +99 -0
  30. create_pyproj-2.1.1/src/create_pyproj/templates/base/src/${package_name}/__init__.py.tmpl +5 -0
  31. create_pyproj-2.1.1/src/create_pyproj/templates/base/src/${package_name}/application/__init__.py.tmpl +1 -0
  32. create_pyproj-2.1.1/src/create_pyproj/templates/base/src/${package_name}/domain/__init__.py.tmpl +1 -0
  33. create_pyproj-2.1.1/src/create_pyproj/templates/base/src/${package_name}/infrastructure/__init__.py.tmpl +1 -0
  34. create_pyproj-2.1.1/src/create_pyproj/templates/ci/github/.github/workflows/ci.yml.tmpl +42 -0
  35. create_pyproj-2.1.1/src/create_pyproj/templates/ci/gitlab/.gitlab-ci.yml.tmpl +49 -0
  36. create_pyproj-2.1.1/src/create_pyproj/templates/infra/terraform/terraform/README.md.tmpl +26 -0
  37. create_pyproj-2.1.1/src/create_pyproj/templates/infra/terraform/terraform/_config.tf.tmpl +24 -0
  38. create_pyproj-2.1.1/src/create_pyproj/templates/infra/terraform/terraform/main.tf.tmpl +14 -0
  39. create_pyproj-2.1.1/src/create_pyproj/templates/infra/terraform/terraform/outputs.tf.tmpl +14 -0
  40. create_pyproj-2.1.1/src/create_pyproj/templates/infra/terraform/terraform/variables.tf.tmpl +15 -0
  41. create_pyproj-2.1.1/src/create_pyproj/templates/interfaces/cli/src/${package_name}/cli.py.tmpl +22 -0
  42. create_pyproj-2.1.1/src/create_pyproj/templates/interfaces/cli/src/main.py.tmpl +4 -0
  43. create_pyproj-2.1.1/src/create_pyproj/templates/interfaces/web/src/${package_name}/ui/__init__.py.tmpl +47 -0
  44. create_pyproj-2.1.1/src/create_pyproj/templates/interfaces/web/src/${package_name}/ui/static/app.css +64 -0
  45. create_pyproj-2.1.1/src/create_pyproj/templates/interfaces/web/src/${package_name}/ui/templates/_greeting.html.tmpl +1 -0
  46. create_pyproj-2.1.1/src/create_pyproj/templates/interfaces/web/src/${package_name}/ui/templates/base.html.tmpl +17 -0
  47. create_pyproj-2.1.1/src/create_pyproj/templates/interfaces/web/src/${package_name}/ui/templates/index.html.tmpl +11 -0
  48. create_pyproj-2.1.1/src/create_pyproj/templates/interfaces/web/src/${package_name}/web.py.tmpl +26 -0
  49. create_pyproj-2.1.1/src/create_pyproj.egg-info/PKG-INFO +111 -0
  50. create_pyproj-2.1.1/src/create_pyproj.egg-info/SOURCES.txt +56 -0
  51. create_pyproj-2.1.1/src/create_pyproj.egg-info/requires.txt +1 -0
  52. {create-pyproj-1.3.4 → create_pyproj-2.1.1}/src/create_pyproj.egg-info/top_level.txt +0 -1
  53. create_pyproj-2.1.1/test/test_main.py +387 -0
  54. create_pyproj-2.1.1/test/test_packaging.py +85 -0
  55. create-pyproj-1.3.4/MANIFEST.in +0 -5
  56. create-pyproj-1.3.4/PKG-INFO +0 -30
  57. create-pyproj-1.3.4/VERSION +0 -1
  58. create-pyproj-1.3.4/pyproject.toml +0 -51
  59. create-pyproj-1.3.4/src/__init__.py +0 -1
  60. create-pyproj-1.3.4/src/create_pyproj/__init__.py +0 -3
  61. create-pyproj-1.3.4/src/create_pyproj/_config/__init__.py +0 -4
  62. create-pyproj-1.3.4/src/create_pyproj/_config/logger.py +0 -41
  63. create-pyproj-1.3.4/src/create_pyproj/_config/logging.yaml +0 -33
  64. create-pyproj-1.3.4/src/create_pyproj/_config/version.py +0 -10
  65. create-pyproj-1.3.4/src/create_pyproj/code/__init__.py.tmpl +0 -5
  66. create-pyproj-1.3.4/src/create_pyproj/code/_config/__init__.py +0 -11
  67. create-pyproj-1.3.4/src/create_pyproj/code/_config/logger.py +0 -58
  68. create-pyproj-1.3.4/src/create_pyproj/code/_config/logging.yaml +0 -33
  69. create-pyproj-1.3.4/src/create_pyproj/code/_config/settings.py +0 -57
  70. create-pyproj-1.3.4/src/create_pyproj/code/_config/version.py +0 -20
  71. create-pyproj-1.3.4/src/create_pyproj/code/main.py.tmpl +0 -54
  72. create-pyproj-1.3.4/src/create_pyproj/code/scripts/__init__.py +0 -0
  73. create-pyproj-1.3.4/src/create_pyproj/code/scripts/pre_commit.py +0 -53
  74. create-pyproj-1.3.4/src/create_pyproj/code/settings.yaml +0 -1
  75. create-pyproj-1.3.4/src/create_pyproj/code/test/__init__.py +0 -1
  76. create-pyproj-1.3.4/src/create_pyproj/code/test/conftest.py +0 -0
  77. create-pyproj-1.3.4/src/create_pyproj/code/test/test_main.py +0 -7
  78. create-pyproj-1.3.4/src/create_pyproj/createfile.py +0 -99
  79. create-pyproj-1.3.4/src/create_pyproj/figlet.py +0 -6
  80. create-pyproj-1.3.4/src/create_pyproj/initialise.py +0 -29
  81. create-pyproj-1.3.4/src/create_pyproj/main.py +0 -89
  82. create-pyproj-1.3.4/src/create_pyproj/templater.py +0 -34
  83. create-pyproj-1.3.4/src/create_pyproj/templates/package/LICENSE.tmpl +0 -21
  84. create-pyproj-1.3.4/src/create_pyproj/templates/package/pyproject.toml.tmpl +0 -45
  85. create-pyproj-1.3.4/src/create_pyproj/templates/project/.env.tmpl +0 -1
  86. create-pyproj-1.3.4/src/create_pyproj/templates/project/.flake8.tmpl +0 -3
  87. create-pyproj-1.3.4/src/create_pyproj/templates/project/.gitignore.tmpl +0 -15
  88. create-pyproj-1.3.4/src/create_pyproj/templates/project/.gitlab-ci.yml.tmpl +0 -18
  89. create-pyproj-1.3.4/src/create_pyproj/templates/project/.pre-commit-config.yaml.tmpl +0 -19
  90. create-pyproj-1.3.4/src/create_pyproj/templates/project/Pipfile.tmpl +0 -27
  91. create-pyproj-1.3.4/src/create_pyproj/templates/project/README.md.tmpl +0 -110
  92. create-pyproj-1.3.4/src/create_pyproj/templates/project/VERSION.tmpl +0 -1
  93. create-pyproj-1.3.4/src/create_pyproj/templates/vscode/extensions.json.tmpl +0 -13
  94. create-pyproj-1.3.4/src/create_pyproj/templates/vscode/launch.json.tmpl +0 -27
  95. create-pyproj-1.3.4/src/create_pyproj/templates/vscode/settings.json.tmpl +0 -25
  96. create-pyproj-1.3.4/src/create_pyproj.egg-info/PKG-INFO +0 -30
  97. create-pyproj-1.3.4/src/create_pyproj.egg-info/SOURCES.txt +0 -48
  98. create-pyproj-1.3.4/test/test_main.py +0 -32
  99. {create-pyproj-1.3.4 → create_pyproj-2.1.1}/LICENSE +0 -0
  100. {create-pyproj-1.3.4 → create_pyproj-2.1.1}/setup.cfg +0 -0
  101. {create-pyproj-1.3.4 → create_pyproj-2.1.1}/src/create_pyproj.egg-info/dependency_links.txt +0 -0
  102. {create-pyproj-1.3.4 → create_pyproj-2.1.1}/src/create_pyproj.egg-info/entry_points.txt +0 -0
@@ -1,6 +1,7 @@
1
1
  recursive-include src *.md
2
2
  recursive-include src *.py
3
- recursive-include src *.yml
4
3
  recursive-include src *.yaml
5
4
  recursive-include src *.tmpl
6
- recursive-include src *.json
5
+ recursive-include src *.json
6
+ recursive-include src *.yml
7
+ recursive-include src *.css
@@ -0,0 +1,111 @@
1
+ Metadata-Version: 2.4
2
+ Name: create-pyproj
3
+ Version: 2.1.1
4
+ Summary: Scaffold uv-first Python projects with a DDD and hexagonal baseline.
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE
8
+ Requires-Dist: mako>=1.3.5
9
+ Dynamic: license-file
10
+
11
+ # create-pyproj
12
+
13
+ `create-pyproj` scaffolds canonical Python projects with a `uv`-first workflow,
14
+ semantic-release, DDD and hexagonal defaults, optional CLI and web stubs,
15
+ starter MkDocs documentation, and an `AGENTS.md` tuned for the canonical
16
+ engineering skills.
17
+
18
+ ## What It Generates
19
+
20
+ The default scaffold includes:
21
+
22
+ - `.python-version`
23
+ - `pyproject.toml` with `uv`-friendly dependency groups and Ruff configuration
24
+ - `mise.toml` with tool pins and common tasks
25
+ - semantic-release configuration for version stamping in `pyproject.toml` and `src/<package>/__init__.py`
26
+ - `src/<package>` with `domain`, `application`, and `infrastructure` package structure
27
+ - `docs/` plus `mkdocs.yml`
28
+ - `AGENTS.md`
29
+ - `.vscode/`, `.pre-commit-config.yaml`, and `.env.example`
30
+
31
+ Optional adapters:
32
+
33
+ - `--interface cli` adds an argparse-based CLI stub and console script entrypoint
34
+ - `--interface web` adds a FastAPI application stub plus a server-rendered UI:
35
+ Jinja2 templates and HTMX fragment swaps served by the same app
36
+
37
+ Optional CI:
38
+
39
+ - `--ci github`
40
+ - `--ci gitlab`
41
+
42
+ Both CI options include lint, test, and semantic-release jobs.
43
+
44
+ Optional infrastructure:
45
+
46
+ - `--terraform` adds a starter Terraform deployment skeleton
47
+
48
+ ## Usage
49
+
50
+ ```bash
51
+ create-pyproj demo-app --interface cli --interface web --ci github --terraform --no-install
52
+ ```
53
+
54
+ To install the local repo as a global command with `uv`:
55
+
56
+ ```bash
57
+ uv tool install --force .
58
+ ```
59
+
60
+ Common flags:
61
+
62
+ - `--python-version 3.12`
63
+ - `--description "Short project summary"`
64
+ - `--author "Your Name"`
65
+ - `--author-email "you@example.com"`
66
+ - `--output-dir /path/to/projects`
67
+ - `--terraform`
68
+ - `--no-git-init`
69
+ - `--no-install`
70
+
71
+ If the target directory already exists, `create-pyproj` will reuse it. Any
72
+ scaffold-managed files with the same path will be overwritten, while unrelated
73
+ existing files and folders are left in place.
74
+
75
+ ## Scaffold Contract
76
+
77
+ The generated project is intended to:
78
+
79
+ - keep the domain and application layers framework-independent
80
+ - make CLI and web adapters optional delivery concerns
81
+ - expose Mise, uv, Ruff, pytest, and pre-commit as the default workflow
82
+ - include semantic-release as the default CI/CD release toolset
83
+ - provide structure without inventing sample business behavior
84
+ - include the same semantic-release approach used elsewhere in this workspace
85
+ - add Terraform only when requested for a deployable service
86
+ - document the architecture and domain through MkDocs
87
+ - include an `AGENTS.md` that points contributors at the canonical skills
88
+
89
+ ## Development
90
+
91
+ ```bash
92
+ mise run setup
93
+ mise run lint
94
+ mise run complexity
95
+ mise run typecheck
96
+ mise run format
97
+ mise run test
98
+ uv run python -m create_pyproj.main --help
99
+ ```
100
+
101
+ The local test suite verifies the emitted scaffold contract rather than just
102
+ individual template files.
103
+
104
+ ## Docs
105
+
106
+ This repo now includes MkDocs content for `create_pyproj` itself under `docs/`,
107
+ with navigation configured in `mkdocs.yml`.
108
+
109
+ ```bash
110
+ mise run docs
111
+ ```
@@ -0,0 +1,76 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "create-pyproj"
7
+ version = "2.1.1"
8
+ description = "Scaffold uv-first Python projects with a DDD and hexagonal baseline."
9
+ readme = "readme.md"
10
+ requires-python = ">=3.10"
11
+ dependencies = ["mako>=1.3.5"]
12
+
13
+ [project.scripts]
14
+ create-pyproj = "create_pyproj.main:main"
15
+
16
+ [tool.ruff]
17
+ line-length = 88
18
+ target-version = "py310"
19
+
20
+ [tool.ruff.lint]
21
+ select = ["E", "F", "W", "I", "S", "C901"]
22
+ ignore = ["E203", "E501"]
23
+
24
+ [tool.ruff.lint.mccabe]
25
+ max-complexity = 10
26
+
27
+ [tool.ruff.lint.per-file-ignores]
28
+ # Tests assert; that is not a security finding.
29
+ "test/**" = ["S101"]
30
+
31
+ [tool.ruff.format]
32
+ docstring-code-format = true
33
+
34
+ [tool.semantic_release]
35
+ commit_message = "chore(release): {version} [skip ci]"
36
+ remote.type = "github"
37
+ version_toml = ["pyproject.toml:project.version"]
38
+ version_variables = ["src/create_pyproj/__init__.py:__version__"]
39
+
40
+ [tool.semantic_release.branches.main]
41
+ match = "main"
42
+
43
+ [tool.semantic_release.branches.master]
44
+ match = "master"
45
+
46
+ [tool.semantic_release.branches.release]
47
+ match = "release"
48
+
49
+ [tool.pytest.ini_options]
50
+ addopts = "-vv"
51
+ pythonpath = ["src", "test"]
52
+ testpaths = ["test"]
53
+
54
+ [tool.setuptools.packages.find]
55
+ where = ["src"]
56
+
57
+ [dependency-groups]
58
+ dev = [
59
+ "build",
60
+ "fastapi>=0.115",
61
+ "httpx",
62
+ "jinja2>=3.1.4",
63
+ "python-multipart>=0.0.9",
64
+ "mkdocs",
65
+ "mkdocs-material",
66
+ "pre-commit>=4.0.1",
67
+ "python-semantic-release",
68
+ "pytest",
69
+ "hypothesis>=6.100",
70
+ "ruff>=0.15.12",
71
+ "twine",
72
+ "ty>=0.0.75,<0.1",
73
+ ]
74
+
75
+ [tool.ty.src]
76
+ include = ["src", "test"]
@@ -0,0 +1,101 @@
1
+ # create-pyproj
2
+
3
+ `create-pyproj` scaffolds canonical Python projects with a `uv`-first workflow,
4
+ semantic-release, DDD and hexagonal defaults, optional CLI and web stubs,
5
+ starter MkDocs documentation, and an `AGENTS.md` tuned for the canonical
6
+ engineering skills.
7
+
8
+ ## What It Generates
9
+
10
+ The default scaffold includes:
11
+
12
+ - `.python-version`
13
+ - `pyproject.toml` with `uv`-friendly dependency groups and Ruff configuration
14
+ - `mise.toml` with tool pins and common tasks
15
+ - semantic-release configuration for version stamping in `pyproject.toml` and `src/<package>/__init__.py`
16
+ - `src/<package>` with `domain`, `application`, and `infrastructure` package structure
17
+ - `docs/` plus `mkdocs.yml`
18
+ - `AGENTS.md`
19
+ - `.vscode/`, `.pre-commit-config.yaml`, and `.env.example`
20
+
21
+ Optional adapters:
22
+
23
+ - `--interface cli` adds an argparse-based CLI stub and console script entrypoint
24
+ - `--interface web` adds a FastAPI application stub plus a server-rendered UI:
25
+ Jinja2 templates and HTMX fragment swaps served by the same app
26
+
27
+ Optional CI:
28
+
29
+ - `--ci github`
30
+ - `--ci gitlab`
31
+
32
+ Both CI options include lint, test, and semantic-release jobs.
33
+
34
+ Optional infrastructure:
35
+
36
+ - `--terraform` adds a starter Terraform deployment skeleton
37
+
38
+ ## Usage
39
+
40
+ ```bash
41
+ create-pyproj demo-app --interface cli --interface web --ci github --terraform --no-install
42
+ ```
43
+
44
+ To install the local repo as a global command with `uv`:
45
+
46
+ ```bash
47
+ uv tool install --force .
48
+ ```
49
+
50
+ Common flags:
51
+
52
+ - `--python-version 3.12`
53
+ - `--description "Short project summary"`
54
+ - `--author "Your Name"`
55
+ - `--author-email "you@example.com"`
56
+ - `--output-dir /path/to/projects`
57
+ - `--terraform`
58
+ - `--no-git-init`
59
+ - `--no-install`
60
+
61
+ If the target directory already exists, `create-pyproj` will reuse it. Any
62
+ scaffold-managed files with the same path will be overwritten, while unrelated
63
+ existing files and folders are left in place.
64
+
65
+ ## Scaffold Contract
66
+
67
+ The generated project is intended to:
68
+
69
+ - keep the domain and application layers framework-independent
70
+ - make CLI and web adapters optional delivery concerns
71
+ - expose Mise, uv, Ruff, pytest, and pre-commit as the default workflow
72
+ - include semantic-release as the default CI/CD release toolset
73
+ - provide structure without inventing sample business behavior
74
+ - include the same semantic-release approach used elsewhere in this workspace
75
+ - add Terraform only when requested for a deployable service
76
+ - document the architecture and domain through MkDocs
77
+ - include an `AGENTS.md` that points contributors at the canonical skills
78
+
79
+ ## Development
80
+
81
+ ```bash
82
+ mise run setup
83
+ mise run lint
84
+ mise run complexity
85
+ mise run typecheck
86
+ mise run format
87
+ mise run test
88
+ uv run python -m create_pyproj.main --help
89
+ ```
90
+
91
+ The local test suite verifies the emitted scaffold contract rather than just
92
+ individual template files.
93
+
94
+ ## Docs
95
+
96
+ This repo now includes MkDocs content for `create_pyproj` itself under `docs/`,
97
+ with navigation configured in `mkdocs.yml`.
98
+
99
+ ```bash
100
+ mise run docs
101
+ ```
@@ -0,0 +1,5 @@
1
+ """Utilities for scaffolding canonical Python projects."""
2
+
3
+ __all__ = ["__version__"]
4
+
5
+ __version__ = "2.1.1"
@@ -0,0 +1,132 @@
1
+ """CLI entrypoint for project scaffolding."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ from pathlib import Path
7
+
8
+ from . import __version__
9
+ from .scaffold import ProjectOptions, create_project
10
+
11
+
12
+ def build_parser() -> argparse.ArgumentParser:
13
+ """Build the command-line parser."""
14
+
15
+ parser = argparse.ArgumentParser(
16
+ prog="create-pyproj",
17
+ description=(
18
+ "Create a uv-first Python scaffold with a DDD/hexagonal core and "
19
+ "optional CLI, web, and CI adapters."
20
+ ),
21
+ )
22
+ parser.add_argument(
23
+ "--version",
24
+ action="version",
25
+ version=f"%(prog)s {__version__}",
26
+ )
27
+ parser.add_argument(
28
+ "project_name",
29
+ help="The directory and package name for the new project.",
30
+ )
31
+ parser.add_argument(
32
+ "--python-version",
33
+ default="3.12",
34
+ help="Version string to write to .python-version. Defaults to 3.12.",
35
+ )
36
+ parser.add_argument(
37
+ "--description",
38
+ default="Canonical Python project scaffold.",
39
+ help="Short project description for pyproject.toml and README.md.",
40
+ )
41
+ parser.add_argument(
42
+ "--author",
43
+ default="",
44
+ help="Optional author name to include in pyproject.toml.",
45
+ )
46
+ parser.add_argument(
47
+ "--author-email",
48
+ default="",
49
+ help="Optional author email to include in pyproject.toml.",
50
+ )
51
+ parser.add_argument(
52
+ "--interface",
53
+ action="append",
54
+ choices=["library", "cli", "web"],
55
+ dest="interfaces",
56
+ help=(
57
+ "Interface to include. Repeat for multiple adapters. "
58
+ "Defaults to library only."
59
+ ),
60
+ )
61
+ parser.add_argument(
62
+ "--ci",
63
+ choices=["none", "github", "gitlab"],
64
+ default="none",
65
+ help="Optional CI provider template to include.",
66
+ )
67
+ parser.add_argument(
68
+ "--terraform",
69
+ action="store_true",
70
+ help="Include a starter Terraform deployment skeleton.",
71
+ )
72
+ parser.add_argument(
73
+ "--output-dir",
74
+ type=Path,
75
+ default=Path.cwd(),
76
+ help="Directory where the new project folder will be created.",
77
+ )
78
+ parser.add_argument(
79
+ "--no-git-init",
80
+ action="store_true",
81
+ help="Skip git init.",
82
+ )
83
+ parser.add_argument(
84
+ "--no-install",
85
+ action="store_true",
86
+ help="Skip uv sync and pre-commit installation.",
87
+ )
88
+ return parser
89
+
90
+
91
+ def main(argv: list[str] | None = None) -> int:
92
+ """Run the scaffolder CLI."""
93
+
94
+ parser = build_parser()
95
+ args = parser.parse_args(argv)
96
+ options = ProjectOptions(
97
+ project_name=args.project_name,
98
+ python_version=args.python_version,
99
+ description=args.description,
100
+ author=args.author,
101
+ author_email=args.author_email,
102
+ interfaces=tuple(args.interfaces or ("library",)),
103
+ ci_provider=args.ci,
104
+ terraform=args.terraform,
105
+ output_dir=args.output_dir,
106
+ git_init=not args.no_git_init,
107
+ install=not args.no_install,
108
+ )
109
+
110
+ try:
111
+ result = create_project(options)
112
+ except FileExistsError:
113
+ parser.error(
114
+ "Destination exists and is not a directory: "
115
+ f"{(args.output_dir / args.project_name)!s}"
116
+ )
117
+ except RuntimeError as error:
118
+ parser.exit(status=1, message=f"{error}\n")
119
+
120
+ if result.used_existing_directory:
121
+ print(
122
+ "Updated existing project at "
123
+ f"{result.project_dir}. Overwrote scaffold-managed files and kept "
124
+ "other existing files and folders."
125
+ )
126
+ else:
127
+ print(f"Created project at {result.project_dir}")
128
+ return 0
129
+
130
+
131
+ if __name__ == "__main__":
132
+ raise SystemExit(main())
@@ -0,0 +1,174 @@
1
+ """Project scaffold orchestration."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+ from pathlib import Path
7
+ from subprocess import CalledProcessError, run # nosec B404
8
+
9
+ from .templater import quoted, render_template_tree
10
+
11
+ TEMPLATES_DIR = Path(__file__).parent / "templates"
12
+
13
+
14
+ @dataclass(frozen=True, slots=True)
15
+ class ProjectOptions:
16
+ """Options that control scaffold generation."""
17
+
18
+ project_name: str
19
+ python_version: str = "3.12"
20
+ description: str = "Canonical Python project scaffold."
21
+ author: str = ""
22
+ author_email: str = ""
23
+ interfaces: tuple[str, ...] = ("library",)
24
+ ci_provider: str = "none"
25
+ terraform: bool = False
26
+ output_dir: Path = Path.cwd()
27
+ git_init: bool = True
28
+ install: bool = True
29
+
30
+ @property
31
+ def package_name(self) -> str:
32
+ """Return the importable package name."""
33
+
34
+ return self.project_name.replace("-", "_")
35
+
36
+ @property
37
+ def project_title(self) -> str:
38
+ """Return a human-readable title."""
39
+
40
+ return self.project_name.replace("-", " ").replace("_", " ").title()
41
+
42
+ @property
43
+ def interfaces_normalised(self) -> tuple[str, ...]:
44
+ """Return de-duplicated interfaces with library always present."""
45
+
46
+ ordered: list[str] = []
47
+ for interface in self.interfaces:
48
+ if interface not in ordered:
49
+ ordered.append(interface)
50
+
51
+ if "library" not in ordered:
52
+ ordered.insert(0, "library")
53
+
54
+ return tuple(ordered)
55
+
56
+ @property
57
+ def has_cli(self) -> bool:
58
+ """Return whether the scaffold should include the CLI adapter."""
59
+
60
+ return "cli" in self.interfaces_normalised
61
+
62
+ @property
63
+ def has_web(self) -> bool:
64
+ """Return whether the scaffold should include the web adapter."""
65
+
66
+ return "web" in self.interfaces_normalised
67
+
68
+ @property
69
+ def python_major_minor(self) -> str:
70
+ """Return the major.minor part of the configured Python version."""
71
+
72
+ parts = self.python_version.split(".")
73
+ if len(parts) >= 2:
74
+ return ".".join(parts[:2])
75
+ return self.python_version
76
+
77
+ @property
78
+ def ruff_target_version(self) -> str:
79
+ """Return the Ruff target-version token."""
80
+
81
+ return f"py{self.python_major_minor.replace('.', '')}"
82
+
83
+
84
+ @dataclass(frozen=True, slots=True)
85
+ class ProjectCreationResult:
86
+ """Outcome of rendering a scaffold into a target directory."""
87
+
88
+ project_dir: Path
89
+ used_existing_directory: bool = False
90
+
91
+
92
+ def create_project(options: ProjectOptions) -> ProjectCreationResult:
93
+ """Render and optionally initialise a new project."""
94
+
95
+ project_dir = options.output_dir / options.project_name
96
+ used_existing_directory = project_dir.is_dir()
97
+ if project_dir.exists() and not used_existing_directory:
98
+ raise FileExistsError(project_dir)
99
+
100
+ project_dir.mkdir(parents=True, exist_ok=True)
101
+ context = _build_context(options)
102
+
103
+ for template_group in _template_groups(options):
104
+ render_template_tree(TEMPLATES_DIR / template_group, project_dir, context)
105
+
106
+ if options.git_init:
107
+ _run_command(["git", "init", "--initial-branch=main"], cwd=project_dir)
108
+
109
+ if options.install:
110
+ _run_command(["uv", "sync", "--all-groups"], cwd=project_dir)
111
+ if options.git_init:
112
+ _run_command(["uv", "run", "pre-commit", "install"], cwd=project_dir)
113
+
114
+ return ProjectCreationResult(
115
+ project_dir=project_dir,
116
+ used_existing_directory=used_existing_directory,
117
+ )
118
+
119
+
120
+ def _build_context(options: ProjectOptions) -> dict[str, object]:
121
+ """Build the template context from scaffold options."""
122
+
123
+ author_has_value = bool(options.author.strip())
124
+ author_email_has_value = bool(options.author_email.strip())
125
+
126
+ return {
127
+ "author": options.author,
128
+ "author_email": options.author_email,
129
+ "author_has_value": author_has_value,
130
+ "author_email_has_value": author_email_has_value,
131
+ "ci_provider": options.ci_provider,
132
+ "description": options.description,
133
+ "has_ci": options.ci_provider != "none",
134
+ "has_cli": options.has_cli,
135
+ "has_terraform": options.terraform,
136
+ "has_web": options.has_web,
137
+ "interfaces": options.interfaces_normalised,
138
+ "package_name": options.package_name,
139
+ "project_name": options.project_name,
140
+ "project_title": options.project_title,
141
+ "python_major_minor": options.python_major_minor,
142
+ "python_version": options.python_version,
143
+ "quoted": quoted,
144
+ "ruff_target_version": options.ruff_target_version,
145
+ }
146
+
147
+
148
+ def _template_groups(options: ProjectOptions) -> list[str]:
149
+ """Return the template groups that apply to the scaffold."""
150
+
151
+ groups = ["base"]
152
+ if options.has_cli:
153
+ groups.append("interfaces/cli")
154
+ if options.has_web:
155
+ groups.append("interfaces/web")
156
+ if options.ci_provider != "none":
157
+ groups.append(f"ci/{options.ci_provider}")
158
+ if options.terraform:
159
+ groups.append("infra/terraform")
160
+ return groups
161
+
162
+
163
+ def _run_command(command: list[str], *, cwd: Path) -> None:
164
+ """Run a command and convert common failures into clear runtime errors."""
165
+
166
+ try:
167
+ # Commands are built from a fixed list, never from shell input.
168
+ run(command, cwd=cwd, check=True) # nosec B603 # noqa: S603
169
+ except FileNotFoundError as error:
170
+ executable = command[0]
171
+ raise RuntimeError(f"Required executable not found: {executable}") from error
172
+ except CalledProcessError as error:
173
+ joined_command = " ".join(command)
174
+ raise RuntimeError(f"Command failed in {cwd}: {joined_command}") from error