Skip to content

Commit fbcadd8

Browse files
Merge pull request #55 from pythoninthegrass/copier
ci: Convert to copier
2 parents 6a4a50e + 28a795c commit fbcadd8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+876
-613
lines changed

.copier/.copier-answers.yml.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{ _copier_answers|to_json -}}

.copier/update_dotenv.py

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,29 @@
1-
#!/usr/bin/env python3
2-
"""
3-
This script updates the .env file with values from the Copier answers.
4-
It allows the .env file to be a regular file (not a template) that works with or without Copier.
5-
"""
6-
7-
from pathlib import Path
81
import json
9-
import yaml
2+
from pathlib import Path
103

114
# Update the .env file with the answers from the .copier-answers.yml file
125
# without using Jinja2 templates in the .env file, this way the code works as is
136
# without needing Copier, but if Copier is used, the .env file will be updated
147
root_path = Path(__file__).parent.parent
15-
answers_path = root_path / ".copier-answers.yml"
16-
17-
# Load the answers from YAML format
18-
with open(answers_path, "r") as f:
19-
answers_yaml = f.read()
20-
# Convert YAML to Python dict
21-
answers = yaml.safe_load(answers_yaml)
22-
8+
answers_path = Path(__file__).parent / ".copier-answers.yml"
9+
answers = json.loads(answers_path.read_text())
2310
env_path = root_path / ".env"
24-
if not env_path.exists():
25-
env_example_path = root_path / ".env.example"
26-
if env_example_path.exists():
27-
with open(env_example_path, "r") as f:
28-
env_content = f.read()
29-
else:
30-
env_content = ""
31-
else:
32-
with open(env_path, "r") as f:
33-
env_content = f.read()
11+
env_content = env_path.read_text()
3412

35-
# Update the .env file
3613
lines = []
14+
3715
for line in env_content.splitlines():
38-
line_updated = False
3916
for key, value in answers.items():
4017
upper_key = key.upper()
4118
if line.startswith(f"{upper_key}="):
42-
if isinstance(value, str) and " " in value:
43-
content = f'{upper_key}="{value}"'
19+
if " " in value:
20+
content = f"{upper_key}={value!r}"
4421
else:
4522
content = f"{upper_key}={value}"
46-
lines.append(content)
47-
line_updated = True
23+
new_line = line.replace(line, content)
24+
lines.append(new_line)
4825
break
49-
if not line_updated:
26+
else:
5027
lines.append(line)
5128

52-
# Write the updated .env file
53-
with open(env_path, "w") as f:
54-
f.write("\n".join(lines))
55-
56-
print(f"Updated {env_path} with values from Copier answers.")
29+
env_path.write_text("\n".join(lines))

.env.example

Lines changed: 0 additions & 28 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,4 +323,4 @@ Temporary Items
323323

324324
# INCLUDE
325325
!**/.gitkeep
326-
!**/*.example
326+
!**/*.example*

README.md

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -56,35 +56,43 @@ devbox run test
5656
### Taskfile
5757
```bash
5858
λ task
59+
task: [default] task --list
5960
task: Available tasks for this project:
60-
* checkbash: Check bash scripts
61-
* default: Default task
62-
* format: Run formatters
63-
* install: Install project dependencies
64-
* install-devbox: Install devbox
65-
* lint: Run linters
66-
* pre-commit: Run pre-commit hooks
67-
* pyclean: Remove .pyc and __pycache__
68-
* test: Run tests
69-
* docker:build: Build the docker image (aliases: docker:build)
70-
* docker:down: Stop and remove containers, networks, and volumes with docker compose (aliases: docker:down)
71-
* docker:exec: Shell into a running container (aliases: docker:exec)
72-
* docker:login: Login to the container registry (aliases: docker:login)
73-
* docker:logs: Follow the logs of a running container (aliases: docker:logs)
74-
* docker:net: Create docker network (aliases: docker:net)
75-
* docker:prune: Prune docker (aliases: docker:prune)
76-
* docker:push: Push the docker image to the registry (aliases: docker:push)
77-
* docker:stop: Stop the project with docker compose (aliases: docker:stop)
78-
* docker:up: Start the project with docker compose (aliases: docker:up)
79-
* docker:vol: Create docker volume (aliases: docker:vol)
80-
* poetry:add-pypi: Add test-pypi repository (aliases: poetry:add-pypi)
81-
* poetry:build: Build the poetry bin (aliases: poetry:build)
82-
* poetry:bump-semver: Bump the project semantic version (aliases: poetry:bump-semver)
83-
* poetry:default: Default task (aliases: poetry:default, poetry, poetry)
84-
* poetry:export-reqs: Export requirements.txt (aliases: poetry:export-reqs)
85-
* poetry:install: Install project dependencies (aliases: poetry:install)
86-
* poetry:publish: Publish the poetry bin (aliases: poetry:publish)
87-
* poetry:update-deps: Update dependencies (aliases: poetry:update-deps)
61+
* default: Default task
62+
* format: Run formatters
63+
* install: Install project dependencies
64+
* install-devbox: Install devbox
65+
* lint: Run linters
66+
* pre-commit: Run pre-commit hooks
67+
* pyclean: Remove .pyc and __pycache__
68+
* test: Run tests
69+
* docker:build: Build the docker image
70+
* docker:down: Stop and remove containers, networks, and volumes with docker compose
71+
* docker:exec: Shell into a running container
72+
* docker:login: Login to the container registry
73+
* docker:logs: Follow the logs of a running container
74+
* docker:net: Create docker network
75+
* docker:prune: Prune docker
76+
* docker:push: Push the docker image to the registry
77+
* docker:stop: Stop the project with docker compose
78+
* docker:up: Start the project with docker compose
79+
* docker:vol: Create docker volume
80+
* orbstack:create: Create an orbstack VM (aliases: orb:create)
81+
* orbstack:delete: Delete an orbstack VM (aliases: orb:delete)
82+
* orbstack:exec: SSH into an orbstack VM (aliases: orb:exec)
83+
* orbstack:list: List orbstack VMs (aliases: orb:list)
84+
* orbstack:start: Start an orbstack VM (aliases: orb:start)
85+
* orbstack:stop: Stop an orbstack VM (aliases: orb:stop)
86+
* orbstack:update: Update orbstack app (aliases: orb:update)
87+
* redis:start: Start Redis server
88+
* redis:stop: Stop Redis server
89+
* uv:export-reqs: Export requirements.txt
90+
* uv:install: Install project dependencies
91+
* uv:install-uv: Install uv
92+
* uv:lock: Update the project's lockfile.
93+
* uv:sync: Sync dependencies with lockfile
94+
* uv:update-deps: Update dependencies
95+
* uv:venv: Create a virtual environment
8896
```
8997
9098
### Tilt

