Skip to content

Commit

Permalink
Update configs and python linters
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Dec 5, 2022
1 parent 6f6bcc6 commit 71b10cb
Show file tree
Hide file tree
Showing 26 changed files with 608 additions and 438 deletions.
30 changes: 24 additions & 6 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,34 @@
color=always
max-line-length=120
ignore=
W503, ; Linebreak before binary operator
Y015, ; Allow default value other than "..."
E402, ; Allow imports at the bottom of file
; Linebreak before binary operator
W503,
; Closing bracket may not match multi-line method invocation style (enforced by add-trailing-comma)
E124,
; Allow imports at the bottom of file
E402,
; contextlib.suppress is roughly 3x slower than try/except
SIM105,
; False positives for attribute docstrings
CCE001,
; Let's use datetime.utcnow()
DTZ003,
; datetime.strptime
DTZ007
per-file-ignores=
; Quotes
; Allow ... on same line as class
; Allow ... on same line as def
; Line too long
; Naming stuff, we don't have control over external libraries' naming conventions
typings/**: Q000,E704,E501,N8
; Naming conventions can't be controlled for external libraries
; Variable names can't be controlled for external libraries
; Argument names can't be controlled for external libraries
; Attribute names can't be controlled for external libraries
; False positive Class level expression with elipsis
; Type re-exports
; mypy 3.7 Union issue
*.pyi: Q000,E701,E704,E501,N8,A001,A002,A003,CCE002,F401,Y037
; McCabe max-complexity is also taken care of by Pylint and doesn't fail the build there
; So this is the hard limit
max-complexity=32
inline-quotes="
inline-quotes=double
80 changes: 48 additions & 32 deletions .github/workflows/lint-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,95 +14,111 @@ on:
paths:
- "**.py"
- "**.pyi"

env:
python-version: "3.10"

jobs:
add-trailing-comma:
runs-on: windows-latest
isort:
runs-on: ubuntu-latest
steps:
- name: Checkout ${{ github.repository }}/${{ github.ref }}
uses: actions/checkout@v3
- name: Set up Python 3.9
- name: Set up Python ${{ env.python-version }}
uses: actions/setup-python@v4
with:
python-version: "3.9"
python-version: ${{ env.python-version }}
cache: "pip"
cache-dependency-path: "scripts/requirements*.txt"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install wheel
pip install -r "scripts/requirements.txt"
- name: Analysing the code with add-trailing-comma
- name: Analysing the code with ${{ job.name }}
run: isort backend/ typings/ --check-only
add-trailing-comma:
runs-on: ubuntu-latest
steps:
- name: Checkout ${{ github.repository }}/${{ github.ref }}
uses: actions/checkout@v3
- name: Set up Python ${{ env.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.python-version }}
cache: "pip"
cache-dependency-path: "scripts/requirements*.txt"
- run: pip install add-trailing-comma
- name: Analysing the code with ${{ job.name }}
run: add-trailing-comma $(git ls-files '**.py*') --py36-plus
Pyright:
Bandit:
runs-on: ubuntu-latest
steps:
- name: Checkout ${{ github.repository }}/${{ github.ref }}
uses: actions/checkout@v3
- name: Set up Node
uses: actions/setup-node@v3
- name: Set up Python 3.9
- name: Set up Python ${{ env.python-version }}
uses: actions/setup-python@v4
with:
python-version: "3.9"
python-version: ${{ env.python-version }}
cache: "pip"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install wheel
pip install -r "scripts/requirements.txt"
cache-dependency-path: "scripts/requirements*.txt"
- run: pip install bandit
- run: mv backend/configs.template.py backend/configs.py
- name: Analysing the code with ${{ job.name }}
run: pyright --warnings backend
Pylint:
run: bandit -n 1 --severity-level medium --recursive backend
Pyright:
runs-on: ubuntu-latest
steps:
- name: Checkout ${{ github.repository }}/${{ github.ref }}
uses: actions/checkout@v3
- name: Set up Python 3.9
- name: Set up Python ${{ env.python-version }}
uses: actions/setup-python@v4
with:
python-version: "3.9"
python-version: ${{ env.python-version }}
cache: "pip"
cache-dependency-path: "scripts/requirements*.txt"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install wheel
pip install -r "scripts/requirements.txt"
- run: mv backend/configs.template.py backend/configs.py
- name: Analysing the code with ${{ job.name }}
run: pylint --reports=y --output-format=colorized $(git ls-files 'backend/*.py')
Flake8:
uses: jakebailey/pyright-action@v1
with:
working-directory: backend/
extra-args: --warnings
Pylint:
runs-on: ubuntu-latest
steps:
- name: Checkout ${{ github.repository }}/${{ github.ref }}
uses: actions/checkout@v3
- name: Set up Python 3.9
- name: Set up Python ${{ env.python-version }}
uses: actions/setup-python@v4
with:
python-version: "3.9"
python-version: ${{ env.python-version }}
cache: "pip"
cache-dependency-path: "scripts/requirements*.txt"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install wheel
pip install -r "scripts/requirements.txt"
- run: mv backend/configs.template.py backend/configs.py
- name: Analysing the code with ${{ job.name }}
run: flake8 backend
Bandit:
run: pylint backend/ --reports=y --output-format=colorized
Flake8:
runs-on: ubuntu-latest
steps:
- name: Checkout ${{ github.repository }}/${{ github.ref }}
uses: actions/checkout@v3
- name: Set up Python 3.9
- name: Set up Python ${{ env.python-version }}
uses: actions/setup-python@v4
with:
python-version: "3.9"
python-version: ${{ env.python-version }}
cache: "pip"
cache-dependency-path: "scripts/requirements*.txt"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install wheel
pip install -r "scripts/requirements.txt"
- run: mv backend/configs.template.py backend/configs.py
- name: Analysing the code with ${{ job.name }}
run: bandit -n 1 --severity-level medium --recursive backend
run: flake8 backend/ typings/
1 change: 1 addition & 0 deletions .sonarcloud.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sonar.python.version=3.10
10 changes: 8 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
"bungcip.better-toml",
"davidanson.vscode-markdownlint",
"dbaeumer.vscode-eslint",
"dotenv.dotenv-vscode",
"eamodio.gitlens",
"emeraldwalk.runonsave",
"meganrogge.template-string-converter",
"mikestead.dotenv",
"ms-python.autopep8",
"ms-python.flake8",
"ms-vscode.powershell",
"ms-python.isort",
"ms-python.pylint",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-vscode.powershell",
"ms-vscode.vscode-typescript-next",
"pkief.material-icon-theme",
"redhat.vscode-yaml",
Expand All @@ -27,6 +31,8 @@
// Replaced by ESLint
"eg2.tslint",
"ms-vscode.vscode-typescript-tslint-plugin",
// Replaced by
"mikestead.dotenv",
// Obsoleted by Pylance
"ms-pyright.pyright",
// Not configurable per workspace, tends to conflict with other linters
Expand Down
81 changes: 48 additions & 33 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"typescript.tsdk": "./tournament-scheduler/node_modules/typescript/lib",
"editor.rulers": [
80,
120
Expand All @@ -8,6 +9,11 @@
72
]
},
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true,
"editor.comments.insertSpace": true,
"editor.insertSpaces": true,
"editor.detectIndentation": false,
"editor.tabSize": 2,
"editor.formatOnSave": true,
Expand All @@ -17,32 +23,33 @@
"source.fixAll.convertImportFormat": true,
"source.organizeImports": false,
},
// Set the default formatter to help avoid Prettier
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features",
},
"[jsonc]": {
"editor.defaultFormatter": "vscode.json-language-features",
"trailing-spaces.includeEmptyLines": true,
"trailing-spaces.trimOnSave": true,
"trailing-spaces.syntaxIgnore": [
"markdown"
],
"emeraldwalk.runonsave": {
"commands": [
{
"match": "\\.pyi?",
"cmd": "unify ${file} --in-place --quote=\"\\\"\""
},
{
"match": "\\.pyi?",
"cmd": "add-trailing-comma ${file} --py36-plus"
},
]
},
"[html]": {
// Set the default formatter to help avoid Prettier
"[json][jsonc][html]": {
"editor.defaultFormatter": "vscode.html-language-features",
},
"[javascript]": {
"editor.defaultFormatter": "vscode.typescript-language-features",
},
"[javascriptreact]": {
"editor.defaultFormatter": "vscode.typescript-language-features",
},
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features",
},
"[typescriptreact]": {
"[javascript][javascriptreact][typescript][typescriptreact]": {
"editor.defaultFormatter": "vscode.typescript-language-features",
},
"javascript.preferences.quoteStyle": "single",
"typescript.preferences.quoteStyle": "single",
"html.format.wrapAttributes": "force-expand-multiline",
"typescript.tsdk": "./tournament-scheduler/node_modules/typescript/lib",
"javascript.format.semicolons": "remove",
"typescript.format.semicolons": "remove",
"eslint.validate": [
Expand All @@ -60,18 +67,10 @@
"severity": "downgrade"
}
],
"files.insertFinalNewline": true,
"trailing-spaces.includeEmptyLines": true,
"trailing-spaces.trimOnSave": true,
"trailing-spaces.syntaxIgnore": [
"markdown"
],
"javascript.preferences.importModuleSpecifier": "non-relative",
"typescript.preferences.importModuleSpecifier": "non-relative",
"files.associations": {
"*.json": "json",
"extensions.json": "jsonc",
"settings.json": "jsonc",
".flake8": "properties",
".eslintrc*.json": "jsonc",
"tsconfig*.json": "jsonc",
// "*.html": "jinja-html"
Expand All @@ -85,7 +84,7 @@
"**/.DS_Store": true,
"**/Thumbs.db": true,
"build": true,
".mypy_cache": true,
"**/.mypy_cache": true,
"**/__pycache__/": true,
"**/node_modules": false,
"*.zip": true,
Expand All @@ -99,27 +98,42 @@
"**/*.code-search": true,
"*.lock": true,
"package-lock.json": true,
"typings": true,
},
"[python]": {
// Cannot use autotpep8 until https://github.com/microsoft/vscode-autopep8/issues/32 is fixed
"editor.defaultFormatter": "ms-python.python",
"editor.tabSize": 4,
"editor.rulers": [
72, // PEP8-17 docstrings
// 79, // PEP8-17 default max
// 88, // Black default
99, // PEP8-17 acceptable max
// 99, // PEP8-17 acceptable max
120, // Our hard rule
],
"editor.codeActionsOnSave": {
"source.organizeImports": true,
},
},
// Important to follow the config in pyrightconfig.json
"python.analysis.useLibraryCodeForTypes": false,
"python.analysis.diagnosticMode": "workspace",
"python.formatting.provider": "autopep8",
"isort.check": true,
"isort.importStrategy": "fromEnvironment",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.linting.pylintCategorySeverity.convention": "Warning",
"python.linting.pylintCategorySeverity.refactor": "Warning",
// Use the new Pylint extension instead
"python.linting.pylintEnabled": false,
"pylint.severity": {
"convention": "Warning",
"error": "Error",
"fatal": "Error",
"refactor": "Warning",
"warning": "Warning",
"info": "Information"
},
// Use the new Flake8 extension instead
"python.linting.flake8Enabled": false,
// Partial codes don't work yet: https://github.com/microsoft/vscode-flake8/issues/7
"flake8.severity": {
"convention": "Warning",
"error": "Error",
Expand Down Expand Up @@ -164,4 +178,5 @@
"powershell.codeFormatting.useCorrectCasing": true,
"powershell.codeFormatting.whitespaceBetweenParameters": true,
"powershell.integratedConsole.showOnStartup": false,
"terminal.integrated.defaultProfile.windows": "PowerShell",
}
Loading

0 comments on commit 71b10cb

Please sign in to comment.