Skip to content

Commit 6413894

Browse files
committed
chore: Template upgrade
1 parent 40940c5 commit 6413894

9 files changed

Lines changed: 64 additions & 93 deletions

File tree

.copier-answers.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Changes here will be overwritten by Copier
2-
_commit: 1.4.0
2+
_commit: 1.4.1
33
_src_path: gh:pawamoy/copier-uv
44
author_email: dev@pawamoy.fr
55
author_fullname: Timothée Mazzucotelli

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ jobs:
8888
python-version: ${{ matrix.python-version }}
8989
allow-prereleases: true
9090

91-
- name: Install uv
92-
run: pip install uv
91+
- name: Setup uv
92+
uses: astral-sh/setup-uv@v1
93+
with:
94+
enable-cache: true
9395

9496
- name: Install dependencies
9597
env:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
/.pdm-build/
1616
/htmlcov/
1717
/site/
18+
uv.lock
1819

1920
# cache
2021
.cache/

devdeps.txt

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

duties.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def changelog(ctx: Context, bump: str = "") -> None:
5353
ctx.run(tools.git_changelog(bump=bump or None), title="Updating changelog")
5454

5555

56-
@duty(pre=["check_quality", "check_types", "check_docs", "check-api"])
56+
@duty(pre=["check-quality", "check-types", "check-docs", "check-api"])
5757
def check(ctx: Context) -> None:
5858
"""Check it all!"""
5959

mkdocs.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,15 @@ plugins:
127127
show_root_heading: true
128128
show_root_full_path: false
129129
show_signature_annotations: true
130+
show_source: true
130131
show_symbol_type_heading: true
131132
show_symbol_type_toc: true
132133
signature_crossrefs: true
133134
summary: true
134-
- git-committers:
135+
- git-revision-date-localized:
135136
enabled: !ENV [DEPLOY, false]
136-
repository: mkdocstrings/autorefs
137+
enable_creation_date: true
138+
type: timeago
137139
- minify:
138140
minify_html: !ENV [DEPLOY, false]
139141
- group:

pyproject.toml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ source-includes = [
6464
"scripts",
6565
"share",
6666
"tests",
67-
"devdeps.txt",
6867
"duties.py",
6968
"mkdocs.yml",
7069
"*.md",
@@ -75,3 +74,39 @@ source-includes = [
7574
data = [
7675
{path = "share/**/*", relative-to = "."},
7776
]
77+
78+
[tool.uv]
79+
dev-dependencies = [
80+
# dev
81+
"editables>=0.5",
82+
83+
# maintenance
84+
"build>=1.2",
85+
"git-changelog>=2.5",
86+
"twine>=5.0; python_version < '3.13'",
87+
88+
# ci
89+
"duty>=1.4",
90+
"ruff>=0.4",
91+
"pytest>=8.2",
92+
"pytest-cov>=5.0",
93+
"pytest-randomly>=3.15",
94+
"pytest-xdist>=3.6",
95+
"mypy>=1.10",
96+
"types-markdown>=3.6",
97+
"types-pyyaml>=6.0",
98+
99+
# docs
100+
"black>=24.4",
101+
"markdown-callouts>=0.4",
102+
"markdown-exec>=1.8",
103+
"mkdocs>=1.6",
104+
"mkdocs-coverage>=1.0",
105+
"mkdocs-gen-files>=0.5",
106+
"mkdocs-git-revision-date-localized-plugin>=1.2",
107+
"mkdocs-literate-nav>=0.6",
108+
"mkdocs-material>=9.5",
109+
"mkdocs-minify-plugin>=0.8",
110+
"mkdocstrings[python]>=0.25",
111+
"tomli>=2.0; python_version < '3.11'",
112+
]

scripts/gen_credits.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
pyproject = tomllib.load(pyproject_file)
2727
project = pyproject["project"]
2828
project_name = project["name"]
29-
with project_dir.joinpath("devdeps.txt").open() as devdeps_file:
30-
devdeps = [line.strip() for line in devdeps_file if line.strip() and not line.strip().startswith(("-e", "#"))]
29+
devdeps = [dep for dep in pyproject["tool"]["uv"]["dev-dependencies"] if not dep.startswith("-e")]
3130

3231
PackageMetadata = Dict[str, Union[str, Iterable[str]]]
3332
Metadata = Dict[str, PackageMetadata]

scripts/make

Lines changed: 16 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ from typing import Any, Iterator
1313

1414
PYTHON_VERSIONS = os.getenv("PYTHON_VERSIONS", "3.8 3.9 3.10 3.11 3.12 3.13").split()
1515

16-
exe = ""
17-
prefix = ""
18-
1916

2017
def shell(cmd: str, capture_output: bool = False, **kwargs: Any) -> str | None:
2118
"""Run a shell command."""
@@ -37,18 +34,11 @@ def environ(**kwargs: str) -> Iterator[None]:
3734
os.environ.update(original)
3835

3936

40-
def uv_install() -> None:
37+
def uv_install(venv: Path) -> None:
4138
"""Install dependencies using uv."""
42-
uv_opts = ""
43-
if "UV_RESOLUTION" in os.environ:
44-
uv_opts = f"--resolution={os.getenv('UV_RESOLUTION')}"
45-
requirements = shell(f"uv pip compile {uv_opts} pyproject.toml devdeps.txt", capture_output=True)
46-
shell("uv pip install -r -", input=requirements, text=True)
47-
if "CI" not in os.environ:
48-
shell("uv pip install --no-deps -e .")
49-
else:
50-
shell("uv pip install --no-deps .")
51-
39+
with environ(UV_PROJECT_ENVIRONMENT=str(venv)):
40+
shell("uv sync")
41+
5242

5343
def setup() -> None:
5444
"""Setup the project."""
@@ -59,47 +49,27 @@ def setup() -> None:
5949
default_venv = Path(".venv")
6050
if not default_venv.exists():
6151
shell("uv venv --python python")
62-
uv_install()
52+
uv_install(default_venv)
6353

6454
if PYTHON_VERSIONS:
6555
for version in PYTHON_VERSIONS:
6656
print(f"\nInstalling dependencies (python{version})") # noqa: T201
6757
venv_path = Path(f".venvs/{version}")
6858
if not venv_path.exists():
6959
shell(f"uv venv --python {version} {venv_path}")
70-
with environ(VIRTUAL_ENV=str(venv_path.resolve())):
71-
uv_install()
72-
73-
74-
def activate(path: str) -> None:
75-
"""Activate a virtual environment."""
76-
global exe, prefix # noqa: PLW0603
77-
78-
if (bin := Path(path, "bin")).exists():
79-
activate_script = bin / "activate_this.py"
80-
elif (scripts := Path(path, "Scripts")).exists():
81-
activate_script = scripts / "activate_this.py"
82-
exe = ".exe"
83-
prefix = f"{path}/Scripts/"
84-
else:
85-
raise ValueError(f"make: activate: Cannot find activation script in {path}")
86-
87-
if not activate_script.exists():
88-
raise ValueError(f"make: activate: Cannot find activation script in {path}")
89-
90-
exec(activate_script.read_text(), {"__file__": str(activate_script)}) # noqa: S102
60+
with environ(UV_PROJECT_ENVIRONMENT=str(venv_path.resolve())):
61+
uv_install(venv_path)
9162

9263

9364
def run(version: str, cmd: str, *args: str, **kwargs: Any) -> None:
9465
"""Run a command in a virtual environment."""
9566
kwargs = {"check": True, **kwargs}
9667
if version == "default":
97-
activate(".venv")
98-
subprocess.run([f"{prefix}{cmd}{exe}", *args], **kwargs) # noqa: S603, PLW1510
68+
with environ(UV_PROJECT_ENVIRONMENT=".venv"):
69+
subprocess.run(["uv", "run", cmd, *args], **kwargs) # noqa: S603, PLW1510
9970
else:
100-
activate(f".venvs/{version}")
101-
os.environ["MULTIRUN"] = "1"
102-
subprocess.run([f"{prefix}{cmd}{exe}", *args], **kwargs) # noqa: S603, PLW1510
71+
with environ(UV_PROJECT_ENVIRONMENT=f".venvs/{version}", MULTIRUN="1"):
72+
subprocess.run(["uv", "run", cmd, *args], **kwargs) # noqa: S603, PLW1510
10373

10474

10575
def multirun(cmd: str, *args: str, **kwargs: Any) -> None:
@@ -124,10 +94,10 @@ def clean() -> None:
12494
for path in paths_to_clean:
12595
shell(f"rm -rf {path}")
12696

127-
cache_dirs = [".cache", ".pytest_cache", ".mypy_cache", ".ruff_cache", "__pycache__"]
128-
for dirpath in Path(".").rglob("*"):
129-
if any(dirpath.match(pattern) for pattern in cache_dirs) and not (dirpath.match(".venv") or dirpath.match(".venvs")):
130-
shutil.rmtree(path, ignore_errors=True)
97+
cache_dirs = {".cache", ".pytest_cache", ".mypy_cache", ".ruff_cache", "__pycache__"}
98+
for dirpath in Path(".").rglob("*/"):
99+
if dirpath.parts[0] not in (".venv", ".venvs") and dirpath.name in cache_dirs:
100+
shutil.rmtree(dirpath, ignore_errors=True)
131101

132102

133103
def vscode() -> None:
@@ -152,11 +122,7 @@ def main() -> int:
152122
print(" 3.x Run a command in the virtual environment for Python 3.x.") # noqa: T201
153123
print(" clean Delete build artifacts and cache files.") # noqa: T201
154124
print(" vscode Configure VSCode to work on this project.") # noqa: T201
155-
try:
156-
run("default", "python", "-V", capture_output=True)
157-
except (subprocess.CalledProcessError, ValueError):
158-
pass
159-
else:
125+
if os.path.exists(".venv"):
160126
print("\nAvailable tasks") # noqa: T201
161127
run("default", "duty", "--list")
162128
return 0

0 commit comments

Comments
 (0)