Skip to content

Commit 0b20a48

Browse files
committed
Update Python build commands for Bookworm
In Bookworm's version of setuptools, direct calls to setup.py are deprecated and no longer guaranteed to work. One of the recommended commands is to use the `build` python package to build packages, and call it with `python -m build`. This, by default, builds the packages in a virtualenv to ensure that only the specified dependencies in setup.py are needed to build the package. This also extends to running tests, where directly calling `setup.py test` may not work, and the recommended alternatives are to either call `pytest` directly, or call `tox` or `nox.` More details are available at [1]. For SONiC's use case, for building python packages, we cannot build all Python packages in a virtualenv since there are dependencies that we would have built earlier, and these packages are not pushed to pypi or any package registry. (There may be a cleaner approach to this, though, but I'm not aware of it.) For this reason, the `-n` flag is added to not build the package in a virtualenv. For testing, `pytest` is now called instead of `setup.py test`. [1] https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html Signed-off-by: Saikrishna Arcot <[email protected]>
1 parent 600538b commit 0b20a48

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

slave.mk

+5
Original file line numberDiff line numberDiff line change
@@ -924,8 +924,13 @@ $(addprefix $(PYTHON_WHEELS_PATH)/, $(SONIC_PYTHON_WHEELS)) : $(PYTHON_WHEELS_PA
924924
ifneq ($(CROSS_BUILD_ENVIRON),y)
925925
# Use pip instead of later setup.py to install dependencies into user home, but uninstall self
926926
pip$($*_PYTHON_VERSION) install . && pip$($*_PYTHON_VERSION) uninstall --yes `python$($*_PYTHON_VERSION) setup.py --name`
927+
ifeq ($(BLDENV),bookworm)
928+
if [ ! "$($*_TEST)" = "n" ]; then pip$($*_PYTHON_VERSION) install ".[testing]" && pip$($*_PYTHON_VERSION) uninstall --yes `python$($*_PYTHON_VERSION) setup.py --name` && python$($*_PYTHON_VERSION) -m pytest $(LOG); fi
929+
python$($*_PYTHON_VERSION) -m build -n $(LOG)
930+
else
927931
if [ ! "$($*_TEST)" = "n" ]; then python$($*_PYTHON_VERSION) setup.py test $(LOG); fi
928932
python$($*_PYTHON_VERSION) setup.py bdist_wheel $(LOG)
933+
endif
929934
else
930935
{
931936
export PATH=$(VIRTENV_BIN_CROSS_PYTHON$($*_PYTHON_VERSION)):${PATH}

0 commit comments

Comments
 (0)