Selaa lähdekoodia

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.
David Robertson 2 vuotta sitten
vanhempi
commit
e53e99edba
5 muutettua tiedostoa jossa 14 lisäystä ja 73 poistoa
  1. 5 14
      .github/workflows/tests.yml
  2. 3 5
      docs/code_style.md
  3. 4 18
      pyproject.toml
  4. 1 7
      scripts-dev/lint.sh
  5. 1 29
      tox.ini

+ 5 - 14
.github/workflows/tests.yml

@@ -20,20 +20,11 @@ jobs:
       - run: scripts-dev/config-lint.sh
 
   lint:
-    runs-on: ubuntu-latest
-    strategy:
-      matrix:
-        toxenv:
-          - "check_codestyle"
-          - "check_isort"
-          - "mypy"
-          - "packaging"
-
-    steps:
-      - uses: actions/checkout@v2
-      - uses: actions/setup-python@v2
-      - run: pip install tox
-      - run: tox -e ${{ matrix.toxenv }}
+    # This does a vanilla `poetry install` - no extras. I'm slightly anxious
+    # that we might skip some typechecks on code that uses extras. However,
+    # I think the right way to fix this is to turn up mypy's strictness:
+    # disallow unknown imports and be accept fewer uses of `Any`.
+    uses: "matrix-org/backend-meta/.github/workflows/python-poetry-ci.yml@v1"
 
   lint-crlf:
     runs-on: ubuntu-latest

+ 3 - 5
docs/code_style.md

@@ -24,7 +24,7 @@ pip install -e ".[lint,mypy]"
     functionality) with:
 
     ```sh
-    black . --exclude="\.tox|build|env"
+    black .
     ```
 
 -   **flake8**
@@ -35,7 +35,7 @@ pip install -e ".[lint,mypy]"
     Check all application and test code with:
 
     ```sh
-    flake8 synapse tests
+    flake8 .
     ```
 
 -   **isort**
@@ -46,11 +46,9 @@ pip install -e ".[lint,mypy]"
     Auto-fix imports with:
 
     ```sh
-    isort -rc synapse tests
+    isort .
     ```
 
-    `-rc` means to recursively search the given directories.
-
 It's worth noting that modern IDEs and text editors can run these tools
 automatically on save. It may be worth looking into whether this
 functionality is supported in your editor for a more convenient

+ 4 - 18
pyproject.toml

@@ -36,24 +36,9 @@
 
 [tool.black]
 target-version = ['py37', 'py38', 'py39', 'py310']
-exclude = '''
-
-(
-  /(
-      \.eggs         # exclude a few common directories in the
-    | \.git          # root of the project
-    | \.tox
-    | \.venv
-    | \.env
-    | env
-    | _build
-    | _trial_temp.*
-    | build
-    | dist
-    | debian
-  )/
-)
-'''
+# black ignores everything in .gitignore by default, see
+# https://black.readthedocs.io/en/stable/usage_and_configuration/file_collection_and_discovery.html#gitignore
+# Use `extend-exclude` if you want to exclude something in addition to this.
 
 [tool.isort]
 line_length = 88
@@ -65,6 +50,7 @@ known_twisted = ["twisted", "OpenSSL"]
 multi_line_output = 3
 include_trailing_comma = true
 combine_as_imports = true
+skip_gitignore = true
 
 [tool.poetry]
 name = "matrix-synapse"

+ 1 - 7
scripts-dev/lint.sh

@@ -80,13 +80,7 @@ else
   # then lint everything!
   if [[ -z ${files+x} ]]; then
     # Lint all source code files and directories
-    # Note: this list aims to mirror the one in tox.ini
-      files=(
-          "synapse" "docker" "tests"
-          # annoyingly, black doesn't find these so we have to list them
-          "scripts-dev"
-          "contrib" "setup.py" "synmark" "stubs" ".ci"
-      )
+      files=( "." )
   fi
 fi
 

+ 1 - 29
tox.ini

@@ -1,5 +1,5 @@
 [tox]
-envlist = packaging, py37, py38, py39, py310, check_codestyle, check_isort
+envlist = packaging, py37, py38, py39, py310
 
 # we require tox>=2.3.2 for the fix to https://github.com/tox-dev/tox/issues/208
 minversion = 2.3.2
@@ -32,19 +32,6 @@ deps =
     # install the "enum34" dependency of cryptography.
     pip>=10
 
-# directories/files we run the linters on.
-# if you update this list, make sure to do the same in scripts-dev/lint.sh
-lint_targets =
-    setup.py
-    synapse
-    tests
-    # annoyingly, black doesn't find these so we have to list them
-    scripts-dev
-    stubs
-    contrib
-    synmark
-    .ci
-    docker
 
 # default settings for all tox environments
 [testenv]
@@ -146,18 +133,3 @@ deps =
 commands =
     check-manifest
 
-[testenv:check_codestyle]
-extras = lint
-commands =
-    python -m black --check --diff {[base]lint_targets}
-    flake8 {[base]lint_targets} {env:PEP8SUFFIX:}
-
-[testenv:check_isort]
-extras = lint
-commands = isort -c --df {[base]lint_targets}
-
-[testenv:mypy]
-deps =
-    {[base]deps}
-extras = all,mypy
-commands = mypy