From fad89de749abdf7dbd208f247e65619a2281a122 Mon Sep 17 00:00:00 2001 From: leohoare Date: Tue, 24 Jun 2025 07:24:38 +0800 Subject: [PATCH] move pre-commit into scripts Signed-off-by: leohoare --- .github/workflows/build.yml | 2 +- CONTRIBUTING.md | 36 +++++++++++------------------------- pyproject.toml | 3 ++- scripts/scripts.py | 5 +++++ 4 files changed, 19 insertions(+), 27 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 33c0213..e27d1ce 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -66,7 +66,7 @@ jobs: run: uv sync --extra dev - name: Run pre-commit - run: uv run pre-commit run --all-files + run: uv run precommit sast: runs-on: ubuntu-latest diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bae1070..eebc06c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,10 +16,6 @@ We use [uv](https://github.com/astral-sh/uv) for fast Python package management 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 `uv run pip install pre-commit`. - ### Setup Development Environment 1. **Clone the repository:** @@ -35,40 +31,30 @@ If you don't have `pre-commit` installed, you can install it with `uv run pip in ### Testing -Run tests with `uv run pytest tests`. - -We use `pytest` for our unit testing, making use of `parametrized` to inject cases at scale. +Run tests: +```bash +uv run test +``` ### Coverage -Run coverage tests with: +Run tests with a coverage report: ```bash -uv run coverage run -m pytest tests/ - # Generate coverage report +uv run cov ``` ### End-to-End Tests Run e2e tests with behave: ```bash -# Update git submodules and run behave tests -git submodule update --init --recursive -cp spec/specification/assets/gherkin/* tests/features/ -uv run behave tests/features/ -rm tests/features/*.feature +uv run e2e ``` -### Code Quality +### Pre-commit -**Linting and Formatting:** +Run pre-commit hooks ```bash -uv run ruff check . # Lint code -uv run ruff format . # Format code -``` - -**Type Checking:** -```bash -uv run mypy openfeature/ +uv run precommit ``` @@ -105,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 -uv run pytest tests/ +uv run test ``` To start working on a new feature or bugfix, create a new branch and start working on it. diff --git a/pyproject.toml b/pyproject.toml index 76afef8..9c4636d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -124,4 +124,5 @@ test = "scripts.scripts:test" test-cov = "scripts.scripts:test_cov" cov-report = "scripts.scripts:cov_report" cov = "scripts.scripts:cov" -e2e = "scripts.scripts:e2e" \ No newline at end of file +e2e = "scripts.scripts:e2e" +precommit = "scripts.scripts:precommit" \ No newline at end of file diff --git a/scripts/scripts.py b/scripts/scripts.py index 1c1c37e..b7f4d15 100644 --- a/scripts/scripts.py +++ b/scripts/scripts.py @@ -31,3 +31,8 @@ def e2e(): ) 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)