From 8016bd5f31f760ca5def957fffe822706b29de9e Mon Sep 17 00:00:00 2001 From: Kenneth Enevoldsen Date: Thu, 7 Dec 2023 10:34:06 +0100 Subject: [PATCH 1/7] Update cruft --- .cruft.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.cruft.json b/.cruft.json index b8da5dd1..53b1d451 100644 --- a/.cruft.json +++ b/.cruft.json @@ -1,5 +1,5 @@ { - "template": "https://github.com/MartinBernstorff/swift-python-cookiecutter", + "template": "https://github.com/KennethEnevoldsen/swift-python-cookiecutter", "commit": "7fdb02999e8596c525377c208ca902645d134f97", "checkout": null, "context": { @@ -16,8 +16,8 @@ "_copy_without_render": [ "*.github" ], - "_template": "https://github.com/MartinBernstorff/swift-python-cookiecutter" + "_template": "https://github.com/KennethEnevoldsen/swift-python-cookiecutter" } }, "directory": null -} +} \ No newline at end of file From 5e055daa2c7c9c8dfbd80aedebb881f24511643d Mon Sep 17 00:00:00 2001 From: Kenneth Enevoldsen Date: Thu, 7 Dec 2023 10:43:36 +0100 Subject: [PATCH 2/7] fix: Update from cruft template --- .cookiecutter.json | 1 - .cruft.json | 5 +- .github/workflows/check_for_rej.yml | 27 -------- .github/workflows/cruft.yml | 66 ------------------ .github/workflows/dependabot_automerge.yml | 30 -------- .github/workflows/lint.yml | 28 ++++++++ .github/workflows/pre-commit.yml | 79 ---------------------- .github/workflows/release.yml | 4 ++ .github/workflows/static_type_checks.yml | 70 ++----------------- .github/workflows/tests.yml | 33 +++------ CONTRIBUTING.md | 27 ++++---- README.md | 4 +- pyproject.toml | 68 +++++-------------- tests/__init__.py | 0 14 files changed, 78 insertions(+), 364 deletions(-) delete mode 100644 .github/workflows/check_for_rej.yml delete mode 100644 .github/workflows/cruft.yml delete mode 100644 .github/workflows/dependabot_automerge.yml create mode 100644 .github/workflows/lint.yml delete mode 100644 .github/workflows/pre-commit.yml create mode 100644 tests/__init__.py diff --git a/.cookiecutter.json b/.cookiecutter.json index 9b7b87b9..7ab91b43 100644 --- a/.cookiecutter.json +++ b/.cookiecutter.json @@ -8,7 +8,6 @@ "email": "Kennethcenevoldsen@gmail.com", "friendly_name": "Scandinavian Embedding Benchmark", "github_user": "KennethEnevoldsen", - "license": "MIT", "package_name": "seb", "project_name": "scandinavian-embedding-benchmark", "version": "0.0.0" diff --git a/.cruft.json b/.cruft.json index 53b1d451..fdaadd68 100644 --- a/.cruft.json +++ b/.cruft.json @@ -1,6 +1,6 @@ { "template": "https://github.com/KennethEnevoldsen/swift-python-cookiecutter", - "commit": "7fdb02999e8596c525377c208ca902645d134f97", + "commit": "c5698bd37fe84cdc5f5f411a56a49c2f5db77dab", "checkout": null, "context": { "cookiecutter": { @@ -12,7 +12,6 @@ "github_user": "KennethEnevoldsen", "version": "0.0.0", "copyright_year": "2023", - "license": "MIT", "_copy_without_render": [ "*.github" ], @@ -20,4 +19,4 @@ } }, "directory": null -} \ No newline at end of file +} diff --git a/.github/workflows/check_for_rej.yml b/.github/workflows/check_for_rej.yml deleted file mode 100644 index ed200fcc..00000000 --- a/.github/workflows/check_for_rej.yml +++ /dev/null @@ -1,27 +0,0 @@ -# .rej files occur when cruft update could not merge two files. -# They need to be handled, but are easy to miss if there's no CI -name: Check for .rej files - -on: - pull_request: - types: [opened, synchronize] - -jobs: - check-for-rej-files: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Check for .rej files - run: | - files=`find . -type f -name "*.rej"` - count=`echo $files | grep -o "\.rej" | wc -l` - if [[ $count != 0 ]]; then - echo "Found .rej files in the repository." - echo $files | - exit 1 - else - echo "No .rej files found in the repository." - fi diff --git a/.github/workflows/cruft.yml b/.github/workflows/cruft.yml deleted file mode 100644 index 714de363..00000000 --- a/.github/workflows/cruft.yml +++ /dev/null @@ -1,66 +0,0 @@ -name: Cruft Check - -on: - pull_request: - branches: - - main - -jobs: - cruft-check: - runs-on: ubuntu-latest - permissions: - pull-requests: write - - steps: - # Avoid infinite loop where main - # Feature PR -> cruft check from main -> - # Cruft update PR -> cruft check from main -> - # Cruft update PR ... - - name: Check if pull request is from a fork - run: | - if [ "${{ github.event.pull_request.head.repo.fork }}" = "true" ]; then - echo "Pull request is from a fork and does not have permissions for PR creation. Exiting gracefully." - exit 0 - elif [ "${{github.event.pull_request.title}}" == "ci - update cruft" ]; then - echo "Pull request is already a cruft update. Exiting gracefully." - exit 0 - else - echo "Pull request is not from a fork, continuing." - fi - - - name: Checkout code - uses: actions/checkout@v3 - with: - ref: main - - - name: Setup Python - uses: actions/setup-python@v4 - with: - python-version: "3.9" - - - name: Install Cruft - run: pip install cruft - - - name: Update cruft - id: cruft_check - run: | - cruft_output=$(cruft update --skip-apply-ask) - if echo "$cruft_output" | grep -q "Good work!"; then - echo "$cruft_output" - echo "cruft_updated=true" >> $GITHUB_OUTPUT - else - echo "$cruft_output" - echo "cruft_updated=false" >> $GITHUB_OUTPUT - fi - - - name: Create Pull Request - uses: peter-evans/create-pull-request@v4 - if: ${{ steps.cruft_check.outputs.cruft_updated == 'true' && github.event.pull_request.title != 'ci - update cruft' }} - continue-on-error: true - with: - title: "ci - update cruft" - branch: "update-cruft" - body: "🌲 Cruft updates" - token: ${{ secrets.PAT }} - commit-message: "ci: update cruft" - labels: "dependencies" # This makes the PR exempt from the stale bot diff --git a/.github/workflows/dependabot_automerge.yml b/.github/workflows/dependabot_automerge.yml deleted file mode 100644 index 22d2ecd7..00000000 --- a/.github/workflows/dependabot_automerge.yml +++ /dev/null @@ -1,30 +0,0 @@ -# GitHub action to automerge dependabot PRs. Only merges if tests passes the -# branch protections in the repository settings. -# You can set branch protections in the repository under Settings > Branches > Add rule -name: automerge-bot-prs - -on: pull_request - -permissions: - contents: write - pull-requests: write - -jobs: - dependabot-automerge: - runs-on: ubuntu-latest - # if actor is dependabot or pre-commit-ci[bot] then run - if: ${{ github.actor == 'dependabot[bot]' }} - - steps: - # Checkout action is required for token to persist - - name: Enable auto-merge for Dependabot PRs - run: gh pr merge --auto --merge "$PR_URL" # Use Github CLI to merge automatically the PR - env: - PR_URL: ${{github.event.pull_request.html_url}} - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Auto approve dependabot PRs - if: ${{ github.actor == 'dependabot[bot]' }} - uses: hmarr/auto-approve-action@v3.1.0 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..cc2ffc80 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,28 @@ +# GitHub action to run linting + +name: run-linting + +on: + pull_request: + branches: [main] + push: + branches: [main] + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-python@v4 + with: + python-version: "3.9" + cache: "pip" + + - name: Install dependencies + run: make install + + - name: Lint + id: lint + run: | + make lint diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml deleted file mode 100644 index 79671c4a..00000000 --- a/.github/workflows/pre-commit.yml +++ /dev/null @@ -1,79 +0,0 @@ -# GitHub action to check if pre-commit has been run. Runs from .pre-commit-config.yaml, where the pre-commit actions are. - -name: run-pre-commit - -on: - pull_request: - branches: [main] - push: - branches: [main] - -jobs: - pre-commit: - permissions: - pull-requests: write - concurrency: - group: "${{ github.workflow }} @ ${{ github.ref }}" - cancel-in-progress: true - if: ${{ github.actor != 'dependabot[bot]' }} - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - repository: ${{ github.event.pull_request.head.repo.full_name }} - ref: ${{ github.event.pull_request.head.ref }} - token: ${{ secrets.PAT }} - - - uses: actions/setup-python@v4 - with: - python-version: "3.9" - - - name: Install pre-commit - run: pip install pre-commit - - - name: Run pre-commit - id: pre_commit - continue-on-error: true - run: | - if pre-commit run --color always --all-files; then - echo "Pre-commit check passed" - echo "pre_commit_failed=0" >> $GITHUB_OUTPUT - else - echo "Pre-commit check failed" - echo "pre_commit_failed=1" >> $GITHUB_OUTPUT - exit 1 - fi - - # Have this step before commit in case the PR is from a fork. In this case, we want the - # add-pr-comment to fail, because it makes it means that the contributer is directed here, - # and are given the informative error message, instead of directed to a "could not commit error message". - - uses: mshick/add-pr-comment@v2 - if: ${{ steps.pre_commit.outputs.pre_commit_failed == 1 && github.event_name == 'pull_request' }} - id: add_comment - with: - message: | - Looks like some formatting rules failed. - - ✨ The action has attempted automatic fixes ✨ - - If any were succesful, they were committed to the branch. - We suggest using `git pull --rebase` to apply them locally. - - If some errors could not be fixed automatically, you can: - - 🏎️ Get results locally by running `pre-commit run --all-files` - πŸ•΅οΈ Examine the results in the `Run pre-commit` section of this workflow `pre-commit` - - We also recommend setting up the `ruff` and `black` extensions to auto-format on save in your chosen editor. - - - name: Commit formatting - if: ${{ steps.pre_commit.outputs.pre_commit_failed == 1 && github.event_name == 'pull_request' }} - run: | - git config user.name github-actions - git config user.email github-actions@github.com - git commit -am "style: linting" - git push --no-verify - - - name: Fail workflow - if: ${{ steps.pre_commit.outputs.pre_commit_failed == 1 && github.event_name == 'pull_request' }} - run: exit 1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f39e1d30..1e055718 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,6 +5,10 @@ # - Upload the package to PyPI # - Create a release on GitHub +# This workflow required the following secrets to be set: +# - a GitHub personal access token with the `repo` scope called `PAT` +# - and that you setup trusted publishing using PyPI as described here: https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/ + name: Release on: workflow_run: diff --git a/.github/workflows/static_type_checks.yml b/.github/workflows/static_type_checks.yml index 72ef703a..bd848472 100644 --- a/.github/workflows/static_type_checks.yml +++ b/.github/workflows/static_type_checks.yml @@ -1,6 +1,3 @@ -# We do not include static_type_checks as a pre-commit hook because pre-commit hooks -# are installed in their own virtual environment, so static_type_checks cannot -# use stubs from imports name: static_type_checks on: @@ -12,11 +9,6 @@ on: jobs: static_type_checks: runs-on: ubuntu-latest - permissions: - pull-requests: write - concurrency: - group: "${{ github.workflow }} @ ${{ github.ref }}" - cancel-in-progress: true strategy: matrix: os: [ubuntu-latest] @@ -24,74 +16,20 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Cache tox - uses: actions/cache@v3.2.6 - id: cache_tox - with: - path: | - .tox - key: ${{ runner.os }}-${{ matrix.python-version }}-static-type-checks - name: Set up Python uses: actions/setup-python@v4 id: setup_python with: python-version: ${{ matrix.python-version}} + cache: pip - name: Install dependencies shell: bash run: | - pip install invoke tox + make install - name: Run static type checker - id: pyright - continue-on-error: true - run: | - if inv static-type-checks; then - echo "pyright check passed" - echo "pyright_failed=0" >> $GITHUB_OUTPUT - else - echo "pyright check failed" - echo "pyright_failed=1" >> $GITHUB_OUTPUT - fi - - - name: Find Comment - uses: peter-evans/find-comment@v2 - id: find_comment - if: ${{github.event_name == 'pull_request'}} - continue-on-error: true - with: - issue-number: ${{ github.event.pull_request.number }} - comment-author: "github-actions[bot]" - body-includes: ✨ Looks like pyright failed ✨ - - - uses: mshick/add-pr-comment@v2 - if: ${{ steps.pyright.outputs.pyright_failed == 1 && github.event_name == 'pull_request'}} - id: add_comment - with: - message: | - ✨ Looks like pyright failed ✨ - - If you want to fix this, we recommend doing it locally by either: - - a) Enabling pyright in VSCode and going through the errors in the problems tab - - `VSCode settings > Python > Analysis: Type checking mode > "basic"` - - b) Debugging via the command line - - 1. Installing pyright, which is included in the dev dependencies: `pip install -e ".[dev]"` - 2. Diagnosing the errors by running `pyright .` - - - uses: mshick/add-pr-comment@v2 - if: ${{ steps.pyright.outputs.pyright_failed == 0 && steps.find_comment.outputs.comment-id != '' && github.event_name == 'pull_request'}} - with: - message-id: ${{ steps.find_comment.outputs.comment-id }} - message: | - 🌟 pyright succeeds! 🌟 - - - name: Show pyright output - id: fail_run - if: ${{steps.pyright.outputs.pyright_failed == 1}} + shell: bash run: | - inv static-type-checks # Rerunning pyright isn't optimal computationally, but typically takes no more than a couple of seconds, and this ensures that the errors are in the failing step + make static-type-check \ No newline at end of file diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e51c84bb..7e2ff3ac 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,6 +1,7 @@ -# This workflow will install Python dependencies, run pytests and run notebooks -# then it will in python 3.9 (ubuntu-latest) create a badge with the coverage -# and add it to the PR. This badge will be updated if the PR is updated. +# This workflow will: +# 1) install Python dependencies +# 2) run make test + name: Tests on: @@ -29,36 +30,18 @@ jobs: steps: - uses: actions/checkout@v3 - - - name: Cache tox - uses: actions/cache@v3.2.6 - id: cache_tox - with: - path: | - .tox - key: ${{ runner.os }}-${{ matrix.python-version }}-tests - - name: Set up Python uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} + cache: "pip" - name: Install dependencies shell: bash run: | - pip install invoke tox + pip install -e ".[tests]" - - name: Run and write pytest + - name: Run tests shell: bash run: | - # Specifying two sets of "--pytest-args" is required for invoke to parse it as a list - inv test --pytest-args="--durations=0" --pytest-args="--junitxml=pytest.xml --cov-report=term-missing --cov=src/" - - - name: Pytest coverage comment - id: coverage-comment - uses: MishaKav/pytest-coverage-comment@v1.1.48 - if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == '3.9' && github.actor != 'dependabot[bot]' && github.event_name == 'pull_request' && (success() || failure()) }} - with: - create-new-comment: false - report-only-changed-files: false - junitxml-path: ./pytest.xml + make test diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2f20bc50..425da603 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,7 +11,7 @@ Here is a list of important resources for contributors: - [Issue Tracker] - [Code of Conduct] -[mit license]: https://opensource.org/licenses/MIT +[MIT license]: https://opensource.org/licenses/MIT [source code]: https://github.com/KennethEnevoldsen/scandinavian-embedding-benchmark [documentation]: https://scandinavian-embedding-benchmark.readthedocs.io/ [issue tracker]: https://github.com/KennethEnevoldsen/scandinavian-embedding-benchmark/issues @@ -37,24 +37,22 @@ Request features on the [Issue Tracker]. ## How to set up your development environment -Install the package with development requirements: +To install all the development dependencies, you can use the [make] command: ```console -$ pip install -e ."[dev,tests]" +$ make install ``` + ## How to test the project Run the full test suite: ```console -$ pytest +$ make test ``` -Unit tests are located in the _tests_ directory, -and are written using the [pytest] testing framework. - -[pytest]: https://pytest.readthedocs.io/ +Unit tests are located in the _tests_ directory. ## How to submit changes @@ -62,23 +60,24 @@ Open a [pull request] to submit changes to this project. Your pull request needs to meet the following guidelines for acceptance: -- The Nox test suite must pass without errors and warnings. -- Include unit tests. This project maintains 100% code coverage. +- The test suite should ideally pass without errors and warnings. +- Ideally add tests for your changes. - If your changes add functionality, update the documentation accordingly. Feel free to submit early, thoughβ€”we can always iterate on this. -To run linting and code formatting checks before committing your change, you can install pre-commit as a Git hook by running the following command: +To run linting and code formatting checks before committing your change, you can run the following [make] command: ```console -$ nox --session=pre-commit -- install +$ make lint ``` -It is recommended to open an issue before starting work on anything. +It is recommended to open an issue before starting work on any major changes. This will allow a chance to talk it over with the owners and validate your approach. [pull request]: https://github.com/KennethEnevoldsen/scandinavian-embedding-benchmark/pulls +[make]: https://makefiletutorial.com -[code of conduct]: CODE_OF_CONDUCT.md +[code of conduct]: CODE_OF_CONDUCT.md \ No newline at end of file diff --git a/README.md b/README.md index d99410b8..9c4018b1 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,13 @@ [![Python Version](https://img.shields.io/pypi/pyversions/seb)][pypi status] [![documentation](https://github.com/KennethEnevoldsen/scandinavian-embedding-benchmark/actions/workflows/documentation.yml/badge.svg)][documentation] [![Tests](https://github.com/KennethEnevoldsen/scandinavian-embedding-benchmark/actions/workflows/tests.yml/badge.svg)][tests] -[![Black](https://img.shields.io/badge/code%20style-black-000000.svg)][black] +[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)]([ruff]) [![DOI](https://zenodo.org/badge/671737258.svg)](https://zenodo.org/doi/10.5281/zenodo.10078411) [pypi status]: https://pypi.org/project/seb/ [documentation]: https://KennethEnevoldsen.github.io/scandinavian-embedding-benchmark/ [tests]: https://github.com/KennethEnevoldsen/scandinavian-embedding-benchmark/actions?workflow=Tests -[black]: https://github.com/psf/black +[ruff]: https://github.com/astral-sh/ruff diff --git a/pyproject.toml b/pyproject.toml index a74cd55e..ff27812c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,23 +32,8 @@ file = "LICENSE" name = "MIT" [project.optional-dependencies] -dev = [ - "cruft>=2.0.0", - "pyright==1.1.325", - "pyright-polite>=0.0.1", - "pre-commit>=2.20.0", - "ruff>=0.0.254", - "black[jupyter]>=22.8.0", - "pandas-stubs>=0.0.0", # type stubs for pandas - "invoke==2.2.0", -] -tests = [ - "pytest>=7.1.3", - "pytest-cov>=3.0.0", - "pytest-xdist>=3.0.0", - "pytest-sugar>=0.9.4", - "tox>=4.5.0", -] +dev = ["cruft>=2.0.0", "pyright==1.1.338", "ruff>=0.0.254"] +tests = ["pytest>=7.1.3", "pytest-cov>=3.0.0"] docs = [ "mkdocs-jupyter==0.24.2", "mkdocs-material==9.1.21", @@ -76,10 +61,11 @@ repository = "https://github.com/KennethEnevoldsen/scandinavian-embedding-benchm documentation = "https://KennethEnevoldsen.github.io/scandinavian-embedding-benchmark/" [tool.pyright] -exclude = [".*venv*", ".tox"] +exclude = [".*venv*"] pythonPlatform = "Darwin" [tool.ruff] +extend-include = ["*.ipynb"] # Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default. select = [ "A", @@ -109,7 +95,17 @@ select = [ "SIM", "W", ] -ignore = ["ANN101", "ANN401", "E402", "E501", "E741", "F401", "F841", "RET504"] +ignore = [ + "ANN101", + "ANN401", + "E402", + "E501", + "E741", + "F401", + "F841", + "RET504", + "COM812", +] ignore-init-module-imports = true # Allow autofix for all enabled rules (when `--fix`) is provided. unfixable = ["ERA"] @@ -145,8 +141,8 @@ target-version = "py39" mypy-init-return = true suppress-none-returning = true -[tool.ruff.isort] -known-third-party = ["wandb"] +[tool.ruff.lint.pydocstyle] +convention = "google" [tool.ruff.mccabe] # Unlike Flake8, default to a complexity level of 10. @@ -159,33 +155,3 @@ build_command = "python -m pip install build; python -m build" [tool.setuptools] include-package-data = true - - -[tool.tox] -legacy_tox_ini = """ -[tox] -envlist = py{39,310} - -[testenv] -description: run unit tests -extras = tests -use_develop = true -commands = - pytest -n auto {posargs:test} - -[testenv:type] -description: run type checks -extras = tests, dev, docs -basepython = py310 # Setting these explicitly avoid recreating env if your shell is set to a different version -use_develop = true -commands = - pyright src/ - -[testenv:docs] -description: build docs -extras = docs -basepython = py39 # Setting these explicitly avoid recreating env if your shell is set to a different version -use_develop = true -commands = - mkdocs build -""" diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..e69de29b From 3ec0673f33a1270bff0b4ba8ccdcfb79784d838b Mon Sep 17 00:00:00 2001 From: Kenneth Enevoldsen Date: Thu, 7 Dec 2023 11:26:12 +0100 Subject: [PATCH 3/7] fix: change to relative import for tests --- tests/test_all_models.py | 3 ++- tests/test_benchmark.py | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/test_all_models.py b/tests/test_all_models.py index 6427f204..1e613f0a 100644 --- a/tests/test_all_models.py +++ b/tests/test_all_models.py @@ -4,7 +4,8 @@ import pytest import seb -from dummy_task import create_test_encode_task # noqa: F401 + +from .dummy_task import create_test_encode_task # noqa: F401 all_models = seb.get_all_models() openai_models = [] diff --git a/tests/test_benchmark.py b/tests/test_benchmark.py index bb85e08a..492ac45e 100644 --- a/tests/test_benchmark.py +++ b/tests/test_benchmark.py @@ -9,9 +9,10 @@ import pytest import seb -from dummy_model import create_test_model # noqa: F401 -from dummy_task import create_test_task # noqa: F401 -from test_tasks import all_tasks_names + +from .dummy_model import create_test_model # noqa: F401 +from .dummy_task import create_test_task # noqa: F401 +from .test_tasks import all_tasks_names @pytest.mark.parametrize( From 614479197ffba5951d49501e5f0be8902fec7adb Mon Sep 17 00:00:00 2001 From: Kenneth Enevoldsen Date: Thu, 7 Dec 2023 11:41:33 +0100 Subject: [PATCH 4/7] ci: ensure full install in test ci --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7e2ff3ac..ea939d8c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -39,7 +39,7 @@ jobs: - name: Install dependencies shell: bash run: | - pip install -e ".[tests]" + make install - name: Run tests shell: bash From ec857ab924ebf1a4efff7b58630607cd013810e1 Mon Sep 17 00:00:00 2001 From: Kenneth Enevoldsen Date: Thu, 7 Dec 2023 11:44:06 +0100 Subject: [PATCH 5/7] add missing updated to the makefile --- makefile | 25 ++++++++++++++++++++++--- pyproject.toml | 2 +- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/makefile b/makefile index 52d71f90..aa67b295 100644 --- a/makefile +++ b/makefile @@ -1,23 +1,42 @@ install: + @echo "--- πŸš€ Installing project ---" pip install -e ".[dev, docs, openai, cohere, tests]" static-type-check: + @echo "--- πŸ” Running static type check ---" pyright src/ lint: - pre-commit run --all-files + @echo "--- 🧹 Running linters ---" + ruff format . # running ruff formatting + ruff src/ --fix # running ruff linting + ruff tests/ --fix + ruff docs/conf.py --fix test: + @echo "--- πŸ§ͺ Running tests ---" pytest tests/ pr: + @echo "--- πŸš€ Running PR checks ---" make lint make static-type-check make test - echo "Ready to make a PR" + @echo "Ready to make a PR" -docs-serve: +build-docs: + @echo "--- πŸ“š Building docs ---" + @echo "Builds the docs and puts them in the 'site' folder" + mkdocs build + +view-docs: + @echo "--- πŸ‘€ Viewing docs ---" mkdocs serve + +update-from-template: + @echo "--- πŸ”„ Updating from template ---" + @echo "This will update the project from the template, make sure to resolve any .rej files" + cruft update --skip-apply-ask update-benchmark: python docs/run_benchmark.py --data-wrapper-api-token MISSING diff --git a/pyproject.toml b/pyproject.toml index ff27812c..d3d14f25 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,7 +32,7 @@ file = "LICENSE" name = "MIT" [project.optional-dependencies] -dev = ["cruft>=2.0.0", "pyright==1.1.338", "ruff>=0.0.254"] +dev = ["cruft>=2.0.0", "pyright==1.1.338", "ruff>=0.0.281"] tests = ["pytest>=7.1.3", "pytest-cov>=3.0.0"] docs = [ "mkdocs-jupyter==0.24.2", From 1d2341c5b9bf4df95bd6513acb21516a3d5f45fc Mon Sep 17 00:00:00 2001 From: Kenneth Enevoldsen Date: Thu, 7 Dec 2023 11:52:12 +0100 Subject: [PATCH 6/7] fix: ran ruff formatter --- docs/getting_started.ipynb | 3 ++- makefile | 4 +--- src/seb/seb_models/hf_models.py | 12 +++++++++--- tests/test_all_models.py | 2 +- tests/test_benchmark.py | 4 ++-- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/docs/getting_started.ipynb b/docs/getting_started.ipynb index d9324a2b..35eb2ca5 100644 --- a/docs/getting_started.ipynb +++ b/docs/getting_started.ipynb @@ -71,7 +71,7 @@ } ], "source": [ - "benchmark_result[0] # examine the results for the first task" + "benchmark_result[0] # examine the results for the first task" ] }, { @@ -93,6 +93,7 @@ "\n", "model_name = \"sentence-transformers/all-MiniLM-L12-v2\"\n", "\n", + "\n", "def get_my_model():\n", " from sentence_transformers import SentenceTransformer\n", "\n", diff --git a/makefile b/makefile index aa67b295..e171ca85 100644 --- a/makefile +++ b/makefile @@ -9,9 +9,7 @@ static-type-check: lint: @echo "--- 🧹 Running linters ---" ruff format . # running ruff formatting - ruff src/ --fix # running ruff linting - ruff tests/ --fix - ruff docs/conf.py --fix + ruff **/*.py --fix # running ruff linting test: @echo "--- πŸ§ͺ Running tests ---" diff --git a/src/seb/seb_models/hf_models.py b/src/seb/seb_models/hf_models.py index 04c959d8..7ba9797c 100644 --- a/src/seb/seb_models/hf_models.py +++ b/src/seb/seb_models/hf_models.py @@ -121,7 +121,9 @@ def create_dansk_bert() -> SebModel: return SebModel( # see https://huggingface.co/vesteinn/DanskBERT/discussions/3 - loader=partial(get_sentence_transformer, model_name=hf_name, max_seq_length=512), # type: ignore + loader=partial( + get_sentence_transformer, model_name=hf_name, max_seq_length=512 + ), # type: ignore meta=meta, ) @@ -221,7 +223,9 @@ def create_bert_base_swedish_cased() -> SebModel: open_source=True, ) return SebModel( - loader=partial(get_sentence_transformer, model_name=hf_name, max_seq_length=512), # type: ignore + loader=partial( + get_sentence_transformer, model_name=hf_name, max_seq_length=512 + ), # type: ignore meta=meta, ) @@ -254,7 +258,9 @@ def create_xlm_roberta_base() -> SebModel: ) return SebModel( - loader=partial(get_sentence_transformer, model_name=hf_name, max_seq_length=512), # type: ignore + loader=partial( + get_sentence_transformer, model_name=hf_name, max_seq_length=512 + ), # type: ignore meta=meta, ) diff --git a/tests/test_all_models.py b/tests/test_all_models.py index 1e613f0a..31abff92 100644 --- a/tests/test_all_models.py +++ b/tests/test_all_models.py @@ -5,7 +5,7 @@ import pytest import seb -from .dummy_task import create_test_encode_task # noqa: F401 +from .dummy_task import create_test_encode_task all_models = seb.get_all_models() openai_models = [] diff --git a/tests/test_benchmark.py b/tests/test_benchmark.py index 492ac45e..822de9bc 100644 --- a/tests/test_benchmark.py +++ b/tests/test_benchmark.py @@ -10,8 +10,8 @@ import pytest import seb -from .dummy_model import create_test_model # noqa: F401 -from .dummy_task import create_test_task # noqa: F401 +from .dummy_model import create_test_model +from .dummy_task import create_test_task from .test_tasks import all_tasks_names From eb0b6476e3f1b5c7c02e2567a6d9e62d492469e7 Mon Sep 17 00:00:00 2001 From: Kenneth Enevoldsen Date: Thu, 7 Dec 2023 11:53:26 +0100 Subject: [PATCH 7/7] ignore type error --- src/seb/seb_models/openai_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/seb/seb_models/openai_models.py b/src/seb/seb_models/openai_models.py index b54ef75f..1ce3502d 100644 --- a/src/seb/seb_models/openai_models.py +++ b/src/seb/seb_models/openai_models.py @@ -43,7 +43,7 @@ def embed(self, sentences: Sequence[str]) -> torch.Tensor: from openai.error import InvalidRequestError # type: ignore try: - emb = openai.Embedding.create( + emb = openai.Embedding.create( # type: ignore input=sentences, model=self.api_name, )