Skip to content

Commit bfd0f2b

Browse files
committed
feat: more to uv + ruff
1 parent 330a9dc commit bfd0f2b

6 files changed

Lines changed: 174 additions & 143 deletions

File tree

.github/workflows/ci.yml

Lines changed: 69 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,85 @@ name: CI
22

33
on:
44
push:
5-
branches:
6-
- main
5+
branches: [main]
76
pull_request:
87
paths:
9-
- '.github/workflows/ci.yml'
10-
- 'my_repo/**'
11-
- 'poetry.lock'
8+
- ".github/workflows/ci.yml"
9+
- "pyproject.toml"
10+
- "uv.lock"
11+
- "src/**"
12+
- "tests/**"
1213

1314
jobs:
1415
linting:
15-
runs-on: ubuntu-22.04
16+
runs-on: ubuntu-24.04
17+
1618
steps:
17-
- uses: actions/checkout@v3
18-
- uses: actions/setup-python@v4
19+
- uses: actions/checkout@v4
20+
21+
- uses: actions/setup-python@v5
1922
with:
2023
python-version: "3.12"
21-
- name: Install Dependencies
24+
25+
# Cache uv resolver + project venv
26+
- name: Cache uv + venv
27+
uses: actions/cache@v4
28+
with:
29+
path: |
30+
~/.cache/uv
31+
./.venv
32+
key: uv-${{ runner.os }}-${{ runner.arch }}-py${{ steps.setup-python.outputs.python-version || '3.12' }}-${{ hashFiles('uv.lock') }}
33+
restore-keys: |
34+
uv-${{ runner.os }}-${{ runner.arch }}-py${{ steps.setup-python.outputs.python-version || '3.12' }}-
35+
36+
- name: Install uv
2237
run: |
23-
curl -sSL https://install.python-poetry.org | python3 -
24-
poetry install
25-
- name: black
26-
run: poetry run black --check .
27-
- name: isort
28-
run: poetry run isort --check .
29-
- name: flake8
30-
run: poetry run flake8 --exclude .venv .
31-
- name: mypy
32-
run: ./run-mypy
33-
34-
# test:
35-
# runs-on: ubuntu-22.04
38+
python -m pip install --upgrade pip
39+
python -m pip install uv
40+
uv --version
41+
42+
# Install deps (dev group included by default); --frozen enforces uv.lock
43+
- name: Sync dependencies
44+
run: uv sync --frozen
45+
46+
# Ruff: formatting check (no changes) and lint (GitHub format for inline annotations)
47+
- name: Ruff format (check)
48+
run: uv run ruff format --check src tests
49+
50+
- name: Ruff lint
51+
run: uv run ruff check --output-format=github src tests
52+
53+
# MyPy (uses your [tool.mypy] config in pyproject)
54+
- name: MyPy
55+
run: uv run mypy .
56+
57+
# tests:
58+
# runs-on: ubuntu-24.04
3659
# steps:
37-
# - uses: actions/checkout@v3
38-
# - uses: actions/setup-python@v4
60+
# - uses: actions/checkout@v4
61+
62+
# - uses: actions/setup-python@v5
3963
# with:
4064
# python-version: "3.12"
41-
# - name: Install Dependencies
65+
66+
# - name: Cache uv + venv
67+
# uses: actions/cache@v4
68+
# with:
69+
# path: |
70+
# ~/.cache/uv
71+
# ./.venv
72+
# key: uv-${{ runner.os }}-${{ runner.arch }}-py${{ steps.setup-python.outputs.python-version || '3.12' }}-${{ hashFiles('uv.lock') }}
73+
# restore-keys: |
74+
# uv-${{ runner.os }}-${{ runner.arch }}-py${{ steps.setup-python.outputs.python-version || '3.12' }}-
75+
76+
# - name: Install uv
4277
# run: |
43-
# curl -sSL https://install.python-poetry.org | python3 -
44-
# poetry install
45-
# - name: Run Tests
46-
# run: poetry run pytest
78+
# python -m pip install --upgrade pip
79+
# python -m pip install uv
80+
# uv --version
81+
82+
# - name: Sync dependencies
83+
# run: uv sync --frozen
84+
85+
# - name: Run tests
86+
# run: uv run pytest -q

