Преглед изворни кода

Use flake8+ruff for format

Fabian Fulga пре 3 месеци
родитељ
комит
ec6b6284e5
3 измењених фајлова са 54 додато и 2 уклоњено
  1. 26 0
      ruff.toml
  2. 1 0
      test-requirements.txt
  3. 27 2
      tox.ini

+ 26 - 0
ruff.toml

@@ -0,0 +1,26 @@
+line-length = 88
+target-version = "py310"
+
+extend-exclude = [
+    "doc",
+    "tools",
+    "*openstack/common*",
+    "*lib/python*",
+    "*egg",
+]
+
+[lint]
+select = ["E", "W", "F", "I"]
+
+ignore = [
+    "E251",  # Skipped due to https://github.com/jcrocholl/pep8/issues/301
+    "E305",  # Expected 2 blank lines after function/class
+    "E731",  # Do not assign a lambda; use def
+    "E117",  # Over-indented
+    "W605",  # Invalid escape sequence in string literal
+    "F632",  # Use ==/!= to compare str, bytes, and int literals
+    "E501",  # Line length enforced by ruff format (line-length above), not lint
+]
+
+[format]
+quote-style = "preserve"

+ 1 - 0
test-requirements.txt

@@ -10,3 +10,4 @@ oslotest>=3.8.0 # Apache-2.0
 stestr>=4.2.1 # Apache-2.0
 flake8>=7.0.0
 pyflakes>=3.2.0
+ruff>=0.5.0 # MIT

+ 27 - 2
tox.ini

@@ -3,6 +3,9 @@ minversion = 4.0.2
 envlist = py3,pep8,cover
 skipsdist = True
 
+[vars]
+all_path = {toxinidir}
+
 [testenv]
 usedevelop = True
 setenv = VIRTUAL_ENV={envdir}
@@ -12,8 +15,25 @@ deps =
   git+https://github.com/cloudbase/python-coriolisclient.git
 commands = stestr run --slowest --exclude-regex coriolis.tests.integration {posargs}
 
+[testenv:fmt]
+description = Format the code based on the coding style standards.
+deps =
+    ruff
+commands =
+    ruff check --fix {[vars]all_path}
+    ruff format {[vars]all_path}
+
 [testenv:pep8]
-commands = flake8 {posargs}
+description = Verify the coding style (pep8).
+deps =
+    ruff
+    flake8>=7.0.0
+    pyflakes>=3.2.0
+    hacking>=7.0.0,<7.1.0
+commands =
+    ruff format --diff {[vars]all_path}
+    ruff check {[vars]all_path}
+    flake8 {[vars]all_path}
 
 [testenv:cover]
 setenv =
@@ -55,6 +75,11 @@ omit = coriolis/tests/*
 [flake8]
 # E125 is deliberately excluded. See https://github.com/jcrocholl/pep8/issues/126
 # E251 Skipped due to https://github.com/jcrocholl/pep8/issues/301
+#
+# E501 (line too long) is left to ruff line-length option
+# E203 (whitespace before ':') conflicts with how ruff formats slices.
+# H301: Do not import more than one module per line (*)
+# H306: Alphabetically order your imports by the full module path
 
-ignore = E125,E251,W503,W504,E305,E731,E117,W605,F632,H401,H403,H404,H405,H202
+ignore = E125,E251,W503,W504,E305,E731,E117,W605,F632,H401,H403,H404,H405,H202,E501,E203,H301,H306
 exclude =  .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,tools