From c833979c6cea5dad59a2590688e48011fdacb208 Mon Sep 17 00:00:00 2001 From: Madeesh Kannan Date: Wed, 22 May 2024 08:57:21 +0200 Subject: [PATCH] ci: Add workflows (#2) * ci: Add workflows * fix * fix coverage report * clone repo --------- Co-authored-by: Massimiliano Pippi --- .github/CODEOWNERS | 11 ++ .github/dependabot.yml | 6 + .github/pull_request_template.md | 25 ++++ .github/workflows/licensing.yml | 18 +++ .github/workflows/project.yml | 16 +++ .github/workflows/pypi_release.yml | 40 ++++++ .github/workflows/tests.yml | 86 ++++++++++++ .github/workflows/workflows_linting.yml | 19 +++ haystack_experimental/__init__.py | 3 + haystack_experimental/version.py | 7 +- pyproject.toml | 171 +++++------------------- releasenotes/config.yaml | 47 ------- test/test_experimental.py | 2 + 13 files changed, 262 insertions(+), 189 deletions(-) create mode 100644 .github/CODEOWNERS create mode 100644 .github/dependabot.yml create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/licensing.yml create mode 100644 .github/workflows/project.yml create mode 100644 .github/workflows/pypi_release.yml create mode 100644 .github/workflows/tests.yml create mode 100644 .github/workflows/workflows_linting.yml create mode 100644 haystack_experimental/__init__.py delete mode 100644 releasenotes/config.yaml create mode 100644 test/test_experimental.py diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000..c559d08f --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,11 @@ +# See https://help.github.com/articles/about-codeowners/ for syntax + +# Core Engineering will be the default owners for everything +# in the repo. Unless a later match takes precedence, +# @deepset-ai/core-engineering will be requested for review +# when someone opens a pull request. +* @deepset-ai/open-source-engineering + +# Documentation +*.md @deepset-ai/documentation @deepset-ai/open-source-engineering +releasenotes/notes/* @deepset-ai/documentation @deepset-ai/open-source-engineering diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..6778b049 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: 'github-actions' + directory: '/' + schedule: + interval: 'daily' diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000..c6a58287 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,25 @@ +### Related Issues + +- fixes #issue-number + +### Proposed Changes: + + + + +### How did you test it? + + + +### Notes for the reviewer + + + +### Checklist + +- I have read the [contributors guidelines](https://github.com/deepset-ai/haystack/blob/main/CONTRIBUTING.md) and the [code of conduct](https://github.com/deepset-ai/haystack/blob/main/code_of_conduct.txt) +- I have updated the related issue with new insights and changes +- I added unit tests and updated the docstrings +- I've used one of the [conventional commit types](https://www.conventionalcommits.org/en/v1.0.0/) for my PR title: `fix:`, `feat:`, `build:`, `chore:`, `ci:`, `docs:`, `style:`, `refactor:`, `perf:`, `test:`. +- I documented my code +- I ran [pre-commit hooks](https://github.com/deepset-ai/haystack/blob/main/CONTRIBUTING.md#installation) and fixed any issue diff --git a/.github/workflows/licensing.yml b/.github/workflows/licensing.yml new file mode 100644 index 00000000..ebaf4556 --- /dev/null +++ b/.github/workflows/licensing.yml @@ -0,0 +1,18 @@ +name: Licensing + +on: + pull_request: + paths: + - "haystack_experimental/**/*.py" + - "test/**/*.py" + - "pyproject.toml" + +jobs: + license-header: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Check License Header + run: docker run --rm -v "$(pwd):/github/workspace" ghcr.io/korandoru/hawkeye check diff --git a/.github/workflows/project.yml b/.github/workflows/project.yml new file mode 100644 index 00000000..62730b7f --- /dev/null +++ b/.github/workflows/project.yml @@ -0,0 +1,16 @@ +name: Track issues with Github project + +on: + issues: + types: + - opened + +jobs: + add-to-project: + name: Add new issues to project for triage + runs-on: ubuntu-latest + steps: + - uses: actions/add-to-project@v1.0.1 + with: + project-url: https://github.com/orgs/deepset-ai/projects/5 + github-token: ${{ secrets.GH_PROJECT_PAT }} diff --git a/.github/workflows/pypi_release.yml b/.github/workflows/pypi_release.yml new file mode 100644 index 00000000..3c5a3447 --- /dev/null +++ b/.github/workflows/pypi_release.yml @@ -0,0 +1,40 @@ +name: Project release on PyPi + +on: + push: + tags: + - "v[0-9]+.[0-9]+.[0-9]+*" + +env: + HATCH_VERSION: "1.9.4" + +jobs: + release-on-pypi: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Hatch + run: pip install hatch==${{ env.HATCH_VERSION }} + + - name: Build Haystack Experimental + run: hatch build + + - name: Publish on PyPi + env: + HATCH_INDEX_USER: __token__ + HATCH_INDEX_AUTH: ${{ secrets.HAYSTACK_AI_PYPI_TOKEN }} + run: hatch publish -y + + - name: Notify Slack + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + VERSION: ${{ github.ref_name }} + if: always() + uses: act10ns/slack@v2 + with: + status: ${{ job.status }} + channel: "#haystack-notifications" + config: .github/config/pypi-release-slack-notification.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..484b3dee --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,86 @@ +# If you change this name also do it in tests_skipper.yml and ci_metrics.yml +name: Tests + +on: + # Activate this workflow manually + workflow_dispatch: + + # Run tests nightly against Haystack's main branch + schedule: + - cron: "0 0 * * *" + + push: + branches: + - main + + pull_request: + types: + - opened + - reopened + - synchronize + - ready_for_review + paths: + # Keep the list in sync with the paths defined in the `tests_skipper.yml` workflow + - "haystack_experimental/**/*.py" + - "test/**/*.py" + - "pyproject.toml" + +env: + PYTHON_VERSION: "3.8" + HATCH_VERSION: "1.9.4" + +jobs: + linting: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install Hatch + run: pip install hatch==${{ env.HATCH_VERSION }} + + - name: Check code format + run: hatch fmt + + - name: Linting + run: hatch run test:lint + + - name: Typing + run: hatch run test:typing + + unit-tests: + name: Unit / ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + - windows-latest + - macos-latest + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: "${{ env.PYTHON_VERSION }}" + + - name: Install Hatch + run: pip install hatch==${{ env.HATCH_VERSION }} + + - name: Run + run: hatch run test:cov + + - name: Coveralls + # We upload only coverage for ubuntu as handling both os + # complicates the workflow too much for little to no gain + if: matrix.os == 'ubuntu-latest' + uses: coverallsapp/github-action@v2 + with: + path-to-lcov: coverage.xml + + - name: Nightly - run unit tests with Haystack main branch + if: github.event_name == 'schedule' + id: nightly-haystack-main + run: | + hatch run pip install git+https://github.com/deepset-ai/haystack.git + hatch run test:unit diff --git a/.github/workflows/workflows_linting.yml b/.github/workflows/workflows_linting.yml new file mode 100644 index 00000000..6fe24e15 --- /dev/null +++ b/.github/workflows/workflows_linting.yml @@ -0,0 +1,19 @@ +name: Github workflows linter + +on: + pull_request: + paths: + - ".github/workflows" + +jobs: + lint-workflows: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install actionlint + run: go install github.com/rhysd/actionlint/cmd/actionlint@latest + + - name: Run actionlint + run: actionlint diff --git a/haystack_experimental/__init__.py b/haystack_experimental/__init__.py new file mode 100644 index 00000000..c1764a6e --- /dev/null +++ b/haystack_experimental/__init__.py @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2022-present deepset GmbH +# +# SPDX-License-Identifier: Apache-2.0 diff --git a/haystack_experimental/version.py b/haystack_experimental/version.py index 8b18fc69..a4a8d183 100644 --- a/haystack_experimental/version.py +++ b/haystack_experimental/version.py @@ -2,9 +2,4 @@ # # SPDX-License-Identifier: Apache-2.0 -from importlib import metadata - -try: - __version__ = str(metadata.version("haystack-experimental")) -except metadata.PackageNotFoundError: - __version__ = "main" +__version__ = "0.0.0" diff --git a/pyproject.toml b/pyproject.toml index 47bdb0ae..547d69d7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,9 +7,9 @@ name = "haystack-experimental" dynamic = ["version"] description = "Experimental components and features for the Haystack LLM framework." readme = "README.md" -license = "Apache-2.0" +license = {text = "Apache-2.0"} requires-python = ">=3.8" -authors = [{ name = "deepset.ai", email = "malte.pietsch@deepset.ai" }] +authors = [{ name = "deepset.ai", email = "info@deepset.ai" }] classifiers = [ "Development Status :: 4 - Beta", "Intended Audience :: Science/Research", @@ -21,81 +21,64 @@ classifiers = [ "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Topic :: Scientific/Engineering :: Artificial Intelligence", ] -dependencies = ["haystack-ai"] +dependencies = [ + "haystack-ai", +] +[project.urls] +"CI: GitHub" = "https://github.com/deepset-ai/haystack-experimental/actions" +"GitHub: issues" = "https://github.com/deepset-ai/haystack-experimental/issues" +"GitHub: repo" = "https://github.com/deepset-ai/haystack-experimental" +Homepage = "https://github.com/deepset-ai/haystack-experimental" [tool.hatch.envs.default] dependencies = [ - "pre-commit", # Type check "mypy", # Test "pytest", "pytest-cov", - "pytest-custom_exit_code", # used in the CI - "pytest-asyncio", - "pytest-rerunfailures", - "responses", - "tox", - "coverage", - "python-multipart", - "psutil", # Linting "pylint", "ruff", - # Documentation - "toml", - "reno", - # dulwich is a reno dependency, they pin it at >=0.15.0 so pip takes ton of time to resolve the dependency tree. - # We pin it here to avoid taking too much time. - # https://opendev.org/openstack/reno/src/branch/master/requirements.txt#L7 - "dulwich>=0.21.0,<1.0.0", - # Version specified following Black stability policy: - # https://black.readthedocs.io/en/stable/the_black_code_style/index.html#stability-policy - "black[jupyter]~=23.0", ] -[tool.hatch.envs.default.scripts] -format = "black ." -format-check = "black --check ." - [tool.hatch.envs.test] -extra-dependencies = [] +extra-dependencies = [ + # List here dependencies behind lazy-import +] [tool.hatch.envs.test.scripts] -e2e = "pytest e2e" unit = 'pytest --cov-report xml:coverage.xml --cov="haystack-experimental" -m "not integration" {args:test}' integration = 'pytest --maxfail=5 -m "integration" {args:test}' -integration-mac = 'pytest --maxfail=5 -m "integration" -k "not tika" {args:test}' -integration-windows = 'pytest --maxfail=5 -m "integration" -k "not tika" {args:test}' -types = "mypy --install-types --non-interactive --cache-dir=.mypy_cache/ {args:haystack-experimental}" +typing = "mypy --install-types --non-interactive {args:haystack_experimental}" lint = [ - "ruff check {args:haystack-experimental}", - "pylint -ry -j 0 {args:haystack-experimental}", + "ruff check {args:haystack_experimental}", + "pylint -ry -j 0 {args:haystack_experimental}", +] +test-cov = "coverage run -m pytest {args:test}" +cov-report = [ + "- coverage combine", + "coverage xml", +] +cov = [ + "test-cov", + "cov-report", ] -lint-fix = ["black .", "ruff check {args:haystack-experimental} --fix"] [tool.hatch.envs.readme] -detached = true # To avoid installing the dependencies from the default environment +detached = true # To avoid installing the dependencies from the default environment dependencies = ["haystack-pydoc-tools"] [tool.hatch.envs.readme.scripts] sync = "./.github/utils/pydoc-markdown.sh" delete-outdated = "python ./.github/utils/delete_outdated_docs.py {args}" -[tool.hatch.envs.snippets] -extra-dependencies = ["torch", "pydantic"] - -[project.urls] -"CI: GitHub" = "https://github.com/deepset-ai/haystack-experimental/actions" -"GitHub: issues" = "https://github.com/deepset-ai/haystack-experimental/issues" -"GitHub: repo" = "https://github.com/deepset-ai/haystack-experimental" -Homepage = "https://github.com/deepset-ai/haystack-experimental" - [tool.hatch.version] -path = "VERSION.txt" -pattern = "(?P.+)" +path = "haystack_experimental/version.py" [tool.hatch.metadata] allow-direct-references = true @@ -106,97 +89,24 @@ include = ["/haystack-experimental", "/VERSION.txt"] [tool.hatch.build.targets.wheel] packages = ["haystack-experimental"] -[tool.black] -line-length = 120 -skip_magic_trailing_comma = true # For compatibility with pydoc>=4.6, check if still needed. - [tool.codespell] ignore-words-list = "ans,astroid,nd,ned,nin,ue,rouge,ist" quiet-level = 3 skip = "test/nodes/*,test/others/*,test/samples/*,e2e/*" +[tool.pylint] +ignore-paths = [ + "haystack_experimental/__init__.py", + "haystack_experimental/version.py", +] [tool.pylint.'MESSAGES CONTROL'] max-line-length = 120 -disable = [ - - # To keep - "fixme", - "c-extension-no-member", - - # To review: - "missing-docstring", - "unused-argument", - "no-member", - "line-too-long", - "protected-access", - "too-few-public-methods", - "raise-missing-from", - "invalid-name", - "duplicate-code", - "arguments-differ", - "consider-using-f-string", - "no-else-return", - "attribute-defined-outside-init", - "super-with-arguments", - "redefined-builtin", - "abstract-method", - "unspecified-encoding", - "unidiomatic-typecheck", - "no-name-in-module", - "consider-using-with", - "redefined-outer-name", - "arguments-renamed", - "unnecessary-pass", - "broad-except", - "unnecessary-comprehension", - "subprocess-run-check", - "singleton-comparison", - "consider-iterating-dictionary", - "undefined-loop-variable", - "consider-using-in", - "bare-except", - "unexpected-keyword-arg", - "simplifiable-if-expression", - "use-list-literal", - "broad-exception-raised", - - # To review later - "cyclic-import", - "import-outside-toplevel", - "deprecated-method", -] -[tool.pylint.'DESIGN'] -max-args = 38 # Default is 5 -max-attributes = 28 # Default is 7 -max-branches = 34 # Default is 12 -max-locals = 45 # Default is 15 -max-module-lines = 2468 # Default is 1000 -max-nested-blocks = 9 # Default is 5 -max-statements = 206 # Default is 50 -[tool.pylint.'SIMILARITIES'] -min-similarity-lines = 6 [tool.pytest.ini_options] minversion = "6.0" addopts = "--strict-markers" markers = [ - "unit: unit tests", "integration: integration tests", - - "generator: generator tests", - "summarizer: summarizer tests", - "embedding_dim: uses a document store with non-default embedding dimension (e.g @pytest.mark.embedding_dim(128))", - - "tika: requires Tika container", - "parsr: requires Parsr container", - "ocr: requires Tesseract", - - "elasticsearch: requires Elasticsearch container", - "weaviate: requires Weaviate container", - "pinecone: requires Pinecone credentials", - "faiss: uses FAISS", - "opensearch", - "document_store", ] log_cli = true @@ -206,11 +116,10 @@ warn_unused_configs = true ignore_missing_imports = true [tool.ruff] -line-length = 301 +line-length = 120 target-version = "py38" exclude = ["test"] - [tool.ruff.lint] select = [ "ASYNC", # flake8-async @@ -259,13 +168,3 @@ ignore = [ [tool.ruff.lint.mccabe] max-complexity = 28 - -[tool.ruff.lint.per-file-ignores] - -[tool.ruff.lint.pylint] -allow-magic-value-types = ["float", "int", "str"] -max-args = 14 # Default is 5 -max-branches = 21 # Default is 12 -max-public-methods = 20 # Default is 20 -max-returns = 7 # Default is 6 -max-statements = 60 # Default is 50 diff --git a/releasenotes/config.yaml b/releasenotes/config.yaml deleted file mode 100644 index 1becbe28..00000000 --- a/releasenotes/config.yaml +++ /dev/null @@ -1,47 +0,0 @@ -default_branch: main -collapse_pre_releases: true -pre_release_tag_re: (?P-(?:[ab]|rc)+\d*)$ -prelude_section_name: highlights -template: | - --- - highlights: > - Replace this text with content to appear at the top of the section for this - release. The highlights might repeat some details that are also present in other notes - from the same release, that's ok. Not every release note requires highlights, - use this section only to describe major features or notable changes. - upgrade: - - | - List upgrade notes here, or remove this section. - Upgrade notes should be rare: only list known/potential breaking changes, - or major changes that require user action before the upgrade. - Notes here must include steps that users can follow to 1. know if they're - affected and 2. handle the change gracefully on their end. - features: - - | - List new features here, or remove this section. - enhancements: - - | - List new behavior that is too small to be - considered a new feature, or remove this section. - issues: - - | - List known issues here, or remove this section. For example, if some change is experimental or known to not work in some cases, it should be mentioned here. - deprecations: - - | - List deprecations notes here, or remove this section. Deprecations should not be used for something that is removed in the release, use upgrade section instead. Deprecation should allow time for users to make necessary changes for the removal to happen in a future release. - security: - - | - Add security notes here, or remove this section. - fixes: - - | - Add normal bug fixes here, or remove this section. - -sections: - # The prelude section is implicitly included. - - [upgrade, ⬆️ Upgrade Notes] - - [features, 🚀 New Features] - - [enhancements, ⚡️ Enhancement Notes] - - [issues, Known Issues] - - [deprecations, ⚠️ Deprecation Notes] - - [security, Security Notes] - - [fixes, 🐛 Bug Fixes] diff --git a/test/test_experimental.py b/test/test_experimental.py new file mode 100644 index 00000000..f1748238 --- /dev/null +++ b/test/test_experimental.py @@ -0,0 +1,2 @@ +def test(): + pass