Skip to content

Commit 41d8f44

Browse files
committed
Align project with Python template
1 parent fddfa4c commit 41d8f44

22 files changed

+298
-339
lines changed
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,11 @@ jobs:
2121
with:
2222
persist-credentials: false
2323

24-
- name: Install the latest version of uv
25-
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
24+
- name: Set up Python
25+
uses: actions/setup-python@7f4fc3e22c37d6ff65e88745f38bd3157c663f7c # v4.9.1
2626
with:
2727
python-version: ${{ matrix.python-version }}
2828

29-
- name: Install dependencies
30-
run: uv sync --frozen
31-
3229
- name: Run pre-commit
3330
uses: pre-commit/action@646c83fcd040023954eafda54b4db0192ce70507 # v3.0.0
3431

.gitignore

Lines changed: 175 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,176 @@
1-
__pycache__
2-
*.egg-info
1+
# Created by https://www.toptal.com/developers/gitignore/api/python
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=python
33

4-
.pytest_cache
5-
*.pyc
6-
.ctt
4+
### Python ###
5+
# Byte-compiled / optimized / DLL files
6+
__pycache__/
7+
*.py[cod]
8+
*$py.class
9+
10+
# C extensions
11+
*.so
12+
13+
# Distribution / packaging
14+
.Python
15+
build/
16+
develop-eggs/
17+
dist/
18+
downloads/
19+
eggs/
20+
.eggs/
21+
lib/
22+
lib64/
23+
parts/
24+
sdist/
25+
var/
26+
wheels/
27+
share/python-wheels/
28+
*.egg-info/
29+
.installed.cfg
30+
*.egg
31+
MANIFEST
32+
33+
# PyInstaller
34+
# Usually these files are written by a python script from a template
35+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
36+
*.manifest
37+
*.spec
38+
39+
# Installer logs
40+
pip-log.txt
41+
pip-delete-this-directory.txt
42+
43+
# Unit test / coverage reports
44+
htmlcov/
45+
.tox/
46+
.nox/
47+
.coverage
48+
.coverage.*
49+
.cache
50+
nosetests.xml
51+
coverage.xml
52+
*.cover
53+
*.py,cover
54+
.hypothesis/
55+
.pytest_cache/
56+
cover/
57+
58+
# Translations
59+
*.mo
60+
*.pot
61+
62+
# Django stuff:
63+
*.log
64+
local_settings.py
65+
db.sqlite3
66+
db.sqlite3-journal
67+
68+
# Flask stuff:
69+
instance/
70+
.webassets-cache
71+
72+
# Scrapy stuff:
73+
.scrapy
74+
75+
# Sphinx documentation
76+
docs/_build/
77+
78+
# PyBuilder
79+
.pybuilder/
80+
target/
81+
82+
# Jupyter Notebook
83+
.ipynb_checkpoints
84+
85+
# IPython
86+
profile_default/
87+
ipython_config.py
88+
89+
# pyenv
90+
# For a library or package, you might want to ignore these files since the code is
91+
# intended to run in multiple environments; otherwise, check them in:
92+
# .python-version
93+
94+
# pipenv
95+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
96+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
97+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
98+
# install all needed dependencies.
99+
#Pipfile.lock
100+
101+
# poetry
102+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
103+
# This is especially recommended for binary packages to ensure reproducibility, and is more
104+
# commonly ignored for libraries.
105+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
106+
#poetry.lock
107+
108+
# pdm
109+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
110+
#pdm.lock
111+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
112+
# in version control.
113+
# https://pdm.fming.dev/#use-with-ide
114+
.pdm.toml
115+
116+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
117+
__pypackages__/
118+
119+
# Celery stuff
120+
celerybeat-schedule
121+
celerybeat.pid
122+
123+
# SageMath parsed files
124+
*.sage.py
125+
126+
# Environments
127+
.env
128+
.venv
129+
env/
130+
venv/
131+
ENV/
132+
env.bak/
133+
venv.bak/
134+
135+
# Spyder project settings
136+
.spyderproject
137+
.spyproject
138+
139+
# Rope project settings
140+
.ropeproject
141+
142+
# mkdocs documentation
143+
/site
144+
145+
# mypy
146+
.mypy_cache/
147+
.dmypy.json
148+
dmypy.json
149+
150+
# Pyre type checker
151+
.pyre/
152+
153+
# pytype static type analyzer
154+
.pytype/
155+
156+
# Cython debug symbols
157+
cython_debug/
158+
159+
# PyCharm
160+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
161+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
162+
# and can be added to the global gitignore or merged into this file. For a more nuclear
163+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
164+
#.idea/
165+
166+
### Python Patch ###
167+
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
168+
poetry.toml
169+
170+
# ruff
171+
.ruff_cache/
172+
173+
# LSP config files
174+
pyrightconfig.json
175+
176+
# End of https://www.toptal.com/developers/gitignore/api/python

.pre-commit-config-extra.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ repos:
55
rev: 2.2.0
66
hooks:
77
- id: copier-template-tester
8+
additional_dependencies: [copier-template-extensions]

.pre-commit-config.yaml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,7 @@ repos:
5454
hooks:
5555
- id: detect-secrets
5656

