Skip to content

Commit bf17e29

Browse files
committed
CHG: migrate from poetry to uv
- Poetry → uv (package manager) - poetry-core → hatchling (build backend) - black + isort + flake8 → ruff (linting/formatting) - Python 3.10~3.12 → 3.12~3.13 - tox-uv plugin 추가 - Version 1.1.4 → 2.0.0
1 parent e9ebb6d commit bf17e29

11 files changed

Lines changed: 504 additions & 732 deletions

File tree

.flake8

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

.github/workflows/ci.yml

Lines changed: 22 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,52 +7,36 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
python-version: ["3.10", "3.11", "3.12"]
10+
python-version: ["3.12", "3.13"]
1111

1212
steps:
1313
- name: Checkout Project Package
14-
uses: actions/checkout@v3
14+
uses: actions/checkout@v4
1515

16-
- name: Setup Python
17-
uses: actions/setup-python@v4
18-
with:
19-
python-version: ${{ matrix.python-version }}
16+
- name: Install uv
17+
uses: astral-sh/setup-uv@v5
2018

21-
- name: Install Poetry
22-
uses: snok/install-poetry@v1
23-
24-
- name: Install tox
25-
run: pip install tox tox-gh-actions
19+
- name: Install Python
20+
run: uv python install ${{ matrix.python-version }}
2621

2722
- name: Test
28-
run: poetry run tox
23+
run: uv run tox -e py$(echo ${{ matrix.python-version }} | tr -d '.')
2924

3025
unittest:
3126
runs-on: ubuntu-latest
32-
strategy:
33-
matrix:
34-
python-version: ["3.11"]
3527

3628
steps:
3729
- name: Checkout Project Package
38-
uses: actions/checkout@v3
30+
uses: actions/checkout@v4
3931

40-
- name: Setup Python
41-
uses: actions/setup-python@v4
42-
with:
43-
python-version: ${{ matrix.python-version }}
44-
45-
- name: Install Poetry
46-
uses: snok/install-poetry@v1
32+
- name: Install uv
33+
uses: astral-sh/setup-uv@v5
4734

4835
- name: Install Dependencies
49-
run: poetry install --no-root -v
50-
51-
- name: Set Python Path
52-
run: echo "PYTHONPATH=src" >> $GITHUB_ENV
36+
run: uv sync --group dev
5337

5438
- name: Test
55-
run: poetry run pytest tests/ --cov=src/ --cov-report xml:coverage.xml
39+
run: uv run pytest tests/ --cov=src/ --cov-report xml:coverage.xml
5640

5741
- name: Report Coverage
5842
uses: orgoro/coverage@v3.1
@@ -62,29 +46,19 @@ jobs:
6246

6347
lint:
6448
runs-on: ubuntu-latest
65-
strategy:
66-
matrix:
67-
python-version: ["3.11"]
49+
6850
steps:
6951
- name: Checkout Project Package
70-
uses: actions/checkout@v3
71-
72-
- name: Setup Python
73-
uses: actions/setup-python@v4
74-
with:
75-
python-version: ${{ matrix.python-version }}
76-
77-
- name: Install Poetry
78-
uses: snok/install-poetry@v1
52+
uses: actions/checkout@v4
7953

80-
- name: Install Python Dependencies
81-
run: poetry install --no-root -v
54+
- name: Install uv
55+
uses: astral-sh/setup-uv@v5
8256

83-
- name: Flake8
84-
run: poetry run flake8 src/ tests/
57+
- name: Install Dependencies
58+
run: uv sync --group dev
8559

86-
- name: Isort
87-
run: poetry run isort -c src/ tests/
60+
- name: Ruff Check
61+
run: uv run ruff check src/ tests/
8862

89-
- name: Black
90-
run: poetry run black --check src/ tests/
63+
- name: Ruff Format Check
64+
run: uv run ruff format --check src/ tests/

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ ipython_config.py
201201
# https://pdm.fming.dev/#use-with-ide
202202
.pdm.toml
203203

204+
# uv
205+
# Similar to poetry.lock, it is generally recommended to include uv.lock in version control.
206+
# https://docs.astral.sh/uv/concepts/projects/layout/#the-lockfile
207+
#uv.lock
208+
204209
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
205210
__pypackages__/
206211

.pre-commit-config.yaml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.5.0
3+
rev: v5.0.0
44
hooks:
55
- id: check-yaml
66
- id: end-of-file-fixer
77
- id: trailing-whitespace
8-
- repo: https://github.com/psf/black
9-
rev: 24.3.0
8+
- repo: https://github.com/astral-sh/ruff-pre-commit
9+
rev: v0.9.10
1010
hooks:
11-
- id: black
12-
- repo: https://github.com/pycqa/isort
13-
rev: 5.13.2
14-
hooks:
15-
- id: isort
16-
name: isort (python)
17-
- repo: https://github.com/pycqa/flake8
18-
rev: 7.0.0
19-
hooks:
20-
- id: flake8
11+
- id: ruff
12+
args: [--fix]
13+
- id: ruff-format

README.md

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Python Library
22

