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