Skip to content

Commit 2efa688

Browse files
committed
✨ Replace pip, venv and pipx with uv
1 parent 05e5f72 commit 2efa688

7 files changed

Lines changed: 38 additions & 62 deletions

File tree

.github/workflows/update_demo.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ jobs:
2626
token: ${{ secrets.X_GITHUB_PAT }}
2727
path: ${{ env.CURRENT_DEMO }}
2828

29-
- name: Install Python
30-
uses: actions/setup-python@v5
29+
- name: Install the latest version of uv with caching enabled
30+
id: setup-uv
31+
uses: astral-sh/setup-uv@v5
3132
with:
32-
python-version: "3.12"
33-
cache: pip
33+
enable-cache: true
3434

3535
- name: Build Demo
3636
run: |
37-
cat "${{ env.TEMPLATE }}/.github/workflows/input-for-demo.txt" | pipx run cookiecutter "${{ env.TEMPLATE }}"
37+
cat "${{ env.TEMPLATE }}/.github/workflows/input-for-demo.txt" | uvx cookiecutter "${{ env.TEMPLATE }}"
3838
find "${{ env.DEMO }}"
3939
4040
- name: Commit and push changes

hooks/post_gen_project.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,30 @@
33
import sys
44

55

6-
def possibly_install_pipx() -> None:
7-
if shutil.which("pipx") is None:
8-
# install pipx
6+
def possibly_install_uv() -> None:
7+
if shutil.which("uv") is None:
8+
# install uv
99
subprocess.run(
10-
[sys.executable, "-m", "pip", "install", "--user", "pipx"], check=False
10+
[sys.executable, "-m", "pip", "install", "--user", "uv"], check=False
1111
)
12-
# add pipx to PATH
13-
subprocess.run([sys.executable, "-m", "pipx", "ensurepath"], check=False)
1412

1513

1614
def possibly_install_nox() -> None:
1715
if shutil.which("nox") is None:
18-
# possibly install pipx
19-
possibly_install_pipx()
16+
# possibly install uv
17+
possibly_install_uv()
2018

2119
# install nox
22-
subprocess.run([sys.executable, "-m", "pipx", "install", "nox"], check=False)
20+
subprocess.run(["uv", "tool", "install", "nox"], check=False)
2321

2422

2523
def possibly_install_pre_commit() -> None:
2624
if shutil.which("pre-commit") is None:
27-
# possibly install pipx
28-
possibly_install_pipx()
25+
# possibly install uv
26+
possibly_install_uv()
2927

3028
# install pre-commit
31-
subprocess.run(
32-
[sys.executable, "-m", "pipx", "install", "pre-commit"], check=False
33-
)
29+
subprocess.run(["uv", "tool", "install", "pre-commit"], check=False)
3430

3531

3632
def initialize_git_repository() -> None:
@@ -68,9 +64,9 @@ def initialize_venv() -> None:
6864

6965

