From 3730e2e726b514c738aea472eb3849d5a8607bb3 Mon Sep 17 00:00:00 2001 From: gregorni Date: Sun, 9 Jul 2023 14:26:37 +0000 Subject: [PATCH] Add isort to CI and run on files --- .gitlab-ci.yml | 1 + blueprint-compiler.py | 3 +- blueprintcompiler/ast_utils.py | 2 +- blueprintcompiler/completions.py | 4 +-- blueprintcompiler/completions_utils.py | 3 +- blueprintcompiler/decompiler.py | 5 ++- blueprintcompiler/errors.py | 6 ++-- blueprintcompiler/gir.py | 7 +++-- blueprintcompiler/interactive_port.py | 7 ++--- blueprintcompiler/language/__init__.py | 23 +++++++------- .../language/adw_message_dialog.py | 2 +- blueprintcompiler/language/binding.py | 2 +- blueprintcompiler/language/common.py | 31 +++++++++---------- blueprintcompiler/language/contexts.py | 2 +- blueprintcompiler/language/expression.py | 3 +- blueprintcompiler/language/gobject_object.py | 1 - .../language/gobject_property.py | 6 ++-- blueprintcompiler/language/gobject_signal.py | 4 +-- blueprintcompiler/language/gtk_a11y.py | 6 ++-- .../language/gtk_combo_box_text.py | 2 +- blueprintcompiler/language/gtk_file_filter.py | 2 +- blueprintcompiler/language/gtk_layout.py | 2 +- .../language/gtk_list_item_factory.py | 6 ++-- blueprintcompiler/language/gtk_scale.py | 2 +- blueprintcompiler/language/gtk_size_group.py | 2 +- blueprintcompiler/language/gtk_string_list.py | 2 +- blueprintcompiler/language/gtk_styles.py | 2 +- .../language/gtkbuilder_child.py | 2 +- .../language/gtkbuilder_template.py | 4 +-- blueprintcompiler/language/types.py | 2 +- blueprintcompiler/language/ui.py | 8 ++--- blueprintcompiler/language/values.py | 4 +-- blueprintcompiler/lsp.py | 8 +++-- blueprintcompiler/lsp_utils.py | 2 +- blueprintcompiler/main.py | 11 ++++--- blueprintcompiler/outputs/xml/__init__.py | 2 +- blueprintcompiler/outputs/xml/xml_emitter.py | 1 - blueprintcompiler/parse_tree.py | 8 ++--- blueprintcompiler/parser.py | 2 +- blueprintcompiler/tokenizer.py | 2 +- blueprintcompiler/typelib.py | 6 ++-- blueprintcompiler/xml_reader.py | 3 +- build-aux/Dockerfile | 2 +- tests/fuzz.py | 11 ++++--- tests/test_samples.py | 9 +++--- 45 files changed, 112 insertions(+), 113 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 93ef254..7e9ee9c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,6 +7,7 @@ build: stage: build script: - black --check --diff blueprintcompiler tests + - isort --check --diff --profile black blueprintcompiler tests - mypy --python-version=3.9 blueprintcompiler - G_DEBUG=fatal-warnings xvfb-run coverage run -m unittest - coverage report diff --git a/blueprint-compiler.py b/blueprint-compiler.py index 61eae79..0c5c3fd 100755 --- a/blueprint-compiler.py +++ b/blueprint-compiler.py @@ -19,7 +19,8 @@ # # SPDX-License-Identifier: LGPL-3.0-or-later -import os, sys +import os +import sys # These variables should be set by meson. If they aren't, we're running # uninstalled, and we might have to guess some values. diff --git a/blueprintcompiler/ast_utils.py b/blueprintcompiler/ast_utils.py index 13f6eb1..7eebe45 100644 --- a/blueprintcompiler/ast_utils.py +++ b/blueprintcompiler/ast_utils.py @@ -17,9 +17,9 @@ # # SPDX-License-Identifier: LGPL-3.0-or-later +import typing as T from collections import ChainMap, defaultdict from functools import cached_property -import typing as T from .errors import * from .lsp_utils import SemanticToken diff --git a/blueprintcompiler/completions.py b/blueprintcompiler/completions.py index fc6eeee..b189bf1 100644 --- a/blueprintcompiler/completions.py +++ b/blueprintcompiler/completions.py @@ -20,12 +20,12 @@ import typing as T from . import gir, language -from .language.types import ClassName from .ast_utils import AstNode from .completions_utils import * +from .language.types import ClassName from .lsp_utils import Completion, CompletionItemKind from .parser import SKIP_TOKENS -from .tokenizer import TokenType, Token +from .tokenizer import Token, TokenType Pattern = T.List[T.Tuple[TokenType, T.Optional[str]]] diff --git a/blueprintcompiler/completions_utils.py b/blueprintcompiler/completions_utils.py index 094e449..2aae874 100644 --- a/blueprintcompiler/completions_utils.py +++ b/blueprintcompiler/completions_utils.py @@ -20,9 +20,8 @@ import typing as T -from .tokenizer import Token, TokenType from .lsp_utils import Completion - +from .tokenizer import Token, TokenType new_statement_patterns = [ [(TokenType.PUNCTUATION, "{")], diff --git a/blueprintcompiler/decompiler.py b/blueprintcompiler/decompiler.py index d3bf773..98e00af 100644 --- a/blueprintcompiler/decompiler.py +++ b/blueprintcompiler/decompiler.py @@ -18,14 +18,13 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import re -from enum import Enum import typing as T from dataclasses import dataclass +from enum import Enum -from .xml_reader import Element, parse, parse_string from .gir import * from .utils import Colors - +from .xml_reader import Element, parse, parse_string __all__ = ["decompile"] diff --git a/blueprintcompiler/errors.py b/blueprintcompiler/errors.py index 3fc2666..2a14040 100644 --- a/blueprintcompiler/errors.py +++ b/blueprintcompiler/errors.py @@ -17,9 +17,11 @@ # # SPDX-License-Identifier: LGPL-3.0-or-later -from dataclasses import dataclass +import sys +import traceback import typing as T -import sys, traceback +from dataclasses import dataclass + from . import utils from .utils import Colors diff --git a/blueprintcompiler/gir.py b/blueprintcompiler/gir.py index b289b5e..2986447 100644 --- a/blueprintcompiler/gir.py +++ b/blueprintcompiler/gir.py @@ -17,17 +17,18 @@ # # SPDX-License-Identifier: LGPL-3.0-or-later -from functools import cached_property +import os +import sys import typing as T -import os, sys +from functools import cached_property import gi # type: ignore gi.require_version("GIRepository", "2.0") from gi.repository import GIRepository # type: ignore -from .errors import CompileError, CompilerBugError from . import typelib, xml_reader +from .errors import CompileError, CompilerBugError _namespace_cache: T.Dict[str, "Namespace"] = {} _xml_cache = {} diff --git a/blueprintcompiler/interactive_port.py b/blueprintcompiler/interactive_port.py index 1286f0b..43bb03f 100644 --- a/blueprintcompiler/interactive_port.py +++ b/blueprintcompiler/interactive_port.py @@ -18,16 +18,15 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import typing as T import difflib import os +import typing as T -from . import decompiler, tokenizer, parser +from . import decompiler, parser, tokenizer +from .errors import CompilerBugError, MultipleErrors, PrintableError from .outputs.xml import XmlOutput -from .errors import MultipleErrors, PrintableError, CompilerBugError from .utils import Colors - # A tool to interactively port projects to blueprints. diff --git a/blueprintcompiler/language/__init__.py b/blueprintcompiler/language/__init__.py index d785e56..f849c75 100644 --- a/blueprintcompiler/language/__init__.py +++ b/blueprintcompiler/language/__init__.py @@ -1,12 +1,12 @@ -from .gtk_list_item_factory import ExtListItemFactory +from .adw_breakpoint import ( + AdwBreakpointCondition, + AdwBreakpointSetter, + AdwBreakpointSetters, +) from .adw_message_dialog import ExtAdwMessageDialog from .attributes import BaseAttribute -from .adw_breakpoint import ( - AdwBreakpointSetters, - AdwBreakpointSetter, - AdwBreakpointCondition, -) from .binding import Binding +from .common import * from .contexts import ScopeCtx, ValueTypeCtx from .expression import ( CastExpr, @@ -23,23 +23,24 @@ from .gobject_signal import Signal from .gtk_a11y import ExtAccessibility from .gtk_combo_box_text import ExtComboBoxItems from .gtk_file_filter import ( + Filters, ext_file_filter_mime_types, ext_file_filter_patterns, ext_file_filter_suffixes, - Filters, ) from .gtk_layout import ExtLayout -from .gtk_menu import menu, Menu, MenuAttribute +from .gtk_list_item_factory import ExtListItemFactory +from .gtk_menu import Menu, MenuAttribute, menu from .gtk_scale import ExtScaleMarks from .gtk_size_group import ExtSizeGroupWidgets from .gtk_string_list import ExtStringListStrings from .gtk_styles import ExtStyles -from .gtkbuilder_child import Child, ChildType, ChildInternal, ChildExtension +from .gtkbuilder_child import Child, ChildExtension, ChildInternal, ChildType from .gtkbuilder_template import Template from .imports import GtkDirective, Import from .property_binding import PropertyBinding -from .ui import UI from .types import ClassName +from .ui import UI from .values import ( Flag, Flags, @@ -54,8 +55,6 @@ from .values import ( Value, ) -from .common import * - OBJECT_CONTENT_HOOKS.children = [ Signal, Property, diff --git a/blueprintcompiler/language/adw_message_dialog.py b/blueprintcompiler/language/adw_message_dialog.py index 2823f77..98c40cd 100644 --- a/blueprintcompiler/language/adw_message_dialog.py +++ b/blueprintcompiler/language/adw_message_dialog.py @@ -18,7 +18,7 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -from ..decompiler import truthy, decompile_translatable +from ..decompiler import decompile_translatable, truthy from .common import * from .contexts import ValueTypeCtx from .gobject_object import ObjectContent, validate_parent_type diff --git a/blueprintcompiler/language/binding.py b/blueprintcompiler/language/binding.py index b13d5da..e6bffd0 100644 --- a/blueprintcompiler/language/binding.py +++ b/blueprintcompiler/language/binding.py @@ -20,7 +20,7 @@ from dataclasses import dataclass from .common import * -from .expression import Expression, LookupOp, LiteralExpr +from .expression import Expression, LiteralExpr, LookupOp class Binding(AstNode): diff --git a/blueprintcompiler/language/common.py b/blueprintcompiler/language/common.py index 9938bec..f1c6bb9 100644 --- a/blueprintcompiler/language/common.py +++ b/blueprintcompiler/language/common.py @@ -18,36 +18,35 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -from .. import gir -from ..ast_utils import AstNode, validate, docs, context -from ..errors import ( - CompileError, - MultipleErrors, - UpgradeWarning, - CompileWarning, - CodeAction, -) -from ..completions_utils import * from .. import decompiler as decompile +from .. import gir +from ..ast_utils import AstNode, context, docs, validate +from ..completions_utils import * from ..decompiler import ( DecompileCtx, + decompile_translatable, decompiler, escape_quote, truthy, - decompile_translatable, +) +from ..errors import ( + CodeAction, + CompileError, + CompileWarning, + MultipleErrors, + UpgradeWarning, ) from ..gir import ( - StringType, BoolType, - IntType, - FloatType, - GirType, Enumeration, ExternType, + FloatType, + GirType, + IntType, + StringType, ) from ..lsp_utils import Completion, CompletionItemKind, SemanticToken, SemanticTokenType from ..parse_tree import * - OBJECT_CONTENT_HOOKS = AnyOf() LITERAL = AnyOf() diff --git a/blueprintcompiler/language/contexts.py b/blueprintcompiler/language/contexts.py index 29d95de..fb24f5a 100644 --- a/blueprintcompiler/language/contexts.py +++ b/blueprintcompiler/language/contexts.py @@ -38,8 +38,8 @@ class ScopeCtx: @cached_property def template(self): - from .ui import UI from .gtk_list_item_factory import ExtListItemFactory + from .ui import UI if isinstance(self.node, UI): return self.node.template diff --git a/blueprintcompiler/language/expression.py b/blueprintcompiler/language/expression.py index 314c753..a2185a3 100644 --- a/blueprintcompiler/language/expression.py +++ b/blueprintcompiler/language/expression.py @@ -20,9 +20,8 @@ from .common import * from .contexts import ScopeCtx, ValueTypeCtx -from .types import TypeName from .gtkbuilder_template import Template - +from .types import TypeName expr = Sequence() diff --git a/blueprintcompiler/language/gobject_object.py b/blueprintcompiler/language/gobject_object.py index 183ad8e..d247c61 100644 --- a/blueprintcompiler/language/gobject_object.py +++ b/blueprintcompiler/language/gobject_object.py @@ -25,7 +25,6 @@ from .common import * from .response_id import ExtResponse from .types import ClassName, ConcreteClassName - RESERVED_IDS = {"this", "self", "template", "true", "false", "null", "none"} diff --git a/blueprintcompiler/language/gobject_property.py b/blueprintcompiler/language/gobject_property.py index 09873bc..f65c5ca 100644 --- a/blueprintcompiler/language/gobject_property.py +++ b/blueprintcompiler/language/gobject_property.py @@ -18,12 +18,12 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -from .gtkbuilder_template import Template -from .values import Value, ObjectValue +from .binding import Binding from .common import * from .contexts import ValueTypeCtx +from .gtkbuilder_template import Template from .property_binding import PropertyBinding -from .binding import Binding +from .values import ObjectValue, Value class Property(AstNode): diff --git a/blueprintcompiler/language/gobject_signal.py b/blueprintcompiler/language/gobject_signal.py index f08168f..2fc4699 100644 --- a/blueprintcompiler/language/gobject_signal.py +++ b/blueprintcompiler/language/gobject_signal.py @@ -19,9 +19,9 @@ import typing as T -from .gtkbuilder_template import Template -from .contexts import ScopeCtx from .common import * +from .contexts import ScopeCtx +from .gtkbuilder_template import Template class SignalFlag(AstNode): diff --git a/blueprintcompiler/language/gtk_a11y.py b/blueprintcompiler/language/gtk_a11y.py index c378927..f7f89d6 100644 --- a/blueprintcompiler/language/gtk_a11y.py +++ b/blueprintcompiler/language/gtk_a11y.py @@ -17,12 +17,12 @@ # # SPDX-License-Identifier: LGPL-3.0-or-later -from .gobject_object import ObjectContent, validate_parent_type +from ..decompiler import escape_quote from .attributes import BaseAttribute -from .values import Value from .common import * from .contexts import ValueTypeCtx -from ..decompiler import escape_quote +from .gobject_object import ObjectContent, validate_parent_type +from .values import Value def get_property_types(gir): diff --git a/blueprintcompiler/language/gtk_combo_box_text.py b/blueprintcompiler/language/gtk_combo_box_text.py index 275327a..e6c804e 100644 --- a/blueprintcompiler/language/gtk_combo_box_text.py +++ b/blueprintcompiler/language/gtk_combo_box_text.py @@ -18,9 +18,9 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -from .gobject_object import ObjectContent, validate_parent_type from .common import * from .contexts import ValueTypeCtx +from .gobject_object import ObjectContent, validate_parent_type from .values import StringValue diff --git a/blueprintcompiler/language/gtk_file_filter.py b/blueprintcompiler/language/gtk_file_filter.py index 492f19e..53cd102 100644 --- a/blueprintcompiler/language/gtk_file_filter.py +++ b/blueprintcompiler/language/gtk_file_filter.py @@ -18,8 +18,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -from .gobject_object import ObjectContent, validate_parent_type from .common import * +from .gobject_object import ObjectContent, validate_parent_type class Filters(AstNode): diff --git a/blueprintcompiler/language/gtk_layout.py b/blueprintcompiler/language/gtk_layout.py index cceb6c6..7632c7a 100644 --- a/blueprintcompiler/language/gtk_layout.py +++ b/blueprintcompiler/language/gtk_layout.py @@ -18,9 +18,9 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -from .gobject_object import ObjectContent, validate_parent_type from .common import * from .contexts import ValueTypeCtx +from .gobject_object import ObjectContent, validate_parent_type from .values import Value diff --git a/blueprintcompiler/language/gtk_list_item_factory.py b/blueprintcompiler/language/gtk_list_item_factory.py index bbb3bda..f2f9d63 100644 --- a/blueprintcompiler/language/gtk_list_item_factory.py +++ b/blueprintcompiler/language/gtk_list_item_factory.py @@ -1,9 +1,9 @@ -from .gobject_object import ObjectContent, validate_parent_type -from ..parse_tree import Keyword from ..ast_utils import AstNode, validate +from ..parse_tree import Keyword from .common import * -from .types import TypeName from .contexts import ScopeCtx +from .gobject_object import ObjectContent, validate_parent_type +from .types import TypeName class ExtListItemFactory(AstNode): diff --git a/blueprintcompiler/language/gtk_scale.py b/blueprintcompiler/language/gtk_scale.py index a81e03d..18452e1 100644 --- a/blueprintcompiler/language/gtk_scale.py +++ b/blueprintcompiler/language/gtk_scale.py @@ -17,8 +17,8 @@ # # SPDX-License-Identifier: LGPL-3.0-or-later -from .gobject_object import validate_parent_type, ObjectContent from .common import * +from .gobject_object import ObjectContent, validate_parent_type from .values import StringValue diff --git a/blueprintcompiler/language/gtk_size_group.py b/blueprintcompiler/language/gtk_size_group.py index 5ba4325..2a10a35 100644 --- a/blueprintcompiler/language/gtk_size_group.py +++ b/blueprintcompiler/language/gtk_size_group.py @@ -18,9 +18,9 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -from .gobject_object import ObjectContent, validate_parent_type from .common import * from .contexts import ScopeCtx +from .gobject_object import ObjectContent, validate_parent_type class Widget(AstNode): diff --git a/blueprintcompiler/language/gtk_string_list.py b/blueprintcompiler/language/gtk_string_list.py index 78d9c67..455960e 100644 --- a/blueprintcompiler/language/gtk_string_list.py +++ b/blueprintcompiler/language/gtk_string_list.py @@ -18,9 +18,9 @@ # SPDX-License-Identifier: LGPL-3.0-or-later +from .common import * from .gobject_object import ObjectContent, validate_parent_type from .values import StringValue -from .common import * class Item(AstNode): diff --git a/blueprintcompiler/language/gtk_styles.py b/blueprintcompiler/language/gtk_styles.py index 6591aa5..8152b82 100644 --- a/blueprintcompiler/language/gtk_styles.py +++ b/blueprintcompiler/language/gtk_styles.py @@ -18,8 +18,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -from .gobject_object import ObjectContent, validate_parent_type from .common import * +from .gobject_object import ObjectContent, validate_parent_type class StyleClass(AstNode): diff --git a/blueprintcompiler/language/gtkbuilder_child.py b/blueprintcompiler/language/gtkbuilder_child.py index 4de13f2..52c8ad4 100644 --- a/blueprintcompiler/language/gtkbuilder_child.py +++ b/blueprintcompiler/language/gtkbuilder_child.py @@ -20,9 +20,9 @@ from functools import cached_property +from .common import * from .gobject_object import Object from .response_id import ExtResponse -from .common import * ALLOWED_PARENTS: T.List[T.Tuple[str, str]] = [ ("Gtk", "Buildable"), diff --git a/blueprintcompiler/language/gtkbuilder_template.py b/blueprintcompiler/language/gtkbuilder_template.py index 149152a..9de4d66 100644 --- a/blueprintcompiler/language/gtkbuilder_template.py +++ b/blueprintcompiler/language/gtkbuilder_template.py @@ -21,9 +21,9 @@ import typing as T from blueprintcompiler.language.common import GirType -from .gobject_object import Object, ObjectContent -from .common import * from ..gir import TemplateType +from .common import * +from .gobject_object import Object, ObjectContent from .types import ClassName, TemplateClassName diff --git a/blueprintcompiler/language/types.py b/blueprintcompiler/language/types.py index dbce44f..e75ebdc 100644 --- a/blueprintcompiler/language/types.py +++ b/blueprintcompiler/language/types.py @@ -18,8 +18,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -from .common import * from ..gir import Class, ExternType, Interface +from .common import * class TypeName(AstNode): diff --git a/blueprintcompiler/language/ui.py b/blueprintcompiler/language/ui.py index 533d21b..1b7e6e9 100644 --- a/blueprintcompiler/language/ui.py +++ b/blueprintcompiler/language/ui.py @@ -20,12 +20,12 @@ from functools import cached_property from .. import gir -from .imports import GtkDirective, Import -from .gtkbuilder_template import Template -from .gobject_object import Object -from .gtk_menu import menu, Menu from .common import * from .contexts import ScopeCtx +from .gobject_object import Object +from .gtk_menu import Menu, menu +from .gtkbuilder_template import Template +from .imports import GtkDirective, Import class UI(AstNode): diff --git a/blueprintcompiler/language/values.py b/blueprintcompiler/language/values.py index d0f3be5..6981141 100644 --- a/blueprintcompiler/language/values.py +++ b/blueprintcompiler/language/values.py @@ -20,9 +20,9 @@ import typing as T from .common import * -from .types import TypeName -from .gobject_object import Object from .contexts import ScopeCtx, ValueTypeCtx +from .gobject_object import Object +from .types import TypeName class Translated(AstNode): diff --git a/blueprintcompiler/lsp.py b/blueprintcompiler/lsp.py index 58d6fac..e8c37f3 100644 --- a/blueprintcompiler/lsp.py +++ b/blueprintcompiler/lsp.py @@ -18,14 +18,16 @@ # SPDX-License-Identifier: LGPL-3.0-or-later +import json +import sys +import traceback import typing as T -import json, sys, traceback +from . import decompiler, parser, tokenizer, utils, xml_reader from .completions import complete -from .errors import PrintableError, CompileError, MultipleErrors +from .errors import CompileError, MultipleErrors, PrintableError from .lsp_utils import * from .outputs.xml import XmlOutput -from . import tokenizer, parser, utils, xml_reader, decompiler def printerr(*args, **kwargs): diff --git a/blueprintcompiler/lsp_utils.py b/blueprintcompiler/lsp_utils.py index 219cade..7f46680 100644 --- a/blueprintcompiler/lsp_utils.py +++ b/blueprintcompiler/lsp_utils.py @@ -18,9 +18,9 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -from dataclasses import dataclass import enum import typing as T +from dataclasses import dataclass from .errors import * from .utils import * diff --git a/blueprintcompiler/main.py b/blueprintcompiler/main.py index 6ac7a11..db9fb65 100644 --- a/blueprintcompiler/main.py +++ b/blueprintcompiler/main.py @@ -18,15 +18,18 @@ # SPDX-License-Identifier: LGPL-3.0-or-later +import argparse +import json +import os +import sys import typing as T -import argparse, json, os, sys -from .errors import PrintableError, report_bug, MultipleErrors, CompilerBugError +from . import decompiler, interactive_port, parser, tokenizer +from .errors import CompilerBugError, MultipleErrors, PrintableError, report_bug from .gir import add_typelib_search_path from .lsp import LanguageServer -from . import parser, tokenizer, decompiler, interactive_port -from .utils import Colors from .outputs import XmlOutput +from .utils import Colors VERSION = "uninstalled" LIBDIR = None diff --git a/blueprintcompiler/outputs/xml/__init__.py b/blueprintcompiler/outputs/xml/__init__.py index 7d450d1..3ef7375 100644 --- a/blueprintcompiler/outputs/xml/__init__.py +++ b/blueprintcompiler/outputs/xml/__init__.py @@ -1,7 +1,7 @@ import typing as T -from .. import OutputFormat from ...language import * +from .. import OutputFormat from .xml_emitter import XmlEmitter diff --git a/blueprintcompiler/outputs/xml/xml_emitter.py b/blueprintcompiler/outputs/xml/xml_emitter.py index 3dd09a0..44013da 100644 --- a/blueprintcompiler/outputs/xml/xml_emitter.py +++ b/blueprintcompiler/outputs/xml/xml_emitter.py @@ -18,7 +18,6 @@ # SPDX-License-Identifier: LGPL-3.0-or-later import typing as T - from xml.sax import saxutils from blueprintcompiler.gir import GirType diff --git a/blueprintcompiler/parse_tree.py b/blueprintcompiler/parse_tree.py index ff080ea..48f60b1 100644 --- a/blueprintcompiler/parse_tree.py +++ b/blueprintcompiler/parse_tree.py @@ -20,21 +20,19 @@ """ Utilities for parsing an AST from a token stream. """ import typing as T - from collections import defaultdict from enum import Enum -from .ast_utils import AstNode +from .ast_utils import AstNode from .errors import ( - assert_true, - CompilerBugError, CompileError, + CompilerBugError, CompileWarning, UnexpectedTokenError, + assert_true, ) from .tokenizer import Token, TokenType - SKIP_TOKENS = [TokenType.COMMENT, TokenType.WHITESPACE] diff --git a/blueprintcompiler/parser.py b/blueprintcompiler/parser.py index edef840..8b50de5 100644 --- a/blueprintcompiler/parser.py +++ b/blueprintcompiler/parser.py @@ -19,9 +19,9 @@ from .errors import MultipleErrors, PrintableError +from .language import OBJECT_CONTENT_HOOKS, UI, Template from .parse_tree import * from .tokenizer import TokenType -from .language import OBJECT_CONTENT_HOOKS, Template, UI def parse( diff --git a/blueprintcompiler/tokenizer.py b/blueprintcompiler/tokenizer.py index f68f5a7..3c98b94 100644 --- a/blueprintcompiler/tokenizer.py +++ b/blueprintcompiler/tokenizer.py @@ -18,8 +18,8 @@ # SPDX-License-Identifier: LGPL-3.0-or-later -import typing as T import re +import typing as T from enum import Enum from .errors import CompileError, CompilerBugError diff --git a/blueprintcompiler/typelib.py b/blueprintcompiler/typelib.py index 54ee341..8de06c5 100644 --- a/blueprintcompiler/typelib.py +++ b/blueprintcompiler/typelib.py @@ -17,15 +17,15 @@ # # SPDX-License-Identifier: LGPL-3.0-or-later +import math +import mmap +import os import sys import typing as T -import math from ctypes import * -import mmap, os from .errors import CompilerBugError - BLOB_TYPE_STRUCT = 3 BLOB_TYPE_BOXED = 4 BLOB_TYPE_ENUM = 5 diff --git a/blueprintcompiler/xml_reader.py b/blueprintcompiler/xml_reader.py index b2d579b..a3c0e3e 100644 --- a/blueprintcompiler/xml_reader.py +++ b/blueprintcompiler/xml_reader.py @@ -18,12 +18,11 @@ # SPDX-License-Identifier: LGPL-3.0-or-later +import typing as T from collections import defaultdict from functools import cached_property -import typing as T from xml import sax - # To speed up parsing, we ignore all tags except these PARSE_GIR = set( [ diff --git a/build-aux/Dockerfile b/build-aux/Dockerfile index b060765..aa26f43 100644 --- a/build-aux/Dockerfile +++ b/build-aux/Dockerfile @@ -4,7 +4,7 @@ RUN dnf install -y meson gcc g++ python3-pip gobject-introspection-devel \ python3-devel python3-gobject git diffutils xorg-x11-server-Xvfb \ appstream-devel "dnf-command(builddep)" RUN dnf build-dep -y gtk4 libadwaita -RUN pip3 install furo mypy sphinx coverage black +RUN pip3 install furo mypy sphinx coverage black isort COPY install_deps.sh . RUN ./install_deps.sh diff --git a/tests/fuzz.py b/tests/fuzz.py index ad1c764..81a9058 100644 --- a/tests/fuzz.py +++ b/tests/fuzz.py @@ -1,20 +1,21 @@ -import os, sys +import os +import sys + from pythonfuzz.main import PythonFuzz from blueprintcompiler.outputs.xml import XmlOutput sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) -from blueprintcompiler import tokenizer, parser, decompiler, gir +from blueprintcompiler import decompiler, gir, parser, tokenizer, utils from blueprintcompiler.completions import complete from blueprintcompiler.errors import ( - PrintableError, - MultipleErrors, CompileError, CompilerBugError, + MultipleErrors, + PrintableError, ) from blueprintcompiler.tokenizer import Token, TokenType, tokenize -from blueprintcompiler import utils @PythonFuzz diff --git a/tests/test_samples.py b/tests/test_samples.py index 30a41aa..7fe7941 100644 --- a/tests/test_samples.py +++ b/tests/test_samples.py @@ -19,20 +19,19 @@ import difflib # I love Python -from pathlib import Path import unittest +from pathlib import Path import gi gi.require_version("Gtk", "4.0") from gi.repository import Gtk -from blueprintcompiler import tokenizer, parser, decompiler +from blueprintcompiler import decompiler, parser, tokenizer, utils from blueprintcompiler.completions import complete -from blueprintcompiler.errors import PrintableError, MultipleErrors, CompileError -from blueprintcompiler.tokenizer import Token, TokenType, tokenize -from blueprintcompiler import utils +from blueprintcompiler.errors import CompileError, MultipleErrors, PrintableError from blueprintcompiler.outputs.xml import XmlOutput +from blueprintcompiler.tokenizer import Token, TokenType, tokenize class TestSamples(unittest.TestCase):