Skip to content

Commit f2265a6

Browse files
authored
Merge pull request #44 from claui/migrate-to-uv
Migrate from Poetry to uv
2 parents 5f41e9d + 9e69252 commit f2265a6

22 files changed

Lines changed: 959 additions & 1517 deletions

File tree

CONTRIBUTING.md

Lines changed: 11 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,97 +3,42 @@
33
## Requirements for contributing
44

55
To contribute to the `cookiecutter-python-package` template,
6-
you’ll need:
6+
you’ll need the project management tool
7+
[uv](https://docs.astral.sh/uv).
78

8-
1. The Python version manager `pyenv`.
9+
### Installing uv
910

10-
2. The Python dependency manager `poetry`.
11+
To install uv, see its
12+
[installation instructions](https://docs.astral.sh/uv/getting-started/installation/).
1113

12-
### Installing Poetry
14+
#### Checking your uv installation
1315

14-
You’ll need `poetry` to manage development dependencies and the venv.
15-
16-
#### Installing Poetry on Windows
17-
18-
To install Poetry on Windows, use one of the
19-
[installation methods](https://python-poetry.org/docs/master/#installing-with-the-official-installer)
20-
described in Poetry’s documentation.
21-
22-
#### Installing Poetry on Linux
23-
24-
If you’re on Linux or WSL2, use your system package manager to
25-
install Poetry.
26-
27-
Alternatively, use one of the
28-
[installation methods](https://python-poetry.org/docs/master/#installing-with-the-official-installer)
29-
described in Poetry’s documentation.
30-
31-
#### Installing Poetry on macOS
32-
33-
To install Poetry on macOS, run:
34-
35-
```shell
36-
brew install poetry
37-
```
38-
39-
#### Checking your Poetry installation
40-
41-
To verify Poetry is working, run:
16+
To verify uv is working, run:
4217

4318
```shell
44-
poetry --version
19+
uv
4520
```
4621

4722
#### Installing Cookiecutter as a stand-alone tool (optional)
4823

4924
Cookiecutter is already included as a development dependency,
50-
so Poetry will take care of installing it for you.
25+
so uv will take care of installing it for you.
5126
You don’t need to have it installed as a stand-alone tool, but you
5227
may still want to do so for your convenience.
5328

5429
To install Cookiecutter as a stand-alone tool, follow Cookiecutter’s [installation
5530
instructions](https://cookiecutter.readthedocs.io/en/stable/installation.html).
5631

57-
## Setting up your virtual environment
58-
59-
To set up your virtual environment, follow these steps:
60-
61-
1. Go to the project root directory.
62-
63-
2. Run `pyenv install -s`.
64-
65-
3. Run `pyenv exec python -m venv .venv`.
66-
67-
4. Run `poetry install`.
68-
69-
You need to do the above steps only once.
70-
71-
To update your dependencies after a `git pull`, run `poetry install`.
72-
7332
## Development scripts and tasks
7433

75-
To see a list of available tasks, run: `poetry run poe tasks`
34+
To see a list of available tasks, run: `uv run poe tasks`
7635

7736
## Running the end-to-end test
7837

79-
To execute the end-to-end test, run: `poetry run poe e2e`
38+
To execute the end-to-end test, run: `uv run poe e2e`
8039

8140
## FAQ
8241

83-
Q: Why is `pyenv` required even though Cookiecutter accepts any
84-
Python version?
85-
86-
A: Especially because Cookiecutter accepts any Python version,
87-
you’ll want your code to work equally well on all of those supported
88-
Pythons. We achieve that by pinning the minimum Python version
89-
that Cookiecutter supports as our development dependency.
90-
91-
Q: Do I have to add `pyenv` shims to my PATH?
92-
93-
A: No, because this guide
94-
[doesn’t use pyenv’s shims](https://github.com/pyenv/pyenv#using-pyenv-without-shims).
95-
It’s still ok to have them in your PATH if you prefer so.
96-
9742
Q: Why is Cookiecutter a development dependency even though I
9843
already have a stand-alone Cookiecutter install?
9944

README.md

Lines changed: 16 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ The Cookiecutter template will give you:
6565

6666
- a global settings file that all modules can import;
6767

68-
- a `pyproject.toml` file and an initial Poetry lockfile;
68+
- a `pyproject.toml` file and an initial `uv.lock` file;
6969

7070
- a default linter configuration;
7171

@@ -76,7 +76,7 @@ The Cookiecutter template will give you:
7676
- a configuration file for Read the Docs;
7777

7878
- a set of `poe` tasks for running the module scripts, tests and the
79-
linter (for details, run `poetry run poe tasks`);
79+
linter (for details, run `uv run poe tasks`);
8080

8181
- a virtual environment with initial dependencies installed and
8282
ready to use;
@@ -95,117 +95,36 @@ The Cookiecutter template will give you:
9595

9696
To use this Cookiecutter template, you need:
9797

98-
1. The Python version manager `pyenv`.
98+
1. The Python project management tool [uv](https://docs.astral.sh/uv).
9999

100-
2. A system-wide Python installation.
100+
2. Optionally, Cookiecutter version 2.6.0 or newer.
101101

102-
3. Cookiecutter version 2.6.0 or newer.
102+
### Installing uv
103103

104-
4. The Python dependency manager `poetry`.
104+
To install uv, see its
105+
[installation instructions](https://docs.astral.sh/uv/getting-started/installation/).
105106

106-
### Installing pyenv
107-
108-
You need the Python version manager `pyenv` so you can set up your
109-
generated package, and to make sure you can always keep that package
110-
up and running, regardless of your system Python.
111-
112-
#### Installing pyenv on Windows
113-
114-
While `pyenv` doesn’t support Windows, you can use a drop-in
115-
replacement called `pyenv-win`.
116-
117-
To install `pyenv-win` on Windows, go to
118-
[github.com/pyenv-win/pyenv-win](https://github.com/pyenv-win/pyenv-win#installation)
119-
and follow one of the installation methods.
120-
121-
#### Installing pyenv on Linux
122-
123-
To install `pyenv` on Linux or WSL2, first make sure Python 3 is
124-
installed. Then follow the _Basic GitHub Checkout_ method described
125-
at [github.com/pyenv/pyenv](https://github.com/pyenv/pyenv#basic-github-checkout).
126-
127-
#### Installing pyenv on macOS
128-
129-
To install `pyenv` on macOS, run:
130-
131-
```shell
132-
brew install pyenv
133-
```
134-
135-
#### Checking your system-wide pyenv installation
136-
137-
To verify your `pyenv` is working, run:
138-
139-
```shell
140-
pyenv --version
141-
```
142-
143-
### Checking your system-wide Python installation
144-
145-
Make sure you have Python 3.8 or higher installed on your system
146-
and available in your PATH.
147-
148-
To check, run:
149-
150-
```shell
151-
python --version
152-
```
153-
154-
If that fails, try:
107+
To verify uv is working, run:
155108

156109
```shell
157-
python3 --version
110+
uv
158111
```
159112

160-
Proceed after you’ve confirmed one of those to work.
161-
162113
### Installing Cookiecutter
163114

164-
To install Cookiecutter, follow Cookiecutter’s [installation
165-
instructions](https://cookiecutter.readthedocs.io/en/stable/installation.html).
166-
167-
### Installing Poetry
168-
169-
You’ll need `poetry` to manage the generated Python package.
170-
171-
#### Installing Poetry on Windows
172-
173-
To install Poetry on Windows, use one of the
174-
[installation methods](https://python-poetry.org/docs/master/#installing-with-the-official-installer)
175-
described in Poetry’s documentation.
176-
177-
#### Installing Poetry on Linux
178-
179-
If you’re on Linux or WSL2, use your system package manager to
180-
install Poetry.
181-
182-
Alternatively, use one of the
183-
[installation methods](https://python-poetry.org/docs/master/#installing-with-the-official-installer)
184-
described in Poetry’s documentation.
115+
Installing Cookiecutter is optional, because you can run
116+
`uvx cookiecutter` without installing Cookiecutter.
185117

186-
#### Installing Poetry on macOS
187-
188-
To install Poetry on macOS, run:
189-
190-
```shell
191-
brew install poetry
192-
```
193-
194-
#### Checking your Poetry installation
195-
196-
To verify Poetry is working, run:
197-
198-
```shell
199-
poetry --version
200-
```
118+
If you prefer to install Cookiecutter, follow Cookiecutter’s [installation
119+
instructions](https://cookiecutter.readthedocs.io/en/stable/installation.html).
201120

202121
### Basic usage
203122

204123
To run the template generator, make sure you have a working
205124
Cookiecutter installation. Then run:
206125

207126
```shell
208-
cookiecutter gh:claui/cookiecutter-python-package
127+
uvx cookiecutter gh:claui/cookiecutter-python-package
209128
```
210129

211130
### Alternative usage
@@ -221,12 +140,12 @@ abbreviations:
221140
Then, to generate a project, run:
222141
223142
```shell
224-
cookiecutter python
143+
uvx cookiecutter python
225144
```
226145

227146
## License
228147

229-
Copyright (c) 2021 – 2024 Claudia Pellegrino <[email protected]>
148+
Copyright (c) 2021 – 2025 Claudia Pellegrino <[email protected]>
230149

231150
Licensed under the Apache License, Version 2.0 (the "License");
232151
you may not use this file except in compliance with the License.

hooks/post_gen_project.py

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -30,50 +30,12 @@
3030
{% endif -%}
3131

3232
{%- if cookiecutter.install_dependencies_now == "y" %}
33-
def sysexit_formatted(message: str) -> None:
34-
width = max((len(line) for line in message))
35-
print('', width * '-', *message, width * '-',
36-
file=sys.stderr, sep='\n')
37-
sys.exit()
38-
39-
pyenv_commands = [
40-
'pyenv install -s',
41-
'pyenv exec python -m venv .venv',
42-
]
43-
4433
try:
45-
for pyenv_command in pyenv_commands:
46-
subprocess.run(pyenv_command, check=True, shell=True)
47-
except subprocess.CalledProcessError as e:
48-
sysexit_formatted([
49-
f'Pyenv failed with exit code {e.returncode}.',
50-
'Go to the {{ cookiecutter.pypi_package_name }}'
51-
' directory and re-run:',
52-
*[
53-
f' {command}'
54-
for command in pyenv_commands + ['poetry install']
55-
],
56-
])
57-
58-
poetry_environment = os.environ.copy()
59-
poetry_environment.update({
60-
'LANG': poetry_environment.get('LANG', 'en_US.UTF-8'),
61-
# https://github.com/python-poetry/poetry/issues/1917
62-
'PYTHON_KEYRING_BACKEND': 'keyring.backends.null.Keyring',
63-
})
64-
65-
logger.info('Running poetry. This may take a while.')
66-
try:
67-
subprocess.run(
68-
'poetry install',
69-
env=poetry_environment,
70-
check=True,
71-
shell=True,
72-
stdout=sys.stderr,
73-
)
34+
subprocess.run(['uv', 'python', 'install'], check=True, stdout=sys.stderr)
35+
subprocess.run(['uv', 'lock'], check=True, stdout=sys.stderr)
7436
except subprocess.CalledProcessError as e:
7537
print(
76-
f'Poetry failed with exit code {e.returncode}.',
38+
f'uv failed with exit code {e.returncode}.',
7739
'Fix any issues, then go to the '
7840
'{{ cookiecutter.pypi_package_name }} directory and re-run:',
7941
f' {e.cmd}',

hooks/pre_gen_project.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
== '{{ cookiecutter.first_module_name }}':
3636
sys.exit('Package name and first module name cannot be the same')
3737

38-
if not shutil.which('poetry'):
38+
if not shutil.which('uv'):
3939
sys.exit(
4040
"""
41-
This Cookiecutter template depends on Poetry.
42-
For instructions on how to install Poetry, see `README.md`.
41+
This Cookiecutter template depends on uv.
42+
For instructions on how to install uv, see `README.md`.
4343
"""
4444
)

0 commit comments

Comments
 (0)