Просмотр исходного кода

removed black linter in favour for ruff (#582)

* removed black linter in favour for ruff

* Add ruff formatting commands

* Fix indentation in Makefile commands

* Configuration tweaks for latest ruff

* Add pre-commit formatting check with ruff

---------

Co-authored-by: Thibaud Colas <thibaudcolas@gmail.com>
Lupyana Mbembati 1 месяц назад
Родитель
Сommit
d63dd8c310
5 измененных файлов с 28 добавлено и 37 удалено
  1. 4 11
      .pre-commit-config.yaml
  2. 3 3
      Makefile
  3. 10 12
      bakerydemo/settings/production.py
  4. 1 2
      requirements/development.txt
  5. 10 9
      ruff.toml

+ 4 - 11
.pre-commit-config.yaml

@@ -2,19 +2,12 @@ default_language_version:
   node: system
   python: python3
 repos:
-  - repo: https://github.com/psf/black
-    rev: 22.3.0
-    hooks:
-      - id: black
-        language_version: python3
-        args: ['--target-version', 'py38']
-
   - repo: https://github.com/astral-sh/ruff-pre-commit
-    rev: 'v0.0.290'
+    rev: v0.14.8
     hooks:
-      - id: ruff
-        args: [--fix, --exit-non-zero-on-fix]
-
+      - id: ruff-check
+        args: [--fix]
+      - id: ruff-format
   - repo: https://github.com/pre-commit/mirrors-prettier
     rev: v3.1.0
     hooks:

+ 3 - 3
Makefile

@@ -1,11 +1,11 @@
 .PHONY: lint format
 
 help:
-	@echo "lint - check style with black, ruff, sort python with ruff, indent html, and lint frontend css/js"
+	@echo "lint - check style with ruff, sort python with ruff, indent html, and lint frontend css/js"
 	@echo "format - enforce a consistent code style across the codebase, sort python files with ruff and fix frontend css/js"
 
 lint-server:
-	black --target-version py38 --check --diff .
+	ruff format --check .
 	ruff check .
 	curlylint --parse-only bakerydemo
 	git ls-files '*.html' | xargs djhtml --check
@@ -18,7 +18,7 @@ lint-client:
 lint: lint-server lint-client
 
 format-server:
-	black --target-version py38 .
+	ruff format .
 	ruff check . --fix
 	git ls-files '*.html' | xargs djhtml -i
 

+ 10 - 12
bakerydemo/settings/production.py

@@ -129,21 +129,21 @@ if ELASTICSEARCH_ENDPOINT:
         # This may be useful if your credentials are obtained via EC2 instance meta data.
         from aws_requests_auth.boto_utils import BotoAWSRequestsAuth
 
-        WAGTAILSEARCH_BACKENDS["default"]["HOSTS"][0][
-            "http_auth"
-        ] = BotoAWSRequestsAuth(
-            aws_host=ELASTICSEARCH_ENDPOINT,
-            aws_region=AWS_REGION,
-            aws_service="es",
+        WAGTAILSEARCH_BACKENDS["default"]["HOSTS"][0]["http_auth"] = (
+            BotoAWSRequestsAuth(
+                aws_host=ELASTICSEARCH_ENDPOINT,
+                aws_region=AWS_REGION,
+                aws_service="es",
+            )
         )
 
 # Simplified static file serving.
 # https://warehouse.python.org/project/whitenoise/
 
 MIDDLEWARE.append("whitenoise.middleware.WhiteNoiseMiddleware")
-STORAGES["staticfiles"][
-    "BACKEND"
-] = "whitenoise.storage.CompressedManifestStaticFilesStorage"
+STORAGES["staticfiles"]["BACKEND"] = (
+    "whitenoise.storage.CompressedManifestStaticFilesStorage"
+)
 
 if "AWS_STORAGE_BUCKET_NAME" in os.environ:
     AWS_STORAGE_BUCKET_NAME = os.getenv("AWS_STORAGE_BUCKET_NAME")
@@ -265,9 +265,7 @@ SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
 # dev and testing settings.
 # https://docs.djangoproject.com/en/stable/ref/settings/#secure-hsts-seconds
 DEFAULT_HSTS_SECONDS = 30 * 24 * 60 * 60  # 30 days
-SECURE_HSTS_SECONDS = int(
-    os.environ.get("SECURE_HSTS_SECONDS", DEFAULT_HSTS_SECONDS)
-)  # noqa
+SECURE_HSTS_SECONDS = int(os.environ.get("SECURE_HSTS_SECONDS", DEFAULT_HSTS_SECONDS))  # noqa
 
 # Do not use the `includeSubDomains` directive for HSTS. This needs to be prevented
 # because the apps are running on client domains (or our own for staging), that are

+ 1 - 2
requirements/development.txt

@@ -1,5 +1,4 @@
 -r base.txt
-black==22.3.0
-ruff==0.0.290
+ruff==0.14.8
 curlylint==0.13.1
 djhtml==1.4.13

+ 10 - 9
ruff.toml

@@ -1,16 +1,9 @@
-# D100: Missing docstring in public module
-# D101: Missing docstring in public class
-# D102: Missing docstring in public method
-# D103: Missing docstring in public function
-# D105: Missing docstring in magic method
-# N806: Variable in function should be lowercase
-# E501: Line too long
-ignore = ["D100","D101","D102","D103","D105","N806","E501"]
 exclude = ["wagtail/project_template/*","node_modules","venv",".venv","migrations"]
 line-length = 88
 
-target-version = "py38"  # minimum target version
+target-version = "py312"  # minimum target version
 
+[lint]
 # E: pycodestyle errors
 # F: Pyflakes
 # I: isort
@@ -18,3 +11,11 @@ target-version = "py38"  # minimum target version
 # BLE: flake8-blind-except
 # C4: flake8-comprehensions
 select = ["E", "F", "I", "T20", "BLE", "C4"]
+# D100: Missing docstring in public module
+# D101: Missing docstring in public class
+# D102: Missing docstring in public method
+# D103: Missing docstring in public function
+# D105: Missing docstring in magic method
+# N806: Variable in function should be lowercase
+# E501: Line too long
+ignore = ["D100","D101","D102","D103","D105","N806","E501"]