Skip to content

Commit

Permalink
ci: switch to hatch (#297)
Browse files Browse the repository at this point in the history
switch to hatch

Signed-off-by: gruebel <[email protected]>
  • Loading branch information
gruebel authored Apr 5, 2024
1 parent 47ae16c commit 9ba82e3
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 97 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,14 @@ jobs:
python-version: ${{ matrix.python-version }}
cache: "pip"

- name: Install dependencies
run: pip install -r requirements.txt
- name: Install hatch
run: pip install hatch

- name: Test with pytest
run: coverage run --omit="*/test*" -m pytest
run: hatch run cov

- name: Run E2E tests with behave
run: |
cp test-harness/features/evaluation.feature tests/features/
behave tests/features/
run: hatch run e2e

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
Expand Down
30 changes: 3 additions & 27 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,38 +45,14 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Cache virtualenvironment
uses: actions/cache@v4
with:
path: ~/.venv
key: ${{ hashFiles('requirements.txt', 'requirements-dev.txt') }}

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

- name: Create and activate Virtualenv
run: |
[ ! -d ".venv" ] && python -m venv .venv
. .venv/bin/activate
- name: Install dependencies
run: pip install -r requirements.txt

- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Install hatch
run: pip install hatch

- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.
run: hatch build

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

### Installation and Dependencies

A [`Makefile`](./Makefile) has been included in the project which should make it straightforward to start the project locally. We utilize virtual environments (see [`venv`](https://docs.python.org/3/tutorial/venv.html)) in order to provide isolated development environments for the project. This reduces the risk of invalid or corrupt global packages. It also integrates nicely with Make, which will detect changes in the `requirements.txt` file and update the virtual environment if any occur.
We use [Hatch](https://hatch.pypa.io/) to manage the project.

Run `make init` to initialize the project's virtual environment and install all dev dependencies.
To install Hatch, just run `pip install hatch`.

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`.

### Testing

Run tests with `make test`.
Run tests with `hatch run test`.

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

Expand Down Expand Up @@ -55,7 +59,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
make
hatch run test
```

To start working on a new feature or bugfix, create a new branch and start working on it.
Expand Down
47 changes: 0 additions & 47 deletions Makefile

This file was deleted.

46 changes: 38 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# pyproject.toml
[build-system]
requires = ["setuptools>=61.0.0", "wheel"]
build-backend = "setuptools.build_meta"
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "openfeature_sdk"
Expand All @@ -24,12 +24,45 @@ keywords = [
dependencies = []
requires-python = ">=3.8"

[project.optional-dependencies]
dev = ["pip-tools", "pytest", "pre-commit"]

[project.urls]
Homepage = "https://github.com/open-feature/python-sdk"

[tool.hatch]

[tool.hatch.envs.default]
dependencies = [
"behave",
"coverage[toml]>=6.5",
"pytest",
]

[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",
"cp test-harness/features/evaluation.feature tests/features/",
"behave tests/features/",
"rm tests/features/*.feature",
]

[tool.hatch.build.targets.sdist]
exclude = [
".gitignore",
"test-harness",
"venv",
]

[tool.hatch.build.targets.wheel]
packages = ["openfeature"]

[tool.mypy]
files = "openfeature"
namespace_packages = true
Expand Down Expand Up @@ -89,6 +122,3 @@ max-statements = 30
[tool.ruff.lint.pyupgrade]
# Preserve types, even if a file imports `from __future__ import annotations`.
keep-runtime-typing = true

[tool.setuptools.package-data]
openfeature = ["py.typed"]
5 changes: 0 additions & 5 deletions requirements.txt

This file was deleted.

0 comments on commit 9ba82e3

Please sign in to comment.