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

Python 3 Support #6

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

Python 3 Support #6

wants to merge 14 commits into from

Conversation

mottosso
Copy link
Contributor

@mottosso mottosso commented Aug 6, 2020

Maya 2021 and friends are just around the corner, and with it comes Python 3 in full color.

This PR implements support for Python 3 in a series of hopefully self-documented commits. Most of it is self-explanatory, like itervalues -> values, and from qthandler import ... to from .qthandler import ... for relative local imports.

To support metaclasses, I opted to integrate six.py and it's @add_metaclass. Having worked with this before, I found it the most descriptive and hasslefree with only a minimal (bundled) dependency.

Feedback

If there is one thing I'd like to direct your eyes towards it's kikofile.py and how I handled encoding/decoding between unicode and bytes. Unicode still eludes me to this day, so it's possible there are cases unaccounted for in this implementation.

Let me know what you think!

shiboken needs this for pointers
These are no longer supported in Python 3, and would try and import something from PYTHONPATH/sys.path rather than the local directory.
Missing from Python 3
This alias was removed from Python 3, type(None) is identical.
For Python 3
With @six.add_metaclass
For Python 3
For checking against which version is installed
@mottosso
Copy link
Contributor Author

mottosso commented Aug 6, 2020

image

For clarity, the bundled six.py is 983 of those new lines. I considered stripping out the only function used, add_metaclass, but didn't want to separate the logic from its source in case anyone would wonder whether add_metaclass is well-tested and not some ad-hoc version I threw together. With that said, a comment about where it comes from would also suffice. I'll leave that decision to you.

@mottosso
Copy link
Contributor Author

mottosso commented Aug 6, 2020

I also added a version.py, I wasn't sure how else to identify which version was installed, and wasn't able to find any releases here on GitHub either. version.py is how I traditionally handle that, but this one is also up to your discretion of course. It's also not related to Python 3, and could be left out of this particular PR.

version.py

__version_info__ = (1, 1, 0)
__version__ = ".".join(map(str, __version_info__))

@danielefederico
Copy link
Collaborator

Hello Marcus,
can you please confirm you tested this and it is backward compatible with the previous versions of Maya, Nuke and Houdini?
This is a needed change, but unfortunately I won't have time any time soon to test your changes.

Thanks,
Daniele

@mottosso
Copy link
Contributor Author

mottosso commented Aug 7, 2020

Hi Daniele!

I've tested this only on Maya 2018 and 2021, and would be able to test it on Houdini 18, but would need help testing it on Nuke.

Speaking of testing, how do we test?

When I say "tested on Maya", I mean..

from kiko import initialize
initialize()

from kiko.apps.maya.ui import exporter
d = exporter.MayaExporterDialog()
d.show()

Followed by exporting something. And then..

from kiko import initialize
initialize()

from kiko.apps.maya.ui import importer
d = importer.MayaImporterDialog()
d.show()

To import it.

But I noticed there are no GUIs for Houdini nor Nuke, and I just now spotted a few unit tests that cover Maya 2017 and Nuke 11; those won't work under Python 3 as-is, and would need a little push.

for app in apps:
print "\x1b[1;33mRunning %s tests \x1b[0m" % app
if app == 'standalone':
loader = nose.loader.TestLoader()
if module_test is None:

For Houdini and Nuke, would something like this suffice?

from kiko.apps.houdini import manager

m = manager.HoudiniKikoManager()
m.export_to_file(
    "temp.kiko",
    operators=[
        "CurveOperator",
        "StaticOperator",
        "BakeOperator",
        "WorldSpaceOperator",
    ],
    keep_previous_images=False,
    hierarchy=True,
    start_frame=1,
    end_frame=10,
    force_op_evaluation=False
)

m.import_from_file(
    "temp.kiko",
    import_obj_method="hierarchy",
    import_anim_method="apply",
    scale_using_fps=False,
    frame_value=0,
    ignore_item_chunks=True,
    start_frame=1,
    end_frame=10,
)

Under Houdini 18 on Windows, this currently throws an error.

Traceback (most recent call last):
  File "<console>", line 13, in <module>
  File "C:\github\mottosso\kiko\kiko\python\kiko\core\manager.py", line 104, in 
export_to_file
    k_file.save()
  File "C:\github\mottosso\kiko\kiko\python\kiko\io\kikofile.py", line 106, in s
ave
    self._add_to_tar_from_dict(tar_file, KIKO_FILE.METADATA, self._metadata)
  File "C:\github\mottosso\kiko\kiko\python\kiko\io\kikofile.py", line 77, in _a
dd_to_tar_from_dict
    json.dump(data, io)
  File "C:\PROGRA~1\SIDEEF~1\HOUDIN~1.532\python27\lib\json\__init__.py", line 1
90, in dump
    fp.write(chunk)
TypeError: unicode argument expected, got 'str'

Would anyone be able to test on Nuke, and other versions of Maya and/or Houdini? #help

@davidlatwe
Copy link

Hi @mottosso and @danielefederico

Have been watching this project for a long time, and thought this might be the chance for me to join in !

I may able to help on testing in Nuke 9-11 once I get back office.

@danielefederico
Copy link
Collaborator

Thanks David and Marcus!

There are some unit tests on the project for Maya and Nuke, if they don't fail everything should be good to go.

To run them you can use this file:
https://github.com/Toolchefs/kiko/blob/master/kiko/unittests/run_win.py
You might have to edit your environment before launching the script.

Nose is used for the unit tests.

Thanks,
Daniele

@davidlatwe
Copy link

So I forked this branch and run the test in Nuke, all passed ☺️

Nuke 9.0v7

(py27) C:\Users\davidlatwe.lai\pipeline\kiko\kiko\unittests>python .\run_win.py
�[1;33mRunning nuke tests �[0m
C:/Program Files/Nuke9.0v7/Nuke9.0.exe -x -i C:\Users\davidlatwe.lai\pipeline\kiko\kiko\unittests\bin\nose_app.py nuke
Nuke 9.0v7, 64 bit, built Aug 17 2015.
Copyright (c) 2015 The Foundry Visionmongers Ltd.  All Rights Reserved.
sb_addViewerLuts: LUT folder does not exsist.
nose.config: INFO: Ignoring files matching ['^\\.', '^_', '^setup\\.py$']
units.nuke.test_nuke.TestNuke.export_import_baked_values_test ... ok
units.nuke.test_nuke.TestNuke.export_import_simple_kb_file_test ... ok
units.nuke.test_nuke.TestNuke.export_import_simple_kiko_file_test ... ok
units.nuke.test_nuke.TestNuke.export_import_simple_test ... [19:34.08] Warning: C:/Users/davidlatwe.lai/pipeline/kiko/kiko/unittests/fixtures/files/nuke/simple_axis.nk is for nuke11.1v1; this is nuke9.0v7
[19:34.08] Warning: root.colorManagement: no such knob
root.Nuke: no such knob
root.workingSpaceLUT: no such knob
root.linear: no such knob
ok
units.nuke.test_nuke.TestNuke.export_import_static_values_test ... ok

----------------------------------------------------------------------
Ran 5 tests in 0.655s

OK
�[1;33mUNIT TESTS SUCCESSFULL�[0m

Nuke 11.3v4

(py27) C:\Users\davidlatwe.lai\pipeline\kiko\kiko\unittests>python .\run_win.py
�[1;33mRunning nuke tests �[0m
C:/Program Files/Nuke11.3v4/Nuke11.3.exe -x -i C:\Users\davidlatwe.lai\pipeline\kiko\kiko\unittests\bin\nose_app.py nuke
Nuke 11.3v4, 64 bit, built May  1 2019.
Copyright (c) 2019 The Foundry Visionmongers Ltd.  All Rights Reserved.
sb_addViewerLuts: LUT folder does not exsist.
nose.config: INFO: Ignoring files matching ['^\\.', '^_', '^setup\\.py$']
units.nuke.test_nuke.TestNuke.export_import_baked_values_test ... ok
units.nuke.test_nuke.TestNuke.export_import_simple_kb_file_test ... ok
units.nuke.test_nuke.TestNuke.export_import_simple_kiko_file_test ... ok
units.nuke.test_nuke.TestNuke.export_import_simple_test ... ok
units.nuke.test_nuke.TestNuke.export_import_static_values_test ... ok

----------------------------------------------------------------------
Ran 5 tests in 0.637s

OK
�[1;33mUNIT TESTS SUCCESSFULL�[0m

@danielefederico
Copy link
Collaborator

Thanks David!

Marcus, did you have any luck with Houdini?

Thanks,
Daniele

@mottosso
Copy link
Contributor Author

Not yet, I expect to be back on it this weekend.

@mottosso
Copy link
Contributor Author

Sorry for the delay on this one, the project I was on got postponed and I'm still waiting for it to start back up, at which point this will become relevant once again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants