Skip to content

Commit

Permalink
Fixed a ton of code smell from landscape.io check:
Browse files Browse the repository at this point in the history
  • Loading branch information
AndresMWeber committed Feb 17, 2018
1 parent 1ff7014 commit 86a9e66
Show file tree
Hide file tree
Showing 23 changed files with 320 additions and 319 deletions.
7 changes: 3 additions & 4 deletions anvil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class AnvilLog(log.LogMixin):
LOG = log.obtainLogger(__name__)
LOG = log.obtain_logger(__name__)


LOG = AnvilLog
Expand Down Expand Up @@ -79,10 +79,9 @@ def is_anvil(node):
try:
if isinstance(node, node_types.REGISTERED_NODES.get(type(node).__name__)):
return True
except AttributeError:
except TypeError:
pass
finally:
return False
return False


def is_agrouping(node):
Expand Down
2 changes: 1 addition & 1 deletion anvil/grouping/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
from rig import Rig
from traversal import HierarchyChain

__modules__ = [base, control, sub_rig, rig, traversal]
__modules__ = ['base', 'control', 'sub_rig', 'rig', 'traversal']
__all__ = ['Control', 'SubRig', 'Rig', 'AbstractGrouping', 'HierarchyChain']
4 changes: 2 additions & 2 deletions anvil/grouping/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AbstractGrouping(log.LogMixin):
are required to give a performance.
"""
LOG = log.obtainLogger(__name__)
LOG = log.obtain_logger(__name__)
ANVIL_TYPE = cfg.GROUP_TYPE
BUILT_IN_NAME_TOKENS = MetaData({cfg.TYPE: ANVIL_TYPE, cfg.NAME: 'untitled'}, protected=cfg.TYPE)
BUILT_IN_META_DATA = MetaData()
Expand Down Expand Up @@ -143,7 +143,7 @@ def register_node(self, node_key, dag_node, overwrite=True, name_tokens=None, me
dag_node.name_tokens.merge(self.name_tokens, name_tokens)
return dag_node

def auto_color(self, **kwargs):
def auto_color(self):
auto_colorer = lambda n: n.auto_color() if hasattr(n, 'auto_color') else None
self._cascading_function(auto_colorer, auto_colorer)

Expand Down
4 changes: 2 additions & 2 deletions anvil/grouping/rig.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Rig(base.AbstractGrouping):
""" A fully functional and self-contained rig with all requirements implemented that
require it to give a performance. A collection of SubRig(s)
"""
LOG = anvil.log.obtainLogger(__name__)
LOG = anvil.log.obtain_logger(__name__)
BUILT_IN_NAME_TOKENS = MetaData(base.AbstractGrouping.BUILT_IN_NAME_TOKENS)
SUB_RIG_BUILD_ORDER = []
SUB_RIG_BUILD_TABLE = OrderedDict()
Expand Down Expand Up @@ -66,7 +66,7 @@ def build_sub_rig(self, sub_rig_key, sub_rig_candidate=sub_rig.SubRig, **kwargs)
kwargs[cfg.META_DATA] = MetaData(self.meta_data, kwargs.get(cfg.META_DATA, {}))
if inspect.isclass(sub_rig_candidate) and issubclass(sub_rig_candidate, sub_rig.SubRig):
self.info('Registering %s.[%s] = %s(%s)', self, sub_rig_key, sub_rig_candidate.__name__, kwargs)
layout_joints = kwargs.pop('layout_joints')
layout_joints = kwargs.pop(cfg.LAYOUT, None)
self.sub_rigs[sub_rig_key] = sub_rig_candidate(layout_joints, **kwargs)
return self.sub_rigs[sub_rig_key]

Expand Down
2 changes: 1 addition & 1 deletion anvil/grouping/sub_rig.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class SubRig(base.AbstractGrouping):
BUILT_IN_NAME_TOKENS = MetaData(base.AbstractGrouping.BUILT_IN_NAME_TOKENS)
ROOT_NAME_TOKENS = {cfg.RIG_TYPE: cfg.SUB_RIG_TOKEN, cfg.TYPE: cfg.GROUP_TYPE}
LOG = lg.obtainLogger(__name__)
LOG = lg.obtain_logger(__name__)
SUB_GROUPS = ['surfaces', 'joints', 'controls', 'nodes', 'world']

def build(self, parent=None, **kwargs):
Expand Down
6 changes: 3 additions & 3 deletions anvil/grouping/traversal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import anvil.objects as ob
import anvil.utils.generic as gc
import anvil.utils.scene as sc
from anvil.log import LogMixin, obtainLogger
from anvil.log import LogMixin, obtain_logger
import anvil.runtime as rt


class HierarchyChain(LogMixin):
LOG = obtainLogger(__name__)
LOG = obtain_logger(__name__)
DEFAULT_BUFFER_TYPE = ob.Transform

def __init__(self, top_node, end_node=None, duplicate=False, node_filter=None, parent=None):
Expand Down Expand Up @@ -95,7 +95,7 @@ def insert_node(self, index_target, node, beneath=False, pre_hooks=None, post_ho

# If user specified the head we need to set it to the new head which is the buffer node.
if index_target == self.head:
self.head = buffer
self.head = node

if post_hooks:
for post_hook in post_hooks:
Expand Down
8 changes: 4 additions & 4 deletions anvil/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import config as cfg



def obtainLogger(name, json_output=False):
def obtain_logger(name):
"""Get's a logger and attaches the correct DCC compatible Handler.
Args:
name (str): Name of the logger to get / create.
Expand All @@ -28,7 +27,7 @@ def obtainLogger(name, json_output=False):


class LogMixin(object):
LOG = obtainLogger(__name__ + '.LogMixin')
LOG = obtain_logger(__name__ + '.LogMixin')

@classmethod
def info(cls, msg, *args):
Expand Down Expand Up @@ -76,7 +75,7 @@ def error(cls, msg, *args):
class LogInitializer(LogMixin):
HANDLERS = 'handlers'
LOGGERS = 'loggers'
LOG = obtainLogger(__name__)
LOG = obtain_logger(__name__)
DEFAULT_LEVEL = logging.DEBUG
LOG_DIR = cfg.DEFAULT_LOG_DIR
ENV_KEY = cfg.LOG_ENV_KEY
Expand Down Expand Up @@ -180,6 +179,7 @@ def toggle_loggers():
LogInitializer.override_all_loggers('disabled', LogInitializer.STATE)
LogInitializer.set_from_dict()


def set_all_log_levels(level=logging.ERROR):
LogInitializer.override_all_loggers('level', level)
LogInitializer.set_from_dict()
4 changes: 2 additions & 2 deletions anvil/meta_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class MetaData(log.LogMixin):
LOG = log.obtainLogger(__name__)
LOG = log.obtain_logger(__name__)
PROTECTED_KWARG = 'protected'
IGNORED_KWARG = 'ignored'
FORCE_KWARG = 'force'
Expand Down Expand Up @@ -157,7 +157,7 @@ def inner(cls_or_self, *args, **kwargs):
cls_or_self.name_tokens.merge(name_tokens)
cls_or_self.meta_data.merge(meta_data)

if not 'Attribute' in repr(cls_or_self):
if 'Attribute' not in repr(cls_or_self):
MetaData.info('Adding to node %r, name_tokens: %s, meta_data: %s, pre: %s',
cls_or_self, name_tokens, meta_data, pre)
return function_result
Expand Down
2 changes: 1 addition & 1 deletion anvil/objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
from transform import Transform
from unicode_delegate import UnicodeDelegate

__modules__ = [curve, dag_node, joint, transform, unicode_delegate, attribute]
__modules__ = ['curve', 'dag_node', 'joint', 'transform', 'unicode_delegate', 'attribute']
__all__ = ['Curve', 'DagNode', 'Joint', 'Transform', 'UnicodeDelegate', 'Attribute']
4 changes: 2 additions & 2 deletions anvil/objects/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ def is_keyable(self):
def is_muted(self):
return rt.dcc.connections.mute(self, query=True)