33
![Build](https://github.com/8percent/python-library/actions/workflows/ci.yml/badge.svg)
4-
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
4+
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
55
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
66
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/8percent/python-library/master.svg)](https://results.pre-commit.ci/latest/github/8percent/python-library/master)
77

@@ -13,7 +13,7 @@ Developer can start writing code without wasting so much time to set up basic st
1313

1414
- [Usage](#usage)
1515
- [Installation](#installation)
16-
- [Install Poetry](#install-poetry)
16+
- [Install uv](#install-uv)
1717
- [Configuration](#configuration)
1818
- [Architecture](#architecture)
1919
- [Project Layout](#project-layout)
@@ -31,22 +31,22 @@ We recommand to use GitHub's `Use this template` button to kick off this templat
3131
But yet, you can set up copy this template by cloning or downloading this repository.
3232

3333
Once you prepared this repository on your local machine, remaining part is project configuration.
34-
Unless you are familiar with stacks(poetry, tox, GitHub action, etc.),
34+
Unless you are familiar with stacks(uv, tox, GitHub action, etc.),
3535
Subsequent Installation step might be helpful.
3636

3737
---
3838

3939
## Installation
4040

41-
### Install Poetry
41+
### Install uv
4242

43-
Please read this [installation guide](https://python-poetry.org/docs/) to install poetry.
43+
Please read this [installation guide](https://docs.astral.sh/uv/getting-started/installation/) to install uv.
4444

4545
Then install package dependencies with this command at project root.
46-
This will resolve package dependencies and install it in poetry managed virtual environment.
46+
This will resolve package dependencies and install it in uv managed virtual environment.
4747

4848
```shell
49-
poetry install
49+
uv sync --group dev
5050
```
5151

5252
### (Optional) Install Pyenv
@@ -60,14 +60,14 @@ As quoted [pyenv readme](https://github.com/pyenv/pyenv/blob/master/README.md) d
6060

6161
#### pyproject.toml
6262

63-
This file contains build system requirements and information, which are used by poetry to build the package.
63+
This file contains build system requirements and information, which are used by hatchling to build the package.
6464
We tried to gather every package related settings as much as possible here.
65-
Through this design decision, project could remove package dependant configuration files like `.isort.cfg`, `pytest.ini`, etc.
65+
Through this design decision, project could remove package dependant configuration files like `pytest.ini`, etc.
6666

67-
- **[tool.poetry]**: Describe package's metadata. Including package name, versions, dscription, authors etc.
68-
- **[tool.poetry.dependencies]**, **[tool.poetry.dev-dependencies]**: Manage package's dependencies. Poetry will check this section to resolve requirements version.
69-
- **[build-system]**: Define how to build package. Generally no need to edit this section.
70-
- **[tool.isort]**, **[tool.black]**: By Editing this part, you can set how linting library should work.
67+
- **[project]**: Describe package's metadata following PEP 621. Including package name, versions, description, authors etc.
68+
- **[dependency-groups]**: Manage dev dependencies following PEP 735.
69+
- **[build-system]**: Define how to build package using hatchling. Generally no need to edit this section.
70+
- **[tool.ruff]**: Linting and formatting configuration using ruff.
7171
- **[tool.pytest.ini_options]**: pytest configuration.
7272

7373
Except **[build-system]**, We suggest you to update every settings above.
@@ -79,19 +79,19 @@ Each job works concurrently on different virtual machines.
7979

8080
- **package-build**: Use tox to test package against multiple python versions.
8181
- **unittest**: Test code and report coverage using pytest.
82-
- **lint**: Lint code using flake, isort, black.
82+
- **lint**: Lint and format code using ruff.
8383

8484
Change `python-version` value in this file according to package compatible python versions which configured at `pyproject.toml`.
8585

8686
#### tox.ini
8787

8888
Tox runs test against packages which built in isolated virtual environment.
89+
Uses `tox-uv` plugin for uv integration.
8990

90-
- **[tox]**: Tox global settings.
91-
- **[gh-actions]**: Mapping between GitHub action python-version matrix and tox virtual environment.
91+
- **[tox]**: Tox global settings including uv-venv-lock-runner.
9292
- **[testenv]**: Test environment setting.
9393

94-
According to package's python compatible versions, **[tox.envlist]** and **[gh-actions]** should be defined.
94+
According to package's python compatible versions, **[tox.envlist]** should be defined.
9595

9696
#### Source code
9797

@@ -100,9 +100,8 @@ Make your own named package in src directory.
100100
**NOTE**: package setting in `pyproject.toml` should be changed as you set up your own package.
101101

102102
```toml
103-
packages = [
104-
{ include = "{your-python-package-name}", from = "src" },
105-
]
103+
[tool.hatch.build.targets.wheel]
104+
packages = ["src/{your-python-package-name}"]
106105
```
107106

108107
#### Test Code
@@ -113,10 +112,10 @@ To test your source code, simply use 'pytest' or 'tox'.
113112

114113
```shell
115114
# Use pytest
116-
$ pytest tests/
115+
$ uv run pytest tests/
117116

118117
# Use Tox
119-
$ tox
118+
$ uv run tox
120119
```
121120

122121
---
@@ -137,12 +136,12 @@ This layout is better explained in this [blog post by Ionel Cristian Mărieș](h
137136

138137
### Dependency Management & Packaging
139138

140-
We use [Poetry](https://github.com/python-poetry/poetry) to control dependencies and build package.
141-
Advantages of using poetry is well explained in their [README.md](https://github.com/python-poetry/poetry/blob/master/README.md).
139+
We use [uv](https://github.com/astral-sh/uv) to control dependencies and build package.
140+
uv is an extremely fast Python package and project manager, written in Rust.
142141

143-
By default, Poetry automatically manages virtual environment for each project and python version.
144-
It frees developer from virtual environment management. But also offers option to manage virtual environment manually.
145-
For more information read this [docs](https://python-poetry.org/docs/managing-environments/)
142+
By default, uv automatically manages virtual environment for each project.
143+
It frees developer from virtual environment management.
144+
For more information read the [docs](https://docs.astral.sh/uv/).
146145

147146
### Continuous Integration
148147

0 commit comments

Comments
 (0)