Skip to content

Commit fb47cbb

Browse files
leohoareaepfligruebel
authored
feat: starting migration to uv (#512)
* starting migration to uv Signed-off-by: leohoare <[email protected]> * single command for test Signed-off-by: leohoare <[email protected]> * uv-lock in pre-commit, manually run pre-commit instead of action, add mypy and pre-commit to dev dependencies Signed-off-by: leohoare <[email protected]> * ignore nothing to cache Signed-off-by: leohoare <[email protected]> * cleanup and remove comment Signed-off-by: leohoare <[email protected]> * Update .github/workflows/release.yml Co-authored-by: Simon Schrottner <[email protected]> Signed-off-by: Leo <[email protected]> Signed-off-by: leohoare <[email protected]> * cloeset thing to hatch scripts using project scripts Signed-off-by: leohoare <[email protected]> * ignore errors (not ideal) Signed-off-by: leohoare <[email protected]> * move pre-commit into scripts Signed-off-by: leohoare <[email protected]> * update dependency group, add frozen, remove uv-lock precommit, v6 uv, revert precommit Signed-off-by: leohoare <[email protected]> * add comment to github issue Signed-off-by: leohoare <[email protected]> --------- Signed-off-by: leohoare <[email protected]> Signed-off-by: Leo <[email protected]> Co-authored-by: Simon Schrottner <[email protected]> Co-authored-by: Anton Grübel <[email protected]>
1 parent 7783a8b commit fb47cbb

File tree

6 files changed

+603
-49
lines changed

6 files changed

+603
-49
lines changed

.github/workflows/build.yml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,19 @@ jobs:
2828
with:
2929
submodules: recursive
3030

31-
- name: Set up Python ${{ matrix.python-version }}
32-
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
31+
- name: Install uv and set the python version
32+
uses: astral-sh/setup-uv@v6
3333
with:
3434
python-version: ${{ matrix.python-version }}
35-
cache: "pip"
36-
allow-prereleases: true
3735

38-
- name: Install hatch
39-
run: pip install hatch
36+
- name: Install dependencies
37+
run: uv sync --frozen
4038

4139
- name: Test with pytest
42-
run: hatch run cov
40+
run: uv run cov --frozen
4341

4442
- name: Run E2E tests with behave
45-
run: hatch run e2e
43+
run: uv run e2e --frozen
4644

4745
- if: matrix.python-version == '3.13'
4846
name: Upload coverage to Codecov
@@ -59,10 +57,13 @@ jobs:
5957

6058
steps:
6159
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
62-
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
60+
- name: Install uv and set the python version
61+
uses: astral-sh/setup-uv@v6
6362
with:
6463
python-version: "3.13"
65-
cache: "pip"
64+
65+
- name: Install dependencies
66+
run: uv sync --frozen
6667

6768
- name: Run pre-commit
6869
uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
@@ -75,9 +76,11 @@ jobs:
7576
security-events: write
7677
steps:
7778
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
78-
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
79+
- name: Install uv and set the python version
80+
uses: astral-sh/setup-uv@v6
7981
with:
8082
python-version: "3.13"
83+
ignore-nothing-to-cache: true
8184

8285
- name: Initialize CodeQL
8386
uses: github/codeql-action/init@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3

.github/workflows/release.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,16 @@ jobs:
4444
steps:
4545
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
4646

47-
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
47+
- name: Install uv and set the python version
48+
uses: astral-sh/setup-uv@v6
4849
with:
49-
python-version: '3.13'
50+
python-version: "3.13"
5051

51-
- name: Upgrade pip
52-
run: pip install --upgrade pip
53-
54-
- name: Install hatch
55-
run: pip install hatch
52+
- name: Install dependencies
53+
run: uv sync --frozen
5654

5755
- name: Build a binary wheel and a source tarball
58-
run: hatch build
56+
run: uv build
5957

6058
- name: Publish a Python distribution to PyPI
6159
uses: pypa/gh-action-pypi-publish@release/v1

CONTRIBUTING.md

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,51 @@ 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.
15+
We use [uv](https://github.com/astral-sh/uv) for fast Python package management and dependency resolution.
1616

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

19-
You will also need to set up the `pre-commit` hooks.
20-
Run `pre-commit install` in the root directory of the repository.
21-
If you don't have `pre-commit` installed, you can install it with `pip install pre-commit`.
19+
### Setup Development Environment
20+
21+
1. **Clone the repository:**
22+
```bash
23+
git clone https://github.com/open-feature/python-sdk.git
24+
cd python-sdk
25+
```
26+
27+
2. **Install dependencies:**
28+
```bash
29+
uv sync
30+
```
2231

2332
### Testing
2433

25-
Run tests with `hatch run test`.
34+
Run tests:
35+
```bash
36+
uv run test --frozen
37+
```
38+
39+
### Coverage
40+
41+
Run tests with a coverage report:
42+
```bash
43+
uv run cov --frozen
44+
```
45+
46+
### End-to-End Tests
47+
48+
Run e2e tests with behave:
49+
```bash
50+
uv run e2e --frozen
51+
```
52+
53+
### Pre-commit
54+
55+
Run pre-commit hooks
56+
```bash
57+
uv run precommit --frozen
58+
```
2659

27-
We use `pytest` for our unit testing, making use of `parametrized` to inject cases at scale.
2860

2961
### Integration tests
3062

@@ -59,7 +91,7 @@ git remote add fork https://github.com/YOUR_GITHUB_USERNAME/python-sdk.git
5991
Ensure your development environment is all set up by building and testing
6092

6193
```bash
62-
hatch run test
94+
uv run test --frozen
6395
```
6496

6597
To start working on a new feature or bugfix, create a new branch and start working on it.

pyproject.toml

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,14 @@ requires-python = ">=3.9"
2727
[project.urls]
2828
Homepage = "https://github.com/open-feature/python-sdk"
2929

30-
[tool.hatch]
31-
32-
[tool.hatch.envs.default]
33-
dependencies = [
30+
[dependency-groups]
31+
dev = [
3432
"behave",
3533
"coverage[toml]>=6.5",
3634
"pytest",
37-
"pytest-asyncio"
38-
]
39-
40-
[tool.hatch.envs.default.scripts]
41-
test = "pytest {args:tests}"
42-
test-cov = "coverage run -m pytest {args:tests}"
43-
cov-report = [
44-
"coverage xml",
45-
]
46-
cov = [
47-
"test-cov",
48-
"cov-report",
49-
]
50-
e2e = [
51-
"git submodule update --init --recursive",
52-
"cp spec/specification/assets/gherkin/* tests/features/",
53-
"behave tests/features/",
54-
"rm tests/features/*.feature",
35+
"pytest-asyncio",
36+
"mypy",
37+
"pre-commit"
5538
]
5639

5740
[tool.hatch.build.targets.sdist]
@@ -134,3 +117,13 @@ max-statements = 30
134117
[tool.ruff.lint.pyupgrade]
135118
# Preserve types, even if a file imports `from __future__ import annotations`.
136119
keep-runtime-typing = true
120+
121+
[project.scripts]
122+
# workaround while UV doesn't support scripts directly in the pyproject.toml
123+
# see: https://github.com/astral-sh/uv/issues/5903
124+
test = "scripts.scripts:test"
125+
test-cov = "scripts.scripts:test_cov"
126+
cov-report = "scripts.scripts:cov_report"
127+
cov = "scripts.scripts:cov"
128+
e2e = "scripts.scripts:e2e"
129+
precommit = "scripts.scripts:precommit"

scripts/scripts.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# ruff: noqa: S602, S607
2+
import subprocess
3+
4+
5+
def test():
6+
"""Run pytest tests."""
7+
subprocess.run("pytest tests", shell=True, check=True)
8+
9+
10+
def test_cov():
11+
"""Run tests with coverage."""
12+
subprocess.run("coverage run -m pytest tests", shell=True, check=True)
13+
14+
15+
def cov_report():
16+
"""Generate coverage report."""
17+
subprocess.run("coverage xml", shell=True, check=True)
18+
19+
20+
def cov():
21+
"""Run tests with coverage and generate report."""
22+
test_cov()
23+
cov_report()
24+
25+
26+
def e2e():
27+
"""Run end-to-end tests."""
28+
subprocess.run("git submodule update --init --recursive", shell=True, check=True)
29+
subprocess.run(
30+
"cp spec/specification/assets/gherkin/* tests/features/", shell=True, check=True
31+
)
32+
subprocess.run("behave tests/features/", shell=True, check=True)
33+
subprocess.run("rm tests/features/*.feature", shell=True, check=True)
34+
35+
36+
def precommit():
37+
"""Run pre-commit hooks."""
38+
subprocess.run("uv run pre-commit run --all-files", shell=True, check=True)

0 commit comments

Comments
 (0)