def isHidden(self):
def is_hidden(self):
return rt.dcc.connections.query_attr(self, node=self.node(), hidden=True)

def isConnectable(self):
def is_connectable(self):
return rt.dcc.connections.query_attr(self, node=self.node(), connectable=True)

def unmute(self, **kwargs):
Expand Down
8 changes: 4 additions & 4 deletions anvil/objects/curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def _get_shape_constructor(cls, shape_name, return_positions=False):
return lambda: api_function(**shape_entry)

@classmethod
def _populate_shape_file_data(cls, shape_file=None):
def populate_shape_file_data(cls, shape_file=None):
if shape_file is None:
shape_file = cfg.SHAPES_FILE

Expand All @@ -112,11 +112,11 @@ def _populate_shape_file_data(cls, shape_file=None):
cls.SHAPE_CACHE = {}

@staticmethod
def _ordered_dump(data, stream=None, Dumper=yaml.Dumper, **kwargs):
def _ordered_dump(data, stream=None, dumper=yaml.Dumper, **kwargs):
""" Stolen from https://stackoverflow.com/a/21912744. Great way of dumping as OrderedDict.
"""

class OrderedDumper(Dumper):
class OrderedDumper(dumper):
pass

def _dict_representer(dumper, data):
Expand Down Expand Up @@ -158,4 +158,4 @@ def _build_all_controls(cls):
curve.rename(shape)


Curve._populate_shape_file_data()
Curve.populate_shape_file_data()
2 changes: 1 addition & 1 deletion anvil/objects/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_children(self, **kwargs):
def reset_transform(self):
self.translate.set((0, 0, 0))
self.rotate.set((0, 0, 0))
self.scale.set((1,1,1))
self.scale.set((1, 1, 1))

def parent(self, new_parent):
top_node, new_parent = self, new_parent
Expand Down
4 changes: 1 addition & 3 deletions anvil/objects/unicode_delegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class UnicodeDelegate(log.LogMixin):
LOG = log.obtainLogger(__name__)
LOG = log.obtain_logger(__name__)
DCC_TYPE = None
ANVIL_TYPE = 'unicode'
BUILT_IN_METADATA = MetaData({})
Expand All @@ -21,8 +21,6 @@ def __init__(self, node_pointer, meta_data=None, name_tokens=None, **kwargs):
:param kwargs: dict, creation flags specific for the platform environment node creation function
:param meta_data: dict, any object specific meta data we want to record
"""
self.debug('Initializing node %s with ID %s, name_tokens=%s, meta_data=%s, %s',
self.__class__, node_pointer, name_tokens, meta_data, kwargs)
self._dcc_id = rt.dcc.scene.get_persistent_id(str(node_pointer))

self.meta_data = self.BUILT_IN_METADATA.merge(meta_data, new=True)
Expand Down
3 changes: 2 additions & 1 deletion anvil/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import base
import dcc_plugin

__all__ = [base, dcc_plugin]
__all__ = ['base',
'dcc_plugin']
2 changes: 1 addition & 1 deletion anvil/plugins/base/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import api_proxy

__all__ = [api_proxy]
__all__ = ['api_proxy']
4 changes: 2 additions & 2 deletions anvil/plugins/base/api_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@


class APIProxy(object):
LOG = anvil.log.obtainLogger(__name__)
API_LOG = anvil.log.obtainLogger(__name__ + '.api_calls')
LOG = anvil.log.obtain_logger(__name__)
API_LOG = anvil.log.obtain_logger(__name__ + '.api_calls')
CURRENT_API = None

@classmethod
Expand Down
7 changes: 7 additions & 0 deletions anvil/plugins/maya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@
import connections
import rigging
import animation

__all__ = ['dependencies',
'create',
'scene',
'connections',
'rigging',
'animation']
Loading

0 comments on commit 86a9e66

Please sign in to comment.