Files
macports-guide/guide/xml/portgroup-python.xml
2024-03-09 12:52:29 +11:00

402 lines
14 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V5.0//EN"
"http://docbook.org/xml/5.0/dtd/docbook.dtd">
<section xml:id="reference.portgroup.python" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>PortGroup python</title>
<para>PortGroup python allows for efficient porting of python-based open
source software.</para>
<section xml:id="reference.portgroup.python.keywords">
<title>python PortGroup Specific Keywords</title>
<para>Portfiles using the python PortGroup allow for port authors to
set the following keywords in addition to the general Portfile
keywords.</para>
<variablelist>
<varlistentry>
<term>python.versions</term>
<listitem>
<para>Defines the python versions supported by this port. If the
port name starts with <quote>py-</quote>, then a subport will be defined for each
version in the list. For example, if a port named <quote>py-foo</quote> declares
<code>python.versions 39 310</code>, subports <quote>py39-foo</quote> and <quote>py310-foo</quote> will be
created, and will depend on python39 and python310, respectively.</para>
<para>If the port name does not start with <quote>py-</quote>, it is interpreted
as an application written in python rather than a python module. In
this case, no subports are defined, and <varname>python.versions</varname> defaults to
the value of <varname>python.default_version</varname>, which must be set. For example,
if a port named <quote>mercurial</quote> sets <code>python.default_version 310</code>, then
<varname>python.versions</varname> will automatically be set to <quote>310</quote>, and a dependency
on python310 will be added.</para>
<itemizedlist>
<listitem>
<para>Type: required for modules, optional for apps</para>
</listitem>
<listitem>
<para>Example:</para>
<programlisting>python.versions 38 39 310</programlisting>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>python.default_version</term>
<listitem>
<para>For modules (i.e., name starts with <quote>py-</quote>), this sets the
subport that will be installed if the user asks to install <quote>py-foo</quote>
rather than, e.g., <quote>py39-foo</quote> or <quote>py310-foo</quote>. If not explicitly set, a
reasonable default is chosen from the list in <varname>python.versions</varname>.</para>
<para>For applications (i.e., name does not start with <quote>py-</quote>), this chooses
which version of python to use, and must be set. It can be changed
in variants if desired.</para>
<itemizedlist>
<listitem>
<para>Type: required for apps, optional for modules</para>
</listitem>
<listitem>
<para>Example:</para>
<programlisting>python.default_version 310</programlisting>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>python.pep517</term>
<listitem>
<para>If set to <quote>yes</quote>, the port will be built as per
<link xlink:href="https://www.python.org/dev/peps/pep-0517/">PEP 517</link>.
Dependencies on appropriate front end tools will be added
automatically. This is supported when using Python 3.6 or later, though
the supporting module ports for 3.6 and other EOL Python versions may
be removed in future.</para>
<para>If set to <quote>no</quote>, the port will be built with the
traditional distutils/setuptools <code>setup.py</code> commands.</para>
<itemizedlist>
<listitem>
<para>Type: optional</para>
</listitem>
<listitem>
<para>Default (Python &gt;= 3.7): yes</para>
<para>Default (Python &lt;= 3.6): no</para>
</listitem>
<listitem>
<para>Example:</para>
<programlisting>python.pep517 yes</programlisting>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>python.pep517_backend</term>
<listitem>
<para>This can be set to the name of the PEP 517 build back-end used by the port.
If <varname>python.pep517</varname> is set to <quote>yes</quote>, dependencies on the
ports that provide the specified back-end will be added automatically.
Currently supported values are <quote>setuptools</quote>, <quote>flit</quote>,
<quote>poetry</quote>, <quote>hatch</quote>, <quote>maturin</quote>, and
<quote>meson</quote>. Clearing this option or setting it
to an unsupported value will result in no back-end dependencies being added.</para>
<itemizedlist>
<listitem>
<para>Type: optional</para>
</listitem>
<listitem>
<para>Default: setuptools</para>
</listitem>
<listitem>
<para>Example:</para>
<programlisting>python.pep517_backend flit</programlisting>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>python.test_framework</term>
<listitem>
<para>This can be set to the name of testing framework used by the port.
If <varname>test.run</varname> is set to <quote>yes</quote>, dependencies on
the port that provides the specified framework will be added automatically.
Currently supported values are <quote>pytest</quote>, <quote>nose</quote>,
and <quote>unittest</quote>. Clearing this option or setting it to an
unsupported value will result in no framework dependency being added.</para>
<itemizedlist>
<listitem>
<para>Type: optional</para>
</listitem>
<listitem>
<para>Default: pytest</para>
</listitem>
<listitem>
<para>Example:</para>
<programlisting>python.test_framework nose</programlisting>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>python.add_dependencies</term>
<listitem>
<para>If set to <quote>yes</quote>, a dependency on a python interpreter will
be added as per <varname>python.version</varname>, and if <varname>python.pep517</varname>
is also set to <quote>yes</quote>, dependencies on appropriate front- and back-end
tools will also be added.</para>
<para>If set to <quote>no</quote>, the portgroup will not add any dependencies,
and all required dependencies need to be declared in the Portfile.</para>
<itemizedlist>
<listitem>
<para>Type: optional</para>
</listitem>
<listitem>
<para>Default: yes</para>
</listitem>
<listitem>
<para>Example:</para>
<programlisting>python.add_dependencies no</programlisting>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>python.link_binaries</term>
<listitem>
<para>When <quote>yes</quote> (the default), tells the PortGroup to automatically
link any executable binaries installed in the bin/ directory within
the framework into
<filename>${prefix}/bin</filename>.</para>
<itemizedlist>
<listitem>
<para>Type: optional</para>
</listitem>
<listitem>
<para>Example:</para>
<programlisting>python.link_binaries no</programlisting>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>python.link_binaries_suffix</term>
<listitem>
<para>Suffix to add to the names of the links created in
<filename>${prefix}/bin</filename> when <varname>${python.link_binaries}</varname>
is enabled. Can be cleared if no suffix is desired.</para>
<itemizedlist>
<listitem>
<para>Type: optional</para>
</listitem>
<listitem>
<para>Default: -<varname>${python.branch}</varname></para>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
<varlistentry>
<term>python.add_archflags</term>
<listitem>
<para>When yes (the default), the PortGroup will automatically
try to pass the correct arch-specific flags during build time
(via the standard CFLAGS, LDFLAGS, etc environment variables).
Set this to <quote>no</quote> and set up those variables in <code>build.env</code> manually
if the default does not work.</para>
<itemizedlist>
<listitem>
<para>Type: optional</para>
</listitem>
<listitem>
<para>Example:</para>
<programlisting>python.add_archflags no</programlisting>
</listitem>
</itemizedlist>
</listitem>
</varlistentry>
</variablelist>
</section>
<section xml:id="reference.portgroup.python.variables">
<title>python PortGroup Specific Variables</title>
<para>When the python PortGroup is declared within a Portfile, the
following variables are provided.</para>
<variablelist>
<varlistentry>
<term>python.version</term>
<listitem>
<para>The python version in use in the current subport. This will be
one of the versions listed in <code>python.versions</code>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>python.branch</term>
<listitem>
<para>The python version in use in the current subport, in normal
dotted notation. For example, if <code>python.version</code> is <quote>310</quote>,
<code>python.branch</code> will be <quote>3.10</quote>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>python.prefix</term>
<listitem>
<para>The prefix in which the current python version is installed.
For framework builds, this is <filename>${frameworks_dir}/Python.framework/Versions/${python.branch}</filename>,
whereas for non-framework builds, it is the same as <varname>${prefix}</varname>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>python.bin</term>
<listitem>
<para>The path to the MacPorts Python executable.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>python.lib</term>
<listitem>
<para>The Python dynamic library path, i.e.,
<filename>${python.prefix}/Python</filename> (framework builds) or
<filename>${prefix}/lib/libpython2.7.dylib</filename> (python27).</para>
</listitem>
</varlistentry>
<varlistentry>
<term>python.libdir</term>
<listitem>
<para>The path to python's lib directory, i.e.,
<filename>${python.prefix}/lib/python${python.branch}</filename>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>python.include</term>
<listitem>
<para>Path to the Python include directory.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>python.pkgd</term>
<listitem>
<para>Path to the Python site-packages directory. (i.e.,
<filename>${python.prefix}/lib/python${python.branch}/site-packages</filename>).</para>
</listitem>
</varlistentry>
</variablelist>
</section>
<section xml:id="reference.portgroup.python.sugar">
<title>python PortGroup Sugar</title>
<para>Portfiles using PortGroup python do not need to define the
following variables:</para>
<variablelist>
<varlistentry>
<term>categories</term>
<listitem>
<para>Default: python</para>
</listitem>
</varlistentry>
<varlistentry>
<term>depends_lib</term>
<listitem>
<para>Default: port:python<varname>${python.version}</varname></para>
</listitem>
</varlistentry>
<varlistentry>
<term>use_configure</term>
<listitem>
<para>Default: no</para>
</listitem>
</varlistentry>
<varlistentry>
<term>build.cmd</term>
<listitem>
<para>Default (<code>python.pep517 no</code>): <varname>${python.bin}</varname> setup.py --no-user-cfg</para>
<para>Default (<code>python.pep517 yes</code>): <varname>${python.bin}</varname> -m build --wheel --no-isolation --outdir <varname>${workpath}</varname></para>
</listitem>
</varlistentry>
<varlistentry>
<term>build.target</term>
<listitem>
<para>Default (<code>python.pep517 no</code>): build</para>
<para>Default (<code>python.pep517 yes</code>): (empty)</para>
</listitem>
</varlistentry>
<varlistentry>
<term>destroot.cmd</term>
<listitem>
<para>Default (<code>python.pep517 no</code>): <varname>${python.bin}</varname> setup.py --no-user-cfg</para>
<para>Default (<code>python.pep517 yes</code>): <varname>${python.bin}</varname> -m install --verbose</para>
</listitem>
</varlistentry>
<varlistentry>
<term>destroot.destdir</term>
<listitem>
<para>Default (<code>python.pep517 no</code>): --prefix=<varname>${python.prefix}</varname> --root=<varname>${destroot}</varname></para>
<para>Default (<code>python.pep517 yes</code>): --destdir <varname>${destroot}</varname></para>
</listitem>
</varlistentry>
<varlistentry>
<term>pre-destroot</term>
<listitem>
<para>Default: creates directory
<filename>${destroot}${prefix}/share/doc/${subport}/examples</filename>.</para>
</listitem>
</varlistentry>
</variablelist>
</section>
</section>