ansible/facts/.gitkeep

Whitespace-only changes.

copier.yml

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ _jinja_extensions:
1313
- extensions.py:SlugifyExtension
1414
_skip_if_exists:
1515
- CHANGELOG.md
16+
_answers_file: .copier/.copier-answers.yml
17+
_tasks:
18+
- ["{{ _copier_python }}", .copier/update_dotenv.py]
1619

1720
# PROMPT --------------------------------
1821
project_name:
@@ -22,7 +25,6 @@ project_name:
2225
project_description:
2326
type: str
2427
help: Your project description
25-
default: "Minimum Viable Python Template"
2628

2729
author_fullname:
2830
type: str
@@ -37,7 +39,6 @@ author_email:
3739
author_username:
3840
type: str
3941
help: Your username (e.g. on GitHub)
40-
default: "pythoninthegrass"
4142

4243
repository_provider:
4344
type: str
@@ -46,7 +47,6 @@ repository_provider:
4647
choices:
4748
- github.com
4849
- gitlab.com
49-
- bitbucket.org
5050

5151
repository_namespace:
5252
type: str
@@ -78,39 +78,15 @@ copyright_license:
7878
help: Your project's license
7979
default: Unlicense
8080
choices:
81-
Academic Free License v3.0: AFL-3.0
8281
Apache License 2.0: Apache-2.0
83-
Artistic License 2.0: Artistic-2.0
84-
BSD 2-Clause "Simplified" License: BSD-2-Clause
85-
BSD 3-Clause Clear License: BSD-3-Clause-Clear
86-
BSD 3-Clause "New" or "Revised" License: BSD-3-Clause
87-
Boost Software License 1.0: BSL-1.0
8882
Creative Commons Attribution 4.0 International: CC-BY-4.0
89-
Creative Commons Attribution Share Alike 4.0 International: CC-BY-SA-4.0
9083
Creative Commons Zero v1.0 Universal: CC0-1.0
9184
Do What The F*ck You Want To Public License: WTFPL
92-
Educational Community License v2.0: ECL-2.0
93-
Eclipse Public License 1.0: EPL-1.0
94-
Eclipse Public License 2.0: EPL-2.0
95-
European Union Public License 1.1: EUPL-1.1
96-
European Union Public License 1.2: EUPL-1.2
9785
GNU Affero General Public License v3.0: AGPL-3.0
98-
GNU General Public License v2.0 only: GPL-2.0
9986
GNU General Public License v3.0 only: GPL-3.0
100-
GNU Lesser General Public License v2.1 only: LGPL-2.1
101-
GNU Lesser General Public License v3.0 only: LGPL-3.0
102-
ISC License: ISC
103-
LaTeX Project Public License v1.3c: LPPL-1.3c
10487
MIT License: MIT
10588
Mozilla Public License 2.0: MPL-2.0
106-
Microsoft Public License: MS-PL
107-
Microsoft Reciprocal License: MS-RL
108-
University of Illinois/NCSA Open Source License: NCSA
109-
SIL Open Font License 1.1: OFL-1.1
110-
Open Software License 3.0: OSL-3.0
111-
PostgreSQL License: PostgreSQL
11289
The Unlicense: Unlicense
113-
zlib License: Zlib
11490

11591
python_package_distribution_name:
11692
type: str

extensions.py

Lines changed: 0 additions & 73 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)