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

Enable building PyPI packages for Python 3.9 #1513

Merged
merged 3 commits into from
May 17, 2021
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
7 changes: 7 additions & 0 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -603,3 +603,10 @@ platforms to avoid issues with Boost config files (introduced in Boost version
to use Boost specified config files for their USD build, specify
-DBoost_NO_BOOST_CMAKE=OFF when running cmake.

2. Windows and Python 3.8+
Python 3.8 and later on Windows will no longer search PATH for DLL dependencies.
Instead, clients can call `os.add_dll_directory(p)` to set paths to search.
By default on that platform USD will iterate over PATH and add all paths using
`os.add_dll_directory()` when importing Python modules. Users may override
this by setting the environment variable `PXR_USD_WINDOWS_DLL_PATH` to a PATH-like
string. If this is set, USD will use these paths instead.
44 changes: 44 additions & 0 deletions azure-pypi-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ stages:
Python37:
PYTHON_INTERPRETER: /opt/python/cp37-cp37m/bin/python
PYTHON_TAG: cp37
Python38:
PYTHON_INTERPRETER: /opt/python/cp38-cp38/bin/python
PYTHON_TAG: cp38
Python39:
PYTHON_INTERPRETER: /opt/python/cp39-cp39/bin/python
PYTHON_TAG: cp39
timeoutInMinutes: 90
pool:
vmImage: Ubuntu-18.04
Expand Down Expand Up @@ -74,6 +80,12 @@ stages:
Python37:
PYTHON_VERSION_SPEC: 3.7
PYTHON_TAG: cp37
Python38:
PYTHON_VERSION_SPEC: 3.8
PYTHON_TAG: cp38
Python39:
PYTHON_VERSION_SPEC: 3.9
PYTHON_TAG: cp39
timeoutInMinutes: 90
pool:
vmImage: 'VS2017-Win2016'
Expand Down Expand Up @@ -121,6 +133,14 @@ stages:
PYTHON_VERSION_SPEC: 3.7
PYTHON_INTERPRETER: python3.7
PYTHON_TAG: cp37
Python38:
PYTHON_VERSION_SPEC: 3.8
PYTHON_INTERPRETER: python3.8
PYTHON_TAG: cp38
Python39:
PYTHON_VERSION_SPEC: 3.9
PYTHON_INTERPRETER: python3.9
PYTHON_TAG: cp39
timeoutInMinutes: 90
pool:
vmImage: 'macOS-10.14'
Expand Down Expand Up @@ -208,6 +228,14 @@ stages:
PYTHON_VERSION_SPEC: 3.7
IMAGE: 'Ubuntu-18.04'
PYTHON_INTERPRETER: python3
Linux_Python38:
PYTHON_VERSION_SPEC: 3.8
IMAGE: 'Ubuntu-18.04'
PYTHON_INTERPRETER: python3
Linux_Python39:
PYTHON_VERSION_SPEC: 3.9
IMAGE: 'Ubuntu-18.04'
PYTHON_INTERPRETER: python3
Windows_Python36:
PYTHON_VERSION_SPEC: 3.6
IMAGE: 'VS2017-Win2016'
Expand All @@ -216,6 +244,14 @@ stages:
PYTHON_VERSION_SPEC: 3.7
IMAGE: 'VS2017-Win2016'
PYTHON_INTERPRETER: python
Windows_Python38:
PYTHON_VERSION_SPEC: 3.8
IMAGE: 'VS2017-Win2016'
PYTHON_INTERPRETER: python
Windows_Python39:
PYTHON_VERSION_SPEC: 3.9
IMAGE: 'VS2017-Win2016'
PYTHON_INTERPRETER: python
Mac_Python36:
PYTHON_VERSION_SPEC: 3.6
IMAGE: 'macOS-10.14'
Expand All @@ -224,6 +260,14 @@ stages:
PYTHON_VERSION_SPEC: 3.7
IMAGE: 'macOS-10.14'
PYTHON_INTERPRETER: python3
Mac_Python38:
PYTHON_VERSION_SPEC: 3.8
IMAGE: 'macOS-10.14'
PYTHON_INTERPRETER: python3
Mac_Python39:
PYTHON_VERSION_SPEC: 3.9
IMAGE: 'macOS-10.14'
PYTHON_INTERPRETER: python3
timeoutInMinutes: 10
pool:
vmImage: '$(IMAGE)'
Expand Down
9 changes: 0 additions & 9 deletions build_scripts/build_usd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1964,15 +1964,6 @@ def ForceBuildDependency(self, dep):
"PATH")
sys.exit(1)

# Error out on Windows with Python 3.8+. USD currently does not support
# these versions due to:
# https://docs.python.org/3.8/whatsnew/3.8.html#bpo-36085-whatsnew
isPython38 = (sys.version_info.major >= 3 and
sys.version_info.minor >= 8)
if Windows() and isPython38:
PrintError("Python 3.8+ is not supported on Windows")
sys.exit(1)

if find_executable("cmake"):
# Check cmake requirements
if Windows():
Expand Down
4 changes: 2 additions & 2 deletions build_scripts/pypi/package_files/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def windows():
import os, sys
dllPath = os.path.split(os.path.realpath(__file__))[0]
if sys.version_info >= (3, 8, 0):
os.add_dll_directory(dllPath)
os.environ['PXR_USD_WINDOWS_DLL_PATH'] = dllPath
else:
os.environ['PATH'] = dllPath + os.pathsep + os.environ['PATH']
''')
Expand Down Expand Up @@ -128,5 +128,5 @@ def windows():
"Environment :: Console",
"Topic :: Multimedia :: Graphics",
],
python_requires='>=3.6, <3.8',
python_requires='>=3.6, <3.10',
)
43 changes: 42 additions & 1 deletion pxr/base/tf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,44 @@
Tf -- Tools Foundation
"""

# Type to help handle DLL import paths on Windows with python interpreters v3.8
# and newer. These interpreters don't search for DLLs in the path anymore, you
# have to provide a path explicitly. This re-enables path searching for USD
# dependency libraries
import platform, sys
if sys.version_info >= (3, 8) and platform.system() == "Windows":
import contextlib

@contextlib.contextmanager
def WindowsImportWrapper():
import os
dirs = []
import_paths = os.getenv('PXR_USD_WINDOWS_DLL_PATH')
if import_paths is None:
import_paths = os.getenv('PATH', '')
for path in import_paths.split(os.pathsep):
# Calling add_dll_directory raises an exception if paths don't
# exist, or if you pass in dot
if os.path.exists(path) and path != '.':
dirs.append(os.add_dll_directory(path))
# This block guarantees we clear the dll directories if an exception
# is raised in the with block.
try:
yield
finally:
for dll_dir in dirs:
dll_dir.close()
del os
del contextlib
else:
class WindowsImportWrapper(object):
def __enter__(self):
pass
def __exit__(self, exc_type, ex_val, exc_tb):
pass
del platform, sys


def PreparePythonModule(moduleName=None):
"""Prepare an extension module at import time. This will import the
Python module associated with the caller's module (e.g. '_tf' for 'pxr.Tf')
Expand All @@ -46,7 +84,10 @@ def PreparePythonModule(moduleName=None):
moduleName = f_locals["__name__"].split(".")[-1]
moduleName = "_" + moduleName[0].lower() + moduleName[1:]

module = importlib.import_module("." + moduleName, f_locals["__name__"])
with WindowsImportWrapper():
module = importlib.import_module(
"." + moduleName, f_locals["__name__"])

PrepareModule(module, f_locals)
try:
del f_locals[moduleName]
Expand Down