aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdrian Herrmann <[email protected]>2024-06-06 12:44:22 +0200
committerAdrian Herrmann <[email protected]>2024-06-21 12:43:56 +0200
commit12e370d38ab0f88c6ae555793ed5ac6a18343255 (patch)
tree28b5a25972f7ceec46eb69e73dcd930580ea3c94
parenta5308626119ed39a9a367117aa4a16c1a3970185 (diff)
Fix flake8 and typing issues
Fix a number of miscellaneous flake8 and typing issues exposed after updating to the modern typing syntax from 3.10 onwards. Task-number: PYSIDE-2786 Change-Id: I5476d1208dd1da3fa93bdec02bc6124a80b247fc Reviewed-by: Christian Tismer <[email protected]>
-rw-r--r--build_scripts/qfp_tool.py10
-rw-r--r--create_wheels.py8
-rw-r--r--sources/pyside-tools/deploy_lib/android/android_config.py2
-rw-r--r--sources/pyside-tools/metaobjectdump.py2
-rw-r--r--tools/create_changelog.py4
-rw-r--r--tools/cross_compile_android/android_utilities.py9
-rw-r--r--tools/snippets_translate/main.py14
-rw-r--r--tools/uic_test.py2
8 files changed, 29 insertions, 22 deletions
diff --git a/build_scripts/qfp_tool.py b/build_scripts/qfp_tool.py
index 153712d89..916959c8e 100644
--- a/build_scripts/qfp_tool.py
+++ b/build_scripts/qfp_tool.py
@@ -172,7 +172,7 @@ def edit_config_file():
"""
Config file handling, cache and read function
"""
-config_dict = {}
+config_dict: dict = {}
def read_config_file(file_name):
@@ -263,15 +263,15 @@ def read_config_python_binary() -> str:
def get_config_file(base_name) -> Path:
global user
- home = os.getenv('HOME')
+ home = os.getenv('HOME', default="")
if IS_WINDOWS:
# Set a HOME variable on Windows such that scp. etc.
# feel at home (locating .ssh).
if not home:
- home = os.getenv('HOMEDRIVE') + os.getenv('HOMEPATH')
+ home = os.getenv('HOMEDRIVE', default="") + os.getenv('HOMEPATH', default="")
os.environ['HOME'] = home
user = os.getenv('USERNAME')
- config_file = Path(os.getenv('APPDATA')) / base_name
+ config_file = Path(os.getenv('APPDATA', default="")) / base_name
else:
user = os.getenv('USER')
config_dir = Path(home) / '.config'
@@ -290,7 +290,7 @@ def build(target: str):
acceleration = read_acceleration_config()
if not IS_WINDOWS and acceleration == Acceleration.INCREDIBUILD:
arguments.append(INCREDIBUILD_CONSOLE)
- arguments.appendh('--avoid') # caching, v0.96.74
+ arguments.append('--avoid') # caching, v0.96.74
arguments.extend([read_config_python_binary(), 'setup.py', target])
build_arguments = read_config_build_arguments()
if opt_verbose and LOG_LEVEL_OPTION in build_arguments:
diff --git a/create_wheels.py b/create_wheels.py
index e7fbc52cf..45e3ad9ca 100644
--- a/create_wheels.py
+++ b/create_wheels.py
@@ -29,13 +29,13 @@ PYSIDE_DESCRIPTION = "Python bindings for the Qt cross-platform application and
@dataclass
class SetupData:
name: str
- version: str
+ version: tuple[str, str]
description: str
readme: str
console_scripts: list[str]
-def get_version_from_package(name: str, package_path: Path) -> str:
+def get_version_from_package(name: str, package_path: Path) -> tuple[str, str]:
# Get version from the already configured '__init__.py' file
version = ""
with open(package_path / name / "__init__.py") as f:
@@ -122,7 +122,11 @@ def get_platform_tag() -> str:
module_name = config_py.name[:-3]
_spec = importlib.util.spec_from_file_location(f"{module_name}", config_py)
+ if _spec is None:
+ raise RuntimeError(f"Unable to create ModuleSpec from {str(config_py)}")
_module = importlib.util.module_from_spec(_spec)
+ if _spec.loader is None:
+ raise RuntimeError(f"ModuleSpec for {module_name} has no valid loader.")
_spec.loader.exec_module(module=_module)
target = _module.__qt_macos_min_deployment_target__
diff --git a/sources/pyside-tools/deploy_lib/android/android_config.py b/sources/pyside-tools/deploy_lib/android/android_config.py
index 4cca7dfb6..72ae1d409 100644
--- a/sources/pyside-tools/deploy_lib/android/android_config.py
+++ b/sources/pyside-tools/deploy_lib/android/android_config.py
@@ -349,7 +349,7 @@ class AndroidConfig(Config):
self._dependency_files.append(dependency_file)
logging.info("[DEPLOY] The following dependency files were found: "
- f"{*self._dependency_files,}")
+ f"{*self._dependency_files, }")
def _find_local_libs(self):
local_libs = set()
diff --git a/sources/pyside-tools/metaobjectdump.py b/sources/pyside-tools/metaobjectdump.py
index bab4e1c46..d14c3334a 100644
--- a/sources/pyside-tools/metaobjectdump.py
+++ b/sources/pyside-tools/metaobjectdump.py
@@ -116,7 +116,7 @@ def _parse_call_args(call: ast.Call):
"""Parse arguments of a Signal call/Slot decorator (type list)."""
result: Arguments = []
for n, arg in enumerate(call.args):
- par_name = f"a{n+1}"
+ par_name = f"a{n + 1}"
par_type = _parse_pyside_type(arg)
result.append({"name": par_name, "type": par_type})
return result
diff --git a/tools/create_changelog.py b/tools/create_changelog.py
index 6e3e3b1f7..a0d49d83c 100644
--- a/tools/create_changelog.py
+++ b/tools/create_changelog.py
@@ -232,7 +232,7 @@ def git_command(versions: list[str], pattern: str):
task_number_match = task_number_re.match(task)
if task_number_match:
task_number = int(task_number_match.group(1))
- entry = {"title": title, "task": task, "task-number": task_number}
+ entry = {"title": title, "task": task, "task-number": str(task_number)}
if "shiboken" in title:
if sha not in shiboken6_commits:
shiboken6_commits[sha] = entry
@@ -310,7 +310,7 @@ def gen_list(d: dict[str, dict[str, str]]) -> str:
def sort_dict(d: dict[str, dict[str, str]]) -> dict[str, dict[str, str]]:
- return dict(sorted(d.items(), key=lambda kv: kv[1]['task-number']))
+ return dict(sorted(d.items(), key=lambda kv: int(kv[1]['task-number'])))
def sort_changelog(c: list[tuple[int, str]]) -> list[tuple[int, str]]:
diff --git a/tools/cross_compile_android/android_utilities.py b/tools/cross_compile_android/android_utilities.py
index 7f2047a7e..0650bdc41 100644
--- a/tools/cross_compile_android/android_utilities.py
+++ b/tools/cross_compile_android/android_utilities.py
@@ -99,16 +99,19 @@ def extract_zip(file: Path, destination: Path):
raise RuntimeError("Unable to find program unzip. Use `sudo apt-get install unzip`"
"to install it")
- command = [unzip, file, "-d", destination]
+ command = [unzip, str(file), "-d", str(destination)]
run_command(command=command, show_stdout=True)
def extract_dmg(file: Path, destination: Path):
- output = run_command(['hdiutil', 'attach', '-nobrowse', '-readonly', file],
+ output = run_command(['hdiutil', 'attach', '-nobrowse', '-readonly', str(file)],
show_stdout=True, capture_stdout=True)
# find the mounted volume
- mounted_vol_name = re.search(r'/Volumes/(.*)', output).group(1)
+ result = re.search(r'/Volumes/(.*)', output)
+ if not result:
+ raise RuntimeError(f"Unable to find mounted volume for file {file}")
+ mounted_vol_name = result.group(1)
if not mounted_vol_name:
raise RuntimeError(f"Unable to find mounted volume for file {file}")
diff --git a/tools/snippets_translate/main.py b/tools/snippets_translate/main.py
index faa07a0b0..9e63dd8d0 100644
--- a/tools/snippets_translate/main.py
+++ b/tools/snippets_translate/main.py
@@ -201,7 +201,7 @@ def overriden_snippet_lines(lines: list[str], start_id: str) -> list[str]:
return result
-def get_snippet_override(start_id: str, rel_path: str) -> list[str]:
+def get_snippet_override(start_id: str, rel_path: Path) -> list[str]:
"""Check if the snippet is overridden by a local file under
sources/pyside6/doc/snippets."""
file_start_id = start_id.replace(' ', '_')
@@ -243,14 +243,14 @@ def _get_snippets(lines: list[str],
# Find the end of the snippet
j = i
while j < len(lines):
- l = lines[j]
+ line = lines[j]
j += 1
# Add the line to the snippet
- snippet.append(l)
+ snippet.append(line)
# Check if the snippet is complete
- if start_id in get_snippet_ids(l, pattern):
+ if start_id in get_snippet_ids(line, pattern):
# End of snippet
snippet[len(snippet) - 1] = id_line
snippets[start_id] = snippet
@@ -259,7 +259,7 @@ def _get_snippets(lines: list[str],
return snippets
-def get_python_example_snippet_override(start_id: str, rel_path: str) -> list[str]:
+def get_python_example_snippet_override(start_id: str, rel_path: Path) -> list[str]:
"""Check if the snippet is overridden by a python example snippet."""
key = (os.fspath(rel_path), start_id)
value = python_example_snippet_mapping().get(key)
@@ -275,7 +275,7 @@ def get_python_example_snippet_override(start_id: str, rel_path: str) -> list[st
return overriden_snippet_lines(lines, start_id)
-def get_snippets(lines: list[str], rel_path: str) -> list[list[str]]:
+def get_snippets(lines: list[str], rel_path: Path) -> list[list[str]]:
"""Extract (potentially overlapping) snippets from a C++ file indicated
by '//! [1]'."""
result = _get_snippets(lines, '//', CPP_SNIPPET_PATTERN)
@@ -288,7 +288,7 @@ def get_snippets(lines: list[str], rel_path: str) -> list[list[str]]:
if snippet:
result[snippet_id] = snippet
- return result.values()
+ return list(result.values())
def get_license_from_file(lines):
diff --git a/tools/uic_test.py b/tools/uic_test.py
index c0f293ef3..eccddae97 100644
--- a/tools/uic_test.py
+++ b/tools/uic_test.py
@@ -78,7 +78,7 @@ if __name__ == '__main__':
failed = 0
count = len(options.files)
for i, file in enumerate(options.files):
- print(f'{i+1}/{count} {file}')
+ print(f'{i + 1}/{count} {file}')
if not test_file(file, options.uic):
failed += 1
if failed != 0: