xref: /openbsd-src/share/man/man5/python-module.5 (revision f6aab3d83b51b91c24247ad2c2573574de475a82)
1.\"	$OpenBSD: python-module.5,v 1.7 2022/12/06 16:18:51 sthen Exp $
2.\"
3.\" Copyright (c) 2008 Marc Espie
4.\"
5.\" All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
17.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
20.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26.\"
27.Dd $Mdocdate: December 6 2022 $
28.Dt PYTHON-MODULE 5
29.Os
30.Sh NAME
31.Nm python-module
32.Nd lang/python port module
33.Sh DESCRIPTION
34This manual page documents the behavior of setting
35.Li MODULES=lang/python
36in the
37.Xr ports 7
38tree.
39.Pp
40By default, the module sets
41.Ev MODPY_VERSION
42to the appropriate python version
43.Po
44depending on the existence/presence of a
45.Sq python3
46.Ev FLAVOR
47.Pc ,
48but
49.Ev MODPY_VERSION
50may be set manually to ${MODPY_DEFAULT_VERSION_2}
51for legacy ports.
52.Pp
53The module then sets
54.Ev MODPY_BIN ,
55.Ev MODPY_INCDIR ,
56.Ev MODPY_LIBDIR ,
57.Ev MODPY_SITEPKG ,
58.Ev MODPY_SETUP ,
59.Ev MODPY_TEST_DIR ,
60.Ev MODPY_TEST_LOCALE ,
61.Ev MODPY_WANTLIB ,
62.Ev MODPY_LIB_DEPENDS ,
63.Ev MODPY_RUN_DEPENDS ,
64.Ev MODPY_TEST_DEPENDS ,
65.Ev MODPY_BUILD_DEPENDS ,
66and
67.Ev MODPY_ADJ_FILES
68accordingly.
69.Pp
70The module also appends to
71.Bl -bullet
72.It
73.Ev RUN_DEPENDS
74unless
75.Ev MODPY_RUNDEP
76is set to No,
77.It
78.Ev BUILD_DEPENDS
79unless
80.Ev MODPY_BUILDDEP
81is set to No or
82.Ev NO_BUILD
83is set to Yes,
84.It
85.Ev TEST_DEPENDS
86if
87.Ev MODPY_PYTEST
88is set to Yes
89unless
90.Ev MODPY_TESTDEP
91is set to No.
92.El
93.Pp
94It also appends
95.Ev MODPY_TEST_LOCALE
96to
97.Ev TEST_ENV
98and changes to the directory specified in
99.Ev MODPY_TEST_DIR
100.Po
101by default ${WRKSRC}
102.Pc
103before running tests.
104.Pp
105Most modern Python software can be packaged using a PEP 517 build
106frontend (in the
107.Pa devel/py-build
108port).
109To use this, set
110.Ev MODPY_PYBUILD
111to the name of the build backend.
112If the port provides a
113.Pa pyproject.toml
114file, check the "build-backend" line in the [build-system] section.
115.Nm
116currently supports flit_core, hatchling, hatch-vcs, poetry-core, setuptools
117and setuptools_scm.
118If no
119.Pa pyproject.toml
120is provided then it probably uses setuptools.
121Setting
122.Ev MODPY_PYBUILD
123adds the backend to
124.Ev MODPY_BUILD_DEPENDS ,
125and sets
126.Ev MODPY_PYTEST .
127In rare cases, the build backend is distributed with the software
128itself and
129.Ev MODPY_PYBUILD
130can be set to Yes to use this mechanism without adding a dependency
131for another backend.
132.Pp
133Older ports using setuptools still set
134.Ev MODPY_SETUPTOOLS
135to Yes, which appends to
136.Ev MODPY_BUILD_DEPENDS
137and calls the relevant commands to build (these ports are built
138using the deprecated mechanism of calling
139.Pa setup.py
140directly).
141Arguments can be passed to setup.py during
142.Cm configure
143with
144.Ev MODPY_SETUP_ARGS .
145Extra arguments to the build and install commands can be passed via
146.Ev MODPY_DISTUTILS_BUILDARGS
147and
148.Ev MODPY_DISTUTILS_INSTALLARGS .
149These ports can often be converted to
150.Ev MODPY_PYBUILD
151with some small changes to the port.
152.Pp
153Ports which use the pytest module should set
154.Ev MODPY_PYTEST
155to Yes.
156This is set automatically for builds using
157.Ev MODPY_PYBUILD .
158Arguments can be passed to pytest during
159.Cm test
160with
161.Ev MODPY_PYTEST_ARGS ,
162for example to list names of test scripts if the automatic
163detection fails,
164to disable certain test scripts with
165.Sq --ignore ,
166or to disable certain individual tests with
167.Sq -k .
168.Pp
169All ports that generate egg-info or dist-info files should set
170.Ev MODPY_EGG_VERSION
171to the version string used by the
172.Fn setup
173function in the port's
174.Pa setup.py
175or the version in
176.Pa pyproject.toml .
177.Pp
178If any files have a python shebang line where the interpreter should be
179${MODPY_BIN}, list them in
180.Ev MODPY_ADJ_FILES .
181These filenames can be relative to ${WRKSRC} and will be modified
182at the end of
183.Cm pre-configure .
184.Pp
185This module also affects
186.Ev CATEGORIES ,
187.Ev MAKE_ENV ,
188.Ev CONFIGURE_ENV ,
189and
190.Ev SUBST_VARS ,
191and it may affect the
192.Cm test
193target.
194.Pp
195If
196.Ev MODPY_PI
197is set to
198.Sq Yes ,
199the module will provide a default for
200.Ev HOMEPAGE
201and set
202.Ev MASTER_SITES
203.Po
204the subdirectory can be overridden with
205.Ev MODPY_PI_DIR
206.Pc .
207.Ss Packing-list generation
208Python 2.x places .pyc files in the same directory as the associated .py file.
209Python 3.x places these in a separate __pycache__ directory and uses an
210additional suffix.
211In some cases, an ABI tag is also used for names of compiled extensions.
212The python module defines variables to allow a single
213.Pa PLIST
214to be
215used for both versions:
216generate or update the
217.Pa PLIST
218using the python3
219.Ev FLAVOR ,
220then edit it to prefix any lines creating
221.Ev MODPY_PYCACHE
222directories with
223.Ev MODPY_COMMENT .
224As python2 and python3 packages should permit being installed together,
225it may be necessary to suffix names of common binaries or directories,
226or split common files into a subpackage.
227If updating the PLIST without using the python3 flavor,
228take care not to remove ${MODPY_PYCACHE}, ${MODPY_PYC_MAGIC_TAG}, or
229${MODPY_ABI_TAG} variables from the PLIST.
230.Sh SEE ALSO
231.Xr port-modules 5
232