Skip to content

Commit 8c491f7

Browse files
Jaime ResanoFriedemannKleint
Jaime Resano
authored andcommitted
pyproject.toml: 4. Update pyside6-project documentation
This patch modifies the existing pyside6-project documentation to include the new pyproject.toml file format. The .pyproject file format is announced as deprecated. Task-number: PYSIDE-2714 Change-Id: I1efd715babd3f288532b2bbc9d36897fcfc2e2a2 Reviewed-by: Cristian Maureira-Fredes <[email protected]>
1 parent 58dc331 commit 8c491f7

File tree

3 files changed

+115
-26
lines changed

3 files changed

+115
-26
lines changed

sources/pyside6/doc/deployment/deployment-pyside6-deploy.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ The relevant parameters for ``pyside6-deploy`` are:
8888
is the parent directory of the main Python entry point file
8989
* ``input_file``: Path to the main Python entry point file
9090
* ``project_file``: If it exists, this points to the path to the `Qt Creator Python Project File
91-
.pyproject <https://doc.qt.io/qtforpython-6/faq/typesoffiles.html
91+
<https://doc.qt.io/qtforpython-6/faq/typesoffiles.html
9292
#qt-creator-python-project-file-pyproject>`_ file. Such a file makes sure that the deployment
9393
process never considers unnecessary files when bundling the executable.
9494
* ``exec_directory``: The directory where the final executable is generated.

sources/pyside6/doc/faq/typesoffiles.rst

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,21 +132,26 @@ For *Qt Creator* to load and handle Python based projects, a special file is
132132
needed, because C++ based projects could be handle from ``.qmake`` or
133133
``CMakeLists.txt`` file, which are not used with Python-based projects.
134134

135+
The deprecated ``*.pyproject`` project files use JSON format.
136+
Here is an example of such file:
137+
138+
.. code-block:: javascript
139+
140+
{
141+
"files": ["library/server.py", "library/client.py", "logger.py"]
142+
}
143+
144+
*Qt Creator* 16.0 added support for the pyproject.toml file format, which
145+
is the modern standard for Python projects. PySide6 6.9.0 introduced support
146+
for this format, and it is recommended to use it. In order to migrate a
147+
.pyproject file, see `Migrating from *.pyproject to pyproject.toml`
148+
<https://doc.qt.io/qtforpython-6/tools/pyside6-project.html
149+
#migrating_from_pyproject_to_pyproject_toml>`_
150+
135151
Old versions of *Qt Creator*, provided a simple format with the ``.pyqtc``
136152
extension, which were plain-text files with one-file-per-line::
137153

138154
library/server.py
139155
library/client.py
140156
logger.py
141157
...
142-
143-
There were limitations to this format, and further options that might be
144-
added that would not be supported, which was the motivation to create a
145-
``.pyproject`` file, which is a JSON-based file where more options could
146-
be added. Here is an example of such file:
147-
148-
.. code-block:: javascript
149-
150-
{
151-
"files": ["library/server.py", "library/client.py", "logger.py", ...]
152-
}

sources/pyside6/doc/tools/pyside-project.rst

Lines changed: 98 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,74 @@ pyside6-project
44
===============
55

66
`pyside6-project` is a command line tool for creating, building and deploying
7-
|project| applications. It operates on a project file which is also used by
8-
`Qt Creator`_.
7+
|project| applications. It operates on project files which are also supported
8+
by `Qt Creator`_.
99

10-
Project file format
11-
-------------------
10+
A project file contains a list of the source files used in the project. Typically they are
11+
``.py``, ``.qml``, ``.qrc``, ``.ts``, or ``.ui`` files. It can also include other subproject files.
12+
Generated files such as compiled resources or compiled translations should not be included in the
13+
project file.
1214

13-
The project file format is a simple `JSON`_-based format with the suffix
14-
``.pyproject`` listing all files of the project excluding generated files
15-
(typically ``.py``, ``.qml``, ``.qrc``, ``.ts``, or ``.ui`` files):
15+
Currently, two project file formats are supported. Since PySide6 version 6.9.0, the ``*.pyproject``
16+
file format is deprecated in favor of the new ``pyproject.toml`` file format. The ``*.pyproject``
17+
file format is still supported for backward compatibility, but it is recommended to migrate to the
18+
new ``pyproject.toml`` file format. See
19+
:ref:`Migrating from *.pyproject to pyproject.toml<migrating_from_pyproject_to_pyproject_toml>`
20+
for more information.
21+
22+
``pyproject.toml``
23+
------------------
24+
25+
PySide6 version 6.9.0 added support for the new Python standard ``pyproject.toml`` project file
26+
format. It is intended to replace the deprecated ``*.pyproject`` file format. The project source
27+
files are listed in the ``tool.pyside6-project`` table. For example:
28+
29+
.. code-block:: toml
30+
31+
[project]
32+
name = "myproject"
33+
34+
[tool.pyside6-project]
35+
files = ["main.py", "main_window.py"]
36+
37+
More information about the ``pyproject.toml`` file format can be found in
38+
`Python Packaging User Guide specification: "Writing your pyproject.toml"`_.
39+
40+
``*.pyproject``
41+
---------------
42+
43+
The deprecated ``*.pyproject`` project file uses a simple `JSON`_-based format. The source files
44+
are listed in the ``files`` array of the JSON root object. For example:
1645

1746
.. code-block:: json
1847
1948
{
20-
"files": ["main.py"]
49+
"files": ["main.py", "main_window.py"]
2150
}
2251
23-
2452
Usage
2553
-----
2654

2755
The tool has several subcommands. New projects can be created using
2856
the below commands, passing the project name (directory):
2957

3058
*new-ui*
31-
Creates a new QtWidgets project with a *Qt Widgets Designer*-based main
32-
window.
59+
Creates a new QtWidgets project with a *Qt Widgets Designer*-based main window.
3360

3461
*new-widget*
3562
Creates a new QtWidgets project with a main window.
3663

3764
*new-quick*
3865
Creates a new QtQuick project.
3966

40-
The other commands take the project file as an argument.
67+
Using the optional ``--legacy-pyproject`` flag, the tool will create a legacy ``.pyproject`` file
68+
instead of a ``pyproject.toml`` file.
69+
70+
The following commands can receive a project file as an optional argument.
4171
It is also possible to specify a directory containing the project file.
4272

4373
*build*
44-
Builds the project, generating the required build artifacts
74+
Builds the project. Compiles resources, UI files, and QML files if existing and necessary.
4575
(see :ref:`tutorial_uifiles`, :ref:`tutorial_qrcfiles`).
4676

4777
*run*
@@ -54,11 +84,65 @@ It is also possible to specify a directory containing the project file.
5484
Updates translation (.ts) files (see :ref:`tutorial_translations`).
5585

5686
*clean*
57-
Cleans the build artifacts.
87+
Cleans the build artifacts. For example, compiled resources.
5888

5989
*qmllint*
6090
Runs the ``qmllint`` tool, checking the QML files.
6191

92+
*migrate-pyproject*
93+
Migrates the content of one or more ``*.pyproject`` files to a ``pyproject.toml`` file.
94+
See :ref:`Migrating from *.pyproject to pyproject.toml <migrating_from_pyproject_to_pyproject_toml>`.
95+
96+
Considerations
97+
--------------
98+
99+
For each file entry in the project files, ``pyside6-project`` does the following:
100+
101+
* ``<other project file>``: Recursively handle subproject
102+
* ``<name>.qrc``: Runs the resource compiler to create a file rc_<name>.py
103+
* ``<name>.ui``: Runs the user interface compiler to create a file ui_<name>.py
104+
105+
For a Python file declaring a QML module, a directory matching the URI is
106+
created and populated with .qmltypes and qmldir files for use by code analysis
107+
tools. Currently, only one QML module consisting of several classes can be
108+
handled per project file.
109+
110+
.. _migrating_from_pyproject_to_pyproject_toml:
111+
112+
Migrating from ``*.pyproject`` to ``pyproject.toml``
113+
----------------------------------------------------
114+
115+
Since PySide6 6.9.0, ``pyside6-project`` tool can create a new ``pyproject.toml`` file or update an
116+
existing one with the existing ``*.pyproject`` file content. To migrate an existing project, run
117+
``pyside6-project`` command with the ``migrate-pyproject`` argument. For example:
118+
119+
.. code-block:: bash
120+
121+
pyside6-project migrate-pyproject
122+
123+
If no file is specified, the tool will read the ``*.pyproject`` files in the current working
124+
directory. In the case of having multiple ``*.pyproject`` files in the same directory, its contents
125+
will be merged. A new ``pyproject.toml`` file will be created if not existing. If the file already
126+
exists, a confirmation message is displayed to the user asking for confirmation before
127+
updating the file with the new content. For example:
128+
129+
.. code-block:: bash
130+
131+
mkdir myproject
132+
cd myproject
133+
echo {"files": ["main.py", "my_widget.py"]} > myproject.pyproject
134+
pyside6-project migrate-pyproject
135+
136+
Generated pyproject.toml file:
137+
138+
.. code-block:: toml
139+
140+
[project]
141+
name = "myproject"
142+
143+
[tool.pyside6-project]
144+
files = ["main.py", "my_widget.py"]
62145
63146
.. _`Qt Creator`: https://www.qt.io/product/development-tools
147+
.. _`Python Packaging User Guide specification: "Writing your pyproject.toml"`: https://packaging.python.org/en/latest/guides/writing-pyproject-toml/
64148
.. _`JSON`: https://www.json.org/

0 commit comments

Comments
 (0)