Skip to content

Commit

Permalink
style: use ruff for linting instead of flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
rnousia committed Oct 16, 2023
1 parent b00b9c7 commit c3b2277
Show file tree
Hide file tree
Showing 40 changed files with 405 additions and 424 deletions.
21 changes: 0 additions & 21 deletions .flake8

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
__pycache__
.coverage
coverage.xml
.ruff_cache

dist
build
Expand Down
26 changes: 9 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,27 @@ repos:
- id: check-added-large-files
- id: mixed-line-ending
args: [--fix=lf]
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.292
hooks:
- id: isort
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 23.7.0
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.931
rev: v1.4.1
hooks:
- id: mypy
- repo: https://github.com/PyCQA/flake8
rev: 3.9.1
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear==21.4.3
- pep8-naming==0.11.1
- flake8-annotations==2.6.2
- flake8-pyproject==1.2.3
- flake8-spellcheck==0.28.0
- flake8-qgis==1.0.0
- flake8-print==4.0.0
- flake8-tidy-imports==4.4.1
- flake8-comprehensions==3.6.1
- flake8-spellcheck==0.24.0
- flake8-simplify==0.14.1
- flake8-pytest-style==1.5.0
- flake8-pie==0.14.0
- flake8-no-pep420==1.1.1
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.32.2
hooks:
Expand Down
64 changes: 62 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,65 @@
[tool.isort]
profile = "black"
[tool.ruff]
ignore = [
"ANN101", # Missing type annotation for self in method
]
line-length = 88

# List of all rules https://docs.astral.sh/ruff/rules/
select = [
"ANN", # flake8-annotations
"B", # flake8-bugbear
"C", # flake8-comprehensions
"C90", # flake8, mccabe
"E", # flake8, pycodestyle
"F", # flake8, Pyflakes
"I", # isort
"INP", # flake8-no-pep420
"PIE", # flake8-pie
"PGH", # pygrep-hooks
"PL", # pylint
"PT", # flake8-pytest-style
"RUF", # Ruff-specific rules
"SIM", # flake8-simplify
"T", # flake8-print
"ICN", # flake8-import-conventions
"TCH", # flake8-type-checking
"TID", # flake8-tidy-imports
"W", # flake8, pycodestyle
"UP", # pyupgrade
]

# Avoiding flagging (and removing) `SC200` from any `# noqa`
# directives, despite Ruff's lack of support for `flake8-spellcheck`.
external = ["SC200"]

target-version = "py39"

[tool.ruff.flake8-tidy-imports]
ban-relative-imports = "all"

[tool.ruff.per-file-ignores]
"test*" = [
"INP001",
"ANN201",
"ANN202",
"ANN401",
"E501",
"PLR2004", # Magic value used in comparison, consider replacing {value} with a constant variable
"PLR0913", # Too many arguments to function call (len(args) > 5)
]


[tool.flake8]
max-line-length = 88
spellcheck-targets = "names"
dictionaries = "en_US,python,technical"
extend-ignore = [
"E203", # whitespace before ':'
"E501", # line length (checked by ruff now, possible mismatches)
]
per-file-ignores = [
"test/*:INP001,SC200,QGS105",
]

[tool.mypy]
follow_imports = "normal"
Expand Down
111 changes: 60 additions & 51 deletions quality-result-gui.code-workspace
Original file line number Diff line number Diff line change
@@ -1,53 +1,62 @@
{
"extensions": {
"recommendations": [
"editorconfig.editorconfig",
"mikestead.dotenv",
]
},
"folders": [
{
"path": "."
}
],
"settings": {
"python.languageServer": "Pylance",
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false,
"python.linting.enabled": true,
"python.linting.flake8Enabled": true,
"python.linting.mypyEnabled": true,
"python.linting.pylintEnabled": false,
"python.formatting.provider": "black",
"editor.formatOnSave": true,
"[python]": {
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
},
"files.associations": {
"*.ts": "xml"
},
"editor.bracketPairColorization.enabled": true,
"editor.guides.bracketPairs": "active",
},
"launch": {
"configurations": [
{
"name": "QGIS debugpy",
"type": "python",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "${workspaceFolder}"
}
]
}
],
}
"extensions": {
"recommendations": [
"editorconfig.editorconfig",
"mikestead.dotenv",
"ms-python.python",
"ms-python.mypy-type-checker",
"ms-python.black-formatter",
"ms-python.flake8",
"charliermarsh.ruff",
]
},
"folders": [
{
"path": "."
}
],
"settings": {
"python.languageServer": "Pylance",
// Tests
"python.testing.pytestEnabled": true,
// Linting
"flake8.importStrategy": "fromEnvironment",
"ruff.importStrategy": "fromEnvironment",
"mypy-type-checker.importStrategy": "fromEnvironment",
// Formatting
"isort.check": false,
"black-formatter.importStrategy": "fromEnvironment",
"[python]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports.ruff": true,
"source.fixAll": true
},
"editor.defaultFormatter": "ms-python.black-formatter",
},
"files.associations": {
"*.ts": "xml"
},
"editor.bracketPairColorization.enabled": true,
"editor.guides.bracketPairs": "active",
},
"launch": {
"configurations": [
{
"name": "QGIS debugpy",
"type": "python",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "${workspaceFolder}"
}
]
}
],
}
}
33 changes: 13 additions & 20 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,26 @@ pytest-timeout==1.4.2
pytest-order==1.0.0
pytest-dotenv==0.5.2

#stubs
pyqt5-stubs==5.15.6.0

# lock here since 1.4.1 has no binaries
atomicwrites==1.4.0

# linting
pre-commit==3.2.2
mypy==0.931
isort==5.12.0
black==22.3.0
flake8==3.9.1
flake8-bugbear==21.4.3
pep8-naming==0.11.1
flake8-annotations==2.6.2
pre-commit==3.4.0
mypy==1.4.1
black==23.7.0
ruff==0.0.292

# flake8 libraries not included in ruff
flake8==6.0.0
flake8-pyproject==1.2.3
flake8-spellcheck==0.28.0
flake8-qgis==1.0.0
flake8-print==4.0.0
flake8-tidy-imports==4.4.1
flake8-comprehensions==3.6.1
flake8-spellcheck==0.24.0
flake8-simplify==0.14.1
flake8-pytest-style==1.5.0
flake8-pie==0.14.0
flake8-no-pep420==1.1.1

# tools
qgis-plugin-dev-tools==0.6.0

# typing
PyQt5-stubs==5.15.6.0
qgis-plugin-dev-tools==0.5.0

# NOTE: Runtime requirements for QGIS plugin are defined in setup.cfg

Expand Down
Loading

0 comments on commit c3b2277

Please sign in to comment.