diff options
author | Cristián Maureira-Fredes <Cristian.Maureira-Fredes@qt.io> | 2022-03-30 20:51:17 +0200 |
---|---|---|
committer | Cristián Maureira-Fredes <cristian.maureira-fredes@qt.io> | 2022-04-02 16:43:45 +0200 |
commit | 7e87bbbe1f59e275d1076b90ab9b1cd640bef78a (patch) | |
tree | 853311ca24a27d02ca6a7d583a9e22c352fbb822 | |
parent | ea86da2b9cd1996e50f0dce08b9cd144d49b364e (diff) |
flake8: fix styling issues in tools/
Change-Id: I8cbf5d521900df4f55abf8f68997f8a71437f722
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r-- | tools/checklibs.py | 7 | ||||
-rw-r--r-- | tools/create_changelog.py | 6 | ||||
-rw-r--r-- | tools/debug_renamer.py | 14 | ||||
-rw-r--r-- | tools/debug_windows.py | 42 | ||||
-rw-r--r-- | tools/dump_metaobject.py | 3 | ||||
-rw-r--r-- | tools/example_gallery/main.py | 7 | ||||
-rw-r--r-- | tools/leak_finder.py | 5 | ||||
-rw-r--r-- | tools/license_check.py | 3 | ||||
-rw-r--r-- | tools/metaobject_dump.py | 3 | ||||
-rw-r--r-- | tools/missing_bindings/config.py | 104 | ||||
-rw-r--r-- | tools/missing_bindings/main.py | 9 | ||||
-rw-r--r-- | tools/qtpy2cpp.py | 4 | ||||
-rw-r--r-- | tools/qtpy2cpp_lib/astdump.py | 6 | ||||
-rw-r--r-- | tools/qtpy2cpp_lib/formatter.py | 2 | ||||
-rw-r--r-- | tools/qtpy2cpp_lib/visitor.py | 7 | ||||
-rw-r--r-- | tools/regenerate_example_resources.py | 1 | ||||
-rw-r--r-- | tools/regenerate_example_ui.py | 1 | ||||
-rw-r--r-- | tools/snippets_translate/converter.py | 22 | ||||
-rw-r--r-- | tools/snippets_translate/handlers.py | 10 | ||||
-rw-r--r-- | tools/snippets_translate/main.py | 3 | ||||
-rw-r--r-- | tools/snippets_translate/parse_utils.py | 3 | ||||
-rw-r--r-- | tools/uic_test.py | 9 |
22 files changed, 132 insertions, 139 deletions
diff --git a/tools/checklibs.py b/tools/checklibs.py index 18aa11e93..4c8d29721 100644 --- a/tools/checklibs.py +++ b/tools/checklibs.py @@ -49,7 +49,12 @@ # # -import subprocess, sys, re, os.path, optparse, collections +import collections +import optparse +import os.path +import re +import subprocess +import sys from pprint import pprint diff --git a/tools/create_changelog.py b/tools/create_changelog.py index b0fc6e718..73095f315 100644 --- a/tools/create_changelog.py +++ b/tools/create_changelog.py @@ -39,9 +39,9 @@ import re import sys -from argparse import ArgumentParser, Namespace, RawTextHelpFormatter -from subprocess import check_output, Popen, PIPE import textwrap +from argparse import ArgumentParser, Namespace, RawTextHelpFormatter +from subprocess import PIPE, Popen, check_output from typing import Dict, List, Tuple content_header = """Qt for Python @VERSION is a @TYPE release. @@ -160,6 +160,7 @@ def get_commit_content(sha: str) -> str: print(err, file=sys.stderr) return out.decode("utf-8") + def git_get_sha1s(versions: List[str], pattern: str): """Return a list of SHA1s matching a pattern""" command = "git rev-list --reverse --grep '^{}'".format(pattern) @@ -187,7 +188,6 @@ def git_get_sha1s(versions: List[str], pattern: str): print(err, file=sys.stderr) pick_to_sha1 = out_e_sha1.splitlines() - return [s.decode("utf-8") for s in out_sha1.splitlines() if s not in pick_to_sha1] diff --git a/tools/debug_renamer.py b/tools/debug_renamer.py index 9f89c5617..2ae513b49 100644 --- a/tools/debug_renamer.py +++ b/tools/debug_renamer.py @@ -26,6 +26,11 @@ ## ############################################################################# +import re +import sys +from argparse import ArgumentParser, FileType, RawTextHelpFormatter +from collections import OrderedDict + DESC = """ debug_renamer.py ================ @@ -62,12 +67,6 @@ Names of objects which are already deleted should be monitored and not by chance be re-used. We need to think of a way to specify deletion. """ -import re -import sys - -from argparse import ArgumentParser, FileType, RawTextHelpFormatter -from collections import OrderedDict - def make_name(typename, name_pos): """ @@ -83,11 +82,12 @@ known_types = {} pattern = r"0x\w+\s+\S+" # hex word followed by non-WS rex = re.compile(pattern, re.IGNORECASE) + def rename_hexval(line): if not (res := rex.search(line)): return line start_pos, end_pos = res.start(), res.end() - beg, mid, end = line[:start_pos], line[start_pos : end_pos], line[end_pos:] + beg, mid, end = line[:start_pos], line[start_pos:end_pos], line[end_pos:] object_id, typename = mid.split() if int(object_id, 16) == 0: return(f"{beg}{typename}_NULL{end}") diff --git a/tools/debug_windows.py b/tools/debug_windows.py index 8ddbcebbb..3c2542a48 100644 --- a/tools/debug_windows.py +++ b/tools/debug_windows.py @@ -37,6 +37,20 @@ ## ############### +import argparse +import ctypes +import logging +import re +import subprocess +import sys +from os import path +from textwrap import dedent + +is_win = sys.platform == "win32" +if is_win: + import winreg + + EPILOG = """ This is a troubleshooting script that assists finding out which DLLs or which symbols in a DLL are missing when executing a PySide6 python @@ -61,19 +75,6 @@ https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk """ -import sys -import re -import subprocess -import ctypes -import logging -import argparse -from os import path -from textwrap import dedent - -is_win = sys.platform == "win32" -if is_win: - import winreg - def get_parser_args(): desc_msg = "Run an executable under cdb with loader snaps set." @@ -184,10 +185,10 @@ def get_appropriate_kit(kits): log.info("Found Windows kits are: {}".format(kits)) chosen_kit = {'version': "0", 'value': None} for kit in kits: - if (kit['version'] > chosen_kit['version'] and + if (kit['version'] > chosen_kit['version'] # version 8.1 is actually '81', so consider everything # above version 20, as '2.0', etc. - kit['version'] < "20"): + and kit['version'] < "20"): chosen_kit = kit first_kit = kits[0] return first_kit @@ -200,7 +201,8 @@ def get_cdb_and_gflags_path(kits): bits = 'x64' if (sys.maxsize > 2 ** 32) else 'x32' debuggers_path = path.join(first_path_path, 'Debuggers', bits) cdb_path = path.join(debuggers_path, 'cdb.exe') - if not path.exists(cdb_path): # Try for older "Debugging Tools" packages + # Try for older "Debugging Tools" packages + if not path.exists(cdb_path): debuggers_path = "C:\\Program Files\\Debugging Tools for Windows (x64)" cdb_path = path.join(debuggers_path, 'cdb.exe') @@ -229,7 +231,7 @@ def toggle_loader_snaps(executable_name, gflags_path, enable=True): output = subprocess.check_output(gflags_args, stderr=subprocess.STDOUT, universal_newlines=True) log.info(output) - except exceptions.WindowsError as e: + except WindowsError as e: log.error("\nRunning {} exited with exception: " "\n{}".format(gflags_args, e)) exit(1) @@ -244,7 +246,7 @@ def find_error_like_snippets(content): lines = content.splitlines() context_lines = 4 - def error_predicate(l): + def error_predicate(line): # A list of mostly false positives are filtered out. # For deeper inspection, the full log exists. errors = {'errorhandling', @@ -262,8 +264,8 @@ def find_error_like_snippets(content): 'ERR_get_error', ('ERROR: Module load completed but symbols could ' 'not be loaded')} - return (re.search('error', l, re.IGNORECASE) - and all(e not in l for e in errors)) + return (re.search('error', line, re.IGNORECASE) + and all(e not in line for e in errors)) for i in range(1, len(lines)): line = lines[i] diff --git a/tools/dump_metaobject.py b/tools/dump_metaobject.py index 68b89364c..619beac32 100644 --- a/tools/dump_metaobject.py +++ b/tools/dump_metaobject.py @@ -39,8 +39,7 @@ """Helper functions for formatting information on QMetaObject""" -from PySide6.QtCore import (QMetaEnum, QMetaMethod, - QMetaProperty, QMetaObject, QObject) +from PySide6.QtCore import QMetaMethod def _qbytearray_to_string(b): diff --git a/tools/example_gallery/main.py b/tools/example_gallery/main.py index 2cecab6fb..291514ab0 100644 --- a/tools/example_gallery/main.py +++ b/tools/example_gallery/main.py @@ -48,14 +48,13 @@ For the usage, simply run: since there is no special requirements. """ -from argparse import ArgumentParser, RawTextHelpFormatter import json import math import shutil +from argparse import ArgumentParser, RawTextHelpFormatter from pathlib import Path from textwrap import dedent - opt_quiet = False suffixes = { ".h": "cpp", @@ -112,7 +111,6 @@ def get_module_gallery(examples): name = e["example"] underline = f'{e["module"]}' - if e["extra"]: underline += f'/{e["extra"]}' @@ -183,7 +181,8 @@ def get_code_tabs(files, project_dir): def get_header_title(example_dir): _title = str(example_dir) - url_name = "/".join(example_dir.parts[example_dir.parts.index("examples")+1:]) + _index = example_dir.parts.index("examples") + url_name = "/".join(example_dir.parts[_index + 1:]) url = f"{BASE_URL}/{url_name}" return ( "..\n This file was auto-generated by the 'examples_gallery' " diff --git a/tools/leak_finder.py b/tools/leak_finder.py index 5b5102887..fc7850c14 100644 --- a/tools/leak_finder.py +++ b/tools/leak_finder.py @@ -90,11 +90,10 @@ These objects are real leaks if their number is growing with the probe size. For analysis, the number of new objects per type is counted. """ -import sys -import gc import array +import gc +import sys import unittest - # this comes from Python, too from test import support diff --git a/tools/license_check.py b/tools/license_check.py index 052c41ca5..fe13d0ef4 100644 --- a/tools/license_check.py +++ b/tools/license_check.py @@ -38,10 +38,9 @@ ############################################################################# import os -from pathlib import Path import subprocess import sys - +from pathlib import Path """Tool to run a license check diff --git a/tools/metaobject_dump.py b/tools/metaobject_dump.py index 5495d89ae..cfe53d15e 100644 --- a/tools/metaobject_dump.py +++ b/tools/metaobject_dump.py @@ -38,12 +38,11 @@ ############################################################################# import sys -from dump_metaobject import dump_metaobject +from dump_metaobject import dump_metaobject # Import all widget classes to enable instantiating them by type name from PySide6.QtWidgets import * - DESC = """ metaobject_dump.py <class_name> diff --git a/tools/missing_bindings/config.py b/tools/missing_bindings/config.py index 3419dfdb1..4624d4a74 100644 --- a/tools/missing_bindings/config.py +++ b/tools/missing_bindings/config.py @@ -40,65 +40,65 @@ modules_to_test = { # 6.0 - 'QtCore': 'qtcore-module.html', - 'QtGui': 'qtgui-module.html', - 'QtNetwork': 'qtnetwork-module.html', - 'QtQml': 'qtqml-module.html', - 'QtQuick': 'qtquick-module.html', - 'QtQuickWidgets': 'qtquickwidgets-module.html', - 'QtQuickControls2': 'qtquickcontrols2-module.html', - #QtQuick3D - no python bindings - 'QtSql': 'qtsql-module.html', - 'QtWidgets': 'qtwidgets-module.html', - 'QtConcurrent': 'qtconcurrent-module.html', - #QtDBUS - no python bindings - 'QtHelp': 'qthelp-module.html', - 'QtOpenGL': 'qtopengl-module.html', - 'QtPrintSupport': 'qtprintsupport-module.html', - 'QtSvg': 'qtsvg-module.html', - 'QtUiTools': 'qtuitools-module.html', - 'QtXml': 'qtxml-module.html', - 'QtTest': 'qttest-module.html', - #'QtXmlPatterns': 'qtxmlpatterns-module.html', # in Qt5 compat - 'Qt3DCore': 'qt3dcore-module.html', - 'Qt3DInput': 'qt3dinput-module.html', - 'Qt3DLogic': 'qt3dlogic-module.html', - 'Qt3DRender': 'qt3drender-module.html', - 'Qt3DAnimation': 'qt3danimation-module.html', - 'Qt3DExtras': 'qt3dextras-module.html', - #'QtNetworkAuth': 'qtnetworkauth-module.html', # no python bindings - #'QtCoAp' -- TODO - #'QtMqtt' -- TODO - #'QtOpcUA' -- TODO + 'QtCore': 'qtcore-module.html', + 'QtGui': 'qtgui-module.html', + 'QtNetwork': 'qtnetwork-module.html', + 'QtQml': 'qtqml-module.html', + 'QtQuick': 'qtquick-module.html', + 'QtQuickWidgets': 'qtquickwidgets-module.html', + 'QtQuickControls2': 'qtquickcontrols2-module.html', + # QtQuick3D - no python bindings + 'QtSql': 'qtsql-module.html', + 'QtWidgets': 'qtwidgets-module.html', + 'QtConcurrent': 'qtconcurrent-module.html', + # QtDBUS - no python bindings + 'QtHelp': 'qthelp-module.html', + 'QtOpenGL': 'qtopengl-module.html', + 'QtPrintSupport': 'qtprintsupport-module.html', + 'QtSvg': 'qtsvg-module.html', + 'QtUiTools': 'qtuitools-module.html', + 'QtXml': 'qtxml-module.html', + 'QtTest': 'qttest-module.html', + # 'QtXmlPatterns': 'qtxmlpatterns-module.html', # in Qt5 compat + 'Qt3DCore': 'qt3dcore-module.html', + 'Qt3DInput': 'qt3dinput-module.html', + 'Qt3DLogic': 'qt3dlogic-module.html', + 'Qt3DRender': 'qt3drender-module.html', + 'Qt3DAnimation': 'qt3danimation-module.html', + 'Qt3DExtras': 'qt3dextras-module.html', + # 'QtNetworkAuth': 'qtnetworkauth-module.html', # no python bindings + # 'QtCoAp' -- TODO + # 'QtMqtt' -- TODO + # 'QtOpcUA' -- TODO # 6.1 - #'QtScxml': 'qtscxml-module.html', - #'QtCharts': 'qtcharts-module.html', - #'QtDataVisualization': 'qtdatavisualization-module.html', + # 'QtScxml': 'qtscxml-module.html', + # 'QtCharts': 'qtcharts-module.html', + # 'QtDataVisualization': 'qtdatavisualization-module.html', # 6.2 'QtBluetooth': 'qtbluetooth-module.html', - #'QtPositioning': 'qtpositioning-module.html', - #'QtMultimedia': 'qtmultimedia-module.html', - #'QtRemoteObjects': 'qtremoteobjects-module.html', - #'QtSensors': 'qtsensors-module.html', - #'QtSerialPort': 'qtserialport-module.html', - #'QtWebChannel': 'qtwebchannel-module.html', - #'QtWebEngine': 'qtwebengine-module.html', - #'QtWebEngineCore': 'qtwebenginecore-module.html', - #'QtWebEngineWidgets': 'qtwebenginewidgets-module.html', - #'QtWebSockets': 'qtwebsockets-module.html', + # 'QtPositioning': 'qtpositioning-module.html', + # 'QtMultimedia': 'qtmultimedia-module.html', + # 'QtRemoteObjects': 'qtremoteobjects-module.html', + # 'QtSensors': 'qtsensors-module.html', + # 'QtSerialPort': 'qtserialport-module.html', + # 'QtWebChannel': 'qtwebchannel-module.html', + # 'QtWebEngine': 'qtwebengine-module.html', + # 'QtWebEngineCore': 'qtwebenginecore-module.html', + # 'QtWebEngineWidgets': 'qtwebenginewidgets-module.html', + # 'QtWebSockets': 'qtwebsockets-module.html', - # 6.x - #'QtSpeech': 'qtspeech-module.html', - #'QtMultimediaWidgets': 'qtmultimediawidgets-module.html', - #'QtLocation': 'qtlocation-module.html', + # 6.x + # 'QtSpeech': 'qtspeech-module.html', + # 'QtMultimediaWidgets': 'qtmultimediawidgets-module.html', + # 'QtLocation': 'qtlocation-module.html', - # Not in 6 - #'QtScriptTools': 'qtscripttools-module.html', - #'QtMacExtras': 'qtmacextras-module.html', - #'QtX11Extras': 'qtx11extras-module.html', - #'QtWinExtras': 'qtwinextras-module.html', + # Not in 6 + # 'QtScriptTools': 'qtscripttools-module.html', + # 'QtMacExtras': 'qtmacextras-module.html', + # 'QtX11Extras': 'qtx11extras-module.html', + # 'QtWinExtras': 'qtwinextras-module.html', } types_to_ignore = { diff --git a/tools/missing_bindings/main.py b/tools/missing_bindings/main.py index c2754d5bd..3aac2d5fd 100644 --- a/tools/missing_bindings/main.py +++ b/tools/missing_bindings/main.py @@ -61,7 +61,6 @@ from time import gmtime, strftime from urllib import request from bs4 import BeautifulSoup - from config import modules_to_test, types_to_ignore qt_documentation_website_prefixes = { @@ -271,7 +270,9 @@ if __name__ == "__main__": pyside_qualified_type += qt_type eval(pyside_qualified_type) - except: + except Exception as e: + print("Failed eval-in pyside qualified types") + print(f"{type(e).__name__}: {e}") missing_type = qt_type missing_types_count += 1 total_missing_types_count += 1 @@ -291,8 +292,8 @@ if __name__ == "__main__": missing_types_compared_to_pyqt += 1 total_missing_types_count_compared_to_pyqt += 1 is_present_in_pyqt = True - except: - pass + except Exception as e: + print(f"{type(e).__name__}: {e}") if args.which_missing == "all": missing_types.append(missing_type) diff --git a/tools/qtpy2cpp.py b/tools/qtpy2cpp.py index 52bff787d..3862176fc 100644 --- a/tools/qtpy2cpp.py +++ b/tools/qtpy2cpp.py @@ -37,12 +37,12 @@ ## ############################################################################# -from argparse import ArgumentParser, RawTextHelpFormatter import logging import os import sys -from qtpy2cpp_lib.visitor import ConvertVisitor +from argparse import ArgumentParser, RawTextHelpFormatter +from qtpy2cpp_lib.visitor import ConvertVisitor DESCRIPTION = "Tool to convert Python to C++" diff --git a/tools/qtpy2cpp_lib/astdump.py b/tools/qtpy2cpp_lib/astdump.py index ea37590c2..65954334c 100644 --- a/tools/qtpy2cpp_lib/astdump.py +++ b/tools/qtpy2cpp_lib/astdump.py @@ -40,12 +40,10 @@ """Tool to dump a Python AST""" -from argparse import ArgumentParser, RawTextHelpFormatter import ast -from enum import Enum -import sys import tokenize - +from argparse import ArgumentParser, RawTextHelpFormatter +from enum import Enum from nodedump import debug_format_node diff --git a/tools/qtpy2cpp_lib/formatter.py b/tools/qtpy2cpp_lib/formatter.py index a1e8c69db..2b77d3ee1 100644 --- a/tools/qtpy2cpp_lib/formatter.py +++ b/tools/qtpy2cpp_lib/formatter.py @@ -41,8 +41,6 @@ import ast -import sys - CLOSING = {"{": "}", "(": ")", "[": "]"} # Closing parenthesis for C++ diff --git a/tools/qtpy2cpp_lib/visitor.py b/tools/qtpy2cpp_lib/visitor.py index d17d5f53c..bd5fce7a1 100644 --- a/tools/qtpy2cpp_lib/visitor.py +++ b/tools/qtpy2cpp_lib/visitor.py @@ -44,12 +44,9 @@ import sys import tokenize import warnings -from .formatter import (CppFormatter, format_for_loop, - format_function_def_arguments, format_inheritance, - format_literal, format_reference, - format_start_function_call, +from .formatter import (CppFormatter, format_for_loop, format_literal, + format_reference, format_start_function_call, write_import, write_import_from) - from .nodedump import debug_format_node diff --git a/tools/regenerate_example_resources.py b/tools/regenerate_example_resources.py index 674717885..54522264d 100644 --- a/tools/regenerate_example_resources.py +++ b/tools/regenerate_example_resources.py @@ -49,7 +49,6 @@ import subprocess import sys from pathlib import Path - RCC_COMMAND = "pyside6-rcc" LRELEASE_COMMAND = "lrelease" diff --git a/tools/regenerate_example_ui.py b/tools/regenerate_example_ui.py index 5d701a5c2..44bb87117 100644 --- a/tools/regenerate_example_ui.py +++ b/tools/regenerate_example_ui.py @@ -49,7 +49,6 @@ import subprocess import sys from pathlib import Path - UIC_COMMAND = "pyside6-uic" diff --git a/tools/snippets_translate/converter.py b/tools/snippets_translate/converter.py index 8eeaee551..b437b9757 100644 --- a/tools/snippets_translate/converter.py +++ b/tools/snippets_translate/converter.py @@ -39,17 +39,15 @@ import re - -from handlers import (handle_casts, handle_class, handle_condition, +from handlers import (handle_array_declarations, handle_casts, handle_class, handle_conditions, handle_constructor_default_values, handle_constructors, handle_cout_endl, handle_emit, - handle_for, handle_foreach, handle_inc_dec, - handle_include, handle_keywords, handle_negate, - handle_type_var_declaration, handle_void_functions, - handle_methods_return_type, handle_functions, - handle_array_declarations, handle_useless_qt_classes,) - -from parse_utils import get_indent, dstrip, remove_ref + handle_for, handle_foreach, handle_functions, + handle_inc_dec, handle_include, handle_keywords, + handle_methods_return_type, handle_negate, + handle_type_var_declaration, handle_useless_qt_classes, + handle_void_functions) +from parse_utils import dstrip, get_indent, remove_ref def snippet_translate(x): @@ -260,8 +258,8 @@ def snippet_translate(x): # QSome thing = b(...) # float v = 0.1 # QSome *thing = ... - if (re.search(r"^[a-zA-Z0-9]+(<.*?>)? [\w\*]+ *= *[\w\.\"\']*(\(.*?\))?", x.strip()) and - ("{" not in x and "}" not in x)): + if (re.search(r"^[a-zA-Z0-9]+(<.*?>)? [\w\*]+ *= *[\w\.\"\']*(\(.*?\))?", x.strip()) + and ("{" not in x and "}" not in x)): left, right = x.split("=", 1) var_name = " ".join(left.strip().split()[1:]) x = f"{get_indent(x)}{remove_ref(var_name)} = {right.strip()}" @@ -295,7 +293,7 @@ def snippet_translate(x): # Arrays declarations with the form: # type var_name[] = {... # type var_name {... - #if re.search(r"^[a-zA-Z0-9]+(<.*?>)? [\w\*]+\[\] * = *\{", x.strip()): + # if re.search(r"^[a-zA-Z0-9]+(<.*?>)? [\w\*]+\[\] * = *\{", x.strip()): if re.search(r"^[a-zA-Z0-9]+(<.*?>)? [\w\*]+\[?\]? * =? *\{", x.strip()): x = handle_array_declarations(x) diff --git a/tools/snippets_translate/handlers.py b/tools/snippets_translate/handlers.py index 7da983bc4..8f58d218f 100644 --- a/tools/snippets_translate/handlers.py +++ b/tools/snippets_translate/handlers.py @@ -40,7 +40,8 @@ import re import sys -from parse_utils import get_indent, dstrip, remove_ref, parse_arguments, replace_main_commas, get_qt_module_class +from parse_utils import (dstrip, get_indent, get_qt_module_class, + parse_arguments, remove_ref, replace_main_commas) IF_PATTERN = re.compile(r'^if\s*\(') ELSE_IF_PATTERN = re.compile(r'^}?\s*else if\s*\(') @@ -92,7 +93,6 @@ def handle_inc_dec(x, operator): def handle_casts(x): - cast = None re_type = re.compile(r"<(.*)>") re_data = re.compile(r"_cast<.*>\((.*)\)") type_name = re_type.search(x) @@ -147,7 +147,6 @@ def handle_include(x): def handle_conditions(x): - x_strip = x.strip() if WHILE_PATTERN.match(x): x = handle_condition(x, "while") elif IF_PATTERN.match(x): @@ -197,7 +196,7 @@ def handle_for(x): # Malformed for-loop: # for (; pixel1 > start; pixel1 -= stride) # We return the same line - if not start.strip() or not "=" in start: + if not start.strip() or "=" not in start: return f"{get_indent(x)}{dstrip(x)}" raw_var, value = start.split("=") raw_var = raw_var.strip() @@ -490,6 +489,7 @@ def handle_class(x): else: return x + def handle_array_declarations(x): re_varname = re.compile(r"^[a-zA-Z0-9\<\>]+ ([\w\*]+) *\[?\]?") content = re_varname.search(x.strip()) @@ -499,6 +499,7 @@ def handle_array_declarations(x): x = f"{get_indent(x)}{var_name} = {{{rest_line}" return x + def handle_methods_return_type(x): re_capture = re.compile(r"^ *[a-zA-Z0-9]+ [\w]+::([\w\*\&]+\(.*\)$)") capture = re_capture.search(x) @@ -532,6 +533,7 @@ def handle_functions(x): x = f"{get_indent(x)}def {function_name}({dstrip(arguments)}):" return x + def handle_useless_qt_classes(x): _classes = ("QLatin1String", "QLatin1Char") for i in _classes: diff --git a/tools/snippets_translate/main.py b/tools/snippets_translate/main.py index 936c623b9..0f62ddabd 100644 --- a/tools/snippets_translate/main.py +++ b/tools/snippets_translate/main.py @@ -41,7 +41,6 @@ import argparse import logging import os import re -import shutil import sys from enum import Enum from pathlib import Path @@ -237,6 +236,7 @@ def get_license_from_file(filename): else: return "" + def translate_file(file_path, final_path, debug, write): with open(str(file_path)) as f: snippets = get_snippets(f.read().splitlines()) @@ -298,7 +298,6 @@ def translate_file(file_path, final_path, debug, write): log.warning("No snippets were found") - def copy_file(file_path, qt_path, out_path, write=False, debug=False): # Replicate the Qt path including module under the PySide snippets directory diff --git a/tools/snippets_translate/parse_utils.py b/tools/snippets_translate/parse_utils.py index d82108355..b4ee5f3ff 100644 --- a/tools/snippets_translate/parse_utils.py +++ b/tools/snippets_translate/parse_utils.py @@ -38,6 +38,7 @@ ############################################################################# import re + from module_classes import module_classes @@ -68,6 +69,7 @@ def get_qt_module_class(x): def get_indent(x): return " " * (len(x) - len(x.lstrip())) + # Remove more than one whitespace from the code, but not considering # the indentation. Also removes '&', '*', and ';' from arguments. def dstrip(x): @@ -141,4 +143,3 @@ def replace_main_commas(v): new_v += c return new_v - diff --git a/tools/uic_test.py b/tools/uic_test.py index 5f8a786a9..c889f2c05 100644 --- a/tools/uic_test.py +++ b/tools/uic_test.py @@ -47,7 +47,6 @@ from pathlib import Path from textwrap import dedent from typing import Optional, Tuple - VERSION = 6 @@ -59,15 +58,15 @@ TEMP_DIR = Path(tempfile.gettempdir()) def get_class_name(file: Path) -> Tuple[Optional[str], Optional[str]]: """Return class name and widget name of UI file.""" - pattern = re.compile('^\s*<widget class="(\w+)" name="(\w+)"\s*>.*$') - for l in Path(file).read_text().splitlines(): - match = pattern.match(l) + pattern = re.compile(r'^\s*<widget class="(\w+)" name="(\w+)"\s*>.*$') + for line in Path(file).read_text().splitlines(): + match = pattern.match(line) if match: return (match.group(1), match.group(2)) return (None, None) -def test_file(file: str, uic: bool=False) -> bool: +def test_file(file: str, uic: bool = False) -> bool: """Run uic on a UI file and show the resulting UI.""" path = Path(file) (klass, name) = get_class_name(path) |