Skip to content

Commit

Permalink
Fixing a bunch of Codacy code smell issues and security patches to av…
Browse files Browse the repository at this point in the history
…oid eval/exec statements.

Modified node_types to be explicit imports.
  • Loading branch information
AndresMWeber committed Apr 1, 2018
1 parent a8098d7 commit 46a1392
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 29 deletions.
3 changes: 1 addition & 2 deletions anvil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,4 @@ def is_aobject(node):
'sub_rig_templates',
'rig_templates',
'utils',
'colors',
'decorators.py']
'colors']
3 changes: 0 additions & 3 deletions anvil/decorators.py

This file was deleted.

2 changes: 1 addition & 1 deletion anvil/grouping/sub_rig.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SubRig(base_grouping.AbstractGrouping):

def build(self, parent=None, **kwargs):
super(SubRig, self).build(**kwargs)
if self.root is None:
if getattr(self, 'root') is None:
root_id = '%s_%s' % (cfg.GROUP_TYPE, 'top')
self.build_node(Transform,
hierarchy_id=root_id,
Expand Down
4 changes: 2 additions & 2 deletions anvil/node_types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from six import iteritems
import inspect
from objects import * # noqa
from grouping import * # noqa
from objects import UnicodeDelegate, DagNode, Transform, Curve, Joint
from grouping import AbstractGrouping, SubRig, Rig, BaseCollection, NodeChain, NodeSet, Control

REGISTERED_NODES = {}

Expand Down
2 changes: 1 addition & 1 deletion anvil/objects/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def insert_input(self, node, in_attribute, out_attribute):
node.attr(out_attribute).connect(self, force=True)

def is_dirty(self, **kwargs):
return rt.dcc.connections.dirty_attr(**kwargs)
return rt.dcc.connections.dirty_attr(self, **kwargs)

def is_multi(self, **kwargs):
return rt.dcc.connections.info_attr(self, multi=True, **kwargs)
Expand Down
4 changes: 2 additions & 2 deletions anvil/objects/curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def populate_shape_file_data(cls, shape_file=None):

if not cls.SHAPE_CACHE:
try:
cls.SHAPE_CACHE = yaml.load(open(shape_file, "r"))
cls.SHAPE_CACHE = yaml.safe_load(open(shape_file, "r"))
except IOError:
cls.error('Missing file %s, please reinstall or locate', shape_file)
cls.SHAPE_CACHE = {}
Expand Down Expand Up @@ -134,7 +134,7 @@ def _add_curve_shape_to_shape_file(self, shape_file=None):
shape_file = cfg.SHAPES_FILE
try:
shape_name = self.name()
shapes_data = yaml.load(open(shape_file, "r"))
shapes_data = yaml.safe_load(open(shape_file, "r"))

target_data = shapes_data.get(shape_name, {})
degree = self.get_shape().degree()
Expand Down
2 changes: 1 addition & 1 deletion anvil/utils/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def safe_delete(node_or_nodes):
for node in node_or_nodes:
try:
rt.dcc.scene.delete(node)
except: # noqa
except Exception:
pass


Expand Down
20 changes: 13 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import re
import codecs
from os.path import abspath, dirname, join
import os
from setuptools import setup, find_packages

__author__ = 'Andres Weber'
__author_email__ = 'andresmweber@gmail.com'
__package__ = 'anvil'
__name__ = 'anvil'
__url__ = 'https://github.com/andresmweber/anvil'
__version__ = '0.0.0'

with codecs.open(abspath(join(__package__, 'version.py'))) as ver_file:
exec (ver_file.read())
with codecs.open(os.path.abspath(os.path.join(__name__, 'version.py'))) as ver_file:
version_regex = r"^__version__ = ['\"]([^'\"]*)['\"]"
mo = re.search(version_regex, ver_file.read(), re.M)
try:
__version__ = mo.group(1)
except AttributeError:
pass

with codecs.open(join(abspath(dirname(__file__)), 'README.md'), encoding='utf-8') as readme_file:
long_description = readme_file.read()
with codecs.open(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'README.md'), encoding='utf-8') as readme:
long_description = readme.read()

description = 'Yet another auto-rigger.'

Expand All @@ -36,7 +42,7 @@
dev_requires = ['Sphinx', 'docutils', 'docopt']

setup(
name=__package__,
name=__name__,
version=__version__,
packages=find_packages(exclude=['tests', '*.tests', '*.tests.*']),
package_data={'curve_shapes.yml': ['anvil/objects/curve_shapes.yml']},
Expand Down
11 changes: 6 additions & 5 deletions tests/acceptance/test_template_sub_rigs.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import anvil.runtime as rt
import anvil.node_types as nt
import anvil.sub_rig_templates.spine as spine
import anvil.sub_rig_templates.biped_arm as biped_arm
from tests.base_test import TestBase, sanitize
from anvil.sub_rig_templates.base_sub_rig_template import SubRigTemplate
from anvil.sub_rig_templates.spine import Spine
from anvil.sub_rig_templates.biped_arm import BipedArm


class TestBaseTemplates(TestBase):
name_tokens = {'name': 'eye', 'purpose': 'mvp'}
test_rig = None
TEMPLATE_CLASS = None
TEMPLATE_CLASS = SubRigTemplate

@classmethod
def runner(cls, num_joints=6, template_args=None, template_flags=None, joint_flags=None):
Expand All @@ -33,7 +34,7 @@ def runner(cls, num_joints=6, template_args=None, template_flags=None, joint_fla


class TestBuildSpine(TestBaseTemplates):
TEMPLATE_CLASS = spine.Spine
TEMPLATE_CLASS = Spine

def test_build(self):
self.runner()
Expand All @@ -46,7 +47,7 @@ def test_build_with_parent(self):


class TestBuildBipedArm(TestBaseTemplates):
TEMPLATE_CLASS = biped_arm.BipedArm
TEMPLATE_CLASS = BipedArm

@classmethod
def from_template_file(cls, template_file):
Expand Down
9 changes: 4 additions & 5 deletions tests/resources/cmd_line.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import click
import sys
import os
import cProfile, pstats, StringIO
Expand All @@ -16,16 +17,14 @@
import anvil
anvil.log.set_all_log_levels(anvil.log.logging.CRITICAL)

import click


@click.command()
@click.option('--test_runner', default='biped', help='Which suite to run (control, biped, mvp')
def main(test_runner):
@click.option('--test_runner', default='biped', help='Which suite to run (control, biped, mvp)')
def main(test_runner='test_full_input'):
pr = cProfile.Profile()
pr.enable()

eval('{}_{}()'.format('run', test_runner))
locals()['run_%s' % test_runner]()

pr.disable()
s = StringIO.StringIO()
Expand Down

0 comments on commit 46a1392

Please sign in to comment.