Skip to content

Commit

Permalink
fix: updated from cruft template
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethEnevoldsen committed Oct 10, 2023
1 parent 2e73020 commit 34e6dc9
Show file tree
Hide file tree
Showing 10 changed files with 394 additions and 127 deletions.
1 change: 0 additions & 1 deletion .cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"*.github"
],
"_template": "https://github.com/MartinBernstorff/swift-python-cookiecutter",
"add_makefile": "y",
"author": "Kenneth Enevoldsen",
"copyright_year": "2023",
"email": "[email protected]",
Expand Down
3 changes: 1 addition & 2 deletions .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "https://github.com/MartinBernstorff/swift-python-cookiecutter",
"commit": "691543da74e08c82a24f26eae89536b1c5581673",
"commit": "7fdb02999e8596c525377c208ca902645d134f97",
"checkout": null,
"context": {
"cookiecutter": {
Expand All @@ -12,7 +12,6 @@
"github_user": "centre-for-humanities-computing",
"version": "2.4.2",
"copyright_year": "2023",
"add_makefile": "y",
"license": "MIT",
"_copy_without_render": [
"*.github"
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0 # otherwise, you will failed to push refs to dest repo
token: ${{ secrets.PAT }}

- name: Install dependencies
shell: bash
Expand All @@ -32,5 +33,5 @@ jobs:
if: ${{ github.event_name == 'push' }}
uses: ad-m/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
github_token: ${{ secrets.PAT }}
branch: gh-pages
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
🏎️ 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 strongly recommend setting up the `ruff` and `black` extensions to auto-format on save in your chosen editor.
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' }}
Expand Down
35 changes: 25 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,21 @@ name: Release
on:
push:
branches: [main]
workflow_run:
workflows: ["tests"]
types:
- completed

jobs:
release:
runs-on: ubuntu-latest
concurrency: release
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing using PyPI
# a guide on how to set it up is available here: https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/


if: ${{ github.ref == 'refs/heads/main' }}
if: ${{ github.ref == 'refs/heads/main' && github.event.workflow_run.conclusion == 'success'}}
steps:
# Checkout action is required for token to persist
- uses: actions/checkout@v3
Expand All @@ -22,14 +31,20 @@ jobs:
token: ${{ secrets.PAT }}

- name: Python Semantic Release
uses: relekang/[email protected]
uses: python-semantic-release/[email protected]
id: release
with:
github_token: ${{ secrets.PAT }}

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
if: steps.release.outputs.released == 'true'
# This action supports PyPI's trusted publishing implementation, which allows authentication to PyPI without a manually
# configured API token or username/password combination. To perform trusted publishing with this action, your project's
# publisher must already be configured on PyPI.

- name: Publish package distributions to GitHub Releases
uses: python-semantic-release/upload-to-gh-release@main
if: steps.release.outputs.released == 'true'
with:
github_token: ${{ secrets.PAT }}
# Remember to copy the [tool.semantic_release] section from pyproject.toml
# as well
# To enable pypi,
# 1) Set upload_to_pypi to true in pyproject.toml and
# 2) Set the pypi_token in the repo
# 3) Uncomment the two lines below
repository_username: __token__
repository_password: ${{ secrets.PYPI_API_TOKEN }}
97 changes: 97 additions & 0 deletions .github/workflows/static_type_checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# 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:
pull_request:
branches: [main]
push:
branches: [main]

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]
python-version: ["3.9"]
steps:
- uses: actions/checkout@v3

- name: Cache tox
uses: actions/[email protected]
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}}

- name: Install dependencies
shell: bash
run: |
pip install invoke tox
- 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}}
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
21 changes: 16 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,34 @@ jobs:
steps:
- uses: actions/checkout@v3


- name: Cache tox
uses: actions/[email protected]
id: cache_tox
with:
path: |
.tox
key: ${{ runner.os }}-${{ matrix.python-version }}-tests

- name: Set up Python
uses: actions/setup-python@v4
id: setup_python
with:
python-version: ${{ matrix.python-version }}
cache: 'pip' # caching pip dependencies

- name: Install dependencies
shell: bash
run: |
pip install .[tests]
pip install invoke tox
- name: Run and write pytest
shell: bash
run: |
python -m pytest --durations=0 -x --junitxml=pytest.xml --cov-report=term-missing --cov=src/ tests/
source .venv/bin/activate
pytest --durations=0 -n 2 -x --junitxml=pytest.xml --cov-report=term-missing --cov=src/ tests/
# 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: Test report on failures
uses: EnricoMi/publish-unit-test-result-action@v2
id: test_report_with_annotations
Expand All @@ -62,6 +73,6 @@ jobs:
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: true
report-only-changed-files: false
pytest-coverage-path: pytest-coverage.txt
junitxml-path: ./pytest.xml
52 changes: 37 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]

keywords = ["nlp", "danish", "spacy-universe"]
Expand All @@ -46,13 +48,7 @@ repository = "https://github.com/centre-for-humanities-computing/DaCy"
file = "LICENSE"
name = "Apache License 2.0"
[project.optional-dependencies]
dev = [
"cruft",
"mypy",
"pre-commit>=2.20.0",
"ruff>=0.0.262",
"black[jupyter]>=23.3.0",
]
dev = ["cruft", "pre-commit>=2.20.0", "ruff>=0.0.262", "black[jupyter]>=23.3.0"]
tests = [
"pytest>=7.1.2",
"pytest-cov>=3.0.0",
Expand Down Expand Up @@ -109,10 +105,9 @@ where = ["src"]
[tool.coverage.run]
omit = ["**/tests/*", "**/about.py", "**/dev/*"]

[tool.mypy]
ignore_missing_imports = true
no_implicit_optional = true
warn_unreachable = true
[tool.pyright]
exclude = [".*venv*", ".tox"]
pythonPlatform = "Darwin"

[tool.ruff]
# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default.
Expand Down Expand Up @@ -164,7 +159,6 @@ exclude = [
".eggs",
".git",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
Expand Down Expand Up @@ -206,10 +200,38 @@ max-complexity = 10

[tool.semantic_release]
branch = "main"
version_variable = ["pyproject.toml:version"]
upload_to_pypi = true
upload_to_release = true
version_toml = ["pyproject.toml:project.version"]
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
basepython = py39 # 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 =
sphinx-build -b html docs docs/_build/html
"""
Loading

0 comments on commit 34e6dc9

Please sign in to comment.