diff --git a/addons/io_scene_gltf/__init__.py b/addons/io_scene_gltf/__init__.py index 0bb0bed..67e5cd1 100644 --- a/addons/io_scene_gltf/__init__.py +++ b/addons/io_scene_gltf/__init__.py @@ -68,7 +68,7 @@ def get_mesh(self, idx): def get_camera(self, idx): if idx not in self.cameras: - #TODO actually handle cameras + # TODO: actually handle cameras camera = self.gltf['cameras'][idx] name = camera.get('name', 'cameras[%d]' % idx) self.cameras[idx] = bpy.data.cameras.new(name) @@ -105,16 +105,15 @@ def str_to_version(s): raise Exception('unsupported version: %s' % version) def check_required_extensions(self): - #TODO the below works but it will make the tests fails. + # TODO: the below works but it will make the tests fails. # Can be uncommented when KhronosGroup/glTF-Sample-Models#144 # is closed OR we implement pbrSpecularGlossiness. pass - #for ext in self.gltf.get('extensionsRequired', []): + # for ext in self.gltf.get('extensionsRequired', []): # if ext not in EXTENSIONS: # raise Exception('unsupported extension was required: %s' % ext) - def load(self): filename = self.filepath self.base_path = os.path.dirname(filename) @@ -134,17 +133,17 @@ def parse_glb(self, contents): header = struct.unpack_from('<4sII', contents) glb_version = header[1] if glb_version != 2: - raise Exception('GLB: version not supported: %d' % version) + raise Exception('GLB: version not supported: %d' % glb_version) def parse_chunk(offset): header = struct.unpack_from(' wxyz + # xyzw -> wxyz return Quaternion([q[3], q[0], q[1], q[2]]) + def get_transform(node): if 'matrix' in node: return convert_matrix(node['matrix']) @@ -70,7 +71,7 @@ def create(name, data): ob = bpy.data.objects.new(name, data) ob.parent = op.armature_ob - #TODO make the object a child of the bone instead? Making it a + # TODO: make the object a child of the bone instead? Making it a # child puts it at the tail of the bone and we want it at the # head. We'd just need to translate it along the length of the # bone. @@ -134,7 +135,7 @@ def generate_armature_object(op): op.armature_ob = arma_ob # Turn glTF up (+Y) into Blender up (+Z) - #TODO is this right? + # TODO is this right? arma_ob.matrix_local = Matrix([ [1, 0, 0, 0], [0, 0, -1, 0], @@ -155,7 +156,7 @@ def add_bone(idx, parent, parent_mat): bone.head = mat * Vector((0, 0, 0)) bone.tail = mat * Vector((0, 1, 0)) bone.align_roll(mat * Vector((0, 0, 1)) - bone.head) - #NOTE bones don't seem to have non-uniform scaling. + # NOTE: bones don't seem to have non-uniform scaling. # This appears to be a serious problem for us. op.node_to_bone_name[idx] = bone.name @@ -188,7 +189,7 @@ def create_scene(op, idx): scn = bpy.context.scene scn.name = name scn.render.engine = 'CYCLES' - #scn.world.use_nodes = True + # scn.world.use_nodes = True # Always link in the whole node forest scn.objects.link(op.armature_ob) diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..79a16af --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[flake8] +max-line-length = 120 \ No newline at end of file diff --git a/test/generate_report.py b/test/generate_report.py index 4db4c7e..e918ac7 100644 --- a/test/generate_report.py +++ b/test/generate_report.py @@ -23,7 +23,7 @@ def run_tests(): - report = { 'tests': [] } + report = {'tests': []} tests = report['tests'] files = ( diff --git a/test/run_tests.py b/test/run_tests.py index 8a5bb37..6784328 100755 --- a/test/run_tests.py +++ b/test/run_tests.py @@ -16,7 +16,6 @@ import os import subprocess import sys -import tempfile base_dir = os.path.dirname(os.path.abspath(__file__)) @@ -31,24 +30,24 @@ def fetch_samples(): """ try: print("Checking if we're in a git repo...") - result = subprocess.run( + subprocess.run( ['git', 'rev-parse'], cwd=base_dir, check=True ) - except: + except BaseException: print('Is git installed?') print('Did you get this repo through git (as opposed to eg. a zip)?') raise try: print("Initializing submodules (be patient)...") - result = subprocess.run( + subprocess.run( ['git', 'submodule', 'update', '--init', '--recursive'], cwd=base_dir, check=True ) - except: + except BaseException: print("Couldn't init submodules. Aborting") raise @@ -71,28 +70,28 @@ def generate_report(): # Print Blender version for debugging try: subprocess.run(['blender', '--version'], check=True) - except: + except BaseException: print('Check that Blender is installed!') raise print() # We're going to try to run Blender in a clean-ish environment for - # testing. we want to be sure we're using the current state of + # testing. we want to be sure we're using the current state of # 'io_scene_gltf'. The user scripts variable expects an addons/plugin # directory structure which we have in the projects root directory env = os.environ.copy() env['BLENDER_USER_SCRIPTS'] = scripts_dir - #TODO Should we worry about BLENDER_SYSTEM_SCRIPTS, etc? + # TODO: Should we worry about BLENDER_SYSTEM_SCRIPTS, etc? subprocess.run( [ 'blender', - '-noaudio', # sound ssystem to None (less output on stdout) - '--background', # run UI-less - '--factory-startup', # factory settings - '--addons', 'io_scene_gltf', # enable the addon - '--python', test_script # run the test script + '-noaudio', # sound ssystem to None (less output on stdout) + '--background', # run UI-less + '--factory-startup', # factory settings + '--addons', 'io_scene_gltf', # enable the addon + '--python', test_script # run the test script ], env=env, check=True @@ -113,8 +112,8 @@ def print_report(): num_passed = 0 num_failed = 0 failures = [] - ok = '\033[32m' + 'ok' + '\033[0m' # green 'ok' - failed = '\033[31m' + 'FAILED' + '\033[0m' # red 'FAILED' + ok = '\033[32m' + 'ok' + '\033[0m' # green 'ok' + failed = '\033[31m' + 'FAILED' + '\033[0m' # red 'FAILED' for test in tests: name = os.path.relpath(test['filename'], samples_path) @@ -148,7 +147,7 @@ def print_times(): with open(report_path) as f: report = json.load(f) - test_passed = lambda test: test['result'] == 'PASSED' + def test_passed(test): return test['result'] == 'PASSED' tests = list(filter(test_passed, report['tests'])) tests.sort(key=lambda test: test['timeElapsed'], reverse=True) diff --git a/test/travis/import_file.py b/test/travis/import_file.py index e8910a6..6029479 100644 --- a/test/travis/import_file.py +++ b/test/travis/import_file.py @@ -9,23 +9,20 @@ """ -import glob -import json import os import sys -import bpy - -from timeit import default_timer as timer +import bpy base_dir = os.path.dirname(os.path.abspath(__file__)) + def run_tests(): filename = sys.argv[-1] sys.stderr.write(filename) bpy.ops.wm.read_factory_settings() bpy.ops.import_scene.gltf(filepath=filename) - + def main(): run_tests() diff --git a/test/travis/runtest.py b/test/travis/runtest.py index 101aefe..db279fa 100644 --- a/test/travis/runtest.py +++ b/test/travis/runtest.py @@ -1,7 +1,7 @@ import unittest import glob import os -from subprocess import Popen, DEVNULL, run +from subprocess import DEVNULL, run base_dir = os.path.dirname(os.path.abspath(__file__)) samples_path = os.path.join(base_dir, os.pardir, 'glTF-Sample-Models', '2.0')