Skip to content

Commit

Permalink
Added .landscape.yml
Browse files Browse the repository at this point in the history
Fixed a ton of code smell from landscape.io check:
https://landscape.io/github/AndresMWeber/Anvil/102/
  • Loading branch information
AndresMWeber committed Feb 17, 2018
1 parent c692c84 commit 1ff7014
Show file tree
Hide file tree
Showing 29 changed files with 143 additions and 125 deletions.
11 changes: 11 additions & 0 deletions .landscape.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
doc-warnings: true
test-warnings: false
ignore-paths:
- docs
- tests
- anvil/plugins/maya
- anvil/plugins/standalone
python-targets:
- 2
pep8:
full: true
10 changes: 5 additions & 5 deletions anvil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ class AnvilLog(log.LogMixin):


def check_for_encapsulation(dag_path):
for node_index, node_encapsulation in iteritems(EXISTING_ENCAPSULATIONS):
for _, node_encapsulation in iteritems(EXISTING_ENCAPSULATIONS):
if dag_path == node_encapsulation._dcc_id:
LOG.debug('Found previous encapsulation for %s: %r. Using instead.', dag_path, node_encapsulation)
return node_encapsulation
else:
return None
return None


def factory(dag_path, **kwargs):
Expand Down Expand Up @@ -80,9 +79,10 @@ def is_anvil(node):
try:
if isinstance(node, node_types.REGISTERED_NODES.get(type(node).__name__)):
return True
except:
except AttributeError:
pass
return False
finally:
return False


def is_agrouping(node):
Expand Down
11 changes: 4 additions & 7 deletions anvil/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def as_hex(self):
return '#{:02X}{:02X}{:02X}'.format(int(self.red), int(self.green), int(self.blue))

@classmethod
def from_hex(cls, hex):
hex = hex.lstrip('#')
return cls(*tuple(int(hex[i:i + 2], 16) for i in (0, 2, 4)))
def from_hex(cls, hexadecimal):
hexadecimal = hexadecimal.lstrip('#')
return cls(*tuple(int(hexadecimal[i:i + 2], 16) for i in (0, 2, 4)))

@classmethod
def from_hsv(cls, hsv):
Expand Down Expand Up @@ -78,11 +78,8 @@ def __add__(self, other):
return self


def get_closest_color(r, g, b):
pass


# Color Contants
# Color Constants
ALICEBLUE = RGB(240, 248, 255)
ANTIQUEWHITE = RGB(250, 235, 215)
ANTIQUEWHITE1 = RGB(255, 239, 219)
Expand Down
1 change: 1 addition & 0 deletions anvil/grouping/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
from rig import Rig
from traversal import HierarchyChain

__modules__ = [base, control, sub_rig, rig, traversal]
__all__ = ['Control', 'SubRig', 'Rig', 'AbstractGrouping', 'HierarchyChain']
8 changes: 4 additions & 4 deletions anvil/grouping/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ def parent(self, new_parent):
def rename_chain(self, objects, use_end_naming=False, **name_tokens):
self.chain_nomenclate.merge_dict(self.name_tokens.merge(name_tokens))

for index, object in enumerate(objects):
for index, node in enumerate(objects):
variation_kwargs = {'var': index}
if use_end_naming and index == len(objects) - 1:
variation_kwargs = {'decorator': 'End'}
rt.dcc.scene.rename(object, self.chain_nomenclate.get(**variation_kwargs))
rt.dcc.scene.rename(node, self.chain_nomenclate.get(**variation_kwargs))

def rename(self, *input_dicts, **kwargs):
new_tokens = MetaData(*input_dicts, **kwargs)
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, *args, **kwargs):
def auto_color(self, **kwargs):
auto_colorer = lambda n: n.auto_color() if hasattr(n, 'auto_color') else None
self._cascading_function(auto_colorer, auto_colorer)

Expand All @@ -154,7 +154,7 @@ def find_node(self, node_key):
raise KeyError('Node from key %s not found in hierarchy' % node_key)

