[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 11/46] qapi: enforce import order/styling with isort
From: |
John Snow |
Subject: |
[PATCH v4 11/46] qapi: enforce import order/styling with isort |
Date: |
Wed, 30 Sep 2020 00:31:15 -0400 |
While we're mucking around with imports, we might as well formalize the
style we use. Let's use isort to do it for us.
lines_after_imports=2: Use two lines after imports, to match PEP8's
desire to have "two lines before and after" class definitions, which are
likely to start immediately after imports.
force_sort_within_sections: Intermingles "from x" and "import x" style
statements, such that sorting is always performed strictly on the module
name itself.
force_grid_wrap=4: Four or more imports from a single module will force
the one-per-line style that's more git-friendly. This will generally
happen for 'typing' imports.
multi_line_output=3: Uses the one-per-line indented style for long
imports.
include_trailing_comma: Adds a comma to the last import in a group,
which makes git conflicts nicer to deal with, generally.
line_length: 72 is chosen to match PEP8's "docstrings and comments" line
length limit. If you have a single line import that exceeds 72
characters, your names are too long!
Suggested-by: Cleber Rosa <crosa@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Cleber Rosa <crosa@redhat.com>
Tested-by: Cleber Rosa <crosa@redhat.com>
---
scripts/qapi/.isort.cfg | 7 +++++++
scripts/qapi/expr.py | 3 ++-
scripts/qapi/introspect.py | 7 +++++--
scripts/qapi/parser.py | 2 +-
scripts/qapi/schema.py | 2 +-
5 files changed, 16 insertions(+), 5 deletions(-)
create mode 100644 scripts/qapi/.isort.cfg
diff --git a/scripts/qapi/.isort.cfg b/scripts/qapi/.isort.cfg
new file mode 100644
index 00000000000..6d0fd6cc0d3
--- /dev/null
+++ b/scripts/qapi/.isort.cfg
@@ -0,0 +1,7 @@
+[settings]
+force_grid_wrap=4
+force_sort_within_sections=True
+include_trailing_comma=True
+line_length=72
+lines_after_imports=2
+multi_line_output=3
\ No newline at end of file
diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py
index 03b31ecfc19..e73b65b6a7e 100644
--- a/scripts/qapi/expr.py
+++ b/scripts/qapi/expr.py
@@ -14,8 +14,9 @@
# This work is licensed under the terms of the GNU GPL, version 2.
# See the COPYING file in the top-level directory.
-import re
from collections import OrderedDict
+import re
+
from .common import c_name
from .error import QAPISemError
diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py
index b036fcf9ce7..31acd2f230a 100644
--- a/scripts/qapi/introspect.py
+++ b/scripts/qapi/introspect.py
@@ -17,8 +17,11 @@
mcgen,
)
from .gen import QAPISchemaMonolithicCVisitor
-from .schema import (QAPISchemaArrayType, QAPISchemaBuiltinType,
- QAPISchemaType)
+from .schema import (
+ QAPISchemaArrayType,
+ QAPISchemaBuiltinType,
+ QAPISchemaType,
+)
def _make_tree(obj, ifcond, features, extra=None):
diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py
index a9388eaf765..a6081a0c5d4 100644
--- a/scripts/qapi/parser.py
+++ b/scripts/qapi/parser.py
@@ -14,9 +14,9 @@
# This work is licensed under the terms of the GNU GPL, version 2.
# See the COPYING file in the top-level directory.
+from collections import OrderedDict
import os
import re
-from collections import OrderedDict
from .error import QAPIParseError, QAPISemError
from .source import QAPISourceInfo
diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
index a835ee6fde3..093f7a38d88 100644
--- a/scripts/qapi/schema.py
+++ b/scripts/qapi/schema.py
@@ -14,9 +14,9 @@
# TODO catching name collisions in generated code would be nice
+from collections import OrderedDict
import os
import re
-from collections import OrderedDict
from .common import c_name, pointer_suffix
from .error import QAPIError, QAPISemError
--
2.26.2
- [PATCH v4 00/46] qapi: static typing conversion, pt1, John Snow, 2020/09/30
- [PATCH v4 02/46] docs: repair broken references, John Snow, 2020/09/30
- [PATCH v4 03/46] [DO-NOT-MERGE] docs/sphinx: change default role to "any", John Snow, 2020/09/30
- [PATCH v4 04/46] qapi: modify docstrings to be sphinx-compatible, John Snow, 2020/09/30
- [PATCH v4 01/46] [DO-NOT-MERGE] docs: replace single backtick (`) with double-backtick (``), John Snow, 2020/09/30
- [PATCH v4 05/46] [DO-NOT-MERGE] docs: enable sphinx-autodoc for scripts/qapi, John Snow, 2020/09/30
- [PATCH v4 07/46] qapi: move generator entrypoint into module, John Snow, 2020/09/30
- [PATCH v4 09/46] qapi: Prefer explicit relative imports, John Snow, 2020/09/30
- [PATCH v4 06/46] qapi-gen: Separate arg-parsing from generation, John Snow, 2020/09/30
- [PATCH v4 08/46] [DO-NOT-MERGE] docs: add scripts/qapi/main to python manual, John Snow, 2020/09/30
- [PATCH v4 11/46] qapi: enforce import order/styling with isort,
John Snow <=
- [PATCH v4 10/46] qapi: Remove wildcard includes, John Snow, 2020/09/30
- [PATCH v4 12/46] qapi: delint using flake8, John Snow, 2020/09/30
- [PATCH v4 13/46] qapi: add pylintrc, John Snow, 2020/09/30
- [PATCH v4 14/46] qapi/common.py: Remove python compatibility workaround, John Snow, 2020/09/30
- [PATCH v4 15/46] qapi/common.py: Add indent manager, John Snow, 2020/09/30
- [PATCH v4 16/46] qapi/common.py: delint with pylint, John Snow, 2020/09/30
- [PATCH v4 17/46] qapi/common.py: Replace one-letter 'c' variable, John Snow, 2020/09/30
- [PATCH v4 19/46] qapi/common.py: add type hint annotations, John Snow, 2020/09/30
- [PATCH v4 18/46] qapi/common.py: check with pylint, John Snow, 2020/09/30
- [PATCH v4 20/46] qapi/common.py: Convert comments into docstrings, and elaborate, John Snow, 2020/09/30