Skip to content

Commit

Permalink
use old get python lib for 2
Browse files Browse the repository at this point in the history
  • Loading branch information
guruofquality committed Apr 22, 2024
1 parent b5227a9 commit 8cbd8a1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
7 changes: 6 additions & 1 deletion swig/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,13 @@ function(BUILD_PYTHON_MODULE PYTHON_VERSION)
target_include_directories(${SWIG_MODULE_SoapySDR${PYTHON_VERSION}_REAL_NAME} PRIVATE ${python_includes})
SWIG_LINK_LIBRARIES(SoapySDR${PYTHON_VERSION} ${python_libraries})

set(get_python_lib ${SOAPYSDR_PYTHON_DIR}/get_python_lib.py)
if (${PYTHON_VERSION} EQUAL 2)
set(get_python_lib ${SOAPYSDR_PYTHON_DIR}/get_python2_lib.py)
endif()

execute_process(
COMMAND ${Python${PYTHON_VERSION}_EXECUTABLE} ${SOAPYSDR_PYTHON_DIR}/get_python_lib.py ${CMAKE_INSTALL_PREFIX}
COMMAND ${Python${PYTHON_VERSION}_EXECUTABLE} ${get_python_lib} ${CMAKE_INSTALL_PREFIX}
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE PYTHON_INSTALL_DIR)

Expand Down
19 changes: 19 additions & 0 deletions swig/python/get_python2_lib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os
import sys
import site
from distutils.sysconfig import get_python_lib

if __name__ == '__main__':
prefix = sys.argv[1]

#ask distutils where to install the python module
install_dir = get_python_lib(plat_specific=True, prefix=prefix)

#use sites when the prefix is already recognized
try:
paths = [p for p in site.getsitepackages() if p.startswith(prefix)]
if len(paths) == 1: install_dir = paths[0]
except AttributeError: pass

#strip the prefix to return a relative path
print(os.path.relpath(install_dir, prefix))

0 comments on commit 8cbd8a1

Please sign in to comment.