Skip to content

Commit a476857

Browse files
authored
🏗️ Switch venv and dependency management to uv (#150)
1 parent 433b404 commit a476857

7 files changed

Lines changed: 1184 additions & 94 deletions

File tree

.github/CONTRIBUTING.md

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -43,66 +43,55 @@ When creating each pull request, it is crucial to adhere to the provided
4343
instructions:
4444

4545
01. [Fork][fork] the repo and clone it to your machine.
46-
02. Go to the project's root directory to create the virtual environment and
47-
activate it:
46+
02. Go to the project's root directory and sync development dependencies with
47+
[uv][uv]:
4848

4949
```console
50-
$ python -m venv .venv && . .venv/bin/activate
50+
$ uv sync --locked
5151
```
5252

53-
> In order to precisely reproduce the development environment, it is
54-
> recommended to use the Python version specified in
55-
> [`.python-version`][python-version]. The version given therein is checked
56-
> out by default in all the CI environments.
53+
> The command above creates a local virtual environment (`.venv`) and
54+
> installs all dependencies required for development. If a compatible
55+
> Python version is not available on your machine, `uv` will resolve and
56+
> install one automatically.
5757

58-
03. Install the package in editable (development) mode, along with all the
59-
optional dependencies:
58+
03. Install [Pre-commit][pre-commit] hooks:
6059

6160
```console
62-
$ pip install -e ".[dev,docs,lint,test]"
61+
$ uv run pre-commit install
6362
```
6463

65-
04. Install [Pre-commit][pre-commit] hooks:
64+
04. Run linters and tests using [Nox][nox]:
6665

6766
```console
68-
$ pre-commit install
69-
```
70-
71-
05. Run linters and tests using [Nox][nox]:
72-
73-
```console
74-
$ nox
67+
$ uv run nox
7568
```
7669

7770
This will check your fork's setup, the code quality with linters, run the
7871
existing tests in different Python environments, and measure the coverage.
7972

80-
> Note that you should have all the versions of Python installed on your
81-
> machine. Consider using [`pyenv`][pyenv] to work with multiple Python
82-
> interpreters.
83-
8473
If you want to be more specific, you can only run the linting or testing
8574
suites via the respective Nox sessions. All the available sessions can be
8675
listed using the command:
8776

8877
```console
89-
$ nox -l
78+
$ uv run nox -l
9079
```
9180

9281
For more details, see [`noxfile.py`][noxfile] and [Nox docs][nox-docs].
9382
Besides, note that all the linters and testing tools are installed in the
94-
virtual environment anyway. Therefore, feel absolutely free to use them
95-
independently of Nox as well.
83+
local uv-managed virtual environment. Therefore, feel absolutely free to
84+
invoke them independently of Nox via `uv run`, e.g., `uv run ruff check .`.
9685

97-
06. Check out a new feature branch and introduce changes.
86+
05. Check out a new feature branch and introduce changes.
9887

9988
> All the changes affecting the codebase must be accompanied by relevant
10089
> unit tests and documentation updates. We always attempt to maintain 100%
10190
> test coverage, and we require that from all pull requests as well. Those
10291
> with tests missing (if they are needed, of course) have exactly zero
10392
> chance of being merged!
10493

105-
07. Run Nox.
94+
06. Run Nox.
10695

10796
If all the Nox sessions are successful and the changes are covered by tests,
10897
commit your changes and push them to remote.
@@ -112,7 +101,7 @@ instructions:
112101
> test everything locally before pushing to remote and opening a pull
113102
> request.
114103

115-
08. [Create a pull request][create-pull-request] from the feature branch of your
104+
07. [Create a pull request][create-pull-request] from the feature branch of your
116105
fork to the `main` branch of the original repository.
117106

118107
> Don't forget to mark the pull request with an appropriate Gitmoji! 😜
@@ -135,5 +124,4 @@ project's maintainers as soon as possible. 🧐
135124
[open-feature-request]: https://github.com/paduszyk/python-gitmojis/issues/new?template=feature-request.yml
136125
[open-issue]: https://github.com/paduszyk/python-gitmojis/issues/new/choose
137126
[pre-commit]: https://pre-commit.com
138-
[pyenv]: https://github.com/pyenv/pyenv
139-
[python-version]: https://github.com/paduszyk/python-gitmojis/blob/main/.python-version
127+
[uv]: https://docs.astral.sh/uv/

.github/workflows/build-package.yml

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,16 @@ jobs:
2828
steps:
2929
- name: Check out 🎉
3030
uses: actions/checkout@v4.2.2
31-
- name: Set up Python 🐍
32-
uses: actions/setup-python@v5.3.0
31+
- name: Set up uv 🐍
32+
uses: astral-sh/setup-uv@v9.0.0
3333
with:
34-
cache: pip
34+
enable-cache: true
3535
- name: Install Nox 📦
3636
run: |
37-
python -m pip install --upgrade pip
38-
python -m pip install nox
37+
uv sync --only-group=nox --locked
3938
- name: Run Nox 🦊
4039
run:
41-
nox -s ${{ matrix.session }}
40+
uv run nox -s ${{ matrix.session }}
4241
test:
4342
name: Run tests
4443
runs-on: ${{ matrix.platform }}
@@ -52,21 +51,16 @@ jobs:
5251
steps:
5352
- name: Check out 🎉
5453
uses: actions/checkout@v4.2.2
55-
- name: Set up Python 🐍
56-
uses: actions/setup-python@v5.3.0
54+
- name: Set up uv 🐍
55+
uses: astral-sh/setup-uv@v9.0.0
5756
with:
58-
python-version: |
59-
3.10
60-
3.11
61-
3.12
62-
cache: pip
57+
enable-cache: true
6358
- name: Install Nox 📦
6459
run: |
65-
python -m pip install --upgrade pip
66-
python -m pip install nox
60+
uv sync --only-group=nox --locked
6761
- name: Run Nox 🦊
6862
run:
69-
nox -s test
63+
uv run nox -s test
7064
- name: Upload coverage reports to Codecov ⛱️
7165
if: ${{ matrix.platform == 'ubuntu-latest' }}
7266
uses: codecov/codecov-action@v5.1.2

.github/workflows/publish-package.yml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ jobs:
1212
steps:
1313
- name: Check out 🎉
1414
uses: actions/checkout@v4.2.2
15-
- name: Set up Python 🐍
16-
uses: actions/setup-python@v5.3.0
15+
- name: Set up uv 🐍
16+
uses: astral-sh/setup-uv@v9.0.0
1717
with:
18-
cache: pip
18+
enable-cache: true
1919
- name: Get the package version 🔖
2020
id: package-version
21-
run:
22-
echo "package-version=$(python ./scripts/package_version.py)" >> "$GITHUB_OUTPUT"
21+
run: echo "package-version=$(uv run python ./scripts/package_version.py)" >> "$GITHUB_OUTPUT"
2322
pypi-publish:
2423
needs: get-release-tag
2524
name: Upload to PyPI
@@ -32,17 +31,12 @@ jobs:
3231
steps:
3332
- name: Check out 🎉
3433
uses: actions/checkout@v4.2.2
35-
- name: Set up Python 🐍
36-
uses: actions/setup-python@v5.3.0
34+
- name: Set up uv 🐍
35+
uses: astral-sh/setup-uv@v9.0.0
3736
with:
38-
cache: pip
39-
- name: Install PyPA `build` package 📦
40-
run: |
41-
python -m pip install --upgrade pip
42-
python -m pip install build
37+
enable-cache: true
4338
- name: Build the package 👷
44-
run:
45-
python -m build
39+
run: uv build
4640
- name: Publish to PyPI 🚀
4741
uses: pypa/gh-action-pypi-publish@v1.12.3
4842
create-release-tag:

.github/workflows/sync-api-backup.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@ jobs:
1212
steps:
1313
- name: Check out 🎉
1414
uses: actions/checkout@v4.2.2
15-
- name: Set up Python 🐍
16-
uses: actions/setup-python@v5.3.0
15+
- name: Set up uv 🐍
16+
uses: astral-sh/setup-uv@v9.0.0
1717
with:
18-
cache: pip
18+
enable-cache: true
1919
- name: Install the package 📦
2020
run: |
21-
python -m pip install --upgrade pip
22-
python -m pip install -e .
21+
uv sync --no-dev --locked
2322
- name: Run the `sync` command 🚀
2423
run:
25-
gitmojis sync
24+
uv run gitmojis sync
2625
- name: Create pull request 🎉
2726
uses: peter-evans/create-pull-request@v7.0.5
2827
with:

noxfile.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
11
import nox
2+
import nox_uv
23

34
# Nox sessions and configuration
45
# https://nox.thea.codes/en/stable/config.html
56

7+
nox.options.default_venv_backend = "uv"
68

7-
@nox.session()
9+
10+
@nox_uv.session(uv_only_groups=["black"])
811
def black(session: nox.Session) -> None:
9-
session.install("black")
1012
session.run("black", "--check", "--diff", ".")
1113

1214

13-
@nox.session()
15+
@nox_uv.session(uv_groups=["mypy"])
1416
def mypy(session: nox.Session) -> None:
15-
session.install("-e", ".")
16-
session.install("mypy")
1717
session.run("mypy", "--install-types", "--non-interactive", ".")
1818

1919

20-
@nox.session()
20+
@nox_uv.session(uv_only_groups=["ruff"])
2121
def ruff(session: nox.Session) -> None:
22-
session.install("ruff")
2322
session.run("ruff", "check", "--diff", ".")
2423

2524

26-
@nox.session(
25+
@nox_uv.session(
26+
uv_groups=["test"],
2727
python=[
2828
"3.10",
2929
"3.11",
3030
"3.12",
31-
]
31+
],
3232
)
3333
def test(session: nox.Session) -> None:
34-
session.install("-e", ".[test]")
3534
session.run("pytest")

pyproject.toml

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,47 @@ classifiers = [
2727
]
2828
requires-python = ">= 3.10"
2929
dependencies = [
30-
"click",
31-
"requests",
30+
"click>=8.4.2,<9.0.0",
31+
"requests>=2.34.2,<3.0.0",
3232
]
3333

34-
[project.optional-dependencies]
34+
[project.scripts]
35+
"gitmojis" = "gitmojis.__main__:main"
36+
37+
[dependency-groups]
38+
black = [
39+
"black>=26.5.1,<27.0.0",
40+
]
3541
dev = [
36-
"nox",
37-
"pre-commit",
42+
{ include-group = "black" },
43+
{ include-group = "local" },
44+
{ include-group = "nox" },
45+
{ include-group = "mypy" },
46+
{ include-group = "ruff" },
47+
{ include-group = "test" },
48+
]
49+
local = [
50+
"pre-commit>=4.6.1,<5.0.0",
3851
]
39-
lint = [
40-
"black",
41-
"mypy",
42-
"ruff",
43-
"types-requests",
52+
nox = [
53+
"nox>=2026.7.11,<2027.0.0",
54+
"nox-uv>=0.8.0",
55+
]
56+
ruff = [
57+
"ruff>=0.15.22,<0.16.0",
58+
]
59+
mypy = [
60+
"mypy>=2.3.0,<3.0.0",
61+
"types-requests>=2.33.0.20260712,<3.0.0.0",
4462
]
4563
test = [
46-
"pytest",
47-
"pytest-click",
48-
"pytest-cov",
49-
"pytest-custom-exit-code",
50-
"pytest-mock",
64+
"pytest>=9.1.1,<10.0.0",
65+
"pytest-click>=1.1.0,<2.0.0",
66+
"pytest-cov>=7.1.0,<8.0.0",
67+
"pytest-custom-exit-code>=0.3.0,<0.4.0",
68+
"pytest-mock>=3.15.1,<4.0.0",
5169
]
5270

53-
[project.scripts]
54-
"gitmojis" = "gitmojis.__main__:main"
55-
5671
[tool.setuptools.packages.find]
5772
include = ["gitmojis*"]
5873
where = ["src"]

0 commit comments

Comments
 (0)