pytemplate-uv 0.1.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 (63) hide show
  1. pytemplate_uv-0.1.0/.gitignore +82 -0
  2. pytemplate_uv-0.1.0/.python-version +1 -0
  3. pytemplate_uv-0.1.0/LICENSE +21 -0
  4. pytemplate_uv-0.1.0/PKG-INFO +142 -0
  5. pytemplate_uv-0.1.0/README.md +105 -0
  6. pytemplate_uv-0.1.0/pyproject.toml +103 -0
  7. pytemplate_uv-0.1.0/pytemplate/__init__.py +1 -0
  8. pytemplate_uv-0.1.0/pytemplate/main.py +142 -0
  9. pytemplate_uv-0.1.0/pytemplate_uv.egg-info/PKG-INFO +142 -0
  10. pytemplate_uv-0.1.0/pytemplate_uv.egg-info/SOURCES.txt +74 -0
  11. pytemplate_uv-0.1.0/pytemplate_uv.egg-info/dependency_links.txt +1 -0
  12. pytemplate_uv-0.1.0/pytemplate_uv.egg-info/entry_points.txt +3 -0
  13. pytemplate_uv-0.1.0/pytemplate_uv.egg-info/requires.txt +16 -0
  14. pytemplate_uv-0.1.0/pytemplate_uv.egg-info/top_level.txt +1 -0
  15. pytemplate_uv-0.1.0/setup.cfg +4 -0
  16. pytemplate_uv-0.1.0/templates/fastapi-template/.github/workflows/ci.yml +30 -0
  17. pytemplate_uv-0.1.0/templates/fastapi-template/.gitignore +89 -0
  18. pytemplate_uv-0.1.0/templates/fastapi-template/cookiecutter.json +23 -0
  19. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/Dockerfile +38 -0
  20. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/Makefile +145 -0
  21. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/README.md +99 -0
  22. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/pyproject.toml +115 -0
  23. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/tests/__init__.py +0 -0
  24. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/tests/conftest.py +85 -0
  25. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/tests/test_cli.py +33 -0
  26. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/tests/test_example.py +104 -0
  27. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/{{cookiecutter.envfile}} +40 -0
  28. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/{{cookiecutter.package_name}}/__init__.py +0 -0
  29. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/{{cookiecutter.package_name}}/__pycache__/__init__.cpython-311.pyc +0 -0
  30. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/{{cookiecutter.package_name}}/__pycache__/db.cpython-311.pyc +0 -0
  31. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/{{cookiecutter.package_name}}/__pycache__/main.cpython-311.pyc +0 -0
  32. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/{{cookiecutter.package_name}}/__pycache__/models.cpython-311.pyc +0 -0
  33. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/{{cookiecutter.package_name}}/cli.py +61 -0
  34. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/{{cookiecutter.package_name}}/core/__pycache__/config.cpython-311.pyc +0 -0
  35. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/{{cookiecutter.package_name}}/core/__pycache__/exceptions.cpython-311.pyc +0 -0
  36. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/{{cookiecutter.package_name}}/core/__pycache__/middleware.cpython-311.pyc +0 -0
  37. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/{{cookiecutter.package_name}}/core/config.py +48 -0
  38. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/{{cookiecutter.package_name}}/core/exceptions.py +73 -0
  39. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/{{cookiecutter.package_name}}/core/middleware.py +100 -0
  40. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/{{cookiecutter.package_name}}/db.py +12 -0
  41. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/{{cookiecutter.package_name}}/main.py +62 -0
  42. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/{{cookiecutter.package_name}}/models.py +7 -0
  43. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/{{cookiecutter.package_name}}/routers/__init__.py +0 -0
  44. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/{{cookiecutter.package_name}}/routers/__pycache__/__init__.cpython-311.pyc +0 -0
  45. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/{{cookiecutter.package_name}}/routers/__pycache__/example.cpython-311.pyc +0 -0
  46. pytemplate_uv-0.1.0/templates/fastapi-template/{{cookiecutter.project_name}}/{{cookiecutter.package_name}}/routers/example.py +102 -0
  47. pytemplate_uv-0.1.0/templates/pyproject-template/cookiecutter.json +24 -0
  48. pytemplate_uv-0.1.0/templates/pyproject-template/{{cookiecutter.project_name}}/Dockerfile +35 -0
  49. pytemplate_uv-0.1.0/templates/pyproject-template/{{cookiecutter.project_name}}/Makefile +145 -0
  50. pytemplate_uv-0.1.0/templates/pyproject-template/{{cookiecutter.project_name}}/README.md +80 -0
  51. pytemplate_uv-0.1.0/templates/pyproject-template/{{cookiecutter.project_name}}/pyproject.toml +106 -0
  52. pytemplate_uv-0.1.0/templates/pyproject-template/{{cookiecutter.project_name}}/tests/__init__.py +0 -0
  53. pytemplate_uv-0.1.0/templates/pyproject-template/{{cookiecutter.project_name}}/tests/test_cli.py +33 -0
  54. pytemplate_uv-0.1.0/templates/pyproject-template/{{cookiecutter.project_name}}/tests/test_main.py +2 -0
  55. pytemplate_uv-0.1.0/templates/pyproject-template/{{cookiecutter.project_name}}/{{cookiecutter.envfile}} +41 -0
  56. pytemplate_uv-0.1.0/templates/pyproject-template/{{cookiecutter.project_name}}/{{cookiecutter.package_name}}/__init__.py +0 -0
  57. pytemplate_uv-0.1.0/templates/pyproject-template/{{cookiecutter.project_name}}/{{cookiecutter.package_name}}/__pycache__/__init__.cpython-311.pyc +0 -0
  58. pytemplate_uv-0.1.0/templates/pyproject-template/{{cookiecutter.project_name}}/{{cookiecutter.package_name}}/__pycache__/example_module.cpython-311.pyc +0 -0
  59. pytemplate_uv-0.1.0/templates/pyproject-template/{{cookiecutter.project_name}}/{{cookiecutter.package_name}}/__pycache__/main.cpython-311.pyc +0 -0
  60. pytemplate_uv-0.1.0/templates/pyproject-template/{{cookiecutter.project_name}}/{{cookiecutter.package_name}}/cli.py +61 -0
  61. pytemplate_uv-0.1.0/templates/pyproject-template/{{cookiecutter.project_name}}/{{cookiecutter.package_name}}/example_module.py +1 -0
  62. pytemplate_uv-0.1.0/templates/pyproject-template/{{cookiecutter.project_name}}/{{cookiecutter.package_name}}/main.py +5 -0
  63. pytemplate_uv-0.1.0/tests/test_cli.py +47 -0