57-
- repo: https://github.com/fpgmaas/deptry.git
58-
rev: "0.23.1"
59-
hooks:
60-
- id: deptry
61-
args: ["--ignore", "DEP001"]
62-
6357
- repo: https://github.com/woodruffw/zizmor-pre-commit
6458
rev: v1.11.0
6559
hooks:
6660
- id: zizmor
67-
68-
- repo: https://github.com/astral-sh/uv-pre-commit
69-
rev: 0.8.5
70-
hooks:
71-
- id: uv-lock

_extensions/__init__.py

Whitespace-only changes.

_extensions/include_raw.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
"""Custom Jinja2 extension to include files without rendering them.
2+
3+
This solves the issue where GitHub Actions variables (${{ }}) conflict
4+
with Jinja2 syntax.
5+
"""
6+
7+
from pathlib import Path
8+
from typing import TYPE_CHECKING, ClassVar
9+
10+
from jinja2 import nodes
11+
from jinja2.ext import Extension
12+
13+
if TYPE_CHECKING:
14+
from jinja2.parser import Parser
15+
16+
17+
class IncludeRawExtension(Extension):
18+
"""A Jinja2 extension that adds an 'include_raw' tag to include files.
19+
20+
Without processing them through the Jinja2 template engine.
21+
22+
Usage:
23+
{% include_raw '.github/workflows/pre-commit.yml' %}
24+
"""
25+
26+
tags: ClassVar[set[str]] = {"include_raw"}
27+
28+
def parse(self, parser: "Parser") -> nodes.Output:
29+
# Get the tag token
30+
lineno = next(parser.stream).lineno
31+
32+
# Parse the filename argument
33+
filename_node = parser.parse_expression()
34+
35+
# Create a call node to our _include_raw method
36+
call_node = self.call_method("_include_raw", [filename_node])
37+
38+
# Return an output node
39+
return nodes.Output([call_node], lineno=lineno)
40+
41+
def _include_raw(self, filename: str) -> str:
42+
"""Read and return file contents without processing them.
43+
44+
Args:
45+
filename: Path to the file relative to template root
46+
47+
Returns:
48+
Raw file contents or error message
49+
50+
"""
51+
# Get the template directory from the environment
52+
template_dir_str = (
53+
self.environment.loader.searchpath[0]
54+
if hasattr(self.environment.loader, "searchpath")
55+
else "."
56+
)
57+
template_dir = Path(template_dir_str).resolve()
58+
59+
# Security: Resolve the requested file path and check it's within template_dir
60+
requested_path = Path(filename)
61+
62+
# Prevent absolute paths
63+
if requested_path.is_absolute():
64+
msg = f"Absolute paths not allowed: {filename}"
65+
raise ValueError(msg)
66+
67+
# Resolve the full path
68+
full_path = (template_dir / requested_path).resolve()
69+
70+
# Security check: ensure the resolved path is within template_dir
71+
if not str(full_path).startswith(str(template_dir)):
72+
msg = f"Path outside template directory: {filename}"
73+
raise ValueError(msg)
74+
75+
return full_path.read_text(encoding="utf-8")
76+
77+
78+
# Export the extension for Copier to use
79+
__all__ = ["IncludeRawExtension"]

copier.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ debug:
117117

118118
_subdirectory: "{{ template_type }}"
119119

120+
_jinja_extensions:
121+
- copier_template_extensions.TemplateExtensionLoader
122+
- _extensions/include_raw.py:IncludeRawExtension
123+
120124
_envops:
121125
keep_trailing_newline: true
122126
trim_blocks: true

ctt.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
[defaults]
22
# Test pre-commit functionality
33
_extra_tasks = [
4-
# "rm -rf .git",
54
"git init",
65
"git add .",
76
"uv sync",
8-
"uv run pre-commit run --all-files || uv run pre-commit run --all-files"
7+
"uv run pre-commit run --all-files end-of-file-fixer || uv run pre-commit run --all-files"
98
]
109
author_name = "Test Author"
1110
debug = true

pyproject.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ dev = [
77
]
88

99
[project]
10-
authors = [{name = "Niccolò Cantù", email = "[email protected]"}]
10+
authors = [
11+
{name = "Niccolò Cantù", email = "[email protected]"},
12+
{name = "Francesco Frassinelli", email = "[email protected]"}
13+
]
1114
# PEP 621 project metadata
1215
# See https://www.python.org/dev/peps/pep-0621/
1316
dependencies = []
@@ -40,8 +43,8 @@ tag_name = "v{new_version}"
4043
fix = true
4144

4245
[tool.ruff.lint]
43-
ignore = ["COM812"]
44-
select = ["E", "W", "I", "F", "UP", "S", "B", "A", "COM", "LOG", "PTH", "Q"]
46+
ignore = ["D203", "D213", "COM812", "ISC001"]
47+
select = ["ALL"]
4548

4649
[tool.ruff.lint.per-file-ignores]
4750
"**/migrations/*.py" = ["E501", "ANN"]

python/.editorconfig.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
{% include ".editorconfig" %}
1+
{% include_raw ".editorconfig" %}
22
{% block extra %}{% endblock extra %}

0 commit comments

Comments
 (0)