7066
if __name__ == "__main__":
71-
# possibly install nox (and pipx)
67+
# possibly install nox (and uv)
7268
possibly_install_nox()
73-
# possibly install pre-commit (and pipx)
69+
# possibly install pre-commit (and uv)
7470
possibly_install_pre_commit()
7571
# perform git initialization
7672
if "{{ cookiecutter.init_git }}" == "True":

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.ruff]
2-
select = ["ALL"]
3-
ignore = [
2+
lint.select = ["ALL"]
3+
lint.ignore = [
44
"E501", # line too long, handled by ruff-format
55
"COM", # flake8-commas, handled by ruff-format
66
"CPY", # flake8-copyright

{{ cookiecutter.app_name }}/.github/workflows/publish.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ jobs:
1313
- name: Checkout the repo
1414
uses: actions/checkout@v4
1515

16-
- name: Install Python
17-
uses: actions/setup-python@v5
16+
- name: Install the latest version of uv with caching enabled
17+
id: setup-uv
18+
uses: astral-sh/setup-uv@v5
1819
with:
19-
python-version: "3.13"
20-
cache: pip
20+
enable-cache: true
2121

2222
- name: Publish to PyPI
2323
env:
2424
FLIT_USERNAME: __token__
2525
FLIT_PASSWORD: ${{ secrets.PYPI_TOKEN }}
26-
run: pipx run flit publish
26+
run: uvx flit publish
2727
{% endraw -%}

{{ cookiecutter.app_name }}/.github/workflows/test.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ jobs:
2727
- name: Checkout the repo
2828
uses: actions/checkout@v4
2929

30-
- name: Install Python ${{ matrix.python_version }}
31-
uses: actions/setup-python@v5
30+
- name: Install the latest version of uv with caching enabled
31+
id: setup-uv
32+
uses: astral-sh/setup-uv@v5
3233
with:
33-
python-version: ${{ matrix.python_version }}
34-
cache: "pip"
34+
enable-cache: true
3535

3636
- name: Run nox "tests" session
37-
run: pipx run nox --error-on-missing-interpreters --session tests-${{ matrix.python_version }}
37+
run: uvx nox --error-on-missing-interpreters --session tests-${{ matrix.python_version }}
3838
{% endraw -%}

{{ cookiecutter.app_name }}/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
<!-- start docs-include-installation -->
1919

20-
{{ cookiecutter.friendly_name }} is available on [PyPI](https://pypi.org/project/{{ cookiecutter.app_name }}/). Install with [pipx](https://pypa.github.io/pipx/) or your package manager of choice:
20+
{{ cookiecutter.friendly_name }} is available on [PyPI](https://pypi.org/project/{{ cookiecutter.app_name }}/). Install with [uv](https://docs.astral.sh/uv/) or your package manager of choice:
2121

2222
```sh
23-
pipx install {{ cookiecutter.app_name }}
23+
uv tool install {{ cookiecutter.app_name }}
2424
```
2525

2626
<!-- end docs-include-installation -->

{{ cookiecutter.app_name }}/noxfile.py

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import os
21
from pathlib import Path
32
from shutil import rmtree
43

54
import nox
65

76
nox.options.sessions = ["pre-commit", "tests", "docs"]
7+
nox.options.default_venv_backend = "uv|virtualenv"
88
nox.options.reuse_existing_virtualenvs = True
99
nox.options.error_on_external_run = True
1010

@@ -45,46 +45,26 @@
4545
@nox.session
4646
def dev(session: nox.Session) -> None:
4747
"""Sets up a Python development environment for the project."""
48-
# install `virtualenv` CLI tool into nox's "dev" virtual environment (venv)
49-
session.install("virtualenv")
50-
51-
# initialize development environment (venv)
48+
# create the development environment (venv)
5249
session.run(
53-
"virtualenv",
50+
"uv",
51+
"venv",
52+
"--seed",
5453
"--prompt",
5554
"{{ cookiecutter.app_name }}",
5655
str(VENV_DIR),
57-
silent=True,
58-
)
59-
60-
# determine venv executable
61-
if os.name == "posix":
62-
venv_executable = VENV_DIR / "bin" / "python"
63-
else:
64-
venv_executable = VENV_DIR / "Scripts" / "python.exe"
65-
66-
# upgrade pip, setuptools and wheel
67-
session.run(
68-
str(venv_executable),
69-
"-m",
70-
"pip",
71-
"install",
72-
"--upgrade",
73-
"pip",
74-
"setuptools",
75-
"wheel",
7656
external=True,
7757
silent=True,
7858
)
7959

8060
# install the current package in editable mode (along with its dependencies)
8161
session.run(
82-
str(venv_executable),
83-
"-m",
62+
"uv",
8463
"pip",
8564
"install",
8665
"--editable",
8766
".[dev]",
67+
env={"VIRTUAL_ENV": str(VENV_DIR)},
8868
external=True,
8969
silent=True,
9070
)

0 commit comments

Comments
 (0)