.pre-commit-config.yaml

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
11
repos:
2-
- repo: https://github.com/psf/black
3-
rev: 24.2.0
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.6.7
44
hooks:
5-
- id: black
6-
language_version: python3
7-
args: [--line-length=120]
8-
9-
- repo: https://github.com/pycqa/isort
10-
rev: 5.13.2
11-
hooks:
12-
- id: isort
13-
args: ["--profile", "black", "--filter-files"]
14-
15-
- repo: https://github.com/pycqa/flake8.git
16-
rev: 7.0.0
17-
hooks:
18-
- id: flake8
19-
args: [--ignore=E203 E266 E501 W503 E741 C901 W405 E402 E211 W291 F722 --max-line-length=120]
5+
- id: ruff
6+
args: [--fix]
7+
exclude: '(^dev/)|(\.ipynb$)'
8+
- id: ruff-format
9+
exclude: '(^dev/)|(\.ipynb$)'
2010

2111
- repo: local
2212
hooks:
@@ -28,10 +18,27 @@ repos:
2818
require_serial: true
2919
verbose: true
3020

31-
- repo: https://github.com/python-poetry/poetry
32-
rev: '1.7.0'
21+
# Keep uv.lock up to date
22+
- repo: https://github.com/astral-sh/uv-pre-commit
23+
rev: 0.8.22 # pin to your uv version
24+
hooks:
25+
- id: uv-lock
26+
27+
# Fail if uv.lock would change
28+
- repo: https://github.com/astral-sh/uv-pre-commit
29+
rev: 0.8.22
30+
hooks:
31+
- id: uv-lock
32+
args: ["--check"] # or "--locked"
33+
34+
# Export requirements
35+
- repo: https://github.com/astral-sh/uv-pre-commit
36+
rev: 0.8.22
3337
hooks:
34-
- id: poetry-check
35-
- id: poetry-lock
36-
- id: poetry-export
37-
args: ["-f", "requirements.txt", "-o", "requirements.txt", "--with", "dev", "--without-hashes"]
38+
- id: uv-export
39+
args:
40+
- "--format=requirements.txt"
41+
- "--all-groups" # or: "--group=dev"
42+
- "--no-hashes"
43+
- "--output-file=requirements.txt"
44+
- "--frozen" # don’t re-lock during export

README.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
# my_repo
1+
# my_package
22

33
## Installation
44

