An Example
In this section we walk through the pyproject.toml file for the
PyQt6-Charts project. PyQt6-Charts is the set of bindings for the QtCharts v6
library and is built on top of PyQt6. It comprises a single extension module.
The simplicitly of PyQt6-Charts means that there is no need to provide any
additional code in a project.py file.
If you want to look at a more complicated examples that require a
project.py file then the QScintilla Python bindings and PyQt itself are
good examples.
We show PyQt6-Chart’s pyproject.toml file (downloadable from
here) in its entirety below.
# Specify the build system for the project.
[build-system]
requires = ["sip >=6.8, <7", "PyQt-builder >=1.10, <2"]
build-backend = "sipbuild.api"
[project]
name = "PyQt6-Charts"
version = "6.7.0"
description = "Python bindings for the Qt Charts library"
readme = "README.md"
urls.homepage = "https://www.riverbankcomputing.com/software/pyqtchart/"
dependencies = ["PyQt6 (>=6.2.0)"]
license = {text = "GPL v3"}
[[project.authors]]
name = "Riverbank Computing Limited"
email = "info@riverbankcomputing.com"
# Specify a PyQt-based project.
[tool.sip]
project-factory = "pyqtbuild:PyQtProject"
# Configure the project.
[tool.sip.project]
tag-prefix = "QtCharts"
# Define and configure each set of bindings.
[tool.sip.bindings.QtCharts]
qmake-QT = ["charts"]
We will now explain each section in turn. We assume you are familiar with the examples described in the SIP documentation.
The [build-system] section is used to specify the build system package
requirements. For projects using SIP this will include the version
requirements of the sip project. For PyQt projects it must also include
the version requirements of the PyQt-builder project. Both SIP and
PyQt-builder use semantic versioning so it is important that an upper version
number is specified for each that will exclude future incompatible versions.
The [project] section specifies the meta-data for the project. The format
was originally described in PEP 621.
The dependencies key is used to specify the minimum version of PyQt that
is required.
The [tool.sip] section is used to configure the build system itself and we
use the project-factory key to specify that the
PyQtProject class is used to implement the concept of a
project in the build system. This class implements the many PyQt-specific
features of the build system including the definition of additional
PyQt-specific keys in the pyproject.toml file itself.
The [tool.sip.project] section is used to specify one such PyQt-specific
key tag-prefix. PyQt6-Charts uses SIP’s %Timeline directive to define
tags that are of the form QtCharts_x_y_0 where x and y correspond to
the major and minor versions of PyQt6-Charts and, consequently, Qt. Projects
that follow this convention do not need to use the tags key in the bindings
sections to specify the particular %Timeline tag to use and can leave it to
the build system to determine it dynamically from the version of Qt being used.
The [tool.sip.bindings.QtCharts] section makes use of another PyQt-specific
key added by PyQt-builder. This specifies that charts is added to the
QT variable in any generated .pro file for this set of bindings. This
is all that qmake needs in order to locate the header files and
libraries of QtCharts.