Closed jjburton closed 1 year ago
Mark
JB
Ryan
General flow
pip install 2to3
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
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
__import__('cgm.core.cgm_General', globals(), locals(), ['*'],-1)
no bueno. Lose the -1 at the endtime.clock
| is no more. Tried a push with just swapping to time.time
. Fingers crossedGet tests working
cgmMeta.base
int
no longer in use || this ended up being long
flag but the 2to3 thought it was a declaration and changed them to int
cgmMeta.mClasses
int
flag again__new__
usage appears to have changed.
return super(cls.__class__, cls).__new__(cls,*args,**kws)
>> return super(cls.__class__, cls).__new__(cls)
Path.asString()
call to get a string to use.
import cgm.core.cgmPy.path_Utils as PATH
importlib.reload(PATH)
os.path.no
import cgm
_dir = PATH.Path(cgm.__path__[0])
type(_dir.up().asString())
issubclass(type(_dir.up()),str)
_file = os.path.normpath(os.path.join(_dir.up().asString(),'cgmToolbox.py'))
_file
unicode
went away and was throwing errorslong
flags on ls
for example were changed to int=
. Did a find and replace of ,int=
to ,long=
. ,
protects against other kws ending in 'int'. , int=
to , long=
good as well.reload
now importlib.reload
. | 2to3 is pretty good at these but found a few issues.dict.iteritems
is gone. /cry. for k,v in list(d.items()):
return super(cls.__class__, cls).__new__(cls,*args,**kws)
>> return super(cls.__class__, cls).__new__(cls)
time.clock
| is no more. Use time.time
. reload(module
>> importlib.reload(module)
if buffer > 0
>> if len(buffer) > 0
or just if buffer
Python 3 wants more explicit ==
rather than is
declarations for string variables
_keys = list(_d.keys())
_keys.sort()
to...
_keys = sorted(_d)
_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]))
except Exception as err
|| raise Exception(err)
>> raise err
-Hamish's old code doesn't work. Need to look for a cleaner solution in time
#loc = p / filename
loc = Path(os.path.join(p.asString(), filename))
def get_image_size(file_path):
import maya.api.OpenMaya as om
img = om.MImage()
img.readFromFile(file_path)
return img.getSize()
This has been a bugger. Lots of issues with how MRS is handling errors. Trying to sort it
finally
was what was causing real issuesBuilder - Build Modules
This has been a bugger. Lots of issues with how MRS is handling errors. Trying to sort it
finally
was what was causing real issuesfinally
section well. Needs to be before thatSegment 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.
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))
Coming back from Holiday break. Trying to remember where I was. Going to look for the sort error in the code base.
Other stuff
==
from is
changes.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
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
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
Blockdat -- added blockparent string validation with new call SEARCH.find_from_string to deal with 'cgmRigBlocks|BlockParent' specifically. Working better
Figure out how to do this.
RD