Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit e53e99e

Browse files
author
David Robertson
committed
CI: Use common linting workflow
After #12107 it's much easier for black, isort and flake8 to find the scripts we want them to lint.
1 parent d820ff2 commit e53e99e

File tree

5 files changed

+14
-73
lines changed

5 files changed

+14
-73
lines changed

.github/workflows/tests.yml

+5-14
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,11 @@ jobs:
2020
- run: scripts-dev/config-lint.sh
2121

2222
lint:
23-
runs-on: ubuntu-latest
24-
strategy:
25-
matrix:
26-
toxenv:
27-
- "check_codestyle"
28-
- "check_isort"
29-
- "mypy"
30-
- "packaging"
31-
32-
steps:
33-
- uses: actions/checkout@v2
34-
- uses: actions/setup-python@v2
35-
- run: pip install tox
36-
- run: tox -e ${{ matrix.toxenv }}
23+
# This does a vanilla `poetry install` - no extras. I'm slightly anxious
24+
# that we might skip some typechecks on code that uses extras. However,
25+
# I think the right way to fix this is to turn up mypy's strictness:
26+
# disallow unknown imports and be accept fewer uses of `Any`.
27+
uses: "matrix-org/backend-meta/.github/workflows/python-poetry-ci.yml@v1"
3728

3829
lint-crlf:
3930
runs-on: ubuntu-latest

docs/code_style.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pip install -e ".[lint,mypy]"
2424
functionality) with:
2525

2626
```sh
27-
black . --exclude="\.tox|build|env"
27+
black .
2828
```
2929

3030
- **flake8**
@@ -35,7 +35,7 @@ pip install -e ".[lint,mypy]"
3535
Check all application and test code with:
3636

3737
```sh
38-
flake8 synapse tests
38+
flake8 .
3939
```
4040

4141
- **isort**
@@ -46,11 +46,9 @@ pip install -e ".[lint,mypy]"
4646
Auto-fix imports with:
4747

4848
```sh
49-
isort -rc synapse tests
49+
isort .
5050
```
5151

52-
`-rc` means to recursively search the given directories.
53-
5452
It's worth noting that modern IDEs and text editors can run these tools
5553
automatically on save. It may be worth looking into whether this
5654
functionality is supported in your editor for a more convenient

pyproject.toml

+4-18
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,9 @@
3636

3737
[tool.black]
3838
target-version = ['py37', 'py38', 'py39', 'py310']
39-
exclude = '''
40-
41-
(
42-
/(
43-
\.eggs # exclude a few common directories in the
44-
| \.git # root of the project
45-
| \.tox
46-
| \.venv
47-
| \.env
48-
| env
49-
| _build
50-
| _trial_temp.*
51-
| build
52-
| dist
53-
| debian
54-
)/
55-
)
56-
'''
39+
# black ignores everything in .gitignore by default, see
40+
# https://black.readthedocs.io/en/stable/usage_and_configuration/file_collection_and_discovery.html#gitignore
41+
# Use `extend-exclude` if you want to exclude something in addition to this.
5742

5843
[tool.isort]
5944
line_length = 88
@@ -65,6 +50,7 @@ known_twisted = ["twisted", "OpenSSL"]
6550
multi_line_output = 3
6651
include_trailing_comma = true
6752
combine_as_imports = true
53+
skip_gitignore = true
6854

6955
[tool.poetry]
7056
name = "matrix-synapse"

scripts-dev/lint.sh

+1-7
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,7 @@ else
8080
# then lint everything!
8181
if [[ -z ${files+x} ]]; then
8282
# Lint all source code files and directories
83-
# Note: this list aims to mirror the one in tox.ini
84-
files=(
85-
"synapse" "docker" "tests"
86-
# annoyingly, black doesn't find these so we have to list them
87-
"scripts-dev"
88-
"contrib" "setup.py" "synmark" "stubs" ".ci"
89-
)
83+
files=( "." )
9084
fi
9185
fi
9286

tox.ini

+1-29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = packaging, py37, py38, py39, py310, check_codestyle, check_isort
2+
envlist = packaging, py37, py38, py39, py310
33

44
# we require tox>=2.3.2 for the fix to https://github.com/tox-dev/tox/issues/208
55
minversion = 2.3.2
@@ -32,19 +32,6 @@ deps =
3232
# install the "enum34" dependency of cryptography.
3333
pip>=10
3434

35-
# directories/files we run the linters on.
36-
# if you update this list, make sure to do the same in scripts-dev/lint.sh
37-
lint_targets =
38-
setup.py
39-
synapse
40-
tests
41-
# annoyingly, black doesn't find these so we have to list them
42-
scripts-dev
43-
stubs
44-
contrib
45-
synmark
46-
.ci
47-
docker
4835

4936
# default settings for all tox environments
5037
[testenv]
@@ -146,18 +133,3 @@ deps =
146133
commands =
147134
check-manifest
148135

149-
[testenv:check_codestyle]
150-
extras = lint
151-
commands =
152-
python -m black --check --diff {[base]lint_targets}
153-
flake8 {[base]lint_targets} {env:PEP8SUFFIX:}
154-
155-
[testenv:check_isort]
156-
extras = lint
157-
commands = isort -c --df {[base]lint_targets}
158-
159-
[testenv:mypy]
160-
deps =
161-
{[base]deps}
162-
extras = all,mypy
163-
commands = mypy

0 commit comments

Comments
 (0)