Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround for distutils bug in Ubuntu/Debian's Python3 versions #2220

Merged
merged 2 commits into from
Jun 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ IF(HAVE_PY_INTERP)
# Find python destination dir for python bindings
# because it may differ on each operating system.
EXECUTE_PROCESS(
COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import *;print(get_python_lib(True, False, '${CMAKE_INSTALL_PREFIX}'))"
COMMAND ${PYTHON_EXECUTABLE} "${PROJECT_SOURCE_DIR}/scripts/get_python_lib.py" "${CMAKE_INSTALL_PREFIX}"
OUTPUT_VARIABLE PYTHON_DEST
)

Expand Down
26 changes: 26 additions & 0 deletions scripts/get_python_lib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import sys
import sysconfig
import site

if __name__ == '__main__':
# This is a hack due to the distutils in debian/ubuntu's python3 being misconfigured
# see discussion https://github.com/opencog/atomspace/issues/1782
#
# If the bug is fixed, most of this script could be replaced by:
#
# from distutils.sysconfig import get_python_lib; print(get_python_lib(plat_specific=True, prefix=prefix))
#
# However, using this would not respect a python virtual environments, so in a way this is better!

prefix = sys.argv[1]

# use sites if the prefix is recognized and the sites module is available
# (virtualenv is missing getsitepackages())
if hasattr(site, 'getsitepackages'):
paths = [p for p in site.getsitepackages() if p.startswith(prefix)]
if len(paths) == 1:
print(paths[0])
exit(0)

# use sysconfig platlib as the fall back
print(sysconfig.get_paths()['platlib'])