diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..a9d57ee --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,51 @@ +name: CI + +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 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..286412b 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\"" @@ -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 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 ." [tool.mypy] diff --git a/tests/example_components/test_keyword_booster.py b/tests/example_components/test_keyword_booster.py index 651cb13..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, @@ -86,7 +85,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",