@@ -0,0 +1,82 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ build/
8
+ develop-eggs/
9
+ dist/
10
+ downloads/
11
+ eggs/
12
+ .eggs/
13
+ lib/
14
+ lib64/
15
+ parts/
16
+ sdist/
17
+ var/
18
+ wheels/
19
+ *.egg-info/
20
+ .installed.cfg
21
+ *.egg
22
+ MANIFEST
23
+
24
+ # Virtual Environments
25
+ .env
26
+ .venv
27
+ venv/
28
+ ENV/
29
+ env.bak/
30
+ venv.bak/
31
+
32
+ # IDEs and Editors
33
+ .idea/
34
+ .vscode/
35
+ *.swp
36
+ *.swo
37
+ *~
38
+
39
+ # OS Generated Files
40
+ .DS_Store
41
+ .DS_Store?
42
+ ._*
43
+ .Spotlight-V100
44
+ .Trashes
45
+ ehthumbs.db
46
+ Thumbs.db
47
+
48
+ # Testing and Coverage
49
+ .tox/
50
+ .coverage
51
+ .coverage.*
52
+ .cache
53
+ .pytest_cache/
54
+ htmlcov/
55
+ coverage.xml
56
+ *.cover
57
+ .hypothesis/
58
+
59
+ # Logs
60
+ *.log
61
+ logs/
62
+
63
+ # UV Package Manager
64
+ uv.lock
65
+
66
+ # Jupyter Notebooks
67
+ .ipynb_checkpoints
68
+
69
+ # Mypy
70
+ .mypy_cache/
71
+
72
+ # Compiled files
73
+ *.pyc
74
+ *.pyo
75
+ *.pyd
76
+
77
+ # Project Specific Ignores
78
+ *.sqlite3
79
+ .env.local
80
+ .env.development.local
81
+ .env.test.local
82
+ .env.production.local
@@ -0,0 +1 @@
1
+ 3.11
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Leo Liu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,142 @@
1
+ Metadata-Version: 2.2
2
+ Name: pytemplate-uv
3
+ Version: 0.1.0
4
+ Summary: A template for creating Python projects using uv package manager
5
+ Author-email: Leo Liu <yuxuzi@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/yuxuzi/pytemplate-uv
8
+ Project-URL: Repository, https://github.com/yuxuzi/pytemplate-uv
9
+ Project-URL: Issues, https://github.com/yuxuzi/pytemplate-uv/issues
10
+ Project-URL: Changelog, https://github.com/yuxuzi/pytemplate-uv/blob/main/CHANGELOG.md
11
+ Keywords: python,template,project-generator,uv,cookiecutter,cli
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
+ Classifier: Topic :: Utilities
19
+ Classifier: Typing :: Typed
20
+ Requires-Python: >=3.11
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: typer>=0.9.0
24
+ Requires-Dist: rich>=13.7.0
25
+ Requires-Dist: cookiecutter>=2.5.0
26
+ Requires-Dist: pytest>=7.4.4
27
+ Provides-Extra: dev
28
+ Requires-Dist: ruff>=0.1.9; extra == "dev"
29
+ Requires-Dist: black>=23.12.1; extra == "dev"
30
+ Requires-Dist: pytest>=7.4.4; extra == "dev"
31
+ Requires-Dist: pre-commit>=3.6.0; extra == "dev"
32
+ Requires-Dist: mypy>=1.7.1; extra == "dev"
33
+ Requires-Dist: coverage>=7.3.2; extra == "dev"
34
+ Provides-Extra: docs
35
+ Requires-Dist: mkdocs>=1.5.3; extra == "docs"
36
+ Requires-Dist: mkdocstrings[python]>=0.24.0; extra == "docs"
37
+
38
+ # PyTemplate UV
39
+
40
+ ## Overview
41
+
42
+ PyTemplate UV is a powerful CLI tool for creating Python project templates using the `uv` package manager. It provides a seamless way to generate standardized project structures with modern development practices.
43
+
44
+ ## Features
45
+
46
+ - 🚀 Quick project initialization
47
+ - 🔧 Support for multiple project templates (FastAPI, Standard Python)
48
+ - 📦 Integrated with `uv` package management
49
+ - 🧪 Comprehensive testing infrastructure
50
+ - 🔍 Linting and type checking support
51
+
52
+ ## Prerequisites
53
+
54
+ - Python 3.11+
55
+ - `uv` package manager
56
+ - `cookiecutter`
57
+
58
+ ## Installation
59
+
60
+ ```bash
61
+ pip install pytemplate-uv
62
+ # or
63
+ uv pip install pytemplate-uv
64
+ ```
65
+
66
+ ## Usage
67
+
68
+ ### Create a Project
69
+
70
+ ```bash
71
+ # Create a standard Python project (default)
72
+ pytemplate-uv create-project
73
+
74
+ # Create a FastAPI project
75
+ pytemplate-uv create-project --template fastapi
76
+
77
+ # Create a project with a custom name
78
+ pytemplate-uv create-project --name my-awesome-project
79
+
80
+ # Create a project with custom template and name
81
+ pytemplate-uv create-project --template fastapi --name my-api-project
82
+ ```
83
+
84
+ ### Project Creation Options
85
+
86
+ - `--template`: Choose the project template (default: pyproject)
87
+ - Options: `pyproject`, `fastapi`
88
+ - `--name`: Specify a custom project name
89
+ - Additional template-specific options can be passed as needed
90
+
91
+ ### Next Steps After Project Creation
92
+
93
+ 1. `cd` into your project directory
94
+ 2. Run `uv venv` to create a virtual environment
95
+ 3. Run `uv pip install -e .` to install dependencies
96
+ 4. Run `make setup` to set up the development environment
97
+
98
+ ## Development
99
+
100
+ ### Setup
101
+
102
+ 1. Clone the repository
103
+ 2. Create a virtual environment:
104
+ ```bash
105
+ uv venv
106
+ source .venv/bin/activate
107
+ ```
108
+
109
+ 3. Install development dependencies:
110
+ ```bash
111
+ uv pip install -e .[dev]
112
+ ```
113
+
114
+ ### Running Tests
115
+
116
+ ```bash
117
+ pytest
118
+ ```
119
+
120
+ ### Linting
121
+
122
+ ```bash
123
+ ruff check .
124
+ black .
125
+ mypy .
126
+ ```
127
+
128
+ ## Contributing
129
+
130
+ Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.
131
+
132
+ ## License
133
+
134
+ MIT License - See [LICENSE](LICENSE) for details.
135
+
136
+ ## Contact
137
+
138
+ Leo Liu - [GitHub](https://github.com/yuxuzi)
139
+
140
+ ---
141
+
142
+ *Simplifying Python project creation with modern best practices* 🐍✨
@@ -0,0 +1,105 @@
1
+ # PyTemplate UV
2
+
3
+ ## Overview
4
+
5
+ PyTemplate UV is a powerful CLI tool for creating Python project templates using the `uv` package manager. It provides a seamless way to generate standardized project structures with modern development practices.
6
+
7
+ ## Features
8
+
9
+ - 🚀 Quick project initialization
10
+ - 🔧 Support for multiple project templates (FastAPI, Standard Python)
11
+ - 📦 Integrated with `uv` package management
12
+ - 🧪 Comprehensive testing infrastructure
13
+ - 🔍 Linting and type checking support
14
+
15
+ ## Prerequisites
16
+
17
+ - Python 3.11+
18
+ - `uv` package manager
19
+ - `cookiecutter`
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ pip install pytemplate-uv
25
+ # or
26
+ uv pip install pytemplate-uv
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ### Create a Project
32
+
33
+ ```bash
34
+ # Create a standard Python project (default)
35
+ pytemplate-uv create-project
36
+
37
+ # Create a FastAPI project
38
+ pytemplate-uv create-project --template fastapi
39
+
40
+ # Create a project with a custom name
41
+ pytemplate-uv create-project --name my-awesome-project
42
+
43
+ # Create a project with custom template and name
44
+ pytemplate-uv create-project --template fastapi --name my-api-project
45
+ ```
46
+
47
+ ### Project Creation Options
48
+
49
+ - `--template`: Choose the project template (default: pyproject)
50
+ - Options: `pyproject`, `fastapi`
51
+ - `--name`: Specify a custom project name
52
+ - Additional template-specific options can be passed as needed
53
+
54
+ ### Next Steps After Project Creation
55
+
56
+ 1. `cd` into your project directory
57
+ 2. Run `uv venv` to create a virtual environment
58
+ 3. Run `uv pip install -e .` to install dependencies
59
+ 4. Run `make setup` to set up the development environment
60
+
61
+ ## Development
62
+
63
+ ### Setup
64
+
65
+ 1. Clone the repository
66
+ 2. Create a virtual environment:
67
+ ```bash
68
+ uv venv
69
+ source .venv/bin/activate
70
+ ```
71
+
72
+ 3. Install development dependencies:
73
+ ```bash
74
+ uv pip install -e .[dev]
75
+ ```
76
+
77
+ ### Running Tests
78
+
79
+ ```bash
80
+ pytest
81
+ ```
82
+
83
+ ### Linting
84
+
85
+ ```bash
86
+ ruff check .
87
+ black .
88
+ mypy .
89
+ ```
90
+
91
+ ## Contributing
92
+
93
+ Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.
94
+
95
+ ## License
96
+
97
+ MIT License - See [LICENSE](LICENSE) for details.
98
+
99
+ ## Contact
100
+
101
+ Leo Liu - [GitHub](https://github.com/yuxuzi)
102
+
103
+ ---
104
+
105
+ *Simplifying Python project creation with modern best practices* 🐍✨
@@ -0,0 +1,103 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.2.0", "wheel", "setuptools_scm[toml]>=7.1.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "pytemplate-uv"
7
+ version = "0.1.0"
8
+ description = "A template for creating Python projects using uv package manager"
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = {text = "MIT"}
12
+ authors = [
13
+ {name = "Leo Liu", email = "yuxuzi@gmail.com"}
14
+ ]
15
+ keywords = [
16
+ "python",
17
+ "template",
18
+ "project-generator",
19
+ "uv",
20
+ "cookiecutter",
21
+ "cli"
22
+ ]
23
+ classifiers = [
24
+ "Development Status :: 3 - Alpha",
25
+ "Intended Audience :: Developers",
26
+ "License :: OSI Approved :: MIT License",
27
+ "Programming Language :: Python :: 3.11",
28
+ "Programming Language :: Python :: 3.12",
29
+ "Topic :: Software Development :: Libraries :: Python Modules",
30
+ "Topic :: Utilities",
31
+ "Typing :: Typed"
32
+ ]
33
+
34
+ dependencies = [
35
+ "typer>=0.9.0",
36
+ "rich>=13.7.0",
37
+ "cookiecutter>=2.5.0",
38
+ "pytest>=7.4.4"
39
+ ]
40
+
41
+ [project.urls]
42
+ Homepage = "https://github.com/yuxuzi/pytemplate-uv"
43
+ Repository = "https://github.com/yuxuzi/pytemplate-uv"
44
+ Issues = "https://github.com/yuxuzi/pytemplate-uv/issues"
45
+ Changelog = "https://github.com/yuxuzi/pytemplate-uv/blob/main/CHANGELOG.md"
46
+
47
+ [project.optional-dependencies]
48
+ dev = [
49
+ "ruff>=0.1.9",
50
+ "black>=23.12.1",
51
+ "pytest>=7.4.4",
52
+ "pre-commit>=3.6.0",
53
+ "mypy>=1.7.1",
54
+ "coverage>=7.3.2"
55
+ ]
56
+ docs = [
57
+ "mkdocs>=1.5.3",
58
+ "mkdocstrings[python]>=0.24.0"
59
+ ]
60
+
61
+ [tool.setuptools]
62
+ packages = ["pytemplate"]
63
+
64
+ [project.scripts]
65
+ # Project management scripts
66
+ pytemplate = "pytemplate.main:app"
67
+ create-project = "pytemplate.main:app"
68
+
69
+ [tool.setuptools.package-data]
70
+ "pytemplate" = ["../templates/*", "../templates/**/*", "../templates/**/**/*"]
71
+
72
+ [tool.setuptools_scm]
73
+ write_to = "version.py"
74
+
75
+ [tool.ruff]
76
+ line-length = 100
77
+ target-version = "py311"
78
+ select = [
79
+ "E", # pycodestyle errors
80
+ "W", # pycodestyle warnings
81
+ "F", # pyflakes
82
+ "I", # isort
83
+ "B", # flake8-bugbear
84
+ "UP", # pyupgrade
85
+ "C90", # mccabe complexity
86
+ "N", # pep8-naming
87
+ "D", # pydocstyle
88
+ ]
89
+ ignore = [
90
+ "D100", # Missing docstring in public module
91
+ "D101", # Missing docstring in public class
92
+ ]
93
+
94
+ [tool.ruff.per-file-ignores]
95
+ "tests/**" = ["D103"] # Ignore missing docstrings in tests
96
+
97
+ [tool.black]
98
+ line-length = 100
99
+ target-version = ['py311']
100
+
101
+ [tool.mypy]
102
+ python_version = "3.11"
103
+ warn_return_any = true
@@ -0,0 +1 @@
1
+ # Pytemplate package initialization
@@ -0,0 +1,142 @@
1
+ """Command-line interface for creating Python projects from templates."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ import subprocess
7
+ from pathlib import Path
8
+
9
+ import typer
10
+ from rich.console import Console
11
+ from rich.panel import Panel
12
+ from rich.text import Text
13
+
14
+ app = typer.Typer(
15
+ name="pytemplate-uv",
16
+ help="Create Python projects from templates using uv package manager",
17
+ add_completion=True,
18
+ rich_help_panel=True,
19
+ )
20
+ console = Console()
21
+
22
+
23
+ def _validate_template(template: str) -> Path:
24
+ """Validate and return the path to the specified template.
25
+
26
+ Args:
27
+ template (str): Name of the project template.
28
+
29
+ Returns:
30
+ Path: Path to the template directory.
31
+
32
+ Raises:
33
+ typer.BadParameter: If template is not found.
34
+
35
+ """
36
+ templates_dir = Path(__file__).parent.parent / "templates"
37
+ template_path = templates_dir / f"{template}-template"
38
+
39
+ console.print(f"[yellow]Checking template path: {template_path}[/]")
40
+
41
+ if not template_path.exists():
42
+ available_templates = [
43
+ d.name.replace("-template", "") for d in templates_dir.glob("*-template") if d.is_dir()
44
+ ]
45
+
46
+ error_text = Text("Template not found!", style="bold red")
47
+ suggestion_text = Text(
48
+ f"\nAvailable templates: {', '.join(available_templates)}", style="yellow"
49
+ )
50
+
51
+ console.print(Panel(Text.assemble(error_text, suggestion_text), border_style="red"))
52
+ raise typer.BadParameter(f"Template '{template}' not found")
53
+
54
+ console.print(f"[green]Using template path: {template_path}[/]")
55
+ return template_path
56
+
57
+
58
+ def _get_context() -> dict[str, str]:
59
+ """Retrieve context variables for project template.
60
+
61
+ Returns:
62
+ A dictionary of context variables.
63
+
64
+ """
65
+ return {
66
+ "author": os.environ.get("USER", "your name"),
67
+ "email": os.environ.get("USER_EMAIL", "your@email.com"),
68
+ "github_username": os.environ.get("GITHUB_USERNAME", "your_username"),
69
+ }
70
+
71
+
72
+ def _build_cookiecutter_command(
73
+ template_path: Path, context: dict, no_input: bool = False, force: bool = False
74
+ ) -> list[str]:
75
+ """Build the cookiecutter command with appropriate options.
76
+ Args:
77
+ template_path: Path to the project template
78
+ context: Context variables for the template
79
+ no_input: Whether to skip interactive prompts
80
+ force: Whether to overwrite existing project directory
81
+ Returns:
82
+ A list of command arguments.
83
+
84
+ """ # noqa: D205, D411
85
+ cookiecutter_cmd = [
86
+ "cookiecutter",
87
+ str(template_path),
88
+ *[f"{k}={v}" for k, v in context.items()],
89
+ ]
90
+
91
+ if no_input:
92
+ cookiecutter_cmd.append("--no-input")
93
+
94
+ if force:
95
+ cookiecutter_cmd.append("--overwrite-if-exists")
96
+
97
+ return cookiecutter_cmd
98
+
99
+
100
+ @app.command()
101
+ def create_project(
102
+ project_name: str = typer.Argument(None, help="Name of the project"),
103
+ template: str = typer.Option(
104
+ "pyproject", "--template", "-t", help="Template to use for project creation"
105
+ ),
106
+ no_input: bool = typer.Option(
107
+ False, "--no-input", "-y", help="Skip prompts and use default values"
108
+ ),
109
+ force: bool = typer.Option(False, "--force", "-f", help="Overwrite existing project directory"),
110
+ ):
111
+ """Create a new project from a specified template."""
112
+ template_path = _validate_template(template)
113
+ context = _get_context()
114
+ if project_name:
115
+ context["project_name"] = project_name
116
+
117
+ cookiecutter_cmd = _build_cookiecutter_command(template_path, context, no_input, force)
118
+
119
+ try:
120
+ result = subprocess.run(cookiecutter_cmd, text=True, check=True)
121
+ console.print("[green]Project created successfully![/]")
122
+
123
+ if result.stdout:
124
+ console.print(f"[green]{result.stdout.strip()}[/]")
125
+
126
+ except subprocess.CalledProcessError as e:
127
+ console.print("[red]Project creation failed:[/]")
128
+ console.print(f"Command: {' '.join(e.cmd)}")
129
+
130
+ if e.stdout:
131
+ console.print("[yellow]Standard Output:[/]")
132
+ console.print(e.stdout)
133
+
134
+ if e.stderr:
135
+ console.print("[red]Error Output:[/]")
136
+ console.print(e.stderr)
137
+
138
+ raise typer.Exit(code=1) # noqa: B904
139
+
140
+
141
+ if __name__ == "__main__":
142
+ app()