diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1b1c8e5f..9cb863d6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a975c169..7669ac06 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 57d3f261..c5c99761 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. @@ -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. diff --git a/Makefile b/Makefile deleted file mode 100644 index b3605999..00000000 --- a/Makefile +++ /dev/null @@ -1,47 +0,0 @@ -VENV_NAME ?= .venv -VENV_ACTIVATE = . $(VENV_NAME)/bin/activate - -.DEFAULT_GOAL := help - -.PHONY: init -init: venv - -.PHONY: help -help: - @echo "Targets:" - @echo " requirements Installs dependencies" - @echo " venv Creates a virtual environment and install dependencies" - @echo " test Run pytest on the tests/ directory" - @echo " lint Check code with flake8 and black" - @echo " format Format code with black" - -.PHONY: requirements -requirements: - $(VENV_ACTIVATE); pip install -r requirements.txt - -.PHONY: venv -venv: - test -d $(VENV_NAME) || python3 -m venv $(VENV_NAME) - $(VENV_ACTIVATE); pip install -r requirements.txt - -.PHONY: test -test: venv - $(VENV_ACTIVATE); pytest tests/ - -test-harness: - git submodule update --init - -.PHONY: lint -lint: venv - $(VENV_ACTIVATE); pre-commit run -a - -.PHONY: format -format: venv - $(VENV_ACTIVATE); pre-commit run -a ruff-format - -.PHONY: e2e -e2e: venv test-harness - # NOTE: only the evaluation feature is run for now - cp test-harness/features/evaluation.feature tests/features/ - $(VENV_ACTIVATE); behave tests/features/ - rm tests/features/*.feature diff --git a/pyproject.toml b/pyproject.toml index 53ab2b03..ebd791a1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" @@ -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 @@ -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"] diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index aacf1897..00000000 --- a/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -pytest==8.1.1 -pytest-mock==3.14.0 -pre-commit -coverage==7.4.4 -behave==1.2.6