Skip to content

Commit 67004d5

Browse files
committed
python: Replace deprecated setup.py with pypa/build+pip
When setuptools>58.2.0 setup.py installation is a deprecated method, a warning message will be prompted [1]: $ sudo make install .... running install /usr/lib/python3.13/site-packages/setuptools/_distutils/cmd.py:66: SetuptoolsDeprecationWarning: setup.py install is deprecated. !! ******************************************************************************** Please avoid running ``setup.py`` directly. Instead, use pypa/build, pypa/installer or other standards-based tools. See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details. ******************************************************************************** !! self.initialize_options() /usr/lib/python3.13/site-packages/setuptools/_distutils/cmd.py:66: EasyInstallDeprecationWarning: easy_install command is deprecated. !! ******************************************************************************** Please avoid running ``setup.py`` and ``easy_install``. Instead, use pypa/build, pypa/installer or other standards-based tools. See pypa/setuptools#917 for details. ******************************************************************************** !! self.initialize_options() Use the recommended solution [2] to replace setup.py with pypa/build and pip-install to completely solve the problem. It is worth noting that under Debian, you need to add the --break-system-packages parameter to pip-uninstall, as shown in the following prompt: Debian12:~$ sudo pip3 uninstall bcc error: externally-managed-environment × This environment is externally managed ╰─> To install Python packages system-wide, try apt install python3-xyz, where xyz is the package you are trying to install. If you wish to install a non-Debian-packaged Python package, create a virtual environment using python3 -m venv path/to/venv. Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make sure you have python3-full installed. If you wish to install a non-Debian packaged Python application, it may be easiest to use pipx install xyz, which will manage a virtual environment for you. Make sure you have pipx installed. See /usr/share/doc/python3.11/README.venv for more information. note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages. hint: See PEP 668 for the detailed specification. # Successfully uninstalled Debian12:~$ sudo pip3 uninstall bcc --break-system-packages Fix: iovisor#4586 [1] Link: https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html [2] Cc: Jerome Marchand <[email protected]> Cc: Hengqi Chen <[email protected]> Signed-off-by: Rong Tao <[email protected]>
1 parent 1f63ae6 commit 67004d5

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ if(CMAKE_USE_LIBBPF_PACKAGE)
120120
find_package(LibBpf)
121121
endif()
122122

123+
if(NOT PYTHON_CMD)
124+
set(PYTHON_CMD "python3")
125+
endif()
126+
123127
if(NOT PYTHON_ONLY)
124128
find_package(LLVM REQUIRED CONFIG)
125129
message(STATUS "Found LLVM: ${LLVM_INCLUDE_DIRS} ${LLVM_PACKAGE_VERSION} (Use LLVM_ROOT envronment variable for another version of LLVM)")
@@ -233,5 +237,6 @@ if(NOT TARGET uninstall)
233237
IMMEDIATE @ONLY)
234238

235239
add_custom_target(uninstall
236-
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/CmakeUninstall.cmake)
240+
COMMAND ${CMAKE_COMMAND} -DPYTHON_CMD=\"${PYTHON_CMD}\" -P ${CMAKE_CURRENT_BINARY_DIR}/CmakeUninstall.cmake
241+
)
237242
endif()

cmake/CmakeUninstall.cmake.in

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,11 @@ endforeach()
2626
endfunction()
2727

2828
UninstallManifest("@CMAKE_BINARY_DIR@/install_manifest.txt")
29-
UninstallManifest("@CMAKE_BINARY_DIR@/install_manifest_python_bcc.txt")
29+
30+
if(EXISTS "/etc/debian_version")
31+
set(PY_PIP_ARGS "--break-system-packages")
32+
endif()
33+
foreach(PY_CMD ${PYTHON_CMD})
34+
message(STATUS "Uninstall python-bcc for ${PY_CMD}.")
35+
execute_process(COMMAND ${PY_CMD} -m pip uninstall -y ${PY_PIP_ARGS} bcc)
36+
endforeach()

src/python/CMakeLists.txt

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
# Copyright (c) PLUMgrid, Inc.
22
# Licensed under the Apache License, Version 2.0 (the "License")
33

4-
if(NOT PYTHON_CMD)
5-
set(PYTHON_CMD "python3")
6-
endif()
7-
8-
if(EXISTS "/etc/debian_version" AND NOT PY_SKIP_DEB_LAYOUT)
9-
set(PYTHON_FLAGS "${PYTHON_FLAGS} --install-layout deb")
10-
endif()
11-
124
file(GLOB_RECURSE PYTHON_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
135
${CMAKE_CURRENT_SOURCE_DIR}/*.py)
146
file(GLOB_RECURSE PYTHON_INCLUDES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
@@ -27,24 +19,25 @@ foreach(PY_CMD ${PYTHON_CMD})
2719
configure_file(${PY_INC} ${PY_DIRECTORY}/${PY_INC_REPLACED} @ONLY)
2820
endforeach()
2921

30-
set(PIP_INSTALLABLE "${PY_DIRECTORY}/dist/bcc-${REVISION}.tar.gz")
22+
set(PIP_INSTALLABLE "${PY_DIRECTORY}/dist/bcc-${REVISION}-py3-none-any.whl")
3123
add_custom_command(
3224
OUTPUT ${PIP_INSTALLABLE}
33-
COMMAND ${PY_CMD} setup.py sdist
25+
COMMAND ${PY_CMD} -m build --wheel ${PY_DIRECTORY}
3426
WORKING_DIRECTORY ${PY_DIRECTORY}
3527
DEPENDS ${PYTHON_SOURCES} ${PYTHON_INCLUDES}
36-
COMMENT "Building sdist for ${PY_CMD}"
28+
COMMENT "Building ${PIP_INSTALLABLE} for ${PY_CMD}"
3729
)
3830
add_custom_target(bcc_py_${PY_CMD_ESCAPED} ALL DEPENDS ${PIP_INSTALLABLE})
3931

4032
if(NOT PYTHON_PREFIX)
4133
set(PYTHON_PREFIX ${CMAKE_INSTALL_PREFIX})
4234
endif()
4335

36+
message(STATUS "Install ${PIP_INSTALLABLE} for ${PY_CMD}.")
4437
install(
4538
CODE "
4639
execute_process(
47-
COMMAND ${PY_CMD} setup.py install -f ${PYTHON_FLAGS} --prefix=${PYTHON_PREFIX} --record ${CMAKE_BINARY_DIR}/install_manifest_python_bcc.txt
48-
WORKING_DIRECTORY ${PY_DIRECTORY})"
40+
COMMAND ${PY_CMD} -m pip install --force-reinstall --prefix=${PYTHON_PREFIX} ${PIP_INSTALLABLE}
41+
WORKING_DIRECTORY ${PY_DIRECTORY})"
4942
COMPONENT python)
5043
endforeach()

0 commit comments

Comments
 (0)