Skip to content

Commit

Permalink
Add Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Dec 3, 2024
1 parent 0dc34bd commit 91f84f2
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 241 deletions.
31 changes: 0 additions & 31 deletions .bandit.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
# When we upgrade this we should also upgrade the requirements
# in the documentation: doc/integrator/requirements.rst
# and the first pyupgrade pre-commit hook in .pre-commit-config.yaml
MIN_PYTHON_VERSION: '3.8'
MIN_PYTHON_VERSION: '3.10'

steps:
- run: '! ls BACKPORT_TODO'
Expand Down
52 changes: 6 additions & 46 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,64 +104,24 @@ repos:
docker/config/haproxy_dev/localhost\.pem
|geoportal/c2cgeoportal_geoportal/scaffolds/create/{{cookiecutter\.project}}/mapserver/data/TM_EUROPE_BORDERS-0.3\.sql
)$
- repo: https://github.com/asottile/pyupgrade
rev: v3.19.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.1
hooks:
# The script that will run on the project host
- id: pyupgrade
- id: ruff-format
args:
- --py38-plus
files: |-
(?x)^(
geoportal/c2cgeoportal_geoportal/scaffolds/create/{{cookiecutter\.project}}/(build
|scripts/.*)
|scripts/(get-version
|upgrade)
)$
# All other
- id: pyupgrade
args:
- --py310-plus
# geoportal/c2cgeoportal_geoportal/views/theme\.py is present because of issue:
# https://bugs.launchpad.net/lxml/+bug/2079018
exclude: |-
(?x)^(
geoportal/c2cgeoportal_geoportal/scaffolds/create/{{cookiecutter\.project}}/(build
|scripts/.*)
|scripts/(get-version
|upgrade)
|geoportal/c2cgeoportal_geoportal/views/theme\.py
)$
- repo: https://github.com/PyCQA/autoflake
rev: v2.3.1
hooks:
- id: autoflake
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 24.10.0
hooks:
- id: black
exclude: |-
(?x)^(
commons/c2cgeoportal_commons/alembic/script\.py\.mako
|.*\.rst
|.*\.rst\.tmpl
|geoportal/c2cgeoportal_geoportal/scaffolds/advance_create/{{cookiecutter.project}}/geoportal/{{cookiecutter.package}}_geoportal/__init__\.py
)$
- --line-length=110
- repo: https://github.com/PyCQA/prospector
rev: v1.13.3
hooks:
- id: prospector
args:
- --tool=pydocstyle
- --tool=ruff
- --die-on-tool-error
- --output-format=pylint
additional_dependencies:
- prospector-profile-duplicated==1.8.0 # pypi
- prospector-profile-utils==1.13.0 # pypi
- ruff==0.8.1 # pypi
- repo: https://github.com/sbrunner/jsonschema-validator
rev: 0.3.2
hooks:
Expand Down
26 changes: 1 addition & 25 deletions .prospector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,11 @@ inherits:
- utils:base
- utils:fix
- utils:no-design-checks
- utils:unsafe

ignore-paths:
- commons/setup.py
- geoportal/setup.py
- admin/setup.py
- geoportal/c2cgeoportal_geoportal/scaffolds
- docker/qgisserver

pycodestyle:
disable:
# Buggy checks with Python 3.12
- W604 # backticks are deprecated, use 'repr()'
- W603 # '<>' is deprecated, use '!='
- E702 # multiple statements on one line (semicolon)
- E713 # test for membership should be 'not in'

pydocstyle:
disable:
- D102 # Missing docstring in public method
- D104 # Missing docstring in public package
- D105 # Missing docstring in magic method
- D107 # Missing docstring in __init__
- D200 # One-line docstring should fit on one line with quotes
- D202 # No blank lines allowed after function docstring (found 1)
- D203 # 1 blank line required before class docstring (found 0)
- D212 # Multi-line docstring summary should start at the first line
- D407 # Missing dashed underline after section ('Arguments')
- D412 # No blank lines allowed between a section header and its content ('Arguments')

bandit:
options:
config: .bandit.yaml
2 changes: 1 addition & 1 deletion doc/integrator/requirements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ components installed on your system:

* **Git**
* **Docker** >= 17.05
* **Python** >= 3.8, with ``pip``
* **Python** >= 3.10, with ``pip``
* **Apache** >= 2.4 (optional, can be used as a front for SSL)
* **PostgreSQL** >= 9.1/**PostGIS** >= 2.1

Expand Down
8 changes: 0 additions & 8 deletions doc/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
[tool.black]
line-length = 110
target-version = ['py39']

[tool.isort]
profile = "black"
line_length = 110

[tool.poetry]
name = 'c2cgeoportal'
version = '0.0.0'
Expand Down
2 changes: 0 additions & 2 deletions docker/qgisserver/.bandit.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions docker/qgisserver/.prospector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ inherits:
pyroma:
run: False

bandit:
mypy:
options:
config: .bandit.yaml
python_version: '3.10'
32 changes: 30 additions & 2 deletions docker/qgisserver/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 3 additions & 18 deletions docker/qgisserver/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
[tool.mypy]
python_version = 3.10
warn_redundant_casts = true
warn_unused_ignores = true
check_untyped_defs = true
skip_version_check = true
ignore_missing_imports = true

[tool.black]
line-length = 110
target-version = ['py310']

[tool.isort]
profile = "black"
line_length = 110
known_third_party = "c2cwsgiutils,c2cgeoform,qgis,pytest"
known_first_party = ["geomapfish_qgisserver", "c2cgeoportal_commons"]
[tool.ruff]
target-version = 'py310'

[tool.poetry]
name = 'c2cgeoportal'
Expand All @@ -38,7 +23,7 @@ psycopg2 = "2.9.10"
pytz = "2024.2"

[tool.poetry.dev-dependencies]
prospector = { extras = ["with_mypy", "with_bandit"], version = "1.13.3" }
prospector = { version = "1.13.3", extras = ["with_mypy", "with_bandit", "with_ruff"] }
prospector-profile-duplicated = "1.8.0"
prospector-profile-utils = "1.13.0"
types-pyyaml = "6.0.12.20240917"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
inherits:
- duplicated
- utils:no-design-checks

max-line-length: 110

pycodestyle:
options:
max-line-length: 110
disable:
- E203

pylint:
options:
max-line-length: 110
disable:
- too-many-locals
- too-many-statements
- too-many-branches
- c-extension-no-member

pyflakes:
disable:
- F401

mccabe:
run: false

bandit:
run: true
- utils:base-less-strict
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
[tool.black]
line-length = 110
target-version = ['py39']

[tool.isort]
profile = "black"
line_length = 110
[tool.ruff]
target-version = 'py310'
41 changes: 0 additions & 41 deletions geoportal/c2cgeoportal_geoportal/scripts/c2cupgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,51 +61,10 @@

def fix_style() -> None:
"""Fix the style of all the project files using isort, Black and Prettier."""

file_to_clean = []
for filename, content in (
(".prettierignore", "*.min.js\n"),
("pyproject.toml", "[tool.black]\nline-length = 110\ntarget-version = ['py39']\n"),
(".prettierrc.yaml", "bracketSpacing: false\nquoteProps: preserve\n"),
(
".editorconfig",
"""root = true
[*]
max_line_length = 110
""",
),
):
if not os.path.exists(filename):
file_to_clean.append(filename)
if os.path.exists(os.path.join("CONST_create_template", filename)):
shutil.copyfile(os.path.join("CONST_create_template", filename), filename)
else:
with open(filename, "w", encoding="utf8") as file_:
file_.write(content)

if os.path.exists("ci/config.yaml"):
os.rename("ci/config.yaml", "ci/config.yaml_")
if os.path.exists(".pre-commit-config.yaml"):
print("Run pre-commit to fix the style.")
sys.stdout.flush()
subprocess.run(["pre-commit", "run", "--all-files"]) # pylint: disable=subprocess-run-check
else:
print("Run c2cciutils-checks to fix the style.")
sys.stdout.flush()
subprocess.run( # pylint: disable=subprocess-run-check
["c2cciutils-checks", "--fix", "--check=isort"]
)
subprocess.run( # pylint: disable=subprocess-run-check
["c2cciutils-checks", "--fix", "--check=black"]
)
subprocess.run( # pylint: disable=subprocess-run-check
["c2cciutils-checks", "--fix", "--check=prettier"]
)
if os.path.exists("ci/config.yaml_"):
os.rename("ci/config.yaml_", "ci/config.yaml")

for filename in file_to_clean:
os.remove(filename)


def main() -> None:
Expand Down
Loading

0 comments on commit 91f84f2

Please sign in to comment.