Skip to content

Commit

Permalink
Use Ruff ! (#207)
Browse files Browse the repository at this point in the history
https://beta.ruff.rs/docs/
https://github.com/charliermarsh/ruff

Massively simplify configurations and speedup linting thanks to Ruff. Adds more autofixes too.
Using `pathlib` instead of `os.path` is the modern way to go. However fixing this could introduce a bug if not careful. So I'm leaving it for later.

Existing related Ruff requests (nothing here is a blocker, just future improvements):
- astral-sh/ruff#1256
- astral-sh/ruff#3011
- astral-sh/ruff#3072
- astral-sh/ruff#3910
- astral-sh/ruff#2419
- astral-sh/ruff#3115
- astral-sh/ruff#1904
  • Loading branch information
Avasam committed May 23, 2023
1 parent 75a8f39 commit 506bed3
Show file tree
Hide file tree
Showing 32 changed files with 539 additions and 690 deletions.
37 changes: 0 additions & 37 deletions .flake8

This file was deleted.

67 changes: 9 additions & 58 deletions .github/workflows/lint-and-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,25 @@ env:
GITHUB_EXCLUDE_BUILD_NUMBER: ${{ inputs.excludeBuildNumber }}

jobs:
isort:
ruff:
runs-on: windows-latest
strategy:
fail-fast: false
# Ruff is version and platform sensible
matrix:
python-version: ["3.9", "3.10", "3.11"]
steps:
- name: Checkout ${{ github.repository }}/${{ github.ref }}
uses: actions/checkout@v3
- name: Set up Python 3.11
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: "3.11"
python-version: ${{ matrix.python-version }}
cache: "pip"
cache-dependency-path: "scripts/requirements*.txt"
- run: scripts/install.ps1
shell: pwsh
- name: Analysing the code with isort
run: isort src/ typings/ --check-only
- run: ruff check .
add-trailing-comma:
runs-on: windows-latest
steps:
Expand All @@ -61,19 +65,6 @@ jobs:
- run: pip install add-trailing-comma
- name: Analysing the code with add-trailing-comma
run: add-trailing-comma $(git ls-files '**.py*') --py36-plus
Bandit:
# Bandit only matters on the version deployed. Platform checks are ignored
runs-on: windows-latest
steps:
- name: Checkout ${{ github.repository }}/${{ github.ref }}
uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"
- run: pip install bandit
- name: Analysing the code with Bandit
run: bandit src/ -n 1 --severity-level medium --recursive
Pyright:
runs-on: windows-latest
strategy:
Expand All @@ -96,46 +87,6 @@ jobs:
uses: jakebailey/pyright-action@v1
with:
working-directory: src/
Pylint:
runs-on: windows-latest
strategy:
fail-fast: false
# Pylint is version and platform sensible
matrix:
python-version: ["3.9", "3.10", "3.11"]
steps:
- name: Checkout ${{ github.repository }}/${{ github.ref }}
uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
cache-dependency-path: "scripts/requirements*.txt"
- run: scripts/install.ps1
shell: pwsh
- name: Analysing the code with Pylint
run: pylint src/ --reports=y --output-format=colorized
Flake8:
runs-on: windows-latest
strategy:
fail-fast: false
# Flake8 is tied to the version of Python on which it runs. Platform checks are ignored
matrix:
python-version: ["3.9", "3.10", "3.11"]
steps:
- name: Checkout ${{ github.repository }}/${{ github.ref }}
uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
cache-dependency-path: "scripts/requirements*.txt"
- run: scripts/install.ps1
shell: pwsh
- name: Analysing the code with Flake8
run: flake8 src/ typings/
Build:
runs-on: windows-latest
strategy:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# Caches
.cache/
.*cache/

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
9 changes: 5 additions & 4 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@
"eamodio.gitlens",
"emeraldwalk.runonsave",
"ms-python.autopep8",
"ms-python.flake8",
"ms-python.isort",
"ms-python.pylint",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-vscode.powershell",
"pkief.material-icon-theme",
"redhat.vscode-xml",
"redhat.vscode-yaml",
"shardulm94.trailing-spaces",
],
"unwantedRecommendations": [
// Must disable in this workspace //
Expand All @@ -24,13 +20,18 @@
// VSCode has implemented an optimized version
"coenraads.bracket-pair-colorizer",
"coenraads.bracket-pair-colorizer-2",
"shardulm94.trailing-spaces",
// Obsoleted by Pylance
"ms-pyright.pyright",
// Not configurable per workspace, tends to conflict with other linters
"sonarsource.sonarlint-vscode",
//
// Don't recommend to autoinstall //
//
// Use Ruff instead
"ms-python.flake8",
"ms-python.isort",
"ms-python.pylint",
// We use autopep8
"ms-python.black-formatter",
// This is a Git project
Expand Down
79 changes: 17 additions & 62 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
72
]
},
"trailing-spaces.includeEmptyLines": true,
"trailing-spaces.trimOnSave": true,
"trailing-spaces.syntaxIgnore": [
"markdown"
],
"[markdown]": {
"files.trimTrailingWhitespace": false,
},
Expand All @@ -28,14 +23,10 @@
"source.fixAll": true,
"source.fixAll.unusedImports": false,
"source.fixAll.convertImportFormat": true,
"source.organizeImports": true,
"source.organizeImports": false,
},
"emeraldwalk.runonsave": {
"commands": [
{
"match": "\\.pyi?",
"cmd": "unify ${file} --in-place --quote=\"\\\"\""
},
{
"match": "\\.pyi?",
"cmd": "add-trailing-comma ${file} --py36-plus"
Expand All @@ -62,9 +53,13 @@
"**/*.code-search": true,
"*.lock": true,
},
// Set the default formatter to help avoid Prettier
"[json][jsonc]": {
"editor.defaultFormatter": "vscode.json-language-features",
},
"[python]": {
// Cannot use autotpep8 until https://github.com/microsoft/vscode-autopep8/issues/32 is fixed
"editor.defaultFormatter": "ms-python.python",
// Ruff is not yet a formatter: https://github.com/charliermarsh/ruff/issues/1904
"editor.defaultFormatter": "ms-python.autopep8",
"editor.tabSize": 4,
"editor.rulers": [
72, // PEP8-17 docstrings
Expand All @@ -77,60 +72,20 @@
// 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,
// 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
"ruff.importStrategy": "fromEnvironment",
// Use the Ruff extension instead
"isort.check": false,
"python.linting.banditEnabled": false,
"python.linting.flake8Enabled": false,
// Partial codes don't work yet: https://github.com/microsoft/vscode-flake8/issues/7
"flake8.severity": {
"convention": "Warning",
"error": "Error",
"fatal": "Error",
"refactor": "Warning",
"warning": "Warning",
"info": "Warning",
// builtins
"A": "Warning",
// mccabe
"C": "Warning",
// class attributes order
"CCE": "Warning",
// pycodestyles
"E": "Warning",
"E9": "Error", // Runtime
"W": "Warning",
"W6": "Error", // Deprecation warning
// Pyflakes
"F": "Warning",
// PEP8 Naming convention
"N": "Warning",
// Simplify
"SIM": "Warning",
"SIM9": "Information",
// PYI
"Y": "Warning",
},
// PyRight obsoletes mypy
"python.linting.mypyEnabled": false,
// Is already wrapped by Flake8, prospector and pylama
"python.linting.pycodestyleEnabled": false,
// Just another wrapper, use Flake8 OR this
"python.linting.prospectorEnabled": false,
// Just another wrapper, use Flake8 OR this
"python.linting.pycodestyleEnabled": false,
"python.linting.pylamaEnabled": false,
"python.linting.banditEnabled": true,
"python.linting.pylintEnabled": false,
// Use the autopep8 extension instead
"python.formatting.provider": "none",
// Use Pyright/Pylance instead
"python.linting.mypyEnabled": false,
"powershell.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationForFirstPipeline",
"powershell.codeFormatting.autoCorrectAliases": true,
"powershell.codeFormatting.trimWhitespaceAroundPipe": true,
Expand Down
2 changes: 2 additions & 0 deletions PyInstaller/hooks/hook-requests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from PyInstaller.utils.hooks import collect_data_files

# Get the cacert.pem
Expand Down
Loading

0 comments on commit 506bed3

Please sign in to comment.