From 0428302c74f9f3836bd4fc62c24dec8ad8644e18 Mon Sep 17 00:00:00 2001 From: Kristof Herrmann Date: Mon, 9 Dec 2024 12:36:43 +0100 Subject: [PATCH 1/7] feat: tests on PR & push to main --- .github/workflows/tests.yaml | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/tests.yaml diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..0e93b09 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,45 @@ +name: Tests & Code Quality + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.11"] + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Hatch + run: pip install hatch + + - name: Run tests + run: hatch run tests + + code-quality: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python 3.11 + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Install Hatch + run: pip install hatch + + - name: Run code quality checks + run: hatch run code-quality:all From 585e249527aa7308b9b30453184216b5c23b1361 Mon Sep 17 00:00:00 2001 From: Kristof Herrmann Date: Mon, 9 Dec 2024 12:37:19 +0100 Subject: [PATCH 2/7] chore: rename CI --- .github/workflows/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 0e93b09..4481822 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -1,4 +1,4 @@ -name: Tests & Code Quality +name: CI on: push: From 87004eaba33a8d162a6a508b4edcd610bea84481 Mon Sep 17 00:00:00 2001 From: Kristof Herrmann Date: Mon, 9 Dec 2024 12:40:38 +0100 Subject: [PATCH 3/7] fix --- .github/workflows/tests.yaml | 10 ++++++++-- pyproject.toml | 7 +++++++ tests/example_components/test_keyword_booster.py | 1 - 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 4481822..a9d57ee 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -41,5 +41,11 @@ jobs: - name: Install Hatch run: pip install hatch - - name: Run code quality checks - run: hatch run code-quality:all + - name: Run mypy + run: hatch run code-quality:mypy src tests + + - name: Run black + run: hatch run code-quality:format + + - name: Run ruff + run: hatch run code-quality:lint-ci diff --git a/pyproject.toml b/pyproject.toml index b9e7342..8faa91f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -63,6 +63,13 @@ dependencies = [ packages = ["src/dc_custom_component"] [tool.hatch.envs.code-quality.scripts] +format = "black src tests --check" +format-fix = "black src tests" +lint = "ruff ." +lint-ci = "ruff --format=github ." +lint-fix = "ruff --fix ." +hooks = "pre-commit install" +docstrings = "pydocstyle src" all = "mypy src tests && black src tests && ruff check --fix ." [tool.mypy] diff --git a/tests/example_components/test_keyword_booster.py b/tests/example_components/test_keyword_booster.py index 651cb13..258187c 100644 --- a/tests/example_components/test_keyword_booster.py +++ b/tests/example_components/test_keyword_booster.py @@ -86,7 +86,6 @@ def test_serialization(self) -> None: assert deserialized.magic_word == Secret.from_env_var("MY_ENV_VAR") def test_serialization_from_dict(self) -> None: - deserialized: SecretKeywordBooster = SecretKeywordBooster.from_dict( { "type": "dc_custom_component.example_components.rankers.keyword_booster.SecretKeywordBooster", From d94acf5ba482df3244be61976d548e6ac319ff81 Mon Sep 17 00:00:00 2001 From: Kristof Herrmann Date: Mon, 9 Dec 2024 12:41:34 +0100 Subject: [PATCH 4/7] fix --- pyproject.toml | 2 +- tests/example_components/test_keyword_booster.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8faa91f..b5e2844 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,7 +66,7 @@ packages = ["src/dc_custom_component"] format = "black src tests --check" format-fix = "black src tests" lint = "ruff ." -lint-ci = "ruff --format=github ." +lint-ci = "ruff -- --format=github ." lint-fix = "ruff --fix ." hooks = "pre-commit install" docstrings = "pydocstyle src" diff --git a/tests/example_components/test_keyword_booster.py b/tests/example_components/test_keyword_booster.py index 258187c..a5e32fa 100644 --- a/tests/example_components/test_keyword_booster.py +++ b/tests/example_components/test_keyword_booster.py @@ -1,4 +1,3 @@ -import pytest from haystack import Document from dc_custom_component.example_components.rankers.keyword_booster import ( KeywordBooster, From fb0e689b1c6e3ba144ff3f88383efdb7f93621b1 Mon Sep 17 00:00:00 2001 From: Kristof Herrmann Date: Mon, 9 Dec 2024 12:44:28 +0100 Subject: [PATCH 5/7] fix --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b5e2844..8054d09 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,7 +66,7 @@ packages = ["src/dc_custom_component"] format = "black src tests --check" format-fix = "black src tests" lint = "ruff ." -lint-ci = "ruff -- --format=github ." +lint-ci = "ruff check ." lint-fix = "ruff --fix ." hooks = "pre-commit install" docstrings = "pydocstyle src" From cf57298cef43dfda5b2be53a7825382fa22172fb Mon Sep 17 00:00:00 2001 From: Kristof Herrmann Date: Mon, 9 Dec 2024 12:48:59 +0100 Subject: [PATCH 6/7] lint before build and push --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 8054d09..8f664bd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,7 +44,7 @@ detached = true [tool.hatch.envs.dc.scripts] build = "mkdir -p dist && zip -r dist/custom_component.zip ./* -x 'dist/*' '**/__pycache__/*'" push = "curl --request POST --url https://api.cloud.deepset.ai/api/v2/custom_components --header 'accept: application/json' --header \"Authorization: Bearer $API_KEY\" --form 'file=@dist/custom_component.zip;type=application/zip'" -build-and-push = "mkdir -p dist && zip -r dist/custom_component.zip ./* -x 'dist/*' '**/__pycache__/*' && curl --request POST --url https://api.cloud.deepset.ai/api/v2/custom_components --header 'accept: application/json' --header \"Authorization: Bearer $API_KEY\" --form 'file=@dist/custom_component.zip;type=application/zip'" +build-and-push = "hatch run code-quality:all && mkdir -p dist && zip -r dist/custom_component.zip ./* -x 'dist/*' '**/__pycache__/*' && curl --request POST --url https://api.cloud.deepset.ai/api/v2/custom_components --header 'accept: application/json' --header \"Authorization: Bearer $API_KEY\" --form 'file=@dist/custom_component.zip;type=application/zip'" list = "curl --request GET --url https://api.cloud.deepset.ai/api/v2/custom_components --header 'accept: application/json' --header \"Authorization: Bearer $API_KEY\"" build-windows = "powershell -Command \"& {{ if (-Not (Test-Path dist)) {{mkdir dist}}; if (Test-Path dist/custom_component.zip) {{ Remove-Item dist/custom_component.zip }}; Get-ChildItem -Path . | Where-Object {{ $_.FullName -notlike '*\\dist*' }} | Compress-Archive -DestinationPath dist/custom_component.zip -Update }}" push-windows = "curl --request POST --url https://api.cloud.deepset.ai/api/v2/custom_components --header \"accept: application/json\" --header \"Authorization: Bearer %API_KEY%\" --form \"file=@dist/custom_component.zip;type=application/zip\"" From e1a4c9d5a03e0060fb56723417d17af6200b2760 Mon Sep 17 00:00:00 2001 From: Kristof Herrmann Date: Mon, 9 Dec 2024 16:00:19 +0100 Subject: [PATCH 7/7] fix --- pyproject.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8f664bd..286412b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,9 +65,9 @@ packages = ["src/dc_custom_component"] [tool.hatch.envs.code-quality.scripts] format = "black src tests --check" format-fix = "black src tests" -lint = "ruff ." -lint-ci = "ruff check ." -lint-fix = "ruff --fix ." +lint = "ruff check . --output-format=github" +lint-ci = "ruff check . --output-format=github" +lint-fix = "ruff check . --fix --output-format=github" hooks = "pre-commit install" docstrings = "pydocstyle src" all = "mypy src tests && black src tests && ruff check --fix ."