def _cascading_function(self, object_function, grouping_function):
for sub_key, sub_node in iteritems(self.hierarchy):
for _, sub_node in iteritems(self.hierarchy):
if anvil.is_agrouping(sub_node):
grouping_function(sub_node)
elif anvil.is_aobject(sub_node):
Expand Down
3 changes: 1 addition & 2 deletions anvil/grouping/control.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from anvil.meta_data import MetaData
import anvil.config as cfg
import anvil.objects as ob
import anvil.runtime as rt
Expand Down Expand Up @@ -70,7 +69,7 @@ def match_position(self, reference_object, rotate=True, translate=True, **kwargs
target = self.offset_group
except AttributeError:
target = self.control
target.match_transform(reference_object, rotate=rotate, translate=translate)
target.match_transform(reference_object, rotate=rotate, translate=translate, **kwargs)

def build_layout(self):
rt.dcc.scene.parent(getattr(self, cfg.CONTROL_TYPE), getattr(self, cfg.OFFSET_GROUP))
Expand Down
12 changes: 6 additions & 6 deletions anvil/grouping/rig.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from six import iteritems
import base
import anvil
from anvil.meta_data import MetaData, cls_merge_name_tokens_and_meta_data
from anvil.meta_data import MetaData
import anvil.config as cfg
import anvil.objects as ot
import sub_rig
Expand Down Expand Up @@ -32,8 +32,8 @@ def __init__(self, character=None, sub_rig_dict=None, *args, **kwargs):

def rename(self, *input_dicts, **name_tokens):
super(Rig, self).rename(*input_dicts, **name_tokens)
for sub_rig_key, sub_rig in iteritems(self.sub_rigs):
sub_rig.rename() #*input_dicts, **name_tokens)
for _, sub_rig_instance in iteritems(self.sub_rigs):
sub_rig_instance.rename()

def register_sub_rigs_from_dict(self, sub_rig_dict):
""" Only accepts dictionary with keys that match the built in SUB_RIG_BUILD_TABLE for the given Rig.
Expand Down Expand Up @@ -71,14 +71,14 @@ def build_sub_rig(self, sub_rig_key, sub_rig_candidate=sub_rig.SubRig, **kwargs)
return self.sub_rigs[sub_rig_key]

def build_sub_rigs(self):
for sub_rig_key, sub_rig_member in iteritems(self.sub_rigs):
for _, sub_rig_member in iteritems(self.sub_rigs):
self.info('Building sub-rig %s on rig %s', sub_rig_member, self)
sub_rig_member.build(parent=self.group_sub_rigs)

def auto_color(self):
super(Rig, self).auto_color()
for key, sub_rig in iteritems(self.sub_rigs):
sub_rig.auto_color()
for _, sub_rig_instance in iteritems(self.sub_rigs):
sub_rig_instance.auto_color()

def build(self, parent=None, name_tokens=None, **kwargs):
self.info('Building %s(%r) with parent: %s, name_tokens: %s, and kwargs: %s',
Expand Down
8 changes: 4 additions & 4 deletions anvil/grouping/traversal.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ def insert_and_build_buffer(self, index_target, reference_node=None, beneath=Fal
:param buffer_node_class: ob.UnicodeProxy, anvil node type we are going to build
:return: anvil.objects.dag_node.DagNode, anvil node type
"""
buffer = (buffer_node_class if anvil.is_anvil(buffer_node_class) else self.DEFAULT_BUFFER_TYPE).build(**kwargs)
pre_hooks = [lambda: buffer.reset_transform(), lambda: buffer.match_transform(reference_node)]
self.insert_node(index_target, buffer, pre_hooks=pre_hooks, beneath=beneath)
return buffer
buff = (buffer_node_class if anvil.is_anvil(buffer_node_class) else self.DEFAULT_BUFFER_TYPE).build(**kwargs)
pre_hooks = [buff.reset_transform, lambda: buff.match_transform(reference_node)]
self.insert_node(index_target, buff, pre_hooks=pre_hooks, beneath=beneath)
return buff

def depth(self, node_filter=None):
return gc.get_dict_depth(d=self.get_hierarchy(node_filter=node_filter or self.node_filter)) - 1
Expand Down
10 changes: 5 additions & 5 deletions anvil/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ def obtainLogger(name, json_output=False):
Logger: Logger.
"""
logger = structlog.get_logger(name)

"""
if json_output:
format_str = '%(message)%(levelname)%(name)%(asctime)'
# formatter = jslog.JsonFormatter(format_str)
# for handler in logger.handlers:
# handler.setFormatter(formatter)
formatter = jslog.JsonFormatter(format_str)
for handler in logger.handlers:
handler.setFormatter(formatter)
pass

"""
return logger


Expand Down
1 change: 1 addition & 0 deletions anvil/objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
from transform import Transform
from unicode_delegate import UnicodeDelegate

__modules__ = [curve, dag_node, joint, transform, unicode_delegate, attribute]
__all__ = ['Curve', 'DagNode', 'Joint', 'Transform', 'UnicodeDelegate', 'Attribute']
12 changes: 6 additions & 6 deletions anvil/objects/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,19 @@ def set_min(self, value):
def set_max(self, value):
rt.dcc.connections.add_attr(self, maxValue=value, edit=True)

def set_range(self, min, max):
self.set_min(min)
self.set_max(max)
def set_range(self, min_value, max_value):
self.set_min(min_value)
self.set_max(max_value)

def set_soft_min(self, value):
rt.dcc.connections.add_attr(self, softMinValue=value, edit=True)

def set_soft_max(self, value):
rt.dcc.connections.add_attr(self, softMaxValue=value, edit=True)

def set_soft_range(self, min, max):
self.set_soft_min(min)
self.set_soft_max(max)
def set_soft_range(self, min_value, max_value):
self.set_soft_min(min_value)
self.set_soft_max(max_value)

def set_keyframe(self, **kwargs):
return rt.dcc.animation.set_keyframe(self, **kwargs)
Expand Down
6 changes: 3 additions & 3 deletions anvil/objects/curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def build_line_indicator(cls, object1, object2, **kwargs):
kwargs[cfg.DEGREE] = 1
kwargs[cfg.NAME_TOKENS] = MetaData(kwargs.get(cfg.NAME_TOKENS, {}))
kwargs[cfg.NAME_TOKENS].update({cfg.NAME: '%s_to_%s' % (object1, object2), cfg.TYPE: cfg.CURVE_TYPE})
curve = cls.build_from_objects([object1, object2], **kwargs)
curve = cls.build_from_nodes([object1, object2], **kwargs)
object1_cluster, object2_cluster = curve.generate_clusters()
object1_cluster.parent(object1)
object2_cluster.parent(object2)
Expand All @@ -47,8 +47,8 @@ def build_line_indicator(cls, object1, object2, **kwargs):
return (curve, [object1_cluster, object1_cluster])

@classmethod
def build_from_objects(cls, objects, **kwargs):
kwargs[cfg.POINT] = [object.get_world_position() for object in anvil.factory_list(objects)]
def build_from_nodes(cls, nodes, **kwargs):
kwargs[cfg.POINT] = [node.get_world_position() for node in anvil.factory_list(nodes)]
instance = cls.build(**kwargs)
return instance

Expand Down
2 changes: 1 addition & 1 deletion anvil/objects/unicode_delegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, node_pointer, meta_data=None, name_tokens=None, **kwargs):

try:
self._api_class_instance = rt.dcc.scene.APIWrapper(str(node_pointer))
except:
except AttributeError:
self._api_class_instance = object()

def name(self):
Expand Down
2 changes: 2 additions & 0 deletions anvil/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
import base
import dcc_plugin

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

__all__ = [api_proxy]
3 changes: 1 addition & 2 deletions anvil/plugins/base/api_proxy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from six import iteritems, raise_from
from functools import wraps
import sys
import anvil
import anvil.config as cfg
from jsonschema import validate
Expand Down Expand Up @@ -32,7 +31,7 @@ class APIProxy(object):
CURRENT_API = None

@classmethod
def _validate_function(cls, schema, api, function_name):
def validate(cls, schema, api, function_name):
def to_validate(function):
@wraps(function)
def validator(*args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion anvil/plugins/maya/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import anvil.plugins.base.api_proxy as api_proxy


@api_proxy.APIProxy._validate_function(
@api_proxy.APIProxy.validate(
api_proxy.merge_dicts(api_proxy.DEFAULT_SCHEMA,
{'properties':
{'animLayer': api_proxy.STR_TYPE, 'attribute': api_proxy.STR_TYPE,
Expand Down
Loading

0 comments on commit 1ff7014

Please sign in to comment.