Skip to content

Commit

Permalink
Merge pull request #1692 from pmolodo/pr/build_usd_GetPythonInfo
Browse files Browse the repository at this point in the history
better detection of python lib / include dirs in build_usd.py

(Internal change: 2233955)
  • Loading branch information
pixar-oss committed Jun 1, 2022
2 parents 672ab92 + 535f6da commit 4390254
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions build_scripts/build_usd.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,38 @@ def _GetPythonLibraryFilename(context):
pythonLibPath = os.path.join(pythonBaseDir, "lib",
_GetPythonLibraryFilename(context))
else:
pythonIncludeDir = sysconfig.get_config_var("INCLUDEPY")
if Windows():
pythonIncludeDir = sysconfig.get_path("include")
if not pythonIncludeDir or not os.path.isdir(pythonIncludeDir):
# as a backup, and for legacy reasons - not preferred because
# it may be baked at build time
pythonIncludeDir = sysconfig.get_config_var("INCLUDEPY")

# if in a venv, installed_base will be the "original" python,
# which is where the libs are ("base" will be the venv dir)
pythonBaseDir = sysconfig.get_config_var("installed_base")
if not pythonBaseDir or not os.path.isdir(pythonBaseDir):
# for python-2.7
pythonBaseDir = sysconfig.get_config_var("base")

if Windows():
pythonLibPath = os.path.join(pythonBaseDir, "libs",
_GetPythonLibraryFilename(context))
elif Linux():
pythonLibDir = sysconfig.get_config_var("LIBDIR")
pythonMultiarchSubdir = sysconfig.get_config_var("multiarchsubdir")
if pythonMultiarchSubdir:
pythonLibDir = pythonLibDir + pythonMultiarchSubdir
pythonLibPath = os.path.join(pythonLibDir,
_GetPythonLibraryFilename(context))
# Try multiple ways to get the python lib dir
for pythonLibDir in (sysconfig.get_config_var("LIBDIR"),
os.path.join(pythonBaseDir, "lib")):
if pythonMultiarchSubdir:
pythonLibPath = \
os.path.join(pythonLibDir + pythonMultiarchSubdir,
_GetPythonLibraryFilename(context))
if os.path.isfile(pythonLibPath):
break
pythonLibPath = os.path.join(pythonLibDir,
_GetPythonLibraryFilename(context))
if os.path.isfile(pythonLibPath):
break
elif MacOS():
pythonBaseDir = sysconfig.get_config_var("base")
pythonLibPath = os.path.join(pythonBaseDir, "lib",
_GetPythonLibraryFilename(context))
else:
Expand Down

0 comments on commit 4390254

Please sign in to comment.