aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrik Teivonen <patrik.teivonen@qt.io>2022-09-19 13:56:08 +0300
committerPatrik Teivonen <patrik.teivonen@qt.io>2023-01-24 08:16:22 +0000
commitaf577fe8782e18188273e48c3ce3f475ac2debf4 (patch)
treeee765420a3668a22ce476485ae82421f25c79fdd
parente1ade868e5aa13abc368444c582a0de762204ff2 (diff)
PL122: os.path.splitext("foo.bar") should be replaced by path.suffix
os.path.split and os.path.splitext to pathlib equivalents adjust bldinstallercommon.calculate_relpath unit tests Change-Id: Ieb49864ed4f804cfdff61492edfb622ce1c4a9dc Reviewed-by: Antti Kokko <antti.kokko@qt.io>
-rw-r--r--.pre-commit-config.yaml2
-rw-r--r--packaging-tools/bld_openssl.py6
-rw-r--r--packaging-tools/bld_sdktool.py12
-rw-r--r--packaging-tools/bld_utils.py21
-rw-r--r--packaging-tools/bldinstallercommon.py6
-rw-r--r--packaging-tools/build_clang.py15
-rw-r--r--packaging-tools/build_clang_qdoc.py15
-rw-r--r--packaging-tools/build_wrapper.py2
-rw-r--r--packaging-tools/dump_debug_infos.py13
-rwxr-xr-xpackaging-tools/release_repo_updater.py16
-rw-r--r--packaging-tools/tests/test_bldinstallercommon.py27
-rw-r--r--packaging-tools/tests/test_sdkcomponent.py13
12 files changed, 71 insertions, 77 deletions
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 52caa6f9a..192220ce9 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -15,7 +15,7 @@ repos:
# Disable E203 for compatibility with blackformatter, and W503 as it goes against PEP8
# Disable checks that are not relevant to this patch, they will be introduced later
# - pathlib checks PLXXX
- entry: pipenv run python3 -m flake8 --max-line-length=99 --ignore=E203,E501,W503,PL100,PL102,PL103,PL104,PL106,PL107,PL110,PL112,PL113,PL114,PL115,PL116,PL117,PL118,PL120,PL122,PL123
+ entry: pipenv run python3 -m flake8 --max-line-length=99 --ignore=E203,E501,W503,PL100,PL102,PL103,PL104,PL106,PL107,PL110,PL112,PL113,PL114,PL115,PL116,PL117,PL118,PL120,PL123
language: system
types: [python]
fail_fast: true
diff --git a/packaging-tools/bld_openssl.py b/packaging-tools/bld_openssl.py
index 58f951c63..9210a0e65 100644
--- a/packaging-tools/bld_openssl.py
+++ b/packaging-tools/bld_openssl.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
#############################################################################
#
-# Copyright (C) 2022 The Qt Company Ltd.
+# Copyright (C) 2023 The Qt Company Ltd.
# Contact: http://www.qt-project.org/legal
#
# This file is part of the release tools of the Qt Toolkit.
@@ -57,8 +57,8 @@ def build(src_dir: str, install_dir: str, toolset: str) -> None:
def archive(install_dir: str, archive_prefix: str) -> None:
- (directory, name) = os.path.split(install_dir)
- run_cmd(cmd=["7z", "a", archive_prefix + ".7z", name], cwd=directory)
+ install_path = Path(install_dir)
+ run_cmd(cmd=["7z", "a", archive_prefix + ".7z", install_path.name], cwd=install_path.parent)
run_cmd(cmd=["7z", "a", archive_prefix + "-runtime.7z", "*.dll"], cwd=Path(install_dir, "bin"))
diff --git a/packaging-tools/bld_sdktool.py b/packaging-tools/bld_sdktool.py
index 2bc6f40f6..55ca0f5ad 100644
--- a/packaging-tools/bld_sdktool.py
+++ b/packaging-tools/bld_sdktool.py
@@ -3,7 +3,7 @@
#############################################################################
#
-# Copyright (C) 2022 The Qt Company Ltd.
+# Copyright (C) 2023 The Qt Company Ltd.
# Contact: https://www.qt.io/licensing/
#
# This file is part of the release tools of the Qt Toolkit.
@@ -73,14 +73,12 @@ def get_qt_build_path(qt_build_base: str) -> str:
def package_extension(url: str) -> str:
- if url.endswith('.tar.gz'):
+ url_path = Path(url)
+ if url_path.suffixes[-2:] == [".tar", ".gz"]:
return '.tar.gz'
- if url.endswith('.zip'):
- return '.zip'
- if url.endswith('.tar.xz'):
+ if url_path.suffixes[-2:] == [".tar", ".xz"]:
return '.tar.xz'
- (_, ext) = os.path.splitext(url)
- return ext
+ return Path(url).suffix
def get_and_extract_qt_src(url: str, temp: str, path: str) -> None:
diff --git a/packaging-tools/bld_utils.py b/packaging-tools/bld_utils.py
index 730746b79..9be6e8c7e 100644
--- a/packaging-tools/bld_utils.py
+++ b/packaging-tools/bld_utils.py
@@ -84,32 +84,33 @@ def deep_copy_arguments(to_call: Any) -> Any:
class DirRenamer():
def __init__(self, path: str, new_name: str) -> None:
- self.old_name = path
- self.new_name = os.path.join(os.path.split(path)[0], new_name)
+ self.old_name = Path(path)
+ self.new_name = Path(path).with_name(new_name)
log.info("self.old_name: %s", self.old_name)
log.info("self.new_name: %s", self.new_name)
def __enter__(self) -> None:
if self.old_name != self.new_name:
- os.rename(self.old_name, self.new_name)
+ self.old_name.rename(self.new_name)
def __exit__(self, etype: Any, value: Any, etraceback: Any) -> None:
if self.old_name != self.new_name:
- os.rename(self.new_name, self.old_name)
+ self.new_name.rename(self.old_name)
def compress(path: str, directory_name: str, sevenzip_target: str) -> None:
sevenzip_extension = os.extsep + '7z'
+ sevenzip_target_path = Path(sevenzip_target)
parent_directory_path = os.path.abspath(os.path.join(path, '..'))
- if os.path.splitext(sevenzip_target)[1] != sevenzip_extension:
- sevenzip_target = sevenzip_target + sevenzip_extension
- sevenzip_filename = os.path.split(sevenzip_target)[1]
+ if sevenzip_target_path.suffix != sevenzip_extension:
+ sevenzip_target_path.with_suffix(sevenzip_extension)
+ sevenzip_filename = sevenzip_target_path.name
with DirRenamer(path, directory_name):
run_command(' '.join(('7z a -mx9', sevenzip_filename, directory_name)), parent_directory_path)
- current_sevenzip_path = os.path.join(parent_directory_path, sevenzip_filename)
- if current_sevenzip_path != sevenzip_target:
- shutil.move(current_sevenzip_path, sevenzip_target)
+ current_sevenzip_path = Path(parent_directory_path, sevenzip_filename)
+ if current_sevenzip_path != sevenzip_target_path:
+ shutil.move(current_sevenzip_path, sevenzip_target_path)
def strip_vars(sobject: Namespace, chars: str) -> None:
diff --git a/packaging-tools/bldinstallercommon.py b/packaging-tools/bldinstallercommon.py
index 9c25d5745..b1e1475cd 100644
--- a/packaging-tools/bldinstallercommon.py
+++ b/packaging-tools/bldinstallercommon.py
@@ -386,7 +386,9 @@ def sanity_check_rpath_max_length(file_path: str, new_rpath: str) -> bool:
###############################
def pathsplit(path: str, rest: Optional[List[str]] = None) -> List[str]:
rest = rest or []
- (head, tail) = os.path.split(path)
+ split_path = Path(path)
+ head = str(split_path.parent)
+ tail = split_path.name
if len(head) < 1:
return [tail] + rest
if len(tail) < 1:
@@ -412,7 +414,7 @@ def calculate_relpath(path1: str, path2: str) -> str:
tmp = '..' + os.sep
path = [tmp * len(list1)]
path = path + list2
- return os.path.join(*path)
+ return str(Path(*path))
##############################################################
diff --git a/packaging-tools/build_clang.py b/packaging-tools/build_clang.py
index 0c6d145a3..4247b7b16 100644
--- a/packaging-tools/build_clang.py
+++ b/packaging-tools/build_clang.py
@@ -3,7 +3,7 @@
#############################################################################
#
-# Copyright (C) 2022 The Qt Company Ltd.
+# Copyright (C) 2023 The Qt Company Ltd.
# Contact: https://www.qt.io/licensing/
#
# This file is part of the release tools of the Qt Toolkit.
@@ -31,6 +31,7 @@
import os
from contextlib import suppress
+from pathlib import Path
from shutil import rmtree
from subprocess import CalledProcessError
from typing import Dict, List, Optional
@@ -475,16 +476,16 @@ def check_clang(toolchain: str, build_path: str, env: Optional[Dict[str, str]])
def package_clang(install_path: str, result_file_path: str) -> None:
- (basepath, dirname) = os.path.split(install_path)
- zip_command = ['7z', 'a', '-mmt4', result_file_path, dirname]
- run_command(zip_command, basepath)
+ install_dir = Path(install_path)
+ zip_command = ['7z', 'a', '-mmt4', result_file_path, install_dir.name]
+ run_command(zip_command, cwd=str(install_dir.parent))
def upload_clang(file_path: str, remote_path: str) -> None:
- (path, filename) = os.path.split(file_path)
+ local_path = Path(file_path)
scp_bin = '%SCP%' if is_windows() else 'scp'
- scp_command = [scp_bin, filename, remote_path]
- run_command(scp_command, path)
+ scp_command = [scp_bin, local_path.name, remote_path]
+ run_command(scp_command, cwd=str(local_path.parent))
def profile_data(toolchain: str) -> Optional[str]:
diff --git a/packaging-tools/build_clang_qdoc.py b/packaging-tools/build_clang_qdoc.py
index d4d9f78df..97377032a 100644
--- a/packaging-tools/build_clang_qdoc.py
+++ b/packaging-tools/build_clang_qdoc.py
@@ -3,7 +3,7 @@
#############################################################################
#
-# Copyright (C) 2022 The Qt Company Ltd.
+# Copyright (C) 2023 The Qt Company Ltd.
# Contact: https://www.qt.io/licensing/
#
# This file is part of the release tools of the Qt Toolkit.
@@ -31,6 +31,7 @@
import os
from contextlib import suppress
+from pathlib import Path
from subprocess import CalledProcessError
from typing import Dict, List, Optional
@@ -251,16 +252,16 @@ def check_clang(toolchain: str, build_path: str, environment: Optional[Dict[str,
def package_clang(install_path: str, result_file_path: str) -> None:
- (basepath, dirname) = os.path.split(install_path)
- zip_command = ['cmake', '-E', 'tar', 'cvf', result_file_path, '--format=7zip', dirname]
- run_command(zip_command, basepath)
+ install_dir = Path(install_path)
+ zip_cmd = ['cmake', '-E', 'tar', 'cvf', result_file_path, '--format=7zip', install_dir.name]
+ run_command(zip_cmd, cwd=str(install_dir.parent))
def upload_clang(file_path: str, remote_path: str) -> None:
- (path, filename) = os.path.split(file_path)
+ local_path = Path(file_path)
scp_bin = '%SCP%' if is_windows() else 'scp'
- scp_command = [scp_bin, filename, remote_path]
- run_command(scp_command, path)
+ scp_command = [scp_bin, local_path.name, remote_path]
+ run_command(scp_command, cwd=str(local_path.parent))
def main() -> None:
diff --git a/packaging-tools/build_wrapper.py b/packaging-tools/build_wrapper.py
index ffb280430..a31f3138e 100644
--- a/packaging-tools/build_wrapper.py
+++ b/packaging-tools/build_wrapper.py
@@ -234,7 +234,7 @@ def create_download_documentation_task(
def create_download_openssl_task(url: str, download_path: str) -> Tuple[Task, Task, str]:
# create openssl 7zips which just contain the DLLs / SOs, so they can just be extracted
# into the Qt lib directory and later on deployed with Qt
- (_, filename) = os.path.split(url)
+ filename = Path(url).name
download_filepath = os.path.join(download_path, filename)
extract_path = os.path.join(download_path, 'openssl_download')
target_filepath = os.path.join(download_path, 'openssl.7z')
diff --git a/packaging-tools/dump_debug_infos.py b/packaging-tools/dump_debug_infos.py
index 4d2d0381a..391b9aab5 100644
--- a/packaging-tools/dump_debug_infos.py
+++ b/packaging-tools/dump_debug_infos.py
@@ -3,7 +3,7 @@
#############################################################################
#
-# Copyright (C) 2022 The Qt Company Ltd.
+# Copyright (C) 2023 The Qt Company Ltd.
# Contact: https://www.qt.io/licensing/
#
# This file is part of the release tools of the Qt Toolkit.
@@ -33,6 +33,7 @@ import argparse
import os
import subprocess
import sys
+from pathlib import Path
from shutil import rmtree
from typing import List
@@ -44,10 +45,10 @@ log = init_logger(__name__, debug_mode=False)
def is_file_with_debug_information_windows(path: str) -> bool:
if not path.endswith('.pdb'):
return False
- base_path, _ = os.path.splitext(path)
- pdb = base_path + '.pdb'
- exe = base_path + '.exe'
- dll = base_path + '.dll'
+ base_path = Path(path)
+ pdb = base_path.with_suffix('.pdb')
+ exe = base_path.with_suffix('.exe')
+ dll = base_path.with_suffix('.dll')
if os.path.isfile(pdb) and (os.path.isfile(exe) or os.path.isfile(dll)):
return True
return False
@@ -98,7 +99,7 @@ def dump_syms(
for filename in filenames:
absolute_path = os.path.join(root, filename).replace("\\", "/")
if is_file_with_debug_information(absolute_path):
- base_path, _ = os.path.splitext(absolute_path)
+ base_path = str(Path(absolute_path).with_suffix(""))
start_slash = 1
sym_path_base = base_path[start_slash + len(search_path):].replace("/", "_")
sym_filename = f"{sym_path_base}.sym"
diff --git a/packaging-tools/release_repo_updater.py b/packaging-tools/release_repo_updater.py
index 0596af1ae..8abe796fd 100755
--- a/packaging-tools/release_repo_updater.py
+++ b/packaging-tools/release_repo_updater.py
@@ -688,7 +688,7 @@ def update_remote_latest_available_dir(new_installer: str, remote_upload_path: s
log.info("Update latest available installer directory: %s", remote_upload_path)
regex = re.compile('.*' + task.get_version())
new_installer_base_path = "".join(regex.findall(new_installer))
- _, name = os.path.split(new_installer_base_path)
+ name = Path(new_installer_base_path).name
# update latest_available
latest_available_path = re.sub(r"\/" + str(installer_build_id) + r"\/", "/latest_available/", remote_upload_path)
@@ -707,9 +707,11 @@ def update_remote_latest_available_dir(new_installer: str, remote_upload_path: s
def upload_offline_to_remote(installer_path: str, remote_upload_path: str, staging_server: str, task: ReleaseTask,
installer_build_id: str, enable_oss_snapshots: bool, license_: str) -> None:
for file in os.listdir(installer_path):
- if file.endswith(".app"):
+ file_path = Path(file)
+ file_ext = file_path.suffix
+ if file_ext == ".app":
continue
- name, file_ext = os.path.splitext(file)
+ name = str(file_path.with_suffix(""))
file_name_final = name + "_" + installer_build_id + file_ext
installer = os.path.join(installer_path, file_name_final)
os.rename(os.path.join(installer_path, file), installer)
@@ -832,11 +834,9 @@ def upload_snapshots_to_remote(staging_server: str, remote_upload_path: str, tas
version_minor = version_minor_match[0]
else:
raise PackagingError(f"Could not determine minor version from {version_full}")
- base, last_dir = os.path.split(get_pkg_value("SNAPSHOT_PATH").rstrip("/"))
- if last_dir == project_name:
- snapshot_path = get_pkg_value("SNAPSHOT_PATH")
- else:
- snapshot_path = os.path.join(base, project_name)
+ snapshot_path = Path(get_pkg_value("SNAPSHOT_PATH"))
+ if snapshot_path.name != project_name:
+ snapshot_path = snapshot_path.with_name(project_name)
snapshot_upload_path = os.path.join(snapshot_path, version_minor, version_full + task.get_prerelease_version(), installer_build_id)
remote_installer_path = os.path.join(remote_upload_path, installer_filename)
if platform.system() == "Windows":
diff --git a/packaging-tools/tests/test_bldinstallercommon.py b/packaging-tools/tests/test_bldinstallercommon.py
index f6816a76e..88c068b81 100644
--- a/packaging-tools/tests/test_bldinstallercommon.py
+++ b/packaging-tools/tests/test_bldinstallercommon.py
@@ -208,35 +208,28 @@ class TestCommon(unittest.TestCase):
@data( # type: ignore
("/home/qt/bin/foo/bar", "/home/qt/lib", "../../../lib"),
- ("/home/qt/bin/foo/", "/home/qt/lib", "/home/qt/lib"),
+ ("/home/qt/bin/foo/", "/home/qt/lib", "../../lib"),
("/home/qt/bin", "/home/qt/lib", "../lib"),
("/home/qt/bin", "lib", "../../../../lib"),
("/home/qt/bin", "/lib", "../../../lib"),
- ("/home/qt", "./lib", "../../.././lib"),
+ ("/home/qt", "./lib", "../../../lib"),
("bin", "/home/qt/lib", "/home/qt/lib"),
- ("/home/qt/", "/home/qt", "/home/qt"),
- ("/home/qt", "/home/qt/", "/home/qt"),
- ("/home/qt", "/home/qt/", "/home/qt"),
+ ("/home/qt/", "/home/qt", "."),
+ ("/home/qt", "/home/qt/", "."),
+ ("/home/qt", "/home/qt/", "."),
+ ("/home/qt", "/home/qt", "."),
("/", "/home/qt", "home/qt"),
- ("/home/qt", "", "../../../"),
+ ("/home/qt", "", "../../.."),
("", "/home/qt", "/home/qt"),
+ ("lib", "lib", "."),
+ ("/", "/", "."),
+ ("", "", "."),
)
def test_calculate_relpath(self, test_data: Tuple[str, str, str]) -> None:
path1, path2, expected = test_data
result = calculate_relpath(path1, path2)
self.assertEqual(result, expected)
- @data( # type: ignore
- ("/home/qt", "/home/qt"),
- ("/", "/"),
- ("lib", "lib"),
- ("", ""),
- )
- def test_calculate_relpath_invalid(self, test_data: Tuple[str, str]) -> None:
- path1, path2 = test_data
- with self.assertRaises(TypeError):
- calculate_relpath(path1, path2)
-
if __name__ == "__main__":
unittest.main()
diff --git a/packaging-tools/tests/test_sdkcomponent.py b/packaging-tools/tests/test_sdkcomponent.py
index 9d71dd6c3..86a94973b 100644
--- a/packaging-tools/tests/test_sdkcomponent.py
+++ b/packaging-tools/tests/test_sdkcomponent.py
@@ -28,7 +28,6 @@
#
#############################################################################
-import os
import sys
import unittest
from configparser import ConfigParser, ExtendedInterpolation
@@ -100,13 +99,11 @@ def ifw_pkg_templ_dirs(ifw_pkg_names: List[str]) -> List[str]:
def create_paths(root_folder: str, paths: List[str]) -> List[str]:
ret: List[str] = []
for item in paths:
- full_path = os.path.join(root_folder, item)
- ret.append(full_path)
- head, tail = os.path.split(full_path)
- os.makedirs(head, exist_ok=True)
- if tail:
- with open(full_path, "a", encoding="utf-8"):
- pass
+ full_path = Path(root_folder, item)
+ ret.append(str(full_path))
+ full_path.parent.mkdir(parents=True, exist_ok=True)
+ if full_path.name:
+ full_path.touch(exist_ok=True)
return ret