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

Support Python3 for Pixar's UsdMaya and unit tests #555

Merged
merged 11 commits into from
Jun 15, 2020

Conversation

HamedSabri-adsk
Copy link
Contributor

@HamedSabri-adsk HamedSabri-adsk commented Jun 2, 2020

This PR adds Python3 compatibility support for Pixar's MayaUSD and unit tests.

Note: Out of all tests, testUsdExportPackage is not passing right now in python 3.
See #555 (comment)

@HamedSabri-adsk HamedSabri-adsk added pxr Related to Pixar plugin unit test Related to unit tests (both python or c++) labels Jun 2, 2020
@@ -588,6 +591,7 @@ def __init__(self, args):
ctestArgs=context.ctestArgs,
buildVariant=BuildVariant(context),
debugPython=("On" if context.debugPython else "Off"),
enablePython3=("On" if Python3() else "Off"),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simple change to output Python3 state in the output console.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only to indicate that the build.py was called with Python 3 - right? Not that we are actually building python 3 bindings. That is still controlled by the cmake option "BUILD_WITH_PYTHON_3"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seando-adsk Correct, just a simple indication in the output console:

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @seando-adsk's point was that that's indicating that build.py itself is running using Python 3, and not necessarily indicating that you're building for Python 3. You could run build.py using Python 3 but still be building maya-usd for Python 2, in which case that indicator might be misleading.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I already realized that :) I agree with you that this could be misleading and in fact in my mind was thinking to change it. something for another day.

CMakeLists.txt Outdated
if (BUILD_USDMAYA_SCHEMAS)
include(cmake/jinja.cmake)
endif()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seando-adsk This was a bit of a surprise since this code never is called when the clean build happens.

BUILD_USDMAYA_SCHEMAS is an option that is set in AL. This value is not cached until AL's CmakeLists is called which happens later.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what happened is when we moved some schema stuff from AL into core we moved this. But we forgot to move the option. Shouldn't we leave this here and move the option under line 35?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had actually started looking into that once, but got side tracked. I think we should fix this schema stuff in a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, I had to take it out eventually since I was getting bunch of weird issues with Python 3 when doing incremental builds. Let's revisit this together.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized that this needs to remain here. From the Maya build and our internal ecg-maya-usd repo we are setting this flag "BUILD_USDMAYA_SCHEMAS=ON" and providing the jinja/markupsafe locations. The jinja.cmake will check to see if jinja2 and markupsafe are part of the python executable. If not, then it will add them to the python path from the locations provided.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 256 to 276
# swtich between mayapy and mayapy2
set(mayapy_exe mayapy)
if(${MAYA_APP_VERSION} STRGREATER_EQUAL "2021")
if(NOT BUILD_WITH_PYTHON_3)
set(mayapy_exe mayapy2)
endif()
endif()

find_program(MAYA_PY_EXECUTABLE
${mayapy_exe}
HINTS
"${MAYA_LOCATION}"
"$ENV{MAYA_LOCATION}"
"${MAYA_BASE_DIR}"
PATH_SUFFIXES
Maya.app/Contents/bin/
bin/
DOC
"Maya's Python executable path"
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a switch to handle mayapy executable name in dual Maya python.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great.

@@ -47,7 +49,7 @@ def setUpClass(cls):
@classmethod
def tearDownClass(cls):
statsOutputLines = []
for profileScopeName, elapsedTime in cls._profileScopeMetrics.iteritems():
for profileScopeName, elapsedTime in iteritems(cls._profileScopeMetrics):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In python3, dict.iteritems is no longer available. Using python.future function iteritems()

Note: mayapy shipped with Maya already comes with future package installed

@@ -24,7 +23,6 @@

from pxr import Usd, UsdGeom


Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattyjams This test is still failing in Python3 on Windows:

The reason it fails is because GetFileNames which is simply a list of strings is different from the expected list.

zipFile = Usd.ZipFile.Open(usdFile)
fileNames = zipFile.GetFileNames()
self.assertEqual(fileNames, [
    "MyAwesomePackage.usdc",
    "ReferenceModel.usda",
    "BaseModel.usda",
    "card.png"
])

After some debugging , I noticed the list entries in the python 3 version have the path to temp folder which is really bizarre:

['Users/sabrih/AppData/Local/Temp/tmpp7c6l4yj/MyAwesomePackage.usdc', 
'Users/sabrih/AppData/Local/Temp/tmpp7c6l4yj/ReferenceModel.usda', 
'Users/sabrih/AppData/Local/Temp/tmpp7c6l4yj/BaseModel.usda', 
'Users/sabrih/AppData/Local/Temp/tmpp7c6l4yj/card.png']

VS the python 2 version doesn't have this temporary paths:

['MyAwesomePackage.usdc', 'ReferenceModel.usda', 'BaseModel.usda', 'card.png']

To me it looks like something to do with UsdZipFile.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, if that's the case, then it seems like that might be an issue with core USD?

Can you reproduce this in a non-Maya context, and if so, could you open an issue against the core USD GitHub project, if so?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattyjams see 28f6222

I ran part of the test in question in a non-Maya context both in Python 2 and 3. In my test I am not calling cmds.usdExport and as it shown below in both cases fileNames do contain temporary paths in the names. So I don't think this has anything to do with UsdZipFile.

I suspect it either has something to do with os.path.abspath or the call to usdExport. For now I have disabled this assert for Python 3 until further investigation.

Python 3

Python 3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 10:41:24) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> from pxr import Usd, UsdGeom
>>> usdFile = os.path.abspath('C:\\Users\\sabrih\\AppData\\Local\\Temp\\tmpjwhzno7b\\MyAwesomePackage.usdz')
>>> zipFile = Usd.ZipFile.Open(usdFile)
>>> fileNames = zipFile.GetFileNames()
>>> print(fileNames)
['Users/sabrih/AppData/Local/Temp/tmpjwhzno7b/MyAwesomePackage.usdc', 'Users/sabrih/AppData/Local/Temp/tmpjwhzno7b/ReferenceModel.usda', 'Users/sabrih/AppData/Local/Temp/tmpjwhzno7b/BaseModel.usda', 'Users/sabrih/AppData/Local/Temp/tmpjwhzno7b/card.png']

Python 2

Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> from pxr import Usd, UsdGeom
>>> usdFile = os.path.abspath('C:\\Users\\sabrih\\AppData\\Local\\Temp\\tmpjwhzno7b\\MyAwesomePackage.usdz')
>>> zipFile = Usd.ZipFile.Open(usdFile)
>>> fileNames = zipFile.GetFileNames()
>>> print(fileNames)
['Users/sabrih/AppData/Local/Temp/tmpjwhzno7b/MyAwesomePackage.usdc', 'Users/sabrih/AppData/Local/Temp/tmpjwhzno7b/ReferenceModel.usda', 'Users/sabrih/AppData/Local/Temp/tmpjwhzno7b/BaseModel.usda', 'Users/sabrih/AppData/Local/Temp/tmpjwhzno7b/card.png']


# assertCountEqual in python 3 is equivalent to assertItemsEqual
if sys.version_info[0] >= 3:
self.assertItemsEqual = self.assertCountEqual
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python 3 no longer has assertItemsEqual and instead this function has been renamed to assertCountEqual.

added self.assertItemsEqual = self.assertCountEqual for compatibility between Python 2 and Python 3

Copy link
Contributor

@mattyjams mattyjams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one specific change that I think we also need in the testProxyShapeDuplicatePerformance test, and a few other minor little notes, but otherwise looks good to me!

@@ -24,7 +23,6 @@

from pxr import Usd, UsdGeom


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, if that's the case, then it seems like that might be an issue with core USD?

Can you reproduce this in a non-Maya context, and if so, could you open an issue against the core USD GitHub project, if so?

@HamedSabri-adsk HamedSabri-adsk requested a review from mattyjams June 3, 2020 00:33
Copy link
Contributor

@mattyjams mattyjams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

I'm not sure how you want to handle the testUsdExportPackage failure. Maybe for now, just detect when it's running in Python 3 and bypass the problematic assert? If it does look like an issue in core USD, we can put a XXX or TODO or whatever comment there tying it to the GitHub issue.

CMakeLists.txt Outdated
if (BUILD_USDMAYA_SCHEMAS)
include(cmake/jinja.cmake)
endif()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what happened is when we moved some schema stuff from AL into core we moved this. But we forgot to move the option. Shouldn't we leave this here and move the option under line 35?

@@ -588,6 +591,7 @@ def __init__(self, args):
ctestArgs=context.ctestArgs,
buildVariant=BuildVariant(context),
debugPython=("On" if context.debugPython else "Off"),
enablePython3=("On" if Python3() else "Off"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only to indicate that the build.py was called with Python 3 - right? Not that we are actually building python 3 bindings. That is still controlled by the cmake option "BUILD_WITH_PYTHON_3"

Comment on lines 256 to 276
# swtich between mayapy and mayapy2
set(mayapy_exe mayapy)
if(${MAYA_APP_VERSION} STRGREATER_EQUAL "2021")
if(NOT BUILD_WITH_PYTHON_3)
set(mayapy_exe mayapy2)
endif()
endif()

find_program(MAYA_PY_EXECUTABLE
${mayapy_exe}
HINTS
"${MAYA_LOCATION}"
"$ENV{MAYA_LOCATION}"
"${MAYA_BASE_DIR}"
PATH_SUFFIXES
Maya.app/Contents/bin/
bin/
DOC
"Maya's Python executable path"
)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great.

CMakeLists.txt Outdated
if (BUILD_USDMAYA_SCHEMAS)
include(cmake/jinja.cmake)
endif()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had actually started looking into that once, but got side tracked. I think we should fix this schema stuff in a separate PR.

CMakeLists.txt Outdated
if (BUILD_USDMAYA_SCHEMAS)
include(cmake/jinja.cmake)
endif()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized that this needs to remain here. From the Maya build and our internal ecg-maya-usd repo we are setting this flag "BUILD_USDMAYA_SCHEMAS=ON" and providing the jinja/markupsafe locations. The jinja.cmake will check to see if jinja2 and markupsafe are part of the python executable. If not, then it will add them to the python path from the locations provided.

…when maya-usd in the clean build."

This reverts commit 214e85d.

# swtich between mayapy and mayapy2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor typo "switch"

Copy link

@kxl-adsk kxl-adsk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving a comment that we have to address Maya 2019 test failures.

The following tests FAILED:
         20 - testUsdExportEulerFilter (Failed)
         21 - testUsdExportFilterTypes (Failed)
         45 - testUsdImportCamera (Failed)
         58 - testUsdImportXforms (Failed)
         73 - testUsdMayaXformStack (Failed)
Errors while running CTest

Copy link

@kxl-adsk kxl-adsk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to validate that failing tests are passing once Python's future package is installed. What's left to do before we can merge this PR is to document this new requirement for running tests in https://github.com/Autodesk/maya-usd/blob/dev/doc/build.md

FWIW. this is the process I used to get tests running for both Maya 2019 and 2020:
1 - Download get-py.py from https://bootstrap.pypa.io/get-pip.py
2 - Open a command-line and navigate to mayapy.exe for Maya version which needs future package. Run:
mayapy.exe <path_to_downloaded_file>/get-pip.py
3 - Pip will be added to <path_to_maya>Python/Scripts
4 - Install the future package
<path_to_maya>Python/Scripts/pip install future

@HamedSabri-adsk
Copy link
Contributor Author

I was able to validate that failing tests are passing once Python's future package is installed. What's left to do before we can merge this PR is to document this new requirement for running tests in https://github.com/Autodesk/maya-usd/blob/dev/doc/build.md

Thank you @kxl-adsk for the steps. Please see b7aad65

@HamedSabri-adsk HamedSabri-adsk requested a review from kxl-adsk June 15, 2020 13:19
Copy link

@kxl-adsk kxl-adsk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @HamedSabri-adsk - LGTM!

@kxl-adsk kxl-adsk merged commit 1a5d926 into dev Jun 15, 2020
@kxl-adsk kxl-adsk deleted the sabrih/MAYA-104922/support_python3_pxr branch June 15, 2020 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pxr Related to Pixar plugin unit test Related to unit tests (both python or c++)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants