Skip to content

Commit

Permalink
Improve compatibility for Python 3 and Maya 2022
Browse files Browse the repository at this point in the history
  • Loading branch information
tpoveda committed Apr 3, 2021
1 parent 1909c84 commit b043ad8
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 24 deletions.
4 changes: 2 additions & 2 deletions artella/core/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def register(callback_type, fn):
if callback_type.endswith('Callback'):
callback_type = callback_type.replace('Callback', '')

if callback_type in ARTELLA_CALLBACKS_CACHE.keys():
if callback_type in list(ARTELLA_CALLBACKS_CACHE.keys()):
ARTELLA_CALLBACKS_CACHE[callback_type].register(fn)


Expand All @@ -92,7 +92,7 @@ def unregister(callback_type, fn):
if isinstance(callback_type, (list, tuple)):
callback_type = callback_type[0]

if callback_type in ARTELLA_CALLBACKS_CACHE.keys():
if callback_type in list(ARTELLA_CALLBACKS_CACHE.keys()):
ARTELLA_CALLBACKS_CACHE[callback_type].unregister(fn)


Expand Down
20 changes: 12 additions & 8 deletions artella/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import hashlib
import logging
import threading
import traceback
from collections import OrderedDict
try:
from urllib.parse import urlparse, urlencode, urlunparse
Expand Down Expand Up @@ -511,7 +512,7 @@ def translate_path(self, file_path):
path = utils.clean_path(os.path.expanduser(os.path.expandvars(path)))

local_root = self.get_local_root()
local_project_names = (self.get_local_projects() or dict()).keys()
local_project_names = list((self.get_local_projects() or dict()).keys())

for old_alr in consts.OLD_LOCAL_ROOTS:
old_alr_str = '${}'.format(old_alr)
Expand Down Expand Up @@ -622,7 +623,7 @@ def project_name_from_path(self, file_path):
:rtype: str
"""

local_project_names = (self.get_local_projects() or dict()).keys()
local_project_names = list((self.get_local_projects() or dict()).keys())

project_name = None

Expand Down Expand Up @@ -653,7 +654,7 @@ def project_id_from_path(self, file_path):
logger.warning('Was not possible to retrieve Project ID from path: {}!'.format(file_path))
return None

if project_name not in local_projects.keys():
if project_name not in list(local_projects.keys()):
logger.warning(
'Was not possible to retrieve Project ID from path because project "{}" is not recognized!'.format(
project_name))
Expand Down Expand Up @@ -761,7 +762,7 @@ def download(self, paths, version=None, recursive=False, overwrite=True, folders
"""

path_handle_map = paths_to_handles(paths, as_dict=True)
handles = path_handle_map.values()
handles = list(path_handle_map.values())
if not path_handle_map or not handles:
return dict()
logger.debug('Handles: "{}"'.format(handles))
Expand All @@ -774,11 +775,14 @@ def download(self, paths, version=None, recursive=False, overwrite=True, folders
}
if version is not None:
payload['version'] = int(version)
req = Request('http://{}:{}/v2/localserve/transfer/download'.format(self._host, self._port))
rsp = self._communicate(req, json.dumps(payload).encode())
try:
req = Request('http://{}:{}/v2/localserve/transfer/download'.format(self._host, self._port))
rsp = self._communicate(req, json.dumps(payload).encode())
except Exception:
rsp = {'error': traceback.format_exc()}
if 'error' in rsp:
logger.warning(
'Unable to download file paths "{}" "{}"'.format(path_handle_map.keys(), rsp.get('error')))
'Unable to download file paths "{}" "{}"'.format(list(path_handle_map.keys()), rsp.get('error')))
return rsp

return self._track_response(rsp)
Expand Down Expand Up @@ -873,7 +877,7 @@ def upload(self, paths, folders_only=False, comment=''):
rsp = self._communicate(req, json.dumps(payload).encode())
if 'error' in rsp:
logger.warning(
'Unable to upload file paths "{}" "{}"'.format(path_handle_map.keys(), rsp.get('error')))
'Unable to upload file paths "{}" "{}"'.format(list(path_handle_map.keys()), rsp.get('error')))
return rsp

return self._track_response(rsp)
Expand Down
4 changes: 2 additions & 2 deletions artella/core/dcc/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ def __init__(self, parent=None, **kwargs):
self._pos_anim.setTargetObject(self)
self._pos_anim.setEasingCurve(QtCore.QEasingCurve.OutCubic)
self._pos_anim.setDuration(300)
self._pos_anim.setPropertyName('pos')
self._pos_anim.setPropertyName(b'pos')

self._opacity_anim = QtCore.QPropertyAnimation()
self._opacity_anim.setTargetObject(self)
self._opacity_anim.setEasingCurve(QtCore.QEasingCurve.OutCubic)
self._opacity_anim.setDuration(300)
self._opacity_anim.setPropertyName('windowOpacity')
self._opacity_anim.setPropertyName(b'windowOpacity')
self._opacity_anim.setStartValue(0.0)
self._opacity_anim.setEndValue(1.0)

