jjburton / cgmTools

Repository for cgMonastery development
97 stars 21 forks source link

Python 3 Migration #352

Closed jjburton closed 1 year ago

jjburton commented 1 year ago

Figure out how to do this.

RD

jjburton commented 1 year ago

Notes from twitter

Mark

JB

Ryan

jjburton commented 1 year ago

Process

jjburton commented 1 year ago

General flow

Issues

Installing pip https://www.liquidweb.com/kb/install-pip-windows/

Processing directories http://python3porting.com/2to3.html#:~:text=Running%202to3%20is%20very%20simple,the%20changes%20to%20the%20files.

Adding a pip install path to the environment https://superuser.com/questions/1372793/the-script-is-installed-in-directory-which-is-not-path

jjburton commented 1 year ago

Day1

Quirks from conversion -from . import maya doesn't like (Sometimes?) Replaced to just import with find/replace -Ran into issues from red9's _version import. Probably need to run Red9.setup.addPythonPackages() at cgm start to deal with it

jjburton commented 1 year ago

Cull

jjburton commented 1 year ago

Day 2

Get tests working

cgmMeta.base

cgmMeta.mClasses

Class issues

__new__ usage appears to have changed. return super(cls.__class__, cls).__new__(cls,*args,**kws) >> return super(cls.__class__, cls).__new__(cls)

Path issues

NodeFactory issues

Red9 Json

jjburton commented 1 year ago

2to3 issues

jjburton commented 1 year ago

To remember

_d = {0: 'orbFrontLeft',
     4: 'jawTopLeft',
     2: 'orbLeft',
     3: 'cheek_0_3_left',
     1: 'cheek_0_1_left'}
for ii,handle in list(_d.items()):#...no worky
    print("{} | {}".format(ii,handle))

for ii in sorted(_d):#...works as expected
    print("{} | {}".format(ii,_d[ii]))
jjburton commented 1 year ago

Day 3

Exception Handling

This has been a bugger. Lots of issues with how MRS is handling errors. Trying to sort it

Builder - Build Modules

jjburton commented 1 year ago

Day 4

Exception Handling

This has been a bugger. Lots of issues with how MRS is handling errors. Trying to sort it

Process

Build issues

Segment ear wasn't building and in the end it turned out that a dict wasn't returning in order in python 3 with how I was doing things. I reworked it and added a new list return in ATTR.

Python dictionary changes

d = {3:'cat',1:'dog',2:'and',10:'!'}
#py2...
keys = d.keys()
keys.sort()

#py3...
sorted(d)#...just a sorted list of keys
d2 = {k:d[k] for k in sorted(d)}#...sorted dict
list(d2.keys())#...list keys

#p2 iteritems
for k,l in d2.iteritems():
    print("{},{}".format(k,l))

#p3 iteritems
for k,l in list(d2.items()):
    print("{},{}".format(k,l))

https://docs.python.org/3/howto/sorting.html

jjburton commented 1 year ago

Day 5

Coming back from Holiday break. Trying to remember where I was. Going to look for the sort error in the code base.

jjburton commented 1 year ago

Day 6

Other stuff

Does the Python3 code work in 2018

jjburton commented 1 year ago

Playback Cache

Resources

Wrote a new wrapper for cgmGen to handle some of this after testing the playback cache thing

def CleanCall(func):
    '''
    Call to handle the typical pre/post do stuff calls like:
    - undoChunk
    - suspend refresh
    - cached playback (maya 2019+)
    - autokey status
    - closing the maya progress bar if it was stuck open from an exception
    '''
    @wraps(func)
    def CleanCaller(*args, **kws):
        _str_func = 'CleanCaller {}'.format(func)
        res = None
        print(logString_sub(_str_func,'pre'))

        _cachedPlaybackEnable = mc.optionVar(q='cachedPlaybackEnable')
        if _cachedPlaybackEnable:
            mc.optionVar( iv=('cachedPlaybackEnable', 0))
        mc.undoInfo(openChunk=True,chunkName="undo{0}".format(func))
        #mc.undoInfo(openChunk=True)
        _autoKey = mc.autoKeyframe(q=True,state=True)
        mc.refresh(su=1)

        print(logString_sub(_str_func,'do'))
        try:
            res=func(*args,**kws) 
        finally:
            print(logString_sub(_str_func,'post'))

            mc.undoInfo(closeChunk=True)#...close our chunk
            if _autoKey:#turn back on if it was
                mc.autoKeyframe(state=True)

            mc.refresh(su=0) #turn off suspension

            if _cachedPlaybackEnable:
                mc.optionVar( iv=('cachedPlaybackEnable', 1))

            try:
                mayaMainProgressBar = mel.eval('$tmp = $gMainProgressBar')
                mc.progressBar(mayaMainProgressBar, edit=True, endProgress=True)                    
            except:pass
            if res:
                return res
    return CleanCaller
jjburton commented 1 year ago

Day 7

On stack track stuff. To get local dat, the best new way is to

def test_exception(self,*args,**kws):
    try:
        localTest = 'hello world'
        raise ValueError("here")
    except:
        cgmGEN.log_tb()
        raise

If you don't need the local data the new wrappers work fine

jjburton commented 1 year ago

Week 01.01.23

Muzzle issues

Was getting bad data sorts from old usage. new usage sorts

_d = {0: 'orbFrontLeft',
     4: 'jawTopLeft',
     2: 'orbLeft',
     3: 'cheek_0_3_left',
     1: 'cheek_0_1_left'}
for ii,handle in list(_d.items()):#...no worky
    print("{} | {}".format(ii,handle))

for ii in sorted(_d):#...works as expected
    print("{} | {}".format(ii,_d[ii]))

Experiment with Moving modules over from Py3 to Py2 builds to see if all break or just certain ones

reload was the biggest thing that caused issues in code between modules so wrote a simple bridge for cgmGEN

_b_py3 = False
if platform.python_version().startswith('3'):
    _b_py3 = True
    _reloadMod = importlib.reload
else:
    _reloadMod = reload    
jjburton commented 1 year ago

Test tools in Maya 2023

01.04

Blockdat -- added blockparent string validation with new call SEARCH.find_from_string to deal with 'cgmRigBlocks|BlockParent' specifically. Working better