xref: /openbsd-src/share/man/man5/python-module.5 (revision 5771aeffabd5792c224655adc031dfe604f89d36)
1*5771aeffSsthen.\"	$OpenBSD: python-module.5,v 1.15 2025/01/17 08:52:01 sthen Exp $
2be30614aSespie.\"
3be30614aSespie.\" Copyright (c) 2008 Marc Espie
4be30614aSespie.\"
5be30614aSespie.\" All rights reserved.
6be30614aSespie.\"
7be30614aSespie.\" Redistribution and use in source and binary forms, with or without
8be30614aSespie.\" modification, are permitted provided that the following conditions
9be30614aSespie.\" are met:
10be30614aSespie.\" 1. Redistributions of source code must retain the above copyright
11be30614aSespie.\"    notice, this list of conditions and the following disclaimer.
12be30614aSespie.\" 2. Redistributions in binary form must reproduce the above copyright
13be30614aSespie.\"    notice, this list of conditions and the following disclaimer in the
14be30614aSespie.\"    documentation and/or other materials provided with the distribution.
15be30614aSespie.\"
16be30614aSespie.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
17be30614aSespie.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18be30614aSespie.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19be30614aSespie.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
20be30614aSespie.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21be30614aSespie.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22be30614aSespie.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23be30614aSespie.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24be30614aSespie.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25be30614aSespie.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26be30614aSespie.\"
27*5771aeffSsthen.Dd $Mdocdate: January 17 2025 $
28be30614aSespie.Dt PYTHON-MODULE 5
29be30614aSespie.Os
30be30614aSespie.Sh NAME
31be30614aSespie.Nm python-module
32be30614aSespie.Nd lang/python port module
33be30614aSespie.Sh DESCRIPTION
34be30614aSespieThis manual page documents the behavior of setting
357ed6b297Sespie.Li MODULES=lang/python
36be30614aSespiein the
37be30614aSespie.Xr ports 7
38be30614aSespietree.
39be30614aSespie.Pp
40*5771aeffSsthenBy default, the module builds ports using Python 3.
41*5771aeffSsthenFor legacy ports using Python 2,
424bdacbd6Sespie.Ev MODPY_VERSION
43*5771aeffSsthenmay be set manually to ${MODPY_DEFAULT_VERSION_2}.
444bdacbd6Sespie.Pp
454bdacbd6SespieThe module then sets
46be30614aSespie.Ev MODPY_BIN ,
47be30614aSespie.Ev MODPY_INCDIR ,
48be30614aSespie.Ev MODPY_LIBDIR ,
49be30614aSespie.Ev MODPY_SITEPKG ,
50be30614aSespie.Ev MODPY_SETUP ,
51be30614aSespie.Ev MODPY_TEST_DIR ,
52be30614aSespie.Ev MODPY_TEST_LOCALE ,
53be30614aSespie.Ev MODPY_WANTLIB ,
54be30614aSespie.Ev MODPY_LIB_DEPENDS ,
55be30614aSespie.Ev MODPY_RUN_DEPENDS ,
56be30614aSespie.Ev MODPY_TEST_DEPENDS ,
57be30614aSespie.Ev MODPY_BUILD_DEPENDS ,
58be30614aSespieand
594bdacbd6Sespie.Ev MODPY_ADJ_FILES
604bdacbd6Sespieaccordingly.
614bdacbd6Sespie.Pp
624bdacbd6SespieThe module also appends to
634bdacbd6Sespie.Bl -bullet
644bdacbd6Sespie.It
65be30614aSespie.Ev RUN_DEPENDS
66be30614aSespieunless
67be30614aSespie.Ev MODPY_RUNDEP
684bdacbd6Sespieis set to No,
694bdacbd6Sespie.It
70be30614aSespie.Ev BUILD_DEPENDS
71be30614aSespieunless
72be30614aSespie.Ev MODPY_BUILDDEP
73be30614aSespieis set to No or
74be30614aSespie.Ev NO_BUILD
754bdacbd6Sespieis set to Yes,
764bdacbd6Sespie.It
77be30614aSespie.Ev TEST_DEPENDS
78be30614aSespieif
79be30614aSespie.Ev MODPY_PYTEST
80be30614aSespieis set to Yes
81be30614aSespieunless
82be30614aSespie.Ev MODPY_TESTDEP
83be30614aSespieis set to No.
844bdacbd6Sespie.El
854bdacbd6Sespie.Pp
864bdacbd6SespieIt also appends
87be30614aSespie.Ev MODPY_TEST_LOCALE
88be30614aSespieto
894bdacbd6Sespie.Ev TEST_ENV
904bdacbd6Sespieand changes to the directory specified in
914bdacbd6Sespie.Ev MODPY_TEST_DIR
924bdacbd6Sespie.Po
934bdacbd6Sespieby default ${WRKSRC}
944bdacbd6Sespie.Pc
954bdacbd6Sespiebefore running tests.
964bdacbd6Sespie.Pp
974b12175aSsthenMost modern Python software can be packaged using a PEP 517 build
984b12175aSsthenfrontend (in the
994b12175aSsthen.Pa devel/py-build
1004b12175aSsthenport).
1014b12175aSsthenTo use this, set
1024b12175aSsthen.Ev MODPY_PYBUILD
1034b12175aSsthento the name of the build backend.
1044b12175aSsthenIf the port provides a
1054b12175aSsthen.Pa pyproject.toml
1064b12175aSsthenfile, check the "build-backend" line in the [build-system] section.
1074b12175aSsthen.Nm
10846bd5ef8Ssthencurrently supports flit, flit_core, hatchling, hatch-vcs, jupyter_packaging,
109*5771aeffSsthenmaturin, pdm, poetry-core, setuptools, setuptools-rust, and setuptools_scm.
1104b12175aSsthenIf no
1114b12175aSsthen.Pa pyproject.toml
1124b12175aSsthenis provided then it probably uses setuptools.
1134b12175aSsthenSetting
1144b12175aSsthen.Ev MODPY_PYBUILD
1154b12175aSsthenadds the backend to
1164b12175aSsthen.Ev MODPY_BUILD_DEPENDS ,
1174b12175aSsthenand sets
1184b12175aSsthen.Ev MODPY_PYTEST .
119*5771aeffSsthenIn cases where an uncommon backend is used, or where the build backend is
12084e9e36aSsthendistributed with the software itself,
1214b12175aSsthen.Ev MODPY_PYBUILD
12246bd5ef8Ssthencan be set to
12346bd5ef8Ssthen.Sq other
124*5771aeffSsthento use the PEP 517 build mechanism without adding a dependency
12584e9e36aSsthenfor a backend.
1264b12175aSsthen.Pp
127*5771aeffSsthenPython 2 and some older Python 3 ports using setuptools still set
128be30614aSespie.Ev MODPY_SETUPTOOLS
1294b12175aSsthento Yes, which appends to
1304b12175aSsthen.Ev MODPY_BUILD_DEPENDS
1314b12175aSsthenand calls the relevant commands to build (these ports are built
1324b12175aSsthenusing the deprecated mechanism of calling
1334b12175aSsthen.Pa setup.py
1344b12175aSsthendirectly).
135be30614aSespieArguments can be passed to setup.py during
136be30614aSespie.Cm configure
137be30614aSespiewith
138be30614aSespie.Ev MODPY_SETUP_ARGS .
139be30614aSespieExtra arguments to the build and install commands can be passed via
140be30614aSespie.Ev MODPY_DISTUTILS_BUILDARGS
141be30614aSespieand
142be30614aSespie.Ev MODPY_DISTUTILS_INSTALLARGS .
1434b12175aSsthenThese ports can often be converted to
1444b12175aSsthen.Ev MODPY_PYBUILD
1454b12175aSsthenwith some small changes to the port.
146*5771aeffSsthen.Ev MODPY_SETUPTOOLS
147*5771aeffSsthenshould not be used for new ports.
1484b12175aSsthen.Pp
1494b12175aSsthenPorts which use the pytest module should set
1504b12175aSsthen.Ev MODPY_PYTEST
1514b12175aSsthento Yes.
1524b12175aSsthenThis is set automatically for builds using
1534b12175aSsthen.Ev MODPY_PYBUILD .
1544b12175aSsthenArguments can be passed to pytest during
1554b12175aSsthen.Cm test
1564b12175aSsthenwith
1574305ac2cSsthen.Ev MODPY_PYTEST_ARGS ,
1584305ac2cSsthenfor example to list names of test scripts if the automatic
1594305ac2cSsthendetection fails,
1604305ac2cSsthento disable certain test scripts with
1614305ac2cSsthen.Sq --ignore ,
1624305ac2cSsthenor to disable certain individual tests with
1634305ac2cSsthen.Sq -k .
1644d1706f2SsthenUser setting
1654d1706f2Ssthen.Ev MODPY_PYTEST_USERARGS ,
1664d1706f2Ssthenif present, is passed on the command line.
1674d1706f2SsthenThis allows setting py.test flags to increase verbosity,
1684d1706f2Ssthenshow test durations, enable colours, etc.
1694b12175aSsthen.Pp
170*5771aeffSsthenIf
171*5771aeffSsthen.Ev MODPY_TEST_LINK_SO
172*5771aeffSsthenis set to Yes, symbolic links to all .so files in the build directory
173*5771aeffSsthenwill be created before running tests.
174*5771aeffSsthenThese are created in
175*5771aeffSsthen.Ev MODPY_TEST_LINK_SRC ,
176*5771aeffSsthenwhich defaults to ${WRKSRC}.
177*5771aeffSsthenThis is required when tests load .so files via relative imports.
178*5771aeffSsthen.Pp
1794b12175aSsthenAll ports that generate egg-info or dist-info files should set
180*5771aeffSsthen.Ev MODPY_DISTV
1814b12175aSsthento the version string used by the
1824b12175aSsthen.Fn setup
1834b12175aSsthenfunction in the port's
1844b12175aSsthen.Pa setup.py
1854b12175aSsthenor the version in
1864b12175aSsthen.Pa pyproject.toml .
1874bdacbd6Sespie.Pp
1884bdacbd6SespieIf any files have a python shebang line where the interpreter should be
1894bdacbd6Sespie${MODPY_BIN}, list them in
190be30614aSespie.Ev MODPY_ADJ_FILES .
1914bdacbd6SespieThese filenames can be relative to ${WRKSRC} and will be modified
192be30614aSespieat the end of
193be30614aSespie.Cm pre-configure .
1944bdacbd6Sespie.Pp
1954d1706f2SsthenFor ports not using standard Python build infrastructure,
1964d1706f2Ssthenit may be necessary to bytecode-compile installed .py files.
1974d1706f2SsthenThis can be done by using
1984d1706f2Ssthen.Ev ${MODPY_COMPILEALL} ,
1994d1706f2Ssthenusually in a post-install target.
2004d1706f2SsthenThis passes flags to use MAKE_JOBS, strip off WRKINST, and use
2014d1706f2Ssthenstandard optimization passes.
2024d1706f2SsthenFile or directory names can be given.
2034d1706f2SsthenDirectories are handled recursively.
2044d1706f2Ssthen.Pp
2054bdacbd6SespieThis module also affects
206be30614aSespie.Ev CATEGORIES ,
207be30614aSespie.Ev MAKE_ENV ,
208be30614aSespie.Ev CONFIGURE_ENV ,
209be30614aSespieand
2104bdacbd6Sespie.Ev SUBST_VARS ,
2114bdacbd6Sespieand it may affect the
212be30614aSespie.Cm test
213be30614aSespietarget.
2144bdacbd6Sespie.Pp
215be30614aSespieIf
216be30614aSespie.Ev MODPY_PI
2174bdacbd6Sespieis set to
21841ce3b17Snaddy.Sq Yes ,
2194bdacbd6Sespiethe module will provide a default for
220be30614aSespie.Ev HOMEPAGE
2214bdacbd6Sespieand set
2224bdacbd6Sespie.Ev MASTER_SITES
2234bdacbd6Sespie.Po
2244bdacbd6Sespiethe subdirectory can be overridden with
2254bdacbd6Sespie.Ev MODPY_PI_DIR
2264bdacbd6Sespie.Pc .
2274bdacbd6Sespie.Ss Packing-list generation
228be30614aSespiePython 2.x places .pyc files in the same directory as the associated .py file.
229be30614aSespiePython 3.x places these in a separate __pycache__ directory and uses an
230*5771aeffSsthenadditional suffix that includes the Python version.
231be30614aSespieIn some cases, an ABI tag is also used for names of compiled extensions.
232*5771aeffSsthenThe python module defines variables so that a
2334bdacbd6Sespie.Pa PLIST
234*5771aeffSsthenis likely to still work with a newer Python version without changes.
235be30614aSespie.Sh SEE ALSO
236be30614aSespie.Xr port-modules 5
237