5-
For development usage, we use [`poetry`](https://python-poetry.org/docs/#installing-with-the-official-installer) to handle dependency installation.
6-
Poetry can be installed via, e.g.
5+
For development usage, we use [`uv`](https://docs.astral.sh/uv/) to handle dependency installation.
6+
uv can be installed via, e.g.
77

88
```bash
9-
curl -sSL https://install.python-poetry.org | python3 -
10-
poetry self update
9+
curl -LsSf https://astral.sh/uv/install.sh | sh
1110
```
1211

13-
and ensuring that `poetry` is available in your `$PATH`
12+
and ensuring that `uv` is available in your `$PATH`
1413

1514
Install the dependencies:
1615

1716
```bash
18-
poetry install
19-
poetry self add poetry-plugin-export
20-
poetry config warnings.export false
21-
poetry run pre-commit install
17+
uv install
18+
uv tool install pre-commit --with pre-commit-uv --force-reinstall
19+
uvx pre-commit install
2220
```

poetry.toml

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

pyproject.toml

Lines changed: 67 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,77 @@
1-
[tool.poetry]
2-
name = "my_repo"
1+
[project]
2+
name = "my_package"
33
version = "0.1.0"
44
description = ""
55
authors = [
6-
"Giles Strong <giles.c.strong@gmail.com>",
6+
{name = "Giles Strong", email = "giles.c.strong@gmail.com"},
77
]
88
readme = "README.md"
99
keywords = []
10-
include = ["py.typed"]
11-
12-
[tool.poetry.dependencies]
13-
python = "~3.12"
14-
15-
[tool.poetry.group.dev.dependencies]
16-
notebook = "^7.0.0"
17-
jupyter = "^1.0.0"
18-
traitlets = "5.9.0"
19-
ipykernel = "^6.29.5"
20-
pre-commit = "^3.6.1"
21-
flake8 = "^7.0.0"
22-
mypy = "^1.8.0"
23-
pytest-mock = "^3.12.0"
24-
flaky = "^3.7.0"
25-
pytest-lazy-fixture = "^0.6.3"
26-
isort = "^5.13.2"
27-
black = "^24.10.0"
28-
pytest = "<8.0.0"
29-
pandas-stubs = "^2.2.2"
10+
requires-python = ">=3.12,<4.0"
11+
dependencies = [
12+
]
13+
14+
[dependency-groups]
15+
dev = [
16+
"notebook>=7.0.0",
17+
"jupyter>=1.0.0",
18+
"traitlets==5.9.0",
19+
"ipykernel>=6.29.5",
20+
"pre-commit>=3.6.1",
21+
"mypy>=1.8.0",
22+
"pytest-mock>=3.12.0",
23+
"flaky>=3.7.0",
24+
"pytest-lazy-fixture>=0.6.3",
25+
"pytest<8.0.0",
26+
"pandas-stubs>=2.2.2",
27+
"ruff>=0.6",
28+
"pytest-asyncio>=0.23.8",
29+
]
3030

3131
[build-system]
32-
requires = ["poetry-core"]
33-
build-backend = "poetry.core.masonry.api"
32+
requires = ["hatchling>=1.25"]
33+
build-backend = "hatchling.build"
34+
35+
[tool.hatch.build.targets.wheel]
36+
packages = ["src/my_package"]
37+
sources = ["src"]
38+
include = ["src/my_package/py.typed"]
3439

35-
[tool.black]
40+
[tool.hatch.build.targets.sdist]
41+
include = ["src/my_package/py.typed"]
42+
43+
[tool.ruff]
3644
line-length = 120
37-
target-version = ['py310']
38-
include = '\.pyi?$'
39-
exclude = '''
40-
/(
41-
\.git
42-
| \.mypy_cache
43-
| \.tox
44-
| \.venv
45-
| _build
46-
| build
47-
| dist
48-
)/
49-
'''
50-
51-
[tool.isort]
52-
profile = "black"
53-
line_length = 120
45+
target-version = "py312"
46+
extend-exclude = [
47+
"dev/",
48+
"**/*.ipynb",
49+
]
50+
51+
[tool.ruff.lint]
52+
select = ["E", "F", "W", "B", "C90", "I"]
53+
ignore = ["B007", "E203", "E266", "E501", "E741", "C901", "E402", "E211", "W291", "F722"]
54+
55+
[tool.ruff.lint.mccabe]
56+
max-complexity = 18
57+
58+
[tool.ruff.format]
59+
quote-style = "preserve"
60+
61+
[tool.mypy]
62+
python_version = "3.12"
63+
disallow_untyped_calls = false
64+
disallow_untyped_defs = true
65+
check_untyped_defs = true
66+
exclude = "tests/|\\.venv/|dev/"
67+
no_strict_optional = true
68+
disable_error_code = "attr-defined, override, union-attr"
69+
70+
[[tool.mypy.overrides]]
71+
module = [
72+
]
73+
ignore_missing_imports = true
74+
75+
[tool.pytest.ini_options]
76+
addopts = "-m 'not long'"
77+
asyncio_mode = "auto"

setup.cfg

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

0 commit comments

Comments
 (0)