4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
21 # Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
25 # The Python build infrastructure in setup.py.mk and pyproject.mk files uses
26 # several Python projects to work properly. Since we cannot use these projects
27 # until they are actually built and installed we need to bootstrap.
29 # We do have several sequential bootstrap checkpoints during the process:
31 # (0) Nothing works yet.
33 # Just core Python runtime is available (with no additional projects).
34 # While here almost nothing works. We cannot do following tasks with
35 # regular Python projects:
36 # - detect their requirements,
37 # - build and publish them,
40 # (1) The bootstrapper is ready.
42 # The bootstrapper is special tool that requires just core Python with no
43 # dependency on other Python projects and it is able to build and publish
44 # itself and other Python projects.
46 # For projects using the 'setup.py' build style we do not need any
47 # special bootstrapper because such projects are built using their own
48 # 'setup.py' script. The only issue with the 'setup.py' build style
49 # projects is that their 'setup.py' script usually depends on some other
50 # projects (typically setuptools) to get successfully built.
52 # For 'pyproject'-style projects we use pyproject_installer as the
55 # To achieve this checkpoint we just need to build pyproject_installer
56 # using pyproject_installer without detecting its requirements (they are
57 # none anyway) and without testing it (since no testing infrastructure is
60 # (2) The python-requires script works.
62 # Once the python-requires script works we can start to detect runtime
63 # dependencie of other Python projects automatically.
65 # To achieve this checkpoint we need to build the packaging project
66 # (directly needed by the python-requires script) and all projects
67 # required by packaging. During this all projects' dependencies needs to
68 # be manually evaluated to make sure they are correct.
70 # (3) The build infrastructure is fully working.
72 # Once we are here we can build any Python project, but we cannot test it
75 # For projects using the 'setup.py' build style we do not need any
76 # special build infrastructure. See checkpoint (1) above for detialed
77 # discussion about 'setup.py' build style projects.
79 # For 'pyproject'-style projects we need to build both 'build' and
80 # 'installer' projects and all projects they depends on.
82 # (4) The testing infrastructure is fully working.
84 # Once we are here we can finally use all features of the Python build
85 # framework. Including testing.
87 # To achieve this we need to build tox, tox-current-env, and pytest
88 # projects together with their dependencies.
90 # All projects needed to achieve checkpoints (1), (2), and (3) should set
91 # PYTHON_BOOTSTRAP to 'yes' in their Makefile to make sure the regular build
92 # infrastructure is not used for them and special set of build rules is applied
95 # All projects needed to go from checkpoint (3) to checkpoint (4) should set
96 # PYTHON_TEST_BOOTSTRAP to 'yes' in their Makefile to let the build
97 # infrastructure know that testing for such projects might not work properly.
99 # The PYTHON_BOOTSTRAP set to 'yes' implies PYTHON_TEST_BOOTSTRAP set to 'yes'
102 ifeq ($(strip $(PYTHON_BOOTSTRAP
)),yes
)
103 PYTHON_TEST_BOOTSTRAP
= yes
107 # Lists of Python projects needed to achieve particular bootstrap checkpoint.
108 # Indentation shows project dependencies (e.g. packaging requires flit_core).
110 PYTHON_BOOTSTRAP_CHECKPOINT_1
+= pyproject_installer
112 PYTHON_BOOTSTRAP_CHECKPOINT_2
+= $(PYTHON_BOOTSTRAP_CHECKPOINT_1
)
113 PYTHON_BOOTSTRAP_CHECKPOINT_2
+= packaging
114 PYTHON_BOOTSTRAP_CHECKPOINT_2
+= flit_core
116 # Particular python runtime is always required (at least to run setup.py)
117 PYTHON_REQUIRED_PACKAGES
+= runtime
/python
120 $(BUILD_DIR
)/%-$(1)/.built
: PYTHON_VERSION
=$(1)
121 $(BUILD_DIR
)/%-$(1)/.installed
: PYTHON_VERSION
=$(1)
122 $(BUILD_DIR
)/%-$(1)/.tested
: PYTHON_VERSION
=$(1)
123 $(BUILD_DIR
)/%-$(1)/.tested-and-compared
: PYTHON_VERSION
=$(1)
126 $(foreach pyver
, $(PYTHON_VERSIONS
), $(eval
$(call python-rule
,$(pyver
))))
128 $(BUILD_DIR
)/$(MACH32
)-%/.built
: BITS
=32
129 $(BUILD_DIR
)/$(MACH64
)-%/.built
: BITS
=64
130 $(BUILD_DIR
)/$(MACH32
)-%/.installed
: BITS
=32
131 $(BUILD_DIR
)/$(MACH64
)-%/.installed
: BITS
=64
132 $(BUILD_DIR
)/$(MACH32
)-%/.tested
: BITS
=32
133 $(BUILD_DIR
)/$(MACH64
)-%/.tested
: BITS
=64
134 $(BUILD_DIR
)/$(MACH32
)-%/.tested-and-compared
: BITS
=32
135 $(BUILD_DIR
)/$(MACH64
)-%/.tested-and-compared
: BITS
=64
137 PYTHON_32_VERSIONS
= $(filter-out $(PYTHON_64_ONLY_VERSIONS
), $(PYTHON_VERSIONS
))
139 BUILD_32
= $(PYTHON_32_VERSIONS
:%=$(BUILD_DIR
)/$(MACH32
)-%/.built
)
140 BUILD_64
= $(PYTHON_VERSIONS
:%=$(BUILD_DIR
)/$(MACH64
)-%/.built
)
141 BUILD_NO_ARCH
= $(PYTHON_VERSIONS
:%=$(BUILD_DIR
)/$(MACH
)-%/.built
)
143 ifeq ($(filter-out $(PYTHON_64_ONLY_VERSIONS
), $(PYTHON_VERSION
)),)
144 BUILD_32_and_64
= $(BUILD_64
)
147 INSTALL_32
= $(PYTHON_32_VERSIONS
:%=$(BUILD_DIR
)/$(MACH32
)-%/.installed
)
148 INSTALL_64
= $(PYTHON_VERSIONS
:%=$(BUILD_DIR
)/$(MACH64
)-%/.installed
)
149 INSTALL_NO_ARCH
= $(PYTHON_VERSIONS
:%=$(BUILD_DIR
)/$(MACH
)-%/.installed
)
151 PYTHON_ENV
= CC
="$(CC)"
152 PYTHON_ENV
+= CFLAGS
="$(CFLAGS)"
153 PYTHON_ENV
+= CXX
="$(CXX)"
154 PYTHON_ENV
+= CXXFLAGS
="$(CXXFLAGS)"
155 PYTHON_ENV
+= LDFLAGS
="$(LDFLAGS)"
156 PYTHON_ENV
+= PKG_CONFIG_PATH
="$(PKG_CONFIG_PATH)"
158 COMPONENT_BUILD_ENV
+= $(PYTHON_ENV
)
159 COMPONENT_INSTALL_ENV
+= $(PYTHON_ENV
)
160 COMPONENT_TEST_ENV
+= $(PYTHON_ENV
)
162 # Set CARGO_HOME to make sure projects built using rust (for example via
163 # setuptools-rust) do not pollute user's home directory with cargo bits.
164 COMPONENT_BUILD_ENV
+= CARGO_HOME
=$(@D
)/.cargo
166 # Make sure the default Python version is installed last and so is the
167 # canonical version. This is needed for components that keep PYTHON_VERSIONS
168 # set to more than single value, but deliver unversioned binaries in usr/bin or
169 # other overlapping files.
170 define python-order-rule
171 $(BUILD_DIR
)/%-$(PYTHON_VERSION
)/.installed
: $(BUILD_DIR
)/%-$(1)/.installed
173 $(foreach pyver
,$(filter-out $(PYTHON_VERSION
),$(PYTHON_VERSIONS
)),$(eval
$(call python-order-rule
,$(pyver
))))
175 # We need to copy the source dir to avoid its modification by install target
176 # where egg-info is re-generated
177 CLONEY_ARGS
= CLONEY_MODE
="copy"
179 COMPONENT_BUILD_CMD
= $(PYTHON
) setup.py
--no-user-cfg build
$(COMPONENT_BUILD_SETUP_PY_ARGS
)
182 COMPONENT_INSTALL_CMD
= $(PYTHON
) setup.py
--no-user-cfg
install
184 COMPONENT_INSTALL_ARGS
+= --root
$(PROTO_DIR
)
185 COMPONENT_INSTALL_ARGS
+= --install-lib
=$(PYTHON_LIB
)
186 COMPONENT_INSTALL_ARGS
+= --install-data
=$(PYTHON_DATA
)
187 COMPONENT_INSTALL_ARGS
+= --skip-build
188 COMPONENT_INSTALL_ARGS
+= --force
190 ifeq ($(strip $(SINGLE_PYTHON_VERSION
)),no
)
191 # Rename binaries in /usr/bin to contain version number
192 COMPONENT_POST_INSTALL_ACTION
+= \
193 for f in
$(PROTOUSRBINDIR
)/* ; do \
194 [ -f
$$f ] || continue
; \
195 for v in
$(PYTHON_VERSIONS
) ; do \
196 [ "$$f" == "$${f%%$$v}" ] || continue
2 ; \
198 $(MV
) $$f $$f-$(PYTHON_VERSION
) ; \
202 # Remove any previous dependency files
203 COMPONENT_POST_INSTALL_ACTION
+= $(RM
) $(@D
)/.depend-runtime
$(@D
)/.depend-test
;
205 # Define Python version specific filenames for tests.
206 ifeq ($(strip $(USE_COMMON_TEST_MASTER
)),no
)
207 COMPONENT_TEST_MASTER
= $(COMPONENT_TEST_RESULTS_DIR
)/results-
$(PYTHON_VERSION
).master
209 COMPONENT_TEST_BUILD_DIR
= $(BUILD_DIR
)/test-
$(PYTHON_VERSION
)
210 COMPONENT_TEST_OUTPUT
= $(COMPONENT_TEST_BUILD_DIR
)/test-
$(PYTHON_VERSION
)-results
211 COMPONENT_TEST_DIFFS
= $(COMPONENT_TEST_BUILD_DIR
)/test-
$(PYTHON_VERSION
)-diffs
212 COMPONENT_TEST_SNAPSHOT
= $(COMPONENT_TEST_BUILD_DIR
)/results-
$(PYTHON_VERSION
).snapshot
213 COMPONENT_TEST_TRANSFORM_CMD
= $(COMPONENT_TEST_BUILD_DIR
)/transform-
$(PYTHON_VERSION
)-results
215 # Generic transforms for Python test results.
216 # See below for test style specific transforms.
217 COMPONENT_TEST_TRANSFORMS
+= "-e 's|$(PYTHON_DIR)|\$$(PYTHON_DIR)|g'"
219 # Testing depends on install target because we want to test installed modules
220 COMPONENT_TEST_DEP
+= $(BUILD_DIR
)/%/.installed
221 # Point Python to the proto area so it is able to find installed modules there
222 COMPONENT_TEST_ENV
+= PYTHONPATH
=$(PROTO_DIR
)/$(PYTHON_LIB
)
223 # Make sure testing is able to find own installed executables (if any)
224 COMPONENT_TEST_ENV
+= PATH
=$(PROTOUSRBINDIR
):$(PATH
)
226 # determine the type of tests we want to run.
227 ifeq ($(strip $(wildcard $(COMPONENT_TEST_RESULTS_DIR
)/results-
*.master
)),)
228 TEST_32
= $(PYTHON_32_VERSIONS
:%=$(BUILD_DIR
)/$(MACH32
)-%/.tested
)
229 TEST_64
= $(PYTHON_VERSIONS
:%=$(BUILD_DIR
)/$(MACH64
)-%/.tested
)
230 TEST_NO_ARCH
= $(PYTHON_VERSIONS
:%=$(BUILD_DIR
)/$(MACH
)-%/.tested
)
232 TEST_32
= $(PYTHON_32_VERSIONS
:%=$(BUILD_DIR
)/$(MACH32
)-%/.tested-and-compared
)
233 TEST_64
= $(PYTHON_VERSIONS
:%=$(BUILD_DIR
)/$(MACH64
)-%/.tested-and-compared
)
234 TEST_NO_ARCH
= $(PYTHON_VERSIONS
:%=$(BUILD_DIR
)/$(MACH
)-%/.tested-and-compared
)
238 # Testing in the Python world is complex. Python projects usually do not
239 # support Makefile with common 'check' or 'test' target to get built bits
242 # De facto standard way to test Python projects these days is tox which is
243 # designed and used primarily for release testing; to make sure the released
244 # python project runs on all supported Python versions, platforms, etc. tox
245 # does so using virtualenv and creates isolated test environments where the
246 # tested package together with all its dependencies is automatically installed
247 # (using pip) and tested. This is great for Python projects developers but it
248 # is hardly usable for operating system distributions like OpenIndiana.
250 # We do not need such release testing. Instead we need something closer to
251 # integration testing: we need to test the built component in our real
252 # environment without automatic installation of any dependencies using pip. In
253 # addition, we need to run tests only for Python versions we actually support
254 # and the component is built for.
256 # To achieve that we do few things. First, to avoid isolated environments
257 # (virtualenv) we run tox with the tox-current-env plugin. Second, to test
258 # only Python versions we are interested in we use -e option for tox to select
259 # single Python version only. Since we run separate test target per Python
260 # version this will make sure we test all needed Python versions.
262 # The tox tool itself uses some other tools under the hood to run tests, for
263 # example pytest. Some projects could even support pytest testing directly
264 # without support for tox. For such projects we offer separate "pytest"-style
267 # For projects that do not support testing using neither tox nor pytest we
268 # offer either unittest or (deprecated) "setup.py test" testing too.
270 # The TEST_STYLE variable is used to select (or force) particular test style
271 # for Python projects. Valid values are:
273 # tox - "tox"-style testing
274 # pytest - "pytest"-style testing
275 # unittest - "unittest"-style testing
276 # setup.py - "setup.py test"-style testing
277 # none - no testing is supported (or desired) at all
281 ifeq ($(strip $(TEST_STYLE
)),tox
)
282 # tox needs PATH environment variable - see https://github.com/tox-dev/tox/issues/2538
283 # We already added it to the test environment - see above
284 COMPONENT_TEST_ENV
+= PYTEST_ADDOPTS
="$(PYTEST_ADDOPTS)"
285 COMPONENT_TEST_ENV
+= NOSE_VERBOSE
=2
286 COMPONENT_TEST_CMD
= $(TOX
)
287 COMPONENT_TEST_ARGS
= --current-env
--no-provision
288 COMPONENT_TEST_ARGS
+= --recreate
289 COMPONENT_TEST_ARGS
+= $(TOX_TESTENV
)
290 COMPONENT_TEST_TARGETS
= $(if
$(strip $(TOX_POSARGS
)),-- $(TOX_POSARGS
))
292 TOX_TESTENV
= -e py
$(subst .
,,$(PYTHON_VERSION
))
294 # Make sure following tools are called indirectly to properly support tox-current-env
295 TOX_CALL_INDIRECTLY
+= py.
test
296 TOX_CALL_INDIRECTLY
+= pytest
297 TOX_CALL_INDIRECTLY
+= coverage
298 TOX_CALL_INDIRECTLY
+= zope-testrunner
299 TOX_CALL_INDIRECTLY.zope-testrunner
= zope.testrunner
300 TOX_CALL_INDIRECTLY
+= sphinx-build
301 TOX_CALL_INDIRECTLY.sphinx-build
= sphinx.cmd.build
302 TOX_CALL_INDIRECTLY
+= nosetests
303 TOX_CALL_INDIRECTLY.nosetests
= nose
304 $(foreach indirectly
, $(TOX_CALL_INDIRECTLY
), $(eval TOX_CALL_INDIRECTLY.
$(indirectly
) ?
= $(indirectly
)))
305 COMPONENT_PRE_TEST_ACTION
+= COMPONENT_TEST_DIR
=$(COMPONENT_TEST_DIR
) ;
306 COMPONENT_PRE_TEST_ACTION
+= \
307 $(foreach indirectly
, $(TOX_CALL_INDIRECTLY
), \
308 [ -f
$$COMPONENT_TEST_DIR/tox.ini
] && \
309 $(GSED
) -i
-e
'/^commands *=/,/^$$/{ \
310 s/^\(\(commands *=\)\{0,1\}[ \t]*\)'$(indirectly
)'\([ \t]\{1,\}.*\)\{0,1\}$$/\1python -m '$(TOX_CALL_INDIRECTLY.
$(indirectly
))'\3/ \
311 }' $$COMPONENT_TEST_DIR/tox.ini
; \
313 COMPONENT_PRE_TEST_ACTION
+= true
;
315 # Normalize tox test results.
316 COMPONENT_TEST_TRANSFORMS
+= "-e 's/py$(subst .,,$(PYTHON_VERSION))/py\$$(PYV)/g'" # normalize PYV
317 COMPONENT_TEST_TRANSFORMS
+= "-e '/^py\$$(PYV) installed:/d'" # depends on set of installed packages
318 COMPONENT_TEST_TRANSFORMS
+= "-e '/PYTHONHASHSEED/d'" # this is random
320 # Normalize zope.testrunner test results
321 COMPONENT_TEST_TRANSFORMS
+= \
322 "-e 's/ in \([0-9]\{1,\} minutes \)\{0,1\}[0-9]\{1,\}\.[0-9]\{3\} seconds//'" # timing
324 # Remove timing for tox 4 test results
325 COMPONENT_TEST_TRANSFORMS
+= "-e 's/^\( py\$$(PYV): OK\) (.* seconds)$$/\1/'"
326 COMPONENT_TEST_TRANSFORMS
+= "-e 's/^\( congratulations :)\) (.* seconds)$$/\1/'"
328 # Remove useless lines from the "coverage combine" output
329 COMPONENT_TEST_TRANSFORMS
+= "-e '/^Combined data file .*\.coverage/d'"
330 COMPONENT_TEST_TRANSFORMS
+= "-e '/^Skipping duplicate data .*\.coverage/d'"
332 # sort list of Sphinx doctest results
333 COMPONENT_TEST_TRANSFORMS
+= \
335 $(GSED) -u -e '/^running tests\.\.\.$$/q' ; \
336 $(GSED) -u -e '/^Doctest summary/Q' \
337 | $(NAWK) '/^$$/{\$$0=\"\\\\n\"}1' ORS='|' \
338 | $(GNU_GREP) -v '^|$$' \
340 | tr -d '\\\\n' | tr '|' '\\\\n' \
341 | $(NAWK) '{print}END{if(NR>0)printf(\"\\\\nDoctest summary\\\\n\")}' ; \
343 ) | $(COMPONENT_TEST_TRANSFORMER)"
345 # tox package together with the tox-current-env plugin is needed
346 USERLAND_TEST_REQUIRED_PACKAGES
+= library
/python
/tox
347 USERLAND_TEST_REQUIRED_PACKAGES
+= library
/python
/tox-current-env
349 # The dependency-groups is used to print dependency groups if they are
350 # specified in the tox config (see below)
351 USERLAND_TEST_REQUIRED_PACKAGES
+= library
/python
/dependency-groups
353 # Generate raw lists of test dependencies per Python version
354 # Please note we set PATH below six times for tox to workaround
355 # https://github.com/tox-dev/tox/issues/2538
356 COMPONENT_POST_INSTALL_ACTION
+= \
357 if
[ -x
"$(COMPONENT_TEST_CMD)" ] ; then \
358 cd
$(@D
)$(COMPONENT_SUBDIR
:%=/%) ; \
359 echo
"Testing dependencies:" ; \
360 PATH
=$(PATH
) PYTHONPATH
=$(PROTO_DIR
)/$(PYTHON_DIR
)/site-packages
:$(PROTO_DIR
)/$(PYTHON_LIB
) \
361 $(TOX
) -qq
--no-provision
--print-deps-to
=- $(TOX_TESTENV
) || exit
1 ; \
362 echo
"Testing extras:" ; \
363 PATH
=$(PATH
) PYTHONPATH
=$(PROTO_DIR
)/$(PYTHON_DIR
)/site-packages
:$(PROTO_DIR
)/$(PYTHON_LIB
) \
364 $(TOX
) -qq
--no-provision
--print-extras-to
=- $(TOX_TESTENV
) || exit
1 ; \
365 echo
"Testing dependency groups:" ; \
366 PATH
=$(PATH
) PYTHONPATH
=$(PROTO_DIR
)/$(PYTHON_DIR
)/site-packages
:$(PROTO_DIR
)/$(PYTHON_LIB
) \
367 $(TOX
) -qq
--no-provision
--print-dependency-groups-to
=- $(TOX_TESTENV
) || exit
1 ; \
368 ( PATH
=$(PATH
) PYTHONPATH
=$(PROTO_DIR
)/$(PYTHON_DIR
)/site-packages
:$(PROTO_DIR
)/$(PYTHON_LIB
) \
369 $(TOX
) -qq
--no-provision
--print-deps-to
=- $(TOX_TESTENV
) \
370 |
$(WS_TOOLS
)/python-resolve-deps \
371 PYTHONPATH
=$(PROTO_DIR
)/$(PYTHON_DIR
)/site-packages
:$(PROTO_DIR
)/$(PYTHON_LIB
) \
372 $(PYTHON
) $(WS_TOOLS
)/python-requires
$(COMPONENT_NAME
) \
373 |
$(PYTHON
) $(WS_TOOLS
)/python-requires
- ; \
374 for e in
$$(PATH
=$(PATH
) PYTHONPATH
=$(PROTO_DIR
)/$(PYTHON_DIR
)/site-packages
:$(PROTO_DIR
)/$(PYTHON_LIB
) \
375 $(TOX
) -qq
--no-provision
--print-extras-to
=- $(TOX_TESTENV
)) ; do \
376 PYTHONPATH
=$(PROTO_DIR
)/$(PYTHON_DIR
)/site-packages
:$(PROTO_DIR
)/$(PYTHON_LIB
) \
377 $(PYTHON
) $(WS_TOOLS
)/python-requires
$(COMPONENT_NAME
) $$e ; \
379 PATH
=$(PATH
) PYTHONPATH
=$(PROTO_DIR
)/$(PYTHON_DIR
)/site-packages
:$(PROTO_DIR
)/$(PYTHON_LIB
) \
380 $(TOX
) -qq
--no-provision
--print-dependency-groups-to
=- $(TOX_TESTENV
) \
381 |
/usr
/gnu
/bin
/xargs
-r
/usr
/bin
/dependency-groups-
$(PYTHON_VERSION
) \
382 |
$(WS_TOOLS
)/python-resolve-deps \
383 PYTHONPATH
=$(PROTO_DIR
)/$(PYTHON_DIR
)/site-packages
:$(PROTO_DIR
)/$(PYTHON_LIB
) \
384 $(PYTHON
) $(WS_TOOLS
)/python-requires
$(COMPONENT_NAME
) \
385 |
$(PYTHON
) $(WS_TOOLS
)/python-requires
- \
386 ) |
$(GSED
) -e
'/^tox\(-current-env\)\?$$/d' >> $(@D
)/.depend-test
; \
388 else ifeq ($(strip $(TEST_STYLE
)),pytest
)
389 COMPONENT_TEST_CMD
= $(PYTHON
) -m pytest
390 COMPONENT_TEST_ARGS
= $(PYTEST_ADDOPTS
)
391 COMPONENT_TEST_TARGETS
=
393 USERLAND_TEST_REQUIRED_PACKAGES
+= library
/python
/pytest
394 else ifeq ($(strip $(TEST_STYLE
)),unittest
)
395 COMPONENT_TEST_CMD
= $(PYTHON
) -m unittest
396 COMPONENT_TEST_ARGS
=
397 COMPONENT_TEST_ARGS
+= --verbose
398 COMPONENT_TEST_TARGETS
=
399 else ifeq ($(strip $(TEST_STYLE
)),setup.py
)
400 # Old and deprecated "setup.py test"-style testing
401 COMPONENT_TEST_CMD
= $(PYTHON
) setup.py
402 COMPONENT_TEST_ARGS
= --no-user-cfg
403 COMPONENT_TEST_TARGETS
= test
404 else ifeq ($(strip $(TEST_STYLE
)),none
)
405 TEST_TARGET
= $(NO_TESTS
)
408 # Run pytest verbose to get separate line per test in results output
409 PYTEST_ADDOPTS
+= --verbose
411 # Force pytest to not use colored output so the results normalization is unaffected
412 PYTEST_ADDOPTS
+= --color
=no
414 # Create list of required pytest plugins.
416 PYTEST_PLUGINS
+= $$(if
$$(filter library
/python
/$(1)-$$(subst .
,,$$(PYTHON_VERSION
)), $$(REQUIRED_PACKAGES
) $$(TEST_REQUIRED_PACKAGES
) $$(COMPONENT_FMRI
)-$$(subst .
,,$$(PYTHON_VERSION
))),$(2))
418 $(eval
$(call pytest-plugin
,anyio
,anyio
))
419 $(eval
$(call pytest-plugin
,betamax
,pytest-betamax
))
420 $(eval
$(call pytest-plugin
,faker
,faker
))
421 $(eval
$(call pytest-plugin
,flaky
,flaky
))
422 $(eval
$(call pytest-plugin
,hypothesis
,hypothesispytest
))
423 $(eval
$(call pytest-plugin
,inline-snapshot
,inline_snapshot
))
424 $(eval
$(call pytest-plugin
,jaraco-test
,jaraco.
test.http
))
425 $(eval
$(call pytest-plugin
,jaraco-vcs
,jaraco.vcs.fixtures
))
426 $(eval
$(call pytest-plugin
,kgb
,kgb
))
427 $(eval
$(call pytest-plugin
,pyfakefs
,pytest_fakefs
))
428 $(eval
$(call pytest-plugin
,pytest-asyncio
,asyncio
))
429 $(eval
$(call pytest-plugin
,pytest-benchmark
,benchmark
))
430 $(eval
$(call pytest-plugin
,pytest-black
,black
))
431 $(eval
$(call pytest-plugin
,pytest-check
,check))
432 $(eval
$(call pytest-plugin
,pytest-checkdocs
,checkdocs
))
433 $(eval
$(call pytest-plugin
,pytest-console-scripts
,console-scripts
))
434 $(eval
$(call pytest-plugin
,pytest-cov
,pytest_cov
))
435 $(eval
$(call pytest-plugin
,pytest-custom-exit-code
,custom_exit_code
))
436 $(eval
$(call pytest-plugin
,pytest-datadir
,pytest-datadir
))
437 $(eval
$(call pytest-plugin
,pytest-enabler
,enabler
))
438 $(eval
$(call pytest-plugin
,pytest-env
,env
))
439 $(eval
$(call pytest-plugin
,pytest-expect
,pytest_expect
))
440 $(eval
$(call pytest-plugin
,pytest-flake8
,flake8
))
441 $(eval
$(call pytest-plugin
,pytest-forked
,pytest_forked
))
442 $(eval
$(call pytest-plugin
,pytest-freezer
,freezer
))
443 $(eval
$(call pytest-plugin
,pytest-helpers-namespace
,helpers_namespace
))
444 $(eval
$(call pytest-plugin
,pytest-home
,home
))
445 $(eval
$(call pytest-plugin
,pytest-httpserver
,pytest_httpserver
))
446 $(eval
$(call pytest-plugin
,pytest-ignore-flaky
,pytest_ignore_flaky
))
447 $(eval
$(call pytest-plugin
,pytest-lazy-fixtures
,pytest_lazyfixture
))
448 $(eval
$(call pytest-plugin
,pytest-metadata
,metadata
))
449 $(eval
$(call pytest-plugin
,pytest-mock
,pytest_mock
))
450 $(eval
$(call pytest-plugin
,pytest-mypy
,mypy
))
451 $(eval
$(call pytest-plugin
,pytest-mypy-plugins
,pytest-mypy-plugins
))
452 $(eval
$(call pytest-plugin
,pytest-perf
,perf
))
453 $(eval
$(call pytest-plugin
,pytest-randomly
,randomly
))
454 $(eval
$(call pytest-plugin
,pytest-regressions
,regressions
))
455 $(eval
$(call pytest-plugin
,pytest-relaxed
,relaxed
))
456 $(eval
$(call pytest-plugin
,pytest-reporter
,reporter
))
457 $(eval
$(call pytest-plugin
,pytest-rerunfailures
,rerunfailures
))
458 $(eval
$(call pytest-plugin
,pytest-salt-factories
,salt-factories
))
459 $(eval
$(call pytest-plugin
,pytest-salt-factories
,salt-factories-event-listener
))
460 $(eval
$(call pytest-plugin
,pytest-salt-factories
,salt-factories-factories
))
461 $(eval
$(call pytest-plugin
,pytest-salt-factories
,salt-factories-loader-mock
))
462 $(eval
$(call pytest-plugin
,pytest-salt-factories
,salt-factories-log-server
))
463 $(eval
$(call pytest-plugin
,pytest-salt-factories
,salt-factories-markers
))
464 $(eval
$(call pytest-plugin
,pytest-salt-factories
,salt-factories-sysinfo
))
465 $(eval
$(call pytest-plugin
,pytest-shell-utilities
,shell-utilities
))
466 $(eval
$(call pytest-plugin
,pytest-skip-markers
,skip-markers
))
467 $(eval
$(call pytest-plugin
,pytest-socket
,socket
))
468 $(eval
$(call pytest-plugin
,pytest-subprocess
,pytest-subprocess
))
469 $(eval
$(call pytest-plugin
,pytest-subtests
,subtests
))
470 $(eval
$(call pytest-plugin
,pytest-system-statistics
,system-statistics
))
471 $(eval
$(call pytest-plugin
,pytest-timeout
,timeout
))
472 $(eval
$(call pytest-plugin
,pytest-travis-fold
,travis-fold
))
473 $(eval
$(call pytest-plugin
,pytest-xdist
,xdist
))
474 $(eval
$(call pytest-plugin
,pytest-xdist
,xdist.looponfail
))
475 $(eval
$(call pytest-plugin
,pytest-xprocess
,xprocess
))
476 $(eval
$(call pytest-plugin
,teamcity-messages
,pytest-teamcity
))
477 $(eval
$(call pytest-plugin
,time-machine
,time_machine
))
478 $(eval
$(call pytest-plugin
,typeguard
,typeguard
))
480 # Transitional (indirect) runtime dependencies of pytest plugins.
482 # Note: The list is not exhaustive and contians only entries that proved to be
485 # pytest-datadir is required by pytest-regressions and pytest-regressions is required by coincidence
486 $(eval
$(call pytest-plugin
,coincidence
,regressions
))
487 $(eval
$(call pytest-plugin
,coincidence
,pytest-datadir
))
489 # By default disable all pytest plugins ...
490 COMPONENT_TEST_ENV
+= PYTEST_DISABLE_PLUGIN_AUTOLOAD
=1
491 # ... and load those in the PYTEST_PLUGINS list only.
492 # $(sort) is used to avoid duplicates and to strip spaces.
493 COMPONENT_TEST_ENV
+= PYTEST_PLUGINS
="$(subst $(space),$(comma),$(sort $(PYTEST_PLUGINS)))"
495 # By default we are not interested in full list of test failures so exit on
496 # first failure to save time. This could be easily overridden from environment
497 # if needed (for example to debug test failures) or in per-component Makefile.
499 PYTEST_ADDOPTS
+= $(PYTEST_FASTFAIL
)
501 # By default we are not interested to see the default long tracebacks.
502 # Detailed tracebacks are shown either for failures or xfails. We aim to see
503 # testing passed so there should be no failures. Since xfails are expected
504 # failures we are not interested in detailed tracebacks here at all since they
505 # could contain random data, like pointers, temporary file names, etc.
506 PYTEST_TRACEBACK
= --tb
=line
507 PYTEST_ADDOPTS
+= $(PYTEST_TRACEBACK
)
509 # Normalize pytest test results. The pytest framework could be used either
510 # directly or via tox or setup.py so add these transforms for all test styles
512 COMPONENT_TEST_TRANSFORMS
+= \
513 "-e 's/^\(platform sunos5 -- Python \)$(shell echo $(PYTHON_VERSION) | $(GSED) -e 's/\./\\./g')\.[0-9]\{1,\}.*\( -- .*\)/\1\$$(PYTHON_VERSION).X\2/'"
514 COMPONENT_TEST_TRANSFORMS
+= "-e '/^plugins: /d'" # order of listed plugins could vary
515 COMPONENT_TEST_TRANSFORMS
+= "-e '/^-\{1,\} coverage: /,/^$$/d'" # remove coverage report
516 COMPONENT_TEST_TRANSFORMS
+= "-e 's/ \{1,\}\[...%\]\$$//'" # drop percentage
517 COMPONENT_TEST_TRANSFORMS
+= \
518 "-e 's/^=\{1,\} \(.*\) in [0-9]\{1,\}\.[0-9]\{1,\}s \(([^)]*) \)\?=\{1,\}$$/======== \1 ========/'" # remove timing
519 # Remove slowest durations report for projects that run pytest with --durations option
520 COMPONENT_TEST_TRANSFORMS
+= "-e '/^=\{1,\} slowest [0-9 ]*durations =\{1,\}$$/,/^=/{/^=/!d}'"
521 # Remove short test summary info for projects that run pytest with -r option
522 COMPONENT_TEST_TRANSFORMS
+= "-e '/^=\{1,\} short test summary info =\{1,\}$$/,/^=/{/^=/!d}'"
524 # Normalize test results produced by pytest-benchmark
525 COMPONENT_TEST_TRANSFORMS
+= \
526 $(if
$(filter library
/python
/pytest-benchmark-
$(subst .
,,$(PYTHON_VERSION
)), $(REQUIRED_PACKAGES
) $(TEST_REQUIRED_PACKAGES
)),"| ( \
527 $(GSED) -e '/^-\{1,\} benchmark/,/^=/{/^=/!d}' \
528 ) | $(COMPONENT_TEST_TRANSFORMER) -e ''")
530 # Normalize test results produced by pytest-randomly
531 USE_PYTEST_RANDOMLY
= $(filter library
/python
/pytest-randomly-
$(subst .
,,$(PYTHON_VERSION
)), $(REQUIRED_PACKAGES
) $(TEST_REQUIRED_PACKAGES
))
532 PYTEST_SORT_TESTS
= $(USE_PYTEST_RANDOMLY
)
533 COMPONENT_TEST_TRANSFORMS
+= $(if
$(strip $(USE_PYTEST_RANDOMLY
)),"-e '/^Using --randomly-seed=[0-9]\{1$(comma)\}\$$/d'")
534 COMPONENT_TEST_TRANSFORMS
+= \
535 $(if
$(strip $(PYTEST_SORT_TESTS
)),"| ( \
536 $(GSED) -u -e '/^=\{1$(comma)\} test session starts /q' ; \
537 $(GSED) -u -e '/^\$$/q' ; \
538 $(GSED) -u -e '/^\$$/Q' | $(SORT) | $(GSED) -e '\$$a\'\$$'\\\n\\\n' ; \
540 ) | $(COMPONENT_TEST_TRANSFORMER) -e ''")
542 # Normalize test results produced by pytest-xdist
543 COMPONENT_TEST_TRANSFORMS
+= \
544 $(if
$(filter library
/python
/pytest-xdist-
$(subst .
,,$(PYTHON_VERSION
)), $(REQUIRED_PACKAGES
) $(TEST_REQUIRED_PACKAGES
)),"| ( \
546 -e '/^created: .* workers$$/d' \
547 -e 's/^[0-9]\{1,\}\( workers \[[0-9]\{1,\} items\]\)$$/X\1/' \
548 -e '/^scheduling tests via /q' ; \
549 $(GSED) -u -e '/^$$/q' ; \
550 $(GSED) -u -n -e '/^\[gw/p' -e '/^$$/Q' | ( $(GSED) \
551 -e 's/^\[gw[0-9]\{1,\}\] \[...%\] //' \
553 -e 's/\([^ ]\{1,\}\) \(.*\)$$/\2 \1/' \
554 | $(SORT) | $(NAWK) '{print}END{if(NR>0)printf(\"\\\\n\")}' ; \
557 ) | $(COMPONENT_TEST_TRANSFORMER) -e ''")
559 # Normalize stestr test results
560 USE_STESTR
= $(filter library
/python
/stestr-
$(subst .
,,$(PYTHON_VERSION
)), $(REQUIRED_PACKAGES
) $(TEST_REQUIRED_PACKAGES
))
561 COMPONENT_TEST_TRANSFORMS
+= \
562 $(if
$(strip $(USE_STESTR
)),"| ( \
563 $(GSED) -e '0,/^{[0-9]\{1,\}}/{//i\'\$$'\\\n{0}\\\n}' \
564 -e 's/^\(Ran: [0-9]\{1,\} tests\{0,1\}\) in .*\$$/\1/' \
565 -e '/^Sum of execute time for each test/d' \
566 -e '/^ - Worker /d' \
568 $(GSED) -u -e '/^{0}\$$/Q' ; \
569 $(GSED) -u -e 's/^{[0-9]\{1,\}} //' \
570 -e 's/\[[.0-9]\{1,\}s\] \.\.\./.../' \
571 -e '/^\$$/Q' | $(SORT) | $(GSED) -e '\$$a\'\$$'\\\n\\\n' ; \
573 ) | $(COMPONENT_TEST_TRANSFORMER) -e ''")
575 # Remove timestamp produced by coincidence
576 USE_COINCIDENCE
= $(filter library
/python
/coincidence-
$(subst .
,,$(PYTHON_VERSION
)), $(REQUIRED_PACKAGES
) $(TEST_REQUIRED_PACKAGES
))
577 COMPONENT_TEST_TRANSFORMS
+= $(if
$(strip $(USE_COINCIDENCE
)),"-e '/^Test session started at/d'")
579 # Normalize setup.py test results. The setup.py testing could be used either
580 # directly or via tox so add these transforms for all test styles
582 COMPONENT_TEST_TRANSFORMS
+= "-e '/SetuptoolsDeprecationWarning:/,+1d'" # depends on Python version and is useless
583 COMPONENT_TEST_TRANSFORMS
+= "-e 's/^\(Ran [0-9]\{1,\} tests\{0,1\}\) in .*$$/\1/'" # delete timing from test results
585 COMPONENT_TEST_DIR
= $(@D
)$(COMPONENT_SUBDIR
:%=/%)
587 ifeq ($(strip $(SINGLE_PYTHON_VERSION
)),no
)
588 # Temporarily create symlinks for renamed binaries
589 COMPONENT_PRE_TEST_ACTION
+= \
590 for f in
$(PROTOUSRBINDIR
)/*-$(PYTHON_VERSION
) ; do \
591 [ -f
$$f ] || continue
; \
592 [ -L
$${f
%%-$(PYTHON_VERSION
)} ] && $(RM
) $${f
%%-$(PYTHON_VERSION
)} ; \
593 [ -e
$${f
%%-$(PYTHON_VERSION
)} ] && continue
; \
594 $(SYMLINK
) $$(basename $$f) $${f
%%-$(PYTHON_VERSION
)} ; \
597 # Cleanup of temporary symlinks
598 COMPONENT_POST_TEST_ACTION
+= \
599 for f in
$(PROTOUSRBINDIR
)/*-$(PYTHON_VERSION
) ; do \
600 [ -f
$$f ] || continue
; \
601 [ ! -L
$${f
%%-$(PYTHON_VERSION
)} ] ||
$(RM
) $${f
%%-$(PYTHON_VERSION
)} ; \
606 ifeq ($(strip $(SINGLE_PYTHON_VERSION
)),no
)
607 # We need to add -$(PYV) to package fmri
608 GENERATE_EXTRA_CMD
+= | \
609 $(GSED
) -e
's/^\(set name=pkg.fmri [^@]*\)\(.*\)$$/\1-$$(PYV)\2/'
612 # Add runtime dependencies from project metadata to generated manifest
613 GENERATE_EXTRA_DEPS
+= $(BUILD_DIR
)/META.depend-runtime.res
614 GENERATE_EXTRA_CMD
+= | \
617 echo
"\# python modules are unusable without python runtime binary" ; \
618 echo
"depend type=require fmri=__TBD pkg.debug.depend.file=python\$$(PYVER) \\" ; \
619 echo
" pkg.debug.depend.path=usr/bin" ; \
621 echo
"\# Automatically generated dependencies based on distribution metadata" ; \
622 $(CAT
) $(BUILD_DIR
)/META.depend-runtime.res \
625 # Add runtime dependencies from project metadata to REQUIRED_PACKAGES
626 REQUIRED_PACKAGES_RESOLVED
+= $(BUILD_DIR
)/META.depend-runtime.res
629 # Generate raw lists of runtime dependencies per Python version
630 COMPONENT_POST_INSTALL_ACTION
+= \
631 PYTHONPATH
=$(PROTO_DIR
)/$(PYTHON_DIR
)/site-packages
:$(PROTO_DIR
)/$(PYTHON_LIB
) \
632 $(PYTHON
) $(WS_TOOLS
)/python-requires
$(COMPONENT_NAME
) >> $(@D
)/.depend-runtime
;
634 # Convert raw per version lists of runtime dependencies to single resolved
635 # runtime dependency list. The dependency on META.depend-test.required here is
636 # purely to get the file created as a side effect of this target.
637 $(BUILD_DIR
)/META.depend-runtime.res
: $(INSTALL_
$(MK_BITS
)) $(BUILD_DIR
)/META.depend-test.required
638 $(CAT
) $(INSTALL_
$(MK_BITS
):%.installed
=%.depend-runtime
) |
$(SORT
) -u \
639 |
$(GSED
) -e
's/.*/depend type=require fmri=pkg:\/library\/python\/&-$$(PYV)/' > $@
641 # Generate raw lists of test dependencies per Python version
642 COMPONENT_POST_INSTALL_ACTION
+= \
643 cd
$(@D
)$(COMPONENT_SUBDIR
:%=/%) ; \
644 ( for f in
$(TEST_REQUIREMENTS
) ; do \
645 $(CAT
) $$f |
$(DOS2UNIX
) -ascii
; \
647 for e in
$(TEST_REQUIREMENTS_EXTRAS
) ; do \
648 PYTHONPATH
=$(PROTO_DIR
)/$(PYTHON_DIR
)/site-packages
:$(PROTO_DIR
)/$(PYTHON_LIB
) \
649 $(PYTHON
) $(WS_TOOLS
)/python-requires
$(COMPONENT_NAME
) $$e ; \
650 done
) |
$(WS_TOOLS
)/python-resolve-deps \
651 PYTHONPATH
=$(PROTO_DIR
)/$(PYTHON_DIR
)/site-packages
:$(PROTO_DIR
)/$(PYTHON_LIB
) \
652 $(PYTHON
) $(WS_TOOLS
)/python-requires
$(COMPONENT_NAME
) \
653 |
$(PYTHON
) $(WS_TOOLS
)/python-requires
- >> $(@D
)/.depend-test
;
655 # Convert raw per version lists of test dependencies to single list of
656 # TEST_REQUIRED_PACKAGES entries. Some Python projects lists their own project
657 # as a test dependency so filter this out here too.
658 $(BUILD_DIR
)/META.depend-test.required
: $(INSTALL_
$(MK_BITS
))
659 $(CAT
) $(INSTALL_
$(MK_BITS
):%.installed
=%.depend-test
) |
$(SORT
) -u \
660 |
$(GSED
) -e
's/.*/TEST_REQUIRED_PACKAGES.python += library\/python\/&/' \
661 |
( $(GNU_GREP
) -v
' $(COMPONENT_FMRI)$$' || true
) \
664 # Add META.depend-test.required to the generated list of REQUIRED_PACKAGES
665 REQUIRED_PACKAGES_TRANSFORM
+= -e
'$$r $(BUILD_DIR)/META.depend-test.required'
667 # The python-requires script requires packaging to provide useful output but
668 # packaging might be unavailable during bootstrap until we reach bootstrap
669 # checkpoint 2. So require it conditionally.
670 ifeq ($(filter $(strip $(COMPONENT_NAME
)),$(PYTHON_BOOTSTRAP_CHECKPOINT_2
)),)
671 USERLAND_REQUIRED_PACKAGES.python
+= library
/python
/packaging
676 $(RM
) -r
$(SOURCE_DIR
) $(BUILD_DIR
)
678 # Make it easy to construct a URL for a pypi source download.
679 pypi_url_multi
= pypi
:///$(COMPONENT_NAME_
$(1))==$(COMPONENT_VERSION_
$(1))
680 pypi_url_single
= pypi
:///$(COMPONENT_NAME
)==$(COMPONENT_VERSION
)
681 pypi_url
= $(if
$(COMPONENT_NAME_
$(1)),$(pypi_url_multi
),$(pypi_url_single
))
684 USE_COMMON_RULES
= yes