Skip to content

Commit

Permalink
chore: Update project infrastructure
Browse files Browse the repository at this point in the history
template-version: c90c21e08ac4114bd4c002378c17397566623d36
  • Loading branch information
Wuestengecko committed Oct 2, 2024
1 parent c604f92 commit ad942e0
Show file tree
Hide file tree
Showing 14 changed files with 245 additions and 272 deletions.
2 changes: 2 additions & 0 deletions .commitlintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ rules:
always,
[build, chore, ci, docs, feat, fix, merge, perf, refactor, revert, test],
]
extends:
- '@commitlint/config-conventional'
68 changes: 47 additions & 21 deletions .github/workflows/build-test-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
name: Build

on:
pull_request:
push:
branches: ["*"]
pull_request: [master]
tags: ["v*.*.*"]
workflow_dispatch:

jobs:
test:
Expand All @@ -24,18 +25,13 @@ jobs:
- os: windows-latest
python_version: "3.11"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{matrix.python_version}}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
cache: pip
cache-dependency-path: pyproject.toml
python-version: ${{matrix.python_version}}
- uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{runner.os}}-pip-${{hashFiles('pyproject.toml')}}
restore-keys: |
${{runner.os}}-pip-
${{runner.os}}-
- name: Upgrade Pip
run: |-
python -m pip install -U pip
Expand All @@ -46,14 +42,29 @@ jobs:
run: |-
python -m pytest --cov-report=term --cov=capella_model_explorer --rootdir=.
publish:
name: Publish artifacts
pre-commit:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
cache: pip
cache-dependency-path: pyproject.toml
python-version: "3.11"
- name: Upgrade pip
run: python -m pip install -U pip
- name: Install pre-commit
run: python -m pip install pre-commit types-docutils
- name: Run Pre-Commit
run: pre-commit run --all-files

build:
name: Build wheel
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
Expand All @@ -67,10 +78,25 @@ jobs:
run: |-
python -m twine check dist/*
- name: Upload artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: 'dist/*'
pypi:
name: Publish to PyPI
runs-on: ubuntu-latest
needs: [build, test]
if: startsWith(github.ref, 'refs/tags/v')
environment:
name: pypi
url: https://pypi.org/project/capella-model-explorer
permissions:
id-token: write
steps:
- name: Download built wheel
uses: actions/download-artifact@v4
with:
name: Artifacts
path: "dist/*"
- name: Publish to PyPI (release only)
if: startsWith(github.ref, 'refs/tags/v')
run: python -m twine upload -u __token__ -p ${{ secrets.PYPI_TOKEN }} --non-interactive dist/*
name: python-package-distributions
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
34 changes: 20 additions & 14 deletions .github/workflows/commit-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ on:
jobs:
conventional-commits:
runs-on: ubuntu-latest
concurrency:
group: commit-check-pr-${{ github.event.pull_request.number }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install commitlint
run: npm install -g @commitlint/cli
run: npm install @commitlint/cli @commitlint/config-conventional
- name: Validate commit messages
id: conventional-commits
env:
Expand All @@ -25,14 +28,24 @@ jobs:
delim="_EOF_$(uuidgen)"
echo "validation-result<<$delim" >> "$GITHUB_OUTPUT"
r=0
commitlint --from "$SHA_FROM" --to "$SHA_TO" >> "$GITHUB_OUTPUT" 2>&1 || r=$?
npx commitlint --from "$SHA_FROM" --to "$SHA_TO" >> "$GITHUB_OUTPUT" 2>&1 || r=$?
echo "$delim" >> "$GITHUB_OUTPUT"
exit $r
- name: Find conventional commit comment on PR
uses: peter-evans/find-comment@v3
if: always() && steps.conventional-commits.outcome == 'failure'
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: conventional commit
- name: Post comment if validation failed
uses: peter-evans/create-or-update-comment@v4
if: always() && steps.conventional-commits.outcome == 'failure'
uses: actions/github-script@v6
env:
TEXT: |-
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
The pull request does not conform to the conventional commit specification. Please ensure that your commit messages follow the spec: <https://www.conventionalcommits.org/>.
We also strongly recommend that you set up your development environment with pre-commit, as described in our [CONTRIBUTING guidelines](https://github.com/DSD-DBS/capella-model-explorer/blob/master/CONTRIBUTING.md). This will run all the important checks right before you commit your changes, and avoids lengthy CI wait time and round trips.
Expand All @@ -47,11 +60,4 @@ jobs:
docs(user): Add model creation workflow
feat: Add a monitoring dashboard
```
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: process.env.TEXT
})
edit-mode: replace
26 changes: 0 additions & 26 deletions .github/workflows/lint.yml

This file was deleted.

68 changes: 33 additions & 35 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@

default_install_hook_types: [commit-msg, pre-commit]
default_stages: [commit, merge-commit]
minimum_pre_commit_version: 3.2.0
repos:
- repo: https://github.com/gitleaks/gitleaks.git
rev: v8.19.3
hooks:
- id: gitleaks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
Expand All @@ -25,40 +30,6 @@ repos:
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: trailing-whitespace
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.8.0
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/PyCQA/docformatter
rev: v1.7.5
hooks:
- id: docformatter
additional_dependencies:
- docformatter[tomli]
- repo: https://github.com/PyCQA/pydocstyle
rev: 6.3.0
hooks:
- id: pydocstyle
exclude: '^tests/'
additional_dependencies:
- pydocstyle[toml]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
hooks:
- id: mypy
additional_dependencies:
- capellambse==0.6.6
- types-pyyaml==6.0.11
- repo: https://github.com/pylint-dev/pylint
rev: v3.2.7
hooks:
- id: pylint
require_serial: false
args: [-rn, -sn, -dfixme, -dduplicate-code]
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.5
hooks:
Expand Down Expand Up @@ -112,12 +83,39 @@ repos:
- LICENSES/.license_header.txt
- --comment-style
- '//'
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/PyCQA/docformatter
rev: v1.7.5
hooks:
- id: docformatter
additional_dependencies:
- docformatter[tomli]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.8
hooks:
- id: ruff-format
- id: ruff
args: [--extend-ignore=FIX]
- repo: https://github.com/rhysd/actionlint
rev: v1.7.3
hooks:
- id: actionlint-docker
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
hooks:
- id: mypy
additional_dependencies:
- capellambse==0.6.6
- types-pyyaml==6.0.11
- repo: https://github.com/fsfe/reuse-tool
rev: v4.0.3
hooks:
- id: reuse
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
rev: v9.17.0
rev: v9.18.0
hooks:
- id: commitlint
stages: [commit-msg]
Expand Down
41 changes: 18 additions & 23 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ Thanks for your interest in our project. Contributions are always welcome!
We are committed to fostering a welcoming, respectful, and harassment-free
environment. Be kind!

If you have questions, ideas or want to report a bug, feel free to [open
an issue]. Or go ahead and [open a pull request] to contribute code. In order to
reduce the burden on our maintainers, please make sure that your code follows our
style guidelines outlined below.
If you have questions, ideas or want to report a bug, feel free to [open an
issue]. Or go ahead and [open a pull request] to contribute code. In order to
reduce the burden on our maintainers, please make sure that your code follows
our style guidelines outlined below.

<!-- prettier-ignore -->
[open an issue]: https://github.com/DSD-DBS/capella-model-explorer/issues
[open a pull request]: https://github.com/DSD-DBS/capella-model-explorer/pulls

Expand All @@ -39,8 +38,8 @@ We additionally recommend that you set up your editor / IDE as follows.
- _If you use Visual Studio Code_: Consider using a platform which supports
third-party language servers more easily, and continue with the next point.

Otherwise, set up the editor to run `black`, `pylint` and `mypy` when saving.
To enable automatic import sorting with `isort`, add the following to your
Otherwise, set up the editor to run `ruff` and `mypy` when saving. To enable
automatic import sorting with `isort`, add the following to your
`settings.json`:

```json
Expand All @@ -54,14 +53,16 @@ We additionally recommend that you set up your editor / IDE as follows.
Note that the Pylance language server is not recommended, as it occasionally
causes false-positive errors for perfectly valid code.

- _If you do not use VSC_: Set up your editor to use the [python-lsp-server],
and make sure that the relevant plugins are installed. You can install
everything that's needed into the virtualenv with pip:
- _If you do not use VSC_: Set up your editor to use the [python-lsp-server]
and [ruff], and make sure that the relevant pylsp plugins are installed.

[python-lsp-server]: https://github.com/python-lsp/python-lsp-server
[ruff]: https://github.com/astral-sh/ruff

You can install everything that's needed into the virtualenv with pip:

```sh
pip install "python-lsp-server[pylint]" python-lsp-black pyls-isort pylsp-mypy
pip install "python-lsp-server" pyls-isort pylsp-mypy ruff
```

This will provide as-you-type linting as well as automatic formatting on
Expand All @@ -79,7 +80,7 @@ The key differences are:
[numpy style guide]: https://numpydoc.readthedocs.io/en/latest/format.html#docstring-standard

When writing docstrings for functions, use the imperative style, as per
[PEP-257]). For example, write "Do X and Y" instead of "Does X and Y".
[PEP-257]. For example, write "Do X and Y" instead of "Does X and Y".

[pep-257]: https://peps.python.org/pep-0257/

Expand All @@ -89,20 +90,18 @@ The key differences are:
automated tools pick up the full base class docstring instead, and is
therefore more useful in IDEs etc.

- **Linting**: Use [pylint] for static code analysis, and [mypy] for static
- **Linting**: Use [ruff] for static code analysis, and [mypy] for static
type checking.

[pylint]: https://github.com/PyCQA/pylint
[mypy]: https://github.com/python/mypy

- **Formatting**: Use [black] as code auto-formatter. The maximum line length
- **Formatting**: Use [ruff] as code auto-formatter. The maximum line length
is 79, as per [PEP-8]. This setting should be automatically picked up from
the `pyproject.toml` file. The reason for the shorter line length is that it
avoids wrapping and overflows in side-by-side split views (e.g. diffs) if
there's also information displayed to the side of it (e.g. a tree view of the
modified files).

[black]: https://github.com/psf/black
[pep-8]: https://www.python.org/dev/peps/pep-0008/

Be aware of the different line length of 72 for docstrings. We currently do
Expand All @@ -122,24 +121,20 @@ The key differences are:
writing `from typing import SomeName`, use `import typing as t` and access
typing related classes like `t.TypedDict`.

<!-- prettier-ignore -->
Use the new syntax and classes for typing introduced with Python 3.10.

- Instead of `t.Tuple`, `t.List` etc. use the builtin classes `tuple`, `list`
etc.
- For classes that are not builtin (e.g. `Iterable`),
`import collections.abc as cabc` and then use them like `cabc.Iterable`.
- Use [PEP-604-style unions], e.g. `int | float` instead of `t.Union[int, float]`.
- Use [PEP-604-style unions], e.g. `int | float` instead of
`t.Union[int, float]`.
- Use `... | None` (with `None` always as the last union member) instead of
`t.Optional[...]` and always explicitly annotate where `None` is possible.

[pep-604-style unions]: https://www.python.org/dev/peps/pep-0604/

- **Python style rules**: For conflicting parts, the [Black code style] wins.
If you have set up black correctly, you don't need to worry about this though
:)

[black code style]: https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html
- **Python style rules**: The auto-formatter wins.

- When working with `dict`s, consider using `t.TypedDict` instead of a more
generic `dict[str, float|int|str]`-like annotation where possible, as the
Expand Down
Loading

0 comments on commit ad942e0

Please sign in to comment.