diff options
| author | Jaime Resano <Jaime.Resano-Aisa@qt.io> | 2025-02-24 16:11:28 +0100 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2025-03-12 22:15:36 +0100 |
| commit | 545ca796dbd93edb66dc3c21c74511fab8e9d0a3 (patch) | |
| tree | 864fa936fb5986d39ec2477b87671550f4dae830 /sources/pyside-tools/project_lib/utils.py | |
| parent | 3ea026146e4c4f13d9069099c18f50df62020e62 (diff) | |
pyproject.toml: 2. Add pyproject.toml support for pyside6 tools
This patch adds support for pyproject.toml files to the pyside6-project
tool. A new command argument is added to migrate a .pyproject JSON file
to the new pyproject.toml file:
`pyside6-project migrate-pyproject`
The new features are tested and it is guaranteed that the current
behavior is preserved. A new flag is added to the project creation operations, "--legacy-pyproject", in order to generate a .pyproject file instead of a pyproject.toml file.
Note that the tomlkit library is added to the requirements.txt file.
https://github.com/python-poetry/tomlkit
Task-number: PYSIDE-2714
Change-Id: If33956dea73b79df0a52d4dcda3934c85e57182d
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside-tools/project_lib/utils.py')
| -rw-r--r-- | sources/pyside-tools/project_lib/utils.py | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/sources/pyside-tools/project_lib/utils.py b/sources/pyside-tools/project_lib/utils.py index 183a0aa04..c1c406507 100644 --- a/sources/pyside-tools/project_lib/utils.py +++ b/sources/pyside-tools/project_lib/utils.py @@ -7,7 +7,9 @@ import sys import xml.etree.ElementTree as ET from pathlib import Path -from . import QTPATHS_CMD, PYPROJECT_JSON_PATTERN, PYPROJECT_FILE_PATTERNS, ClOptions +from . import (QTPATHS_CMD, PYPROJECT_JSON_PATTERN, PYPROJECT_TOML_PATTERN, PYPROJECT_FILE_PATTERNS, + ClOptions) +from .pyproject_toml import parse_pyproject_toml from .pyproject_json import parse_pyproject_json @@ -138,16 +140,19 @@ def resolve_valid_project_file( If the provided file name is a valid project file, return it. Otherwise, search for a known project file in the current working directory with the given patterns. - Raises a ValueError if no project file is found or multiple project files are found in the same - directory. + Raises a ValueError if no project file is found, multiple project files are found in the same + directory or the provided path is not a valid project file or folder. - :param project_path_input: The command-line argument specifying a project file path. + :param project_path_input: The command-line argument specifying a project file or folder path. :param project_file_patterns: The list of project file patterns to search for. - :return: The resolved project file path if found, otherwise None. + :return: The resolved project file path """ if project_path_input and (project_file := Path(project_path_input).resolve()).is_file(): - if project_file.match(PYPROJECT_JSON_PATTERN): + if project_file.match(PYPROJECT_TOML_PATTERN): + if bool(parse_pyproject_toml(project_file).errors): + raise ValueError(f"Invalid project file: {project_file}") + elif project_file.match(PYPROJECT_JSON_PATTERN): pyproject_json_result = parse_pyproject_json(project_file) if errors := '\n'.join(str(e) for e in pyproject_json_result.errors): raise ValueError(f"Invalid project file: {project_file}\n{errors}") @@ -163,8 +168,7 @@ def resolve_valid_project_file( # Search a project file in the project folder using the provided patterns for pattern in project_file_patterns: - matches = list(project_folder.glob(pattern)) - if not matches: + if not (matches := list(project_folder.glob(pattern))): # No project files found with the specified pattern continue @@ -174,7 +178,12 @@ def resolve_valid_project_file( project_file = matches[0] - if pattern == PYPROJECT_JSON_PATTERN: + if pattern == PYPROJECT_TOML_PATTERN: + if parse_pyproject_toml(project_file).errors: + # Invalid file, but a .pyproject file may exist + # We can not raise an error due to ensuring backward compatibility + continue + elif pattern == PYPROJECT_JSON_PATTERN: pyproject_json_result = parse_pyproject_json(project_file) if errors := '\n'.join(str(e) for e in pyproject_json_result.errors): raise ValueError(f"Invalid project file: {project_file}\n{errors}") |
