From 0e3ae7e2e1b1db2e2d9d378e53642d9c8e9dc284 Mon Sep 17 00:00:00 2001 From: gruebel Date: Wed, 20 Mar 2024 22:16:26 +0100 Subject: [PATCH] switch to hatch Signed-off-by: gruebel --- .github/workflows/build.yml | 10 +++----- .github/workflows/release.yml | 30 +++------------------- CONTRIBUTING.md | 12 ++++++--- Makefile | 47 ----------------------------------- pyproject.toml | 46 ++++++++++++++++++++++++++++------ requirements.txt | 5 ---- 6 files changed, 53 insertions(+), 97 deletions(-) delete mode 100644 Makefile delete mode 100644 requirements.txt 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 b07d7535..661ffde5 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" @@ -19,12 +19,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 @@ -83,6 +116,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 eed06931..00000000 --- a/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -pytest==8.1.1 -pytest-mock==3.12.0 -pre-commit -coverage==7.4.4 -behave==1.2.6