aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside-tools/project_lib/project_data.py
diff options
context:
space:
mode:
authorJaime Resano <Jaime.Resano-Aisa@qt.io>2025-02-26 14:55:09 +0100
committerJaime Resano <Jaime.RESANO-AISA@qt.io>2025-03-12 08:18:31 +0000
commit69ecc3c71155548f43176e7fcf948f09eaf62416 (patch)
tree98b706a482b74acbd9ffc29cc344ea22bd429e04 /sources/pyside-tools/project_lib/project_data.py
parentd9ce0e405f969d96cad221450b853b411eb96ad3 (diff)
pyproject.toml: 1. Refactor pyside6-project
This patch refactors the code of the pyside6-project tool to simplify the upcoming change of the project file format, pyproject.toml. The CLI tool documentation is also improved. Task-number: PYSIDE-2714 Change-Id: I010bbb58f3ed8be5ad5f38687f36b4641a4a021d Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside-tools/project_lib/project_data.py')
-rw-r--r--sources/pyside-tools/project_lib/project_data.py60
1 files changed, 36 insertions, 24 deletions
diff --git a/sources/pyside-tools/project_lib/project_data.py b/sources/pyside-tools/project_lib/project_data.py
index 445f02b81..1a5055ae7 100644
--- a/sources/pyside-tools/project_lib/project_data.py
+++ b/sources/pyside-tools/project_lib/project_data.py
@@ -7,9 +7,10 @@ import os
import subprocess
import sys
from pathlib import Path
-from . import (METATYPES_JSON_SUFFIX, PROJECT_FILE_SUFFIX, TRANSLATION_SUFFIX,
- qt_metatype_json_dir, MOD_CMD, QML_IMPORT_MAJOR_VERSION,
- QML_IMPORT_MINOR_VERSION, QML_IMPORT_NAME, QT_MODULES)
+from . import (METATYPES_JSON_SUFFIX, PYPROJECT_JSON_PATTERN,
+ PYPROJECT_FILE_PATTERNS, TRANSLATION_SUFFIX, qt_metatype_json_dir, MOD_CMD,
+ QML_IMPORT_MAJOR_VERSION, QML_IMPORT_MINOR_VERSION, QML_IMPORT_NAME, QT_MODULES)
+from .pyproject_json import parse_pyproject_json
def is_python_file(file: Path) -> bool:
@@ -19,7 +20,7 @@ def is_python_file(file: Path) -> bool:
class ProjectData:
def __init__(self, project_file: Path) -> None:
- """Parse the project."""
+ """Parse the project file."""
self._project_file = project_file.resolve()
self._sub_projects_files: list[Path] = []
@@ -37,26 +38,37 @@ class ProjectData:
# ts files
self._ts_files: list[Path] = []
- with project_file.open("r") as pyf:
- pyproject = json.load(pyf)
- for f in pyproject["files"]:
- file = Path(project_file.parent / f)
- if file.suffix == PROJECT_FILE_SUFFIX:
- self._sub_projects_files.append(file)
- else:
- self._files.append(file)
- if file.suffix == ".qml":
- self._qml_files.append(file)
- elif is_python_file(file):
- if file.stem == "main":
- self.main_file = file
- self._python_files.append(file)
- elif file.suffix == ".ui":
- self._ui_files.append(file)
- elif file.suffix == ".qrc":
- self._qrc_files.append(file)
- elif file.suffix == TRANSLATION_SUFFIX:
- self._ts_files.append(file)
+ if project_file.match(PYPROJECT_JSON_PATTERN):
+ project_file_data = parse_pyproject_json(project_file)
+ else:
+ print(f"Unknown project file format: {project_file}", file=sys.stderr)
+ sys.exit(1)
+
+ if project_file_data.errors:
+ print(f"Invalid project file: {project_file}. Errors found:", file=sys.stderr)
+ for error in project_file_data.errors:
+ print(f"{error}", file=sys.stderr)
+ sys.exit(1)
+
+ for f in project_file_data.files:
+ file = Path(project_file.parent / f)
+ if any(file.match(pattern) for pattern in PYPROJECT_FILE_PATTERNS):
+ self._sub_projects_files.append(file)
+ continue
+
+ self._files.append(file)
+ if file.suffix == ".qml":
+ self._qml_files.append(file)
+ elif is_python_file(file):
+ if file.stem == "main":
+ self.main_file = file
+ self._python_files.append(file)
+ elif file.suffix == ".ui":
+ self._ui_files.append(file)
+ elif file.suffix == ".qrc":
+ self._qrc_files.append(file)
+ elif file.suffix == TRANSLATION_SUFFIX:
+ self._ts_files.append(file)
if not self.main_file:
self._find_main_file()