Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,19 @@ jobs:
with:
submodules: recursive

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

- name: Install hatch
run: pip install hatch
- name: Install dependencies
run: uv sync --frozen

- name: Test with pytest
run: hatch run cov
run: uv run cov --frozen

- name: Run E2E tests with behave
run: hatch run e2e
run: uv run e2e --frozen

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

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
- name: Install uv and set the python version
uses: astral-sh/setup-uv@v6
with:
python-version: "3.13"
cache: "pip"

- name: Install dependencies
run: uv sync --frozen

- name: Run pre-commit
uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
Expand All @@ -75,9 +76,11 @@ jobs:
security-events: write
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
- name: Install uv and set the python version
uses: astral-sh/setup-uv@v6
with:
python-version: "3.13"
ignore-nothing-to-cache: true

- name: Initialize CodeQL
uses: github/codeql-action/init@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3
Expand Down
14 changes: 6 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,16 @@ jobs:
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
- name: Install uv and set the python version
uses: astral-sh/setup-uv@v6
with:
python-version: '3.13'
python-version: "3.13"

- name: Upgrade pip
run: pip install --upgrade pip

- name: Install hatch
run: pip install hatch
- name: Install dependencies
run: uv sync --frozen

- name: Build a binary wheel and a source tarball
run: hatch build
run: uv build

- name: Publish a Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
48 changes: 40 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,51 @@ Python 3.9 and above are supported by the SDK.

### Installation and Dependencies

We use [Hatch](https://hatch.pypa.io/) to manage the project.
We use [uv](https://github.com/astral-sh/uv) for fast Python package management and dependency resolution.

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

You will also need to set up 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`.
### Setup Development Environment

1. **Clone the repository:**
```bash
git clone https://github.com/open-feature/python-sdk.git
cd python-sdk
```

2. **Install dependencies:**
```bash
uv sync
```

### Testing

Run tests with `hatch run test`.
Run tests:
```bash
uv run test --frozen
```

### Coverage

Run tests with a coverage report:
```bash
uv run cov --frozen
```

### End-to-End Tests

Run e2e tests with behave:
```bash
uv run e2e --frozen
```

### Pre-commit

Run pre-commit hooks
```bash
uv run precommit --frozen
```

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

### Integration tests

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

```bash
hatch run test
uv run test --frozen
```

To start working on a new feature or bugfix, create a new branch and start working on it.
Expand Down
37 changes: 15 additions & 22 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,14 @@ requires-python = ">=3.9"
[project.urls]
Homepage = "https://github.com/open-feature/python-sdk"

[tool.hatch]

[tool.hatch.envs.default]
dependencies = [
[dependency-groups]
dev = [
"behave",
"coverage[toml]>=6.5",
"pytest",
"pytest-asyncio"
]

[tool.hatch.envs.default.scripts]
test = "pytest {args:tests}"
test-cov = "coverage run -m pytest {args:tests}"
cov-report = [
"coverage xml",
]
cov = [
"test-cov",
"cov-report",
]
e2e = [
"git submodule update --init --recursive",
"cp spec/specification/assets/gherkin/* tests/features/",
"behave tests/features/",
"rm tests/features/*.feature",
"pytest-asyncio",
"mypy",
"pre-commit"
]

[tool.hatch.build.targets.sdist]
Expand Down Expand Up @@ -134,3 +117,13 @@ max-statements = 30
[tool.ruff.lint.pyupgrade]
# Preserve types, even if a file imports `from __future__ import annotations`.
keep-runtime-typing = true

[project.scripts]
# workaround while UV doesn't support scripts directly in the pyproject.toml
# see: https://github.com/astral-sh/uv/issues/5903
test = "scripts.scripts:test"
test-cov = "scripts.scripts:test_cov"
cov-report = "scripts.scripts:cov_report"
cov = "scripts.scripts:cov"
e2e = "scripts.scripts:e2e"
precommit = "scripts.scripts:precommit"
38 changes: 38 additions & 0 deletions scripts/scripts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# ruff: noqa: S602, S607
import subprocess


def test():
"""Run pytest tests."""
subprocess.run("pytest tests", shell=True, check=True)


def test_cov():
"""Run tests with coverage."""
subprocess.run("coverage run -m pytest tests", shell=True, check=True)


def cov_report():
"""Generate coverage report."""
subprocess.run("coverage xml", shell=True, check=True)


def cov():
"""Run tests with coverage and generate report."""
test_cov()
cov_report()


def e2e():
"""Run end-to-end tests."""
subprocess.run("git submodule update --init --recursive", shell=True, check=True)
subprocess.run(
"cp spec/specification/assets/gherkin/* tests/features/", shell=True, check=True
)
subprocess.run("behave tests/features/", shell=True, check=True)
subprocess.run("rm tests/features/*.feature", shell=True, check=True)


def precommit():
"""Run pre-commit hooks."""
subprocess.run("uv run pre-commit run --all-files", shell=True, check=True)
Loading