Expand Down
4 changes: 2 additions & 2 deletions artella/core/dcc/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ def __init__(self, parent=None, **kwargs):
self._pos_anim.setTargetObject(self)
self._pos_anim.setEasingCurve(QtCore.QEasingCurve.OutCubic)
self._pos_anim.setDuration(300)
self._pos_anim.setPropertyName('pos')
self._pos_anim.setPropertyName(b'pos')

self._opacity_anim = QtCore.QPropertyAnimation()
self._opacity_anim.setTargetObject(self)
self._opacity_anim.setEasingCurve(QtCore.QEasingCurve.OutCubic)
self._opacity_anim.setDuration(300)
self._opacity_anim.setPropertyName('windowOpacity')
self._opacity_anim.setPropertyName(b'windowOpacity')
self._opacity_anim.setStartValue(0.0)
self._opacity_anim.setEndValue(1.0)

Expand Down
6 changes: 3 additions & 3 deletions artella/core/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,14 @@ def load_registered_plugins(dev=False):
plugin_index = plugin_class.INDEX or -1
index = 0
for i, plugin_item in enumerate(ordered_plugins_list):
plugin_item_index = plugin_item.values()[0]['index']
plugin_item_index = list(plugin_item.values())[0]['index']
if plugin_index < plugin_item_index:
index += 1
ordered_plugins_list.insert(index, {plugin_id: {'index': plugin_index, 'dict': plugin_dict}})

for plugin_item in ordered_plugins_list:
plugin_id = plugin_item.keys()[0]
plugin_dict = plugin_item.values()[0]['dict']
plugin_id = list(plugin_item.keys())[0]
plugin_dict = list(plugin_item.values())[0]['dict']
plugin_class = plugin_dict['class']
plugin_config_dict = plugin_dict.get('config', dict())
try:
Expand Down
13 changes: 10 additions & 3 deletions artella/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import os
import sys
import imp
import time
import json
import shutil
Expand All @@ -19,6 +18,10 @@
import importlib
import subprocess
from functools import wraps
try:
from importlib.machinery import SourceFileLoader
except ImportError:
import imp

logger = logging.getLogger('artella')

Expand Down Expand Up @@ -350,7 +353,10 @@ def import_module(module_path, name=None, skip_exceptions=False):
module_path = clean_path(os.path.join(module_path, '__init__.py'))
if not os.path.exists(module_path):
raise ValueError('Cannot find module path: "{}"'.format(module_path))
return imp.load_source(name, os.path.realpath(module_path))
if is_python2():
return imp.load_source(name, os.path.realpath(module_path))
else:
return SourceFileLoader(name, os.path.realpath(module_path)).load_module()
except ImportError:
logger.error('Failed to load module: "{}"'.format(module_path))
return None
Expand Down Expand Up @@ -463,7 +469,8 @@ def timestamp(f):
def wrapper(*args, **kwargs):
start_time = time.time()
res = f(*args, **kwargs)
logger.info('<{}> Elapsed time : {}'.format(f.func_name, time.time() - start_time))
func_name = f.func_name if is_python2() else f.__name__
logger.info('<{}> Elapsed time : {}'.format(func_name, time.time() - start_time))
return res
return wrapper

Expand Down
2 changes: 1 addition & 1 deletion artella/widgets/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def _get_value(color, i, is_light):
return max((v_comp * 100 - brightness_step2 * i) / 100, 0.0)

light = index <= 6
hsv_color = QtGui.QColor(primary_color) if isinstance(primary_color, basestring) else primary_color
hsv_color = QtGui.QColor(primary_color) if isinstance(primary_color, str) else primary_color
index = light_color_count + 1 - index if light else index - light_color_count - 1
return QtGui.QColor.fromHsvF(
_get_hue(hsv_color, index, light),
Expand Down
2 changes: 1 addition & 1 deletion artella/widgets/divider.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def set_artella_text(self, value):
def get_artella_text(self):
return self._text

artella_text = QtCore.Property(basestring, get_artella_text, set_artella_text)
artella_text = QtCore.Property(str, get_artella_text, set_artella_text)

@classmethod
def left(cls, text=''):
Expand Down
4 changes: 2 additions & 2 deletions artella/widgets/snackbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ def _setup_timers(self, duration):
self._pos_anim.setTargetObject(self)
self._pos_anim.setEasingCurve(QtCore.QEasingCurve.OutCubic)
self._pos_anim.setDuration(300)
self._pos_anim.setPropertyName('pos')
self._pos_anim.setPropertyName(b'pos')

self._opacity_anim = QtCore.QPropertyAnimation(self)
self._opacity_anim = QtCore.QPropertyAnimation()
self._opacity_anim.setTargetObject(self)
self._opacity_anim.setDuration(300)
self._opacity_anim.setEasingCurve(QtCore.QEasingCurve.OutCubic)
self._opacity_anim.setPropertyName('windowOpacity')
self._opacity_anim.setPropertyName(b'windowOpacity')
self._opacity_anim.setStartValue(0.0)
self._opacity_anim.setEndValue(1.0)

Expand Down

0 comments on commit b043ad8

Please sign in to comment.