Skip to content

Commit

Permalink
PoC: automated linting on CI
Browse files Browse the repository at this point in the history
This PR is to support the discussion on enforcing consistent formatting
on the CI [1].

[1] #1804
  • Loading branch information
romanc committed Feb 28, 2025
1 parent 736e692 commit 9445a10
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 3 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Code Quality

on:
push:
branches: [ main, ci-fix, v1/maintenance ]
pull_request:
branches: [ main, ci-fix, v1/maintenance ]

jobs:
linting:
if: "!contains(github.event.pull_request.labels.*.name, 'no-ci')"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'

- uses: actions/setup-python@v5
with:
python-version: '3.13'

- name: Install pre-commit
run: pip install pre-commit yapf

- name: Run lint via pre-commit
run: pre-commit run --all-files
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
default_language_version:
python: python3

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-merge-conflict
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/google/yapf
rev: v0.43.0
hooks:
- id: yapf
name: yapf
language: python
entry: yapf
args: [-i]
types: [python]
23 changes: 21 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,28 @@ def example_function(param_a: str, *args: Optional[SDFG]) -> bool:
...
```

For automatic styling, we rely on [pre-commit](https://pre-commit.com/) and use the [yapf](https://github.com/google/yapf) file formatter.
**Please run `pre-commit` before making your pull request ready for review.**

For automatic styling, we use the [yapf](https://github.com/google/yapf) file formatter.
**Please run `yapf` before making your pull request ready for review.**
```bash
pre-commit run --all-files
```

Formatting will be evaluated as part of CI and you won't be able to merge unless formatting issues are resolved. To get `pre-commit` and `yapf`, be sure to install the `linting` extra, e.g. for contributors we recommend

```bash
pip install -e ".[testing,linting]"
```

to get testing and linting extras in an editable install.

One way to always ensure consistency with our coding standards is to install pre-commit hooks, which will check formatting issues of changed files before every commit. If you wish to do so, run

```bash
pre-commit install
```

to install the `git` hooks for this repository.

## Tests

Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
] + cmake_requires,
extras_require={
'testing': ['coverage', 'pytest-cov', 'scipy', 'absl-py', 'opt_einsum', 'pymlir', 'click'],
'docs': ['jinja2<3.2.0', 'sphinx-autodoc-typehints', 'sphinx-rtd-theme>=0.5.1']
'docs': ['jinja2<3.2.0', 'sphinx-autodoc-typehints', 'sphinx-rtd-theme>=0.5.1'],
'linting': ['pre-commit', 'yapf'],
},
entry_points={
'console_scripts': [
Expand Down

0 comments on commit 9445a10

Please sign in to comment.