Skip to content

Commit 9590554

Browse files
authored
feat: migrate to uv (#293)
* migrate to uv Signed-off-by: gruebel <[email protected]> * fix build setup Signed-off-by: gruebel <[email protected]> * fix paths-filter Signed-off-by: gruebel <[email protected]> * add uv workspace Signed-off-by: gruebel <[email protected]> * fix type check Signed-off-by: gruebel <[email protected]> --------- Signed-off-by: gruebel <[email protected]>
1 parent 8c015cf commit 9590554

File tree

20 files changed

+1871
-546
lines changed

20 files changed

+1871
-546
lines changed

.github/workflows/build.yml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,27 @@ jobs:
5656
with:
5757
submodules: recursive
5858

59-
- name: Set up Python ${{ matrix.python-version }}
60-
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
59+
- name: Install uv and set the python version ${{ matrix.python-version }}
60+
uses: astral-sh/setup-uv@7edac99f961f18b581bbd960d59d049f04c0002f # v6
6161
with:
6262
python-version: ${{ matrix.python-version }}
63-
cache: "pip"
6463

65-
- name: Install hatch
66-
run: pip install hatch
64+
- name: Install dependencies
65+
working-directory: ${{ matrix.package }}
66+
run: uv sync --frozen
6767

6868
- name: Building first to generate files
69-
run: hatch build
7069
working-directory: ${{ matrix.package }}
70+
run: uv build
7171

7272
- name: Type checking
7373
if: matrix.python-version == '3.13'
7474
working-directory: ${{ matrix.package }}
75-
run: hatch run mypy:run
75+
run: uv run mypy-check --frozen
7676

7777
- name: Test with pytest
78-
run: hatch test -c
7978
working-directory: ${{ matrix.package }}
79+
run: uv run cov --frozen
8080

8181
- if: matrix.python-version == '3.13'
8282
name: Upload coverage to Codecov
@@ -93,10 +93,11 @@ jobs:
9393

9494
steps:
9595
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
96-
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
96+
- name: Install uv and set the python version
97+
uses: astral-sh/setup-uv@7edac99f961f18b581bbd960d59d049f04c0002f # v6
9798
with:
9899
python-version: "3.13"
99-
cache: "pip"
100+
enable-cache: false # caching is done automatically in `pre-commit/action`
100101

101102
- name: Run pre-commit
102103
uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1

.github/workflows/release.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,21 @@ jobs:
5151
with:
5252
submodules: recursive
5353

54-
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
54+
- name: Install uv and set the python version
55+
uses: astral-sh/setup-uv@7edac99f961f18b581bbd960d59d049f04c0002f # v6
5556
with:
56-
python-version: '3.13'
57+
python-version: "3.13"
5758

58-
- name: Upgrade pip
59-
run: pip install --upgrade pip
60-
61-
- name: Install hatch
62-
run: pip install hatch
59+
- name: Install dependencies
60+
working-directory: ${{ matrix.path }}
61+
run: uv sync --frozen
6362

6463
- name: Build a binary wheel and a source tarball
65-
run: hatch build
6664
working-directory: ${{ matrix.path }}
65+
run: uv build
6766

6867
- name: Publish a Python distribution to PyPI
6968
uses: pypa/gh-action-pypi-publish@release/v1
7069
with:
71-
packages-dir: ${{ matrix.path }}/dist
70+
# `uv` stores the build packages in the root `dist` folder
71+
packages-dir: dist

CONTRIBUTING.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ Python 3.9 and above are supported by the SDK.
1212

1313
### Installation and Dependencies
1414

15-
We use [Hatch](https://hatch.pypa.io/) to manage the project. Hatch does not have built-in support for monorepos yet, so you must run it inside each package directory.
15+
We use [uv](https://github.com/astral-sh/uv) for fast Python package management and dependency resolution.
16+
uv does have built-in support for monorepos via workspace, but it is not supported by release-please yet.
1617

17-
To install Hatch, just run `pip install hatch`.
18+
To install uv, follow the [installation guide](https://docs.astral.sh/uv/getting-started/installation/).
1819

1920
You will also need to setup the `pre-commit` hooks. Run `pre-commit install` in the root directory of the repository. If you don't have `pre-commit` installed, you can install it with `pip install pre-commit`.
2021

@@ -35,12 +36,12 @@ The Flagd provider utilizes the [gherkin integration tests](https://github.com/o
3536
To run the integration tests you need to have a container runtime, like docker, ranger, etc. installed.
3637

3738
```bash
38-
hatch run test
39+
uv run test --frozen
3940
```
4041

4142
### Type checking
4243

43-
Run `mypy` by entering the package directory and running `hatch run mypy:run`.
44+
Run `mypy` by entering the package directory and running `uv run mypy-check --frozen`.
4445

4546
## Pull Request
4647

@@ -75,8 +76,8 @@ Ensure your development environment is all set up by building and testing
7576

7677
```bash
7778
cd <package>
78-
hatch build
79-
hatch test
79+
uv build
80+
uv run test --frozen
8081
```
8182

8283
To start working on a new feature or bugfix, create a new branch and start working on it.
Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
# pyproject.toml
21
[build-system]
3-
requires = ["hatchling"]
4-
build-backend = "hatchling.build"
2+
requires = ["uv_build~=0.8.0"]
3+
build-backend = "uv_build"
54

65
[project]
76
name = "openfeature-hooks-opentelemetry"
@@ -25,46 +24,17 @@ requires-python = ">=3.9"
2524
[project.urls]
2625
Homepage = "https://github.com/open-feature/python-sdk-contrib"
2726

28-
[tool.hatch]
29-
30-
[tool.hatch.envs.hatch-test]
31-
dependencies = [
32-
"coverage[toml]>=6.5",
33-
"pytest",
34-
]
35-
pre-install-commands = [
36-
"hatch build",
27+
[dependency-groups]
28+
dev = [
29+
"coverage[toml]>=7.10.0,<8.0.0",
30+
"mypy[faster-cache]>=1.17.0,<2.0.0",
31+
"pytest>=8.4.0,<9.0.0",
3732
]
3833

39-
[tool.hatch.envs.hatch-test.scripts]
40-
run = "pytest {args:tests}"
41-
run-cov = "coverage run -m pytest {args:tests}"
42-
cov-combine = "coverage combine"
43-
cov-report = [
44-
"coverage xml",
45-
"coverage html",
46-
"coverage report",
47-
]
48-
cov = [
49-
"test-cov",
50-
"cov-report",
51-
]
52-
53-
[tool.hatch.envs.mypy]
54-
dependencies = [
55-
"mypy[faster-cache]>=1.13.0",
56-
]
57-
58-
[tool.hatch.envs.mypy.scripts]
59-
run = "mypy"
60-
61-
[tool.hatch.build.targets.sdist]
62-
exclude = [
63-
".gitignore",
64-
]
65-
66-
[tool.hatch.build.targets.wheel]
67-
packages = ["src/openfeature"]
34+
[tool.uv.build-backend]
35+
module-name = "openfeature"
36+
module-root = "src"
37+
namespace = true
6838

6939
[tool.mypy]
7040
mypy_path = "src"
@@ -78,3 +48,13 @@ pretty = true
7848

7949
strict = true
8050
disallow_any_generics = false
51+
52+
[project.scripts]
53+
# workaround while UV doesn't support scripts directly in the pyproject.toml
54+
# see: https://github.com/astral-sh/uv/issues/5903
55+
cov-report = "scripts.scripts:cov_report"
56+
cov = "scripts.scripts:cov"
57+
# don't name it `mypy` otherwise `uv` will override the actual binary
58+
mypy-check = "scripts.scripts:mypy"
59+
test = "scripts.scripts:test"
60+
test-cov = "scripts.scripts:test_cov"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# ruff: noqa: S602, S607
2+
import subprocess
3+
4+
5+
def test() -> None:
6+
"""Run pytest tests."""
7+
subprocess.run("pytest tests", shell=True, check=True)
8+
9+
10+
def test_cov() -> None:
11+
"""Run tests with coverage."""
12+
subprocess.run("coverage run -m pytest tests", shell=True, check=True)
13+
14+
15+
def cov_report() -> None:
16+
"""Generate coverage report."""
17+
subprocess.run("coverage xml", shell=True, check=True)
18+
19+
20+
def cov() -> None:
21+
"""Run tests with coverage and generate report."""
22+
test_cov()
23+
cov_report()
24+
25+
26+
def mypy() -> None:
27+
"""Run mypy."""
28+
subprocess.run("mypy", shell=True, check=True)

mypy.ini

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,53 @@
1+
[build-system]
2+
requires = ["uv_build~=0.8.0"]
3+
build-backend = "uv_build"
4+
15
[project]
26
name = "openfeature-provider-env-var"
37
version = "0.1.0"
48
description = "OpenFeature Python Environment Variable Provider"
59
readme = "README.md"
6-
requires-python = ">=3.9"
10+
authors = [{ name = "OpenFeature", email = "[email protected]" }]
11+
license = { file = "LICENSE" }
12+
classifiers = [
13+
"License :: OSI Approved :: Apache Software License",
14+
"Programming Language :: Python",
15+
"Programming Language :: Python :: 3",
16+
]
17+
keywords = []
718
dependencies = [
819
"openfeature-sdk>=0.8.2",
920
]
10-
authors = [{ name = "OpenFeature", email = "[email protected]" }]
21+
requires-python = ">=3.9"
1122

12-
[build-system]
13-
requires = ["hatchling"]
14-
build-backend = "hatchling.build"
23+
[project.urls]
24+
Homepage = "https://github.com/open-feature/python-sdk-contrib"
1525

1626
[dependency-groups]
1727
dev = [
18-
"pytest>=8.3.5",
19-
"pytest-cov>=6.1.1",
28+
"coverage[toml]>=7.10.0,<8.0.0",
29+
"mypy[faster-cache]>=1.17.0,<2.0.0",
30+
"pytest>=8.4.0,<9.0.0",
2031
]
2132

22-
[tool.hatch.build.targets.wheel]
23-
packages = ["src/openfeature"]
24-
25-
[tool.hatch]
26-
27-
pre-install-commands = [
28-
"hatch build",
29-
]
30-
31-
[tool.hatch.envs.mypy.scripts]
32-
run = "mypy"
33-
34-
[tool.hatch.envs.mypy]
35-
dependencies = ["mypy"]
36-
37-
[tool.uv]
38-
required-version = "~=0.8.0"
33+
[tool.uv.build-backend]
34+
module-name = "openfeature"
35+
module-root = "src"
36+
namespace = true
3937

4038
[tool.mypy]
4139
mypy_path = "src"
4240
files = "src"
4341

42+
python_version = "3.9" # should be identical to the minimum supported version
43+
namespace_packages = true
44+
explicit_package_bases = true
45+
local_partial_types = true
46+
pretty = true
47+
48+
strict = true
49+
disallow_any_generics = false
50+
4451
[tool.hatch.envs.hatch-test]
4552
dependencies = [
4653
"pytest>=8.3.5",
@@ -53,16 +60,13 @@ omit = [
5360
"tests/**",
5461
]
5562

56-
[tool.hatch.envs.hatch-test.scripts]
57-
run = "uv run pytest"
58-
run-cov = "uv run pytest --cov --cov-report xml --cov-report html --junit-xml=tests-results.xml"
59-
cov-combine = "."
60-
cov-report = [
61-
"coverage xml",
62-
"coverage html",
63-
"coverage report",
64-
]
65-
cov = [
66-
".coverage",
67-
"tests-results.xml",
68-
]
63+
[project.scripts]
64+
# workaround while UV doesn't support scripts directly in the pyproject.toml
65+
# see: https://github.com/astral-sh/uv/issues/5903
66+
cov-report = "scripts.scripts:cov_report"
67+
cov = "scripts.scripts:cov"
68+
# don't name it `mypy` otherwise `uv` will override the actual binary
69+
mypy-check = "scripts.scripts:mypy"
70+
test = "scripts.scripts:test"
71+
test-cov = "scripts.scripts:test_cov"
72+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# ruff: noqa: S602, S607
2+
import subprocess
3+
4+
5+
def test() -> None:
6+
"""Run pytest tests."""
7+
subprocess.run("pytest tests", shell=True, check=True)
8+
9+
10+
def test_cov() -> None:
11+
"""Run tests with coverage."""
12+
subprocess.run("coverage run -m pytest tests", shell=True, check=True)
13+
14+
15+
def cov_report() -> None:
16+
"""Generate coverage report."""
17+
subprocess.run("coverage xml", shell=True, check=True)
18+
19+
20+
def cov() -> None:
21+
"""Run tests with coverage and generate report."""
22+
test_cov()
23+
cov_report()
24+
25+
26+
def mypy() -> None:
27+
"""Run mypy."""
28+
subprocess.run("mypy", shell=True, check=True)

0 commit comments

Comments
 (0)