Skip to content

Commit 0bdb2db

Browse files
authored
Use uv for dependencies handling (#31)
1 parent 4842dcb commit 0bdb2db

File tree

8 files changed

+64
-22
lines changed

8 files changed

+64
-22
lines changed

.github/workflows/tests.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ jobs:
1818
with:
1919
python-version: "3.x"
2020

21-
- name: install cookiecutter
22-
run: python -m pip install cookiecutter
21+
- name: install uv
22+
run: >
23+
curl --no-progress-meter --location --fail
24+
--proto '=https' --tlsv1.2
25+
"https://astral.sh/uv/install.sh"
26+
| sh
2327
2428
# we need the git config setup here to make sure the subsequent git commit in each test works
2529
- name: setup fake git committer
@@ -29,7 +33,7 @@ jobs:
2933
3034
- name: run template (default)
3135
run: |
32-
cookiecutter --no-input -o /tmp .
36+
uvx cookiecutter --no-input -o /tmp .
3337
3438
[[ -d /tmp/python-project/src/python_project ]] || { >&2 echo "not generated?"; exit 1; }
3539
@@ -48,7 +52,7 @@ jobs:
4852
4953
- name: run template (no entry point)
5054
run: |
51-
cookiecutter --no-input -o /tmp . entry_point=''
55+
uvx cookiecutter --no-input -o /tmp . entry_point=''
5256
5357
[[ ! -f /tmp/python-project/python_project/__main__.py ]] || { >&2 echo "not expecting main"; exit 1; }
5458
@@ -67,7 +71,7 @@ jobs:
6771
6872
- name: run template (namespace)
6973
run: |
70-
cookiecutter --no-input -o /tmp . project_namespace_import=tob.r_and_e
74+
uvx cookiecutter --no-input -o /tmp . project_namespace_import=tob.r_and_e
7175
7276
[[ -d /tmp/tob-r-and-e-python-project/src/tob/r_and_e/python_project ]] || { >&2 echo "not generated?"; exit 1; }
7377
@@ -86,7 +90,7 @@ jobs:
8690
8791
- name: run template (namespace, short slug)
8892
run: |
89-
cookiecutter --no-input -o /tmp . project_namespace_import=tob.r_and_e "project_name=Bit Trails" project_slug=bit-trails
93+
uvx cookiecutter --no-input -o /tmp . project_namespace_import=tob.r_and_e "project_name=Bit Trails" project_slug=bit-trails
9094
9195
[[ -d /tmp/bit-trails/src/tob/r_and_e/bit_trails ]] || { >&2 echo "not generated?"; exit 1; }
9296
@@ -105,7 +109,7 @@ jobs:
105109
106110
- name: run template (no docs)
107111
run: |
108-
cookiecutter --no-input -o /tmp . documentation='none'
112+
uvx cookiecutter --no-input -o /tmp . documentation='none'
109113
110114
[[ -d /tmp/python-project/src/python_project ]] || { >&2 echo "not generated?"; exit 1; }
111115
[[ ! -f /tmp/python-project/.github/workflows/docs.yml ]] || { >&2 echo "not expecting docs.yml"; exit 1; }

README.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,42 @@ Both command-line and library packages can be generated.
1111

1212
## Usage
1313

14-
Install the `cookiecutter` CLI:
14+
- Install [`uv`](https://docs.astral.sh/uv/)
1515

1616
```bash
17-
python -m pip install cookiecutter
17+
# On any platform with cURL and sh
18+
curl -LsSf https://astral.sh/uv/install.sh | sh
1819

19-
# or, if you have pipx
20-
pipx install cookiecutter
20+
# On Windows
21+
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
22+
23+
# With Brew
24+
brew install uv
2125
```
2226

23-
Use `cookiecutter` to generate a project using this template:
27+
Please refer to [`uv` documentation](https://docs.astral.sh/uv/getting-started/installation/) for more installation options.
28+
29+
- Use `cookiecutter` to generate a project using this template:
2430

2531
```bash
2632
# creates the project directory in $PWD
27-
cookiecutter gh:trailofbits/cookiecutter-python
33+
uvx cookiecutter gh:trailofbits/cookiecutter-python
2834
```
2935

3036
Alternatively, tell `cookiecutter` where to put the new project directory:
3137

3238
```bash
3339
# creates ~/tmp/$project
34-
cookiecutter -o ~/tmp gh:trailofbits/cookiecutter-python
40+
uvx cookiecutter -o ~/tmp gh:trailofbits/cookiecutter-python
3541
```
3642

3743
`cookiecutter` will prompt you for the project's name and all other relevant
3844
metadata.
45+
46+
## Note
47+
48+
The project will be generated using `uv`, a near drop-in replacement for
49+
`pip` which is still in active development.
50+
51+
Packages are installed using `uv pip install <package_name>` (after
52+
activating the virtual environment).

hooks/post_gen_project.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import sys
32

43
REMOVE_PATHS = [
54
# We delete _cli.py and __main__.py if we're not generating a CLI.

{{cookiecutter.project_slug}}/.github/workflows/docs.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ jobs:
1616
python-version-file: pyproject.toml
1717
cache: "pip"
1818
cache-dependency-path: pyproject.toml
19+
20+
- name: install uv
21+
run: >
22+
curl --no-progress-meter --location --fail
23+
--proto '=https' --tlsv1.2
24+
"https://astral.sh/uv/install.sh"
25+
| sh
1926
2027
- name: setup
2128
run: |

{{cookiecutter.project_slug}}/.github/workflows/lint.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ jobs:
1717
python-version-file: pyproject.toml
1818
cache: "pip"
1919
cache-dependency-path: pyproject.toml
20+
21+
- name: install uv
22+
run: >
23+
curl --no-progress-meter --location --fail
24+
--proto '=https' --tlsv1.2
25+
"https://astral.sh/uv/install.sh"
26+
| sh
2027
2128
- name: lint
2229
run: make lint INSTALL_EXTRA=lint

{{cookiecutter.project_slug}}/.github/workflows/tests.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ jobs:
2424
python-version: ${{ matrix.python }}
2525
cache: "pip"
2626
cache-dependency-path: pyproject.toml
27+
28+
- name: install uv
29+
run: >
30+
curl --no-progress-meter --location --fail
31+
--proto '=https' --tlsv1.2
32+
"https://astral.sh/uv/install.sh"
33+
| sh
2734
2835
- name: test
2936
run: make test INSTALL_EXTRA=test

{{cookiecutter.project_slug}}/Makefile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ dev: $(VENV)/pyvenv.cfg
4646
{%- if cookiecutter.entry_point %}
4747
.PHONY: run
4848
run: $(VENV)/pyvenv.cfg
49+
# Once we can specify the default VENV name in uv, use `uv run` here
50+
# https://github.com/astral-sh/uv/issues/1422
4951
@. $(VENV_BIN)/activate && {{ cookiecutter.entry_point }} $(ARGS)
5052
{%- endif %}
5153

5254
$(VENV)/pyvenv.cfg: pyproject.toml
53-
python -m venv env
54-
$(VENV_BIN)/python -m pip install -e .[$(INSTALL_EXTRA)]
55+
uv venv $(VENV)
56+
@. $(VENV_BIN)/activate && uv pip install -e '.[$(INSTALL_EXTRA)]'
5557

5658
.PHONY: lint
5759
lint: $(VENV)/pyvenv.cfg
@@ -68,8 +70,8 @@ lint: $(VENV)/pyvenv.cfg
6870
.PHONY: reformat
6971
reformat:
7072
. $(VENV_BIN)/activate && \
71-
ruff check --fix && \
72-
ruff format
73+
ruff format && \
74+
ruff check --fix
7375

7476
.PHONY: test tests
7577
test tests: $(VENV)/pyvenv.cfg
@@ -89,7 +91,7 @@ doc:
8991

9092
.PHONY: package
9193
package: $(VENV)/pyvenv.cfg
92-
$(VENV_BIN)/python -m build
94+
uvx --from build pyproject-build --installer uv
9395

9496
.PHONY: edit
9597
edit:

{{cookiecutter.project_slug}}/pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ test = ["pytest", "pytest-cov", "pretend", "coverage[toml]"]
3030
lint = [
3131
# NOTE: ruff is under active development, so we pin conservatively here
3232
# and let Dependabot periodically perform this update.
33-
"ruff ~= 0.4.0",
33+
"ruff ~= 0.6.2",
3434
"mypy >= 1.0",
3535
"types-html5lib",
3636
"types-requests",
@@ -77,7 +77,7 @@ warn_unused_ignores = true
7777

7878
[tool.ruff]
7979
line-length = 100
80-
target-version = "py38"
80+
include = ["src/**/*.py", "test/**/*.py"]
8181

8282
[tool.ruff.lint]
8383
select = ["ALL"]
@@ -97,9 +97,11 @@ ignore = ["D203", "D213", "COM812", "ISC001"]
9797
"S101", # asserts are expected in tests
9898
]
9999

100+
{%- if cookiecutter.docstring_coverage %}
100101
[tool.interrogate]
101102
# don't enforce documentation coverage for packaging, testing, the virtual
102103
# environment, or the CLI (which is documented separately).
103104
exclude = ["env", "test", "{{ cookiecutter.__project_src_path }}/_cli.py"]
104105
ignore-semiprivate = true
105106
fail-under = 100
107+
{%- endif %}

0 commit comments

Comments
 (0)