gentem 0.1.3__py3-none-any.whl

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.
gentem/commands/new.py ADDED
@@ -0,0 +1,741 @@
1
+ """Implementation of the `gentem new` command."""
2
+
3
+ from datetime import datetime
4
+ from pathlib import Path
5
+ from typing import Optional
6
+
7
+ from rich import print
8
+ from rich.panel import Panel
9
+ from rich.table import Table
10
+
11
+ from gentem.template_engine import TemplateEngine, get_template_engine
12
+ from gentem.utils.validators import (
13
+ ValidationError,
14
+ validate_license_type,
15
+ validate_project_name,
16
+ validate_project_type,
17
+ validate_output_path,
18
+ )
19
+
20
+
21
+ def generate_slug(name: str) -> str:
22
+ """Generate a URL-safe slug from the project name."""
23
+ return name.lower().replace("_", "-").replace(" ", "-")
24
+
25
+
26
+ def generate_class_name(name: str) -> str:
27
+ """Generate a Python class name from the project name."""
28
+ # Convert to PascalCase
29
+ return "".join(word.capitalize() for word in name.split("_"))
30
+
31
+
32
+ def generate_context(
33
+ project_name: str,
34
+ project_type: str,
35
+ author: str,
36
+ description: str,
37
+ license_type: str,
38
+ ) -> dict:
39
+ """Generate the template context for a new project.
40
+
41
+ Args:
42
+ project_name: Name of the project.
43
+ project_type: Type of project (library, cli, script).
44
+ author: Author name.
45
+ description: Project description.
46
+ license_type: License type.
47
+
48
+ Returns:
49
+ Dictionary of template variables.
50
+ """
51
+ now = datetime.now()
52
+ year = now.year
53
+
54
+ return {
55
+ "project_name": project_name,
56
+ "project_slug": generate_slug(project_name),
57
+ "class_name": generate_class_name(project_name),
58
+ "project_type": project_type,
59
+ "author": author or "Gentem User",
60
+ "email": f"user@{generate_slug(project_name)}.dev",
61
+ "description": description or f"A {project_type} project generated by Gentem.",
62
+ "version": "0.1.0",
63
+ "python_version": "3.9",
64
+ "python_versions": ["3.10", "3.11", "3.12"],
65
+ "license": license_type.upper() if license_type else "MIT",
66
+ "year": year,
67
+ "month": now.strftime("%B"),
68
+ "cli_enabled": project_type == "cli",
69
+ "library_enabled": project_type == "library",
70
+ "script_enabled": project_type == "script",
71
+ }
72
+
73
+
74
+ def get_license_content(license_type: str, context: dict) -> str:
75
+ """Get the license content based on type.
76
+
77
+ Args:
78
+ license_type: Type of license.
79
+ context: Template context.
80
+
81
+ Returns:
82
+ License content string.
83
+ """
84
+ license_type = license_type.lower()
85
+
86
+ if license_type == "mit":
87
+ return f'''MIT License
88
+
89
+ Copyright (c) {context["year"]} {context["author"]}
90
+
91
+ Permission is hereby granted, free of charge, to any person obtaining a copy
92
+ of this software and associated documentation files (the "Software"), to deal
93
+ in the Software without restriction, including without limitation the rights
94
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
95
+ copies of the Software, and to permit persons to whom the Software is
96
+ furnished to do so, subject to the following conditions:
97
+
98
+ The above copyright notice and this permission notice shall be included in all
99
+ copies or substantial portions of the Software.
100
+
101
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
102
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
103
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
104
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
105
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
106
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
107
+ SOFTWARE.
108
+ '''
109
+ elif license_type == "apache":
110
+ return f'''Apache License
111
+ Version 2.0, January 2004
112
+ http://www.apache.org/
113
+
114
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
115
+
116
+ 1. Definitions.
117
+
118
+ "License" shall mean the terms and conditions for use, reproduction,
119
+ and distribution as defined by Sections 1 through 9 of this document.
120
+
121
+ "Licensor" shall mean the copyright owner or entity authorized by
122
+ the copyright owner that is granting the License.
123
+
124
+ "Legal Entity" shall mean the union of the acting entity and all
125
+ other entities that control, are controlled by, or are under common
126
+ control with that entity. For the purposes of this definition,
127
+ "control" means (i) the power, direct or indirect, to cause the
128
+ direction or management of such entity, whether by contract or
129
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
130
+ outstanding shares, or (iii) beneficial ownership of such entity.
131
+
132
+ "You" (or "Your") shall mean an individual or Legal Entity
133
+ exercising permissions granted by this License.
134
+
135
+ 2. Grant of Copyright License. Subject to the terms and conditions of
136
+ this License, each Contributor hereby grants to You a perpetual,
137
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
138
+ copyright license to reproduce, prepare Derivative Works of,
139
+ publicly display, publicly perform, sublicense, and distribute the
140
+ Work and such Derivative Works in Source or Object form.
141
+
142
+ 3. Grant of Patent License. Subject to the terms and conditions of
143
+ this License, each Contributor hereby grants to You a perpetual,
144
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
145
+ (except as stated in this section) patent license to make, have made,
146
+ use, offer to sell, sell, import, and otherwise transfer the Work,
147
+ where such license applies only to those patent claims licensable
148
+ by such Contributor that are necessarily infringed by their
149
+ Contribution(s) alone or by combination of their Contribution(s)
150
+ with the Work to which such Contribution(s) was submitted. If You
151
+ institute patent litigation against any entity (including a
152
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
153
+ or a Contribution incorporated within the Work constitutes direct
154
+ or contributory patent infringement, then any patent licenses
155
+ granted to You under this License for that Work shall terminate
156
+ as of the date such litigation is filed.
157
+
158
+ 4. Redistribution. You may reproduce and distribute copies of the
159
+ Work or Derivative Works thereof in any medium, with or without
160
+ modifications, and in Source or Object form, provided that You
161
+ meet the following conditions:
162
+
163
+ (a) You must give any other recipients of the Work or
164
+ Derivative Works a copy of this License; and
165
+
166
+ (b) You must cause any modified files to carry prominent notices
167
+ stating that You changed the files; and
168
+
169
+ (c) You must retain, in the Source form of any Derivative Works
170
+ that You distribute, all copyright, patent, trademark, and
171
+ attribution notices from the Source form of the Work,
172
+ excluding those notices that do not pertain to any part of the
173
+ Derivative Works; and
174
+
175
+ (d) If the Work includes a "NOTICE" text file as part of its
176
+ distribution, then any Derivative Works that You distribute must
177
+ include a readable copy of the attribution notices contained
178
+ within such NOTICE file, excluding those notices that do not
179
+ pertain to any part of the Derivative Works, in at least one
180
+ of the following places: within a NOTICE text file distributed
181
+ as part of the Derivative Works; within the Source form or
182
+ documentation, if provided along with the Derivative Works; or,
183
+ within a display generated by the Derivative Works, if and
184
+ wherever such third-party notices normally appear. The contents
185
+ of the NOTICE file are for informational purposes only and
186
+ do not modify the License. You may add Your own attribution
187
+ notices within Derivative Works that You distribute, alongside
188
+ or as an addendum to the NOTICE text from the Work, provided
189
+ that such additional attribution notices cannot be construed
190
+ as modifying the License.
191
+
192
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
193
+ any Contribution intentionally submitted for inclusion in the Work
194
+ by You to the Licensor shall be under the terms and conditions of
195
+ this License, without any additional terms or conditions.
196
+ Notwithstanding the above, nothing herein shall supersede or modify
197
+ the terms of any separate license agreement you may have executed
198
+ with Licensor regarding such Contributions.
199
+
200
+ 6. Trademarks. This License does not grant permission to use the
201
+ trade names, trademarks, service marks, or product names of the
202
+ Licensor, except as required for reasonable and customary use
203
+ in describing the origin of the Work and reproducing the content
204
+ of the NOTICE file.
205
+
206
+ 7. Disclaimer of Warranty. Unless required by applicable law or
207
+ agreed to in writing, Licensor provides the Work (and each
208
+ Contributor provides its Contributions) on an "AS IS" BASIS,
209
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
210
+ implied, including, without limitation, any warranties or conditions
211
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
212
+ PARTICULAR PURPOSE. You are solely responsible for determining the
213
+ appropriateness of using or redistributing the Work and assume any
214
+ risks associated with Your exercise of permissions under this License.
215
+
216
+ 8. Limitation of Liability. In no event and under no legal theory,
217
+ whether in tort (including negligence), contract, or otherwise,
218
+ unless required by applicable law (such as deliberate and grossly
219
+ negligent acts) or agreed to in writing, shall any Contributor be
220
+ liable to You for damages, including any direct, indirect, special,
221
+ incidental, or consequential damages of any character arising as a
222
+ result of this License or out of the use or inability to use the
223
+ Work (including but not limited to damages for loss of goodwill,
224
+ work stoppage, computer failure or malfunction, or any and all
225
+ other commercial damages or losses), even if such Contributor
226
+ has been advised of the possibility of such damages.
227
+
228
+ 9. Accepting Warranty or Additional Liability. While redistributing
229
+ the Work or Derivative Works thereof, You may choose to offer,
230
+ and charge a fee for, acceptance of support, warranty, indemnity,
231
+ or other liability obligations and/or rights consistent with this
232
+ License. However, in accepting such obligations, You may act only
233
+ on Your own behalf and on Your sole responsibility, not on behalf
234
+ of any other Contributor, and only if You agree to indemnify,
235
+ defend, and hold each Contributor harmless for any liability
236
+ incurred by, or claims asserted against, such Contributor by reason
237
+ of your accepting any such warranty or additional liability.
238
+
239
+ END OF TERMS AND CONDITIONS
240
+
241
+ APPENDIX: How to apply the Apache License to your work.
242
+
243
+ To apply the Apache License to your work, attach the following
244
+ boilerplate notice, with the fields enclosed by brackets "[]"
245
+ replaced with your own identifying information. (Don't include
246
+ the brackets!) The text should be enclosed in the appropriate
247
+ comment syntax for the file format. We also recommend that a
248
+ file or class name and description of purpose be included on the
249
+ same "printed page" as the copyright notice for easier
250
+ identification within third-party archives.
251
+
252
+ Copyright [yyyy] [name of copyright owner]
253
+
254
+ Licensed under the Apache License, Version 2.0 (the "License");
255
+ you may not use this file except in compliance with the License.
256
+ You may obtain a copy of the License at
257
+
258
+ http://www.apache.org/licenses/LICENSE-2.0
259
+
260
+ Unless required by applicable law or agreed to in writing, software
261
+ distributed under the License is distributed on an "AS IS" BASIS,
262
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
263
+ implied. See the License for the specific language governing
264
+ permissions and limitations under the License.
265
+ '''
266
+ elif license_type == "gpl":
267
+ return f'''GNU GENERAL PUBLIC LICENSE
268
+ Version 3, 29 June 2007
269
+
270
+ Copyright (C) {context["year"]} {context["author"]}
271
+
272
+ This program is free software: you can redistribute it and/or modify
273
+ it under the terms of the GNU General Public License as published by
274
+ the Free Software Foundation, either version 3 of the License, or
275
+ (at your option) any later version.
276
+
277
+ This program is distributed in the hope that it will be useful,
278
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
279
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
280
+ GNU General Public License for more details.
281
+
282
+ You should have received a copy of the GNU General Public License
283
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
284
+ '''
285
+ else:
286
+ return ""
287
+
288
+
289
+ def create_new_project(
290
+ project_name: str,
291
+ project_type: str = "library",
292
+ author: str = "",
293
+ description: str = "",
294
+ license_type: str = "mit",
295
+ dry_run: bool = False,
296
+ verbose: bool = False,
297
+ ) -> None:
298
+ """Create a new Python project.
299
+
300
+ Args:
301
+ project_name: Name of the project to create.
302
+ project_type: Type of project (library, cli, script).
303
+ author: Author name.
304
+ description: Project description.
305
+ license_type: License type.
306
+ dry_run: Preview without creating files.
307
+ verbose: Show verbose output.
308
+ """
309
+ # Validate inputs
310
+ try:
311
+ project_name = validate_project_name(project_name)
312
+ project_type = validate_project_type(project_type)
313
+ license_type = validate_license_type(license_type)
314
+ except ValidationError as e:
315
+ print(f"[red]Error: {e}[/]")
316
+ raise SystemExit(1)
317
+
318
+ # Generate template context
319
+ context = generate_context(
320
+ project_name=project_name,
321
+ project_type=project_type,
322
+ author=author,
323
+ description=description,
324
+ license_type=license_type,
325
+ )
326
+
327
+ # Determine output path
328
+ output_path = Path.cwd() / project_name
329
+
330
+ if verbose:
331
+ print(f"Output path: {output_path}")
332
+ print(f"Project type: {project_type}")
333
+
334
+ # Show summary
335
+ print(Panel(
336
+ f"[bold]Creating new {project_type} project:[/] [cyan]{project_name}[/]\n"
337
+ f"[dim]Author:[/] {context['author']}\n"
338
+ f"[dim]License:[/] {context['license']}\n"
339
+ f"[dim]Python:[/] {', '.join(context['python_versions'])}",
340
+ title="Gentem",
341
+ expand=False,
342
+ ))
343
+
344
+ if dry_run:
345
+ print("[yellow]DRY RUN - No files will be created[/]")
346
+ print(f"\nProject would be created at: {output_path}")
347
+ print("\nFiles that would be created:")
348
+ for item in get_project_files(project_name, project_type):
349
+ print(f" - {item}")
350
+ return
351
+
352
+ # Create project files
353
+ try:
354
+ create_project_files(
355
+ project_name=project_name,
356
+ project_type=project_type,
357
+ context=context,
358
+ output_path=output_path,
359
+ license_content=get_license_content(license_type, context),
360
+ )
361
+ print(f"\n[green]✓ Project '{project_name}' created successfully![/]")
362
+ print(f"\nNext steps:")
363
+ print(f" cd {project_name}")
364
+ if project_type == "library":
365
+ print(f" pip install -e .")
366
+ elif project_type == "cli":
367
+ print(f" pip install -e .")
368
+ print(f" {project_name} --help")
369
+ print(f" git init")
370
+ except Exception as e:
371
+ print(f"[red]Error creating project: {e}[/]")
372
+ raise SystemExit(1)
373
+
374
+
375
+ def get_project_files(project_name: str, project_type: str) -> list[str]:
376
+ """Get list of files that would be created for a project.
377
+
378
+ Args:
379
+ project_name: Name of the project.
380
+ project_type: Type of project.
381
+
382
+ Returns:
383
+ List of file paths.
384
+ """
385
+ slug = generate_slug(project_name)
386
+ files = [
387
+ f"{project_name}/",
388
+ f"{project_name}/pyproject.toml",
389
+ f"{project_name}/README.md",
390
+ f"{project_name}/LICENSE",
391
+ f"{project_name}/.gitignore",
392
+ ]
393
+
394
+ if project_type == "library":
395
+ files.extend([
396
+ f"{project_name}/app/",
397
+ f"{project_name}/app/__init__.py",
398
+ f"{project_name}/tests/",
399
+ f"{project_name}/tests/__init__.py",
400
+ f"{project_name}/tests/test_{slug}.py",
401
+ ])
402
+ elif project_type == "cli":
403
+ files.extend([
404
+ f"{project_name}/app/",
405
+ f"{project_name}/app/__init__.py",
406
+ f"{project_name}/app/cli.py",
407
+ f"{project_name}/app/main.py",
408
+ ])
409
+ elif project_type == "script":
410
+ files.extend([
411
+ f"{project_name}/{slug}.py",
412
+ ])
413
+
414
+ return files
415
+
416
+
417
+ def create_project_files(
418
+ project_name: str,
419
+ project_type: str,
420
+ context: dict,
421
+ output_path: Path,
422
+ license_content: str,
423
+ ) -> None:
424
+ """Create all project files.
425
+
426
+ Args:
427
+ project_name: Name of the project.
428
+ project_type: Type of project.
429
+ context: Template context.
430
+ output_path: Path to create the project at.
431
+ license_content: License file content.
432
+ """
433
+ slug = generate_slug(project_name)
434
+
435
+ # Create directories
436
+ output_path.mkdir(parents=True, exist_ok=False)
437
+
438
+ # Create pyproject.toml
439
+ scripts_line = f'{slug} = "{slug}.main:main"' if project_type == "cli" else ""
440
+ pyproject_content = f'''[build-system]
441
+ requires = ["setuptools>=61.0", "wheel"]
442
+ build-backend = "setuptools.build_meta"
443
+
444
+ [project]
445
+ name = "{slug}"
446
+ version = "{context["version"]}"
447
+ description = "{context["description"]}"
448
+ readme = "README.md"
449
+ license = {{text = "{context["license"]}"}}
450
+ requires-python = ">={context["python_version"]}"
451
+ authors = [{{name = "{context["author"]}", email = "{context["email"]}"}}]
452
+ keywords = ["{slug}"]
453
+ classifiers = [
454
+ "Development Status :: 3 - Alpha",
455
+ "Intended Audience :: Developers",
456
+ "License :: OSI Approved :: {context["license"]} License",
457
+ "Programming Language :: Python :: 3",
458
+ ]
459
+ dependencies = []
460
+
461
+ [project.optional-dependencies]
462
+ dev = [
463
+ "pytest>=7.4.0",
464
+ "black>=23.0.0",
465
+ "ruff>=0.1.0",
466
+ "mypy>=1.5.0",
467
+ ]
468
+
469
+ [project.scripts]
470
+ {str(scripts_line)}
471
+
472
+ [tool.setuptools.packages.find]
473
+ where = ["app"]
474
+
475
+ [tool.pytest.ini_options]
476
+ testpaths = ["tests"]
477
+ python_files = ["test_*.py"]
478
+ addopts = "-v --tb=short"
479
+
480
+ [tool.black]
481
+ line-length = 100
482
+ target-version = ["py39", "py310", "py311", "py312"]
483
+
484
+ [tool.ruff]
485
+ line-length = 100
486
+ select = ["E", "W", "F", "I", "B", "C4", "UP"]
487
+ ignore = ["E501", "B008", "C901"]
488
+ '''
489
+
490
+ # Create README.md
491
+ readme_content = f'''# {project_name}
492
+
493
+ {context["description"]}
494
+
495
+ ## Installation
496
+
497
+ ```bash
498
+ pip install {slug}
499
+ ```
500
+
501
+ ## Usage
502
+
503
+ ```python
504
+ import {slug}
505
+ ```
506
+
507
+ ## Development
508
+
509
+ ```bash
510
+ # Install development dependencies
511
+ pip install -e ".[dev]"
512
+
513
+ # Run tests
514
+ pytest
515
+
516
+ # Format code
517
+ black .
518
+ ruff check --fix .
519
+ ```
520
+
521
+ ## License
522
+
523
+ This project is licensed under the {context["license"]} License - see the [LICENSE](LICENSE) file for details.
524
+ '''
525
+
526
+ # Create .gitignore
527
+ gitignore_content = '''# Byte-compiled / optimized / DLL files
528
+ __pycache__/
529
+ *.py[cod]
530
+ *$py.class
531
+
532
+ # C extensions
533
+ *.so
534
+
535
+ # Distribution / packaging
536
+ .Python
537
+ build/
538
+ develop-eggs/
539
+ dist/
540
+ downloads/
541
+ eggs/
542
+ .eggs/
543
+ lib/
544
+ lib64/
545
+ parts/
546
+ sdist/
547
+ var/
548
+ wheels/
549
+ pip-wheel-metadata/
550
+ share/python-wheels/
551
+ *.egg-info/
552
+ .installed.cfg
553
+ *.egg
554
+ MANIFEST
555
+
556
+ # PyInstaller
557
+ *.manifest
558
+ *.spec
559
+
560
+ # Installer logs
561
+ pip-log.txt
562
+ pip-delete-this-directory.txt
563
+
564
+ # Unit test / coverage reports
565
+ htmlcov/
566
+ .tox/
567
+ .nox/
568
+ .coverage
569
+ .coverage.*
570
+ .cache
571
+ nosetests.xml
572
+ coverage.xml
573
+ *.cover
574
+ *.py,cover
575
+ .hypothesis/
576
+ .pytest_cache/
577
+
578
+ # Translations
579
+ *.mo
580
+ *.pot
581
+
582
+ # Django stuff:
583
+ *.log
584
+ local_settings.py
585
+ db.sqlite3
586
+ db.sqlite3-journal
587
+
588
+ # Flask stuff:
589
+ instance/
590
+ .webassets-cache
591
+
592
+ # Scrapy stuff:
593
+ .scrapy
594
+
595
+ # Sphinx documentation
596
+ docs/_build/
597
+
598
+ # PyBuilder
599
+ target/
600
+
601
+ # Jupyter Notebook
602
+ .ipynb_checkpoints
603
+
604
+ # IPython
605
+ profile_default/
606
+ ipython_config.py
607
+
608
+ # pyenv
609
+ .python-version
610
+
611
+ # pipenv
612
+ Pipfile.lock
613
+
614
+ # PEP 582
615
+ __pypackages__/
616
+
617
+ # Celery stuff
618
+ celerybeat-schedule
619
+ celerybeat.pid
620
+
621
+ # SageMath parsed files
622
+ *.sage.py
623
+
624
+ # Environments
625
+ .env
626
+ .venv
627
+ env/
628
+ venv/
629
+ ENV/
630
+ env.bak/
631
+ venv.bak/
632
+
633
+ # Spyder project settings
634
+ .spyderproject
635
+ .spyproject
636
+
637
+ # Rope project settings
638
+ .ropeproject
639
+
640
+ # mkdocs documentation
641
+ /site
642
+
643
+ # mypy
644
+ .mypy_cache/
645
+ .dmypy.json
646
+ dmypy.json
647
+
648
+ # Pyre type checker
649
+ .pyre/
650
+
651
+ # IDEs
652
+ .vscode/
653
+ .idea/
654
+ *.swp
655
+ *.swo
656
+ *~
657
+
658
+ # OS
659
+ .DS_Store
660
+ Thumbs.db
661
+ '''
662
+
663
+ # Write common files
664
+ (output_path / "pyproject.toml").write_text(pyproject_content, encoding="utf-8")
665
+ (output_path / "README.md").write_text(readme_content, encoding="utf-8")
666
+ (output_path / ".gitignore").write_text(gitignore_content, encoding="utf-8")
667
+ if license_content:
668
+ (output_path / "LICENSE").write_text(license_content, encoding="utf-8")
669
+
670
+ # Create type-specific files
671
+ if project_type == "library":
672
+ app_dir = output_path / "app"
673
+ app_dir.mkdir(parents=True, exist_ok=True)
674
+ (app_dir / "__init__.py").write_text(f'"""{project_name} - {context["description"]}."""\n', encoding="utf-8")
675
+
676
+ tests_dir = output_path / "tests"
677
+ tests_dir.mkdir(parents=True, exist_ok=True)
678
+ (tests_dir / "__init__.py").write_text('"""Tests for app."""\n', encoding="utf-8")
679
+ (tests_dir / f"test_{slug}.py").write_text(f'''"""Tests for {slug}."""
680
+
681
+ import pytest
682
+
683
+ from app import __version__
684
+
685
+
686
+ def test_version():
687
+ """Test that version is set correctly."""
688
+ assert __version__ == "{context["version"]}"
689
+
690
+
691
+ def test_import():
692
+ """Test that the package can be imported."""
693
+ import app
694
+ assert app is not None
695
+ ''', encoding="utf-8")
696
+
697
+ elif project_type == "cli":
698
+ app_dir = output_path / "app"
699
+ app_dir.mkdir(parents=True, exist_ok=True)
700
+
701
+ (app_dir / "__init__.py").write_text(f'"""{project_name} - {context["description"]}."""\n', encoding="utf-8")
702
+ (app_dir / "cli.py").write_text(f'''"""CLI commands for {project_name}."""
703
+
704
+ import typer
705
+
706
+ app = typer.Typer()
707
+
708
+
709
+ @app.command()
710
+ def hello(name: str = "World") -> None:
711
+ """Say hello to someone."""
712
+ print(f"Hello, {{name}}!")
713
+
714
+
715
+ @app.command()
716
+ def version() -> None:
717
+ """Show the version."""
718
+ print("{context["version"]}")
719
+ ''', encoding="utf-8")
720
+ (app_dir / "main.py").write_text(f'''"""Main entry point for {project_name}."""
721
+
722
+ from app.cli import app
723
+
724
+
725
+ def main() -> None:
726
+ """Entry point for the CLI."""
727
+ app()
728
+ ''', encoding="utf-8")
729
+
730
+ elif project_type == "script":
731
+ (output_path / f"{slug}.py").write_text(f'''#!/usr/bin/env python3
732
+ """{project_name} - {context["description"]}."""
733
+
734
+ def main() -> None:
735
+ """Main entry point."""
736
+ print("Hello from {project_name}!")
737
+
738
+
739
+ if __name__ == "__main__":
740
+ main()
741
+ ''', encoding="utf-8")