aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside-tools/project/utils.py
diff options
context:
space:
mode:
authorJaime Resano <Jaime.Resano-Aisa@qt.io>2025-01-21 11:17:07 +0100
committerJaime Resano <Jaime.Resano-Aisa@qt.io>2025-01-22 22:46:43 +0100
commit23b7ff61fb899ef8ae305df134d2c0968dce1fa2 (patch)
tree15f5a0afdf5335b883f531d5824d8994306625b4 /sources/pyside-tools/project/utils.py
parent30f8707e1c677e3a42a93d1b2b17bd563b9de847 (diff)
pyside6-deploy: 3. Rename project folder to project_lib
This is a refactor in order to improve the code clarity. In the testing of the pyside6-project command, importlib.import_module is used to import the project_lib folder. Currently, importlib.import_module("project") is ambiguous because it may refer to both the file and the folder. It chooses the folder over the file. Task-number: PYSIDE-1612 Pick-to: 6.8 Change-Id: I8903ea9d2112cf2eb7a68d0e302d3c74edcf2c22 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside-tools/project/utils.py')
-rw-r--r--sources/pyside-tools/project/utils.py107
1 files changed, 0 insertions, 107 deletions
diff --git a/sources/pyside-tools/project/utils.py b/sources/pyside-tools/project/utils.py
deleted file mode 100644
index a2d91375b..000000000
--- a/sources/pyside-tools/project/utils.py
+++ /dev/null
@@ -1,107 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
-from __future__ import annotations
-
-import sys
-import subprocess
-from pathlib import Path
-
-from . import QTPATHS_CMD, PROJECT_FILE_SUFFIX, ClOptions
-
-
-def run_command(command: list[str], cwd: str = None, ignore_fail: bool = False):
- """Run a command observing quiet/dry run"""
- cloptions = ClOptions()
- if not cloptions.quiet or cloptions.dry_run:
- print(" ".join(command))
- if not cloptions.dry_run:
- ex = subprocess.call(command, cwd=cwd)
- if ex != 0 and not ignore_fail:
- sys.exit(ex)
-
-
-def requires_rebuild(sources: list[Path], artifact: Path) -> bool:
- """Returns whether artifact needs to be rebuilt depending on sources"""
- if not artifact.is_file():
- return True
- artifact_mod_time = artifact.stat().st_mtime
- for source in sources:
- if source.stat().st_mtime > artifact_mod_time:
- return True
- return False
-
-
-def _remove_path_recursion(path: Path):
- """Recursion to remove a file or directory."""
- if path.is_file():
- path.unlink()
- elif path.is_dir():
- for item in path.iterdir():
- _remove_path_recursion(item)
- path.rmdir()
-
-
-def remove_path(path: Path):
- """Remove path (file or directory) observing opt_dry_run."""
- cloptions = ClOptions()
- if not path.exists():
- return
- if not cloptions.quiet:
- print(f"Removing {path.name}...")
- if cloptions.dry_run:
- return
- _remove_path_recursion(path)
-
-
-def package_dir() -> Path:
- """Return the PySide6 root."""
- return Path(__file__).resolve().parents[2]
-
-
-_qtpaths_info: dict[str, str] = {}
-
-
-def qtpaths() -> dict[str, str]:
- """Run qtpaths and return a dict of values."""
- global _qtpaths_info
- if not _qtpaths_info:
- output = subprocess.check_output([QTPATHS_CMD, "--query"])
- for line in output.decode("utf-8").split("\n"):
- tokens = line.strip().split(":", maxsplit=1) # "Path=C:\..."
- if len(tokens) == 2:
- _qtpaths_info[tokens[0]] = tokens[1]
- return _qtpaths_info
-
-
-_qt_metatype_json_dir: Path | None = None
-
-
-def qt_metatype_json_dir() -> Path:
- """Return the location of the Qt QML metatype files."""
- global _qt_metatype_json_dir
- if not _qt_metatype_json_dir:
- qt_dir = package_dir()
- if sys.platform != "win32":
- qt_dir /= "Qt"
- metatypes_dir = qt_dir / "metatypes"
- if metatypes_dir.is_dir(): # Fully installed case
- _qt_metatype_json_dir = metatypes_dir
- else:
- # Fallback for distro builds/development.
- print(
- f"Falling back to {QTPATHS_CMD} to determine metatypes directory.", file=sys.stderr
- )
- _qt_metatype_json_dir = Path(qtpaths()["QT_INSTALL_ARCHDATA"]) / "metatypes"
- return _qt_metatype_json_dir
-
-
-def resolve_project_file(cmdline: str) -> Path | None:
- """Return the project file from the command line value, either
- from the file argument or directory"""
- project_file = Path(cmdline).resolve() if cmdline else Path.cwd()
- if project_file.is_file():
- return project_file
- if project_file.is_dir():
- for m in project_file.glob(f"*{PROJECT_FILE_SUFFIX}"):
- return m
- return None