feat(dev): use ruff for python linting (#355)

This commit is contained in:
Patrick Decat
2023-09-01 00:29:59 +02:00
committed by GitHub
parent 8bf82ac144
commit 0a7775860c
5 changed files with 40 additions and 22 deletions

View File

@@ -11,7 +11,7 @@ jobs:
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Set up Python - name: Set up Python
uses: actions/setup-python@v4 uses: actions/setup-python@v4
with: with:
@@ -20,7 +20,7 @@ jobs:
cache-dependency-path: | cache-dependency-path: |
backend/requirements/default.txt backend/requirements/default.txt
backend/requirements/dev.txt backend/requirements/dev.txt
- run: | - run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install -r backend/requirements/default.txt pip install -r backend/requirements/default.txt
pip install -r backend/requirements/dev.txt pip install -r backend/requirements/dev.txt
@@ -30,6 +30,11 @@ jobs:
cd backend cd backend
mypy . mypy .
- name: Run ruff
run: |
cd backend
ruff .
- name: Check import order with reorder-python-imports - name: Check import order with reorder-python-imports
run: | run: |
cd backend cd backend

View File

@@ -23,10 +23,16 @@ repos:
- id: autoflake - id: autoflake
args: [ '--remove-all-unused-imports', '--remove-unused-variables', '--in-place' , '--recursive'] args: [ '--remove-all-unused-imports', '--remove-unused-variables', '--in-place' , '--recursive']
# We would like to have a mypy pre-commit hook, but due to the fact that - repo: https://github.com/astral-sh/ruff-pre-commit
# pre-commit runs in it's own isolated environment, we would need to install # Ruff version.
rev: v0.0.286
hooks:
- id: ruff
# We would like to have a mypy pre-commit hook, but due to the fact that
# pre-commit runs in it's own isolated environment, we would need to install
# and keep in sync all dependencies so mypy has access to the appropriate type # and keep in sync all dependencies so mypy has access to the appropriate type
# stubs. This does not seem worth it at the moment, so for now we will stick to # stubs. This does not seem worth it at the moment, so for now we will stick to
# having mypy run via Github Actions / manually by contributors # having mypy run via Github Actions / manually by contributors
# - repo: https://github.com/pre-commit/mirrors-mypy # - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v1.1.1 # rev: v1.1.1
@@ -38,15 +44,15 @@ repos:
# # with requirements/dev.txt + requirements/default.txt # # with requirements/dev.txt + requirements/default.txt
# additional_dependencies: [ # additional_dependencies: [
# alembic==1.10.4, # alembic==1.10.4,
# types-beautifulsoup4==4.12.0.3, # types-beautifulsoup4==4.12.0.3,
# types-html5lib==1.1.11.13, # types-html5lib==1.1.11.13,
# types-oauthlib==3.2.0.9, # types-oauthlib==3.2.0.9,
# types-psycopg2==2.9.21.10, # types-psycopg2==2.9.21.10,
# types-python-dateutil==2.8.19.13, # types-python-dateutil==2.8.19.13,
# types-regex==2023.3.23.1, # types-regex==2023.3.23.1,
# types-requests==2.28.11.17, # types-requests==2.28.11.17,
# types-retry==0.9.9.3, # types-retry==0.9.9.3,
# types-urllib3==1.26.25.11 # types-urllib3==1.26.25.11
# ] # ]
# # TODO: add back once errors are addressed # # TODO: add back once errors are addressed
# # args: [--strict] # # args: [--strict]

14
backend/pyproject.toml Normal file
View File

@@ -0,0 +1,14 @@
[tool.mypy]
plugins = "sqlalchemy.ext.mypy.plugin"
mypy_path = "$MYPY_CONFIG_FILE_DIR"
explicit_package_bases = true
disallow_untyped_defs = true
[tool.ruff]
ignore = []
line-length = 130
select = [
"E",
"F",
"W",
]

View File

@@ -3,6 +3,7 @@ mypy-extensions==1.0.0
mypy==1.1.1 mypy==1.1.1
pre-commit==3.2.2 pre-commit==3.2.2
reorder-python-imports==3.9.0 reorder-python-imports==3.9.0
ruff==0.0.286
types-beautifulsoup4==4.12.0.3 types-beautifulsoup4==4.12.0.3
types-html5lib==1.1.11.13 types-html5lib==1.1.11.13
types-oauthlib==3.2.0.9 types-oauthlib==3.2.0.9

View File

@@ -1,8 +0,0 @@
[mypy]
plugins = sqlalchemy.ext.mypy.plugin
mypy_path = $MYPY_CONFIG_FILE_DIR
explicit_package_bases = True
disallow_untyped_defs = True
[flake8]
max-line-length = 88