Skip to content

Commit

Permalink
Linting (without naming convention)
Browse files Browse the repository at this point in the history
  • Loading branch information
Celeborn2BeAlive committed Apr 14, 2020
1 parent 30905a3 commit e887da1
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[flake8]
max-line-length = 120
extend-ignore = E203 # Incompatible with black
ignore = E203, E501, W503 # Incompatible with black

exclude =
.git
Expand Down
2 changes: 0 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from . import data
from . import stats
from .shareData import shareData
import bpy
import atexit
import logging
from pathlib import Path
Expand All @@ -23,7 +22,6 @@


def cleanup():
shareData = operators.shareData
if shareData.current_statistics is not None and shareData.auto_save_statistics:
stats.save_statistics(shareData.current_statistics, shareData.statistics_directory)
try:
Expand Down
15 changes: 8 additions & 7 deletions blender_client/collection.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from ..broadcaster import common
from ..broadcaster.client import Client
from ..shareData import shareData
import logging
import bpy

logger = logging.getLogger(__name__)


def sendCollection(client: "ClientBlender", collection: bpy.types.Collection):
def sendCollection(client: Client, collection: bpy.types.Collection):
logger.debug("sendCollection %s", collection.name_full)
collectionInstanceOffset = collection.instance_offset
buffer = (
Expand All @@ -32,7 +33,7 @@ def buildCollection(data):
collection.instance_offset = offset


def sendCollectionRemoved(client: "ClientBlender", collectionName):
def sendCollectionRemoved(client: Client, collectionName):
logger.debug("sendCollectionRemoved %s", collectionName)
buffer = common.encodeString(collectionName)
client.addCommand(common.Command(common.MessageType.COLLECTION_REMOVED, buffer, 0))
Expand All @@ -46,7 +47,7 @@ def buildCollectionRemoved(data):
bpy.data.collections.remove(collection)


def sendAddCollectionToCollection(client: "ClientBlender", parentCollectionName, collectionName):
def sendAddCollectionToCollection(client: Client, parentCollectionName, collectionName):
logger.debug("sendAddCollectionToCollection %s <- %s", parentCollectionName, collectionName)

buffer = common.encodeString(parentCollectionName) + common.encodeString(collectionName)
Expand All @@ -63,7 +64,7 @@ def buildCollectionToCollection(data):
parent.children.link(child)


def sendRemoveCollectionFromCollection(client: "ClientBlender", parentCollectionName, collectionName):
def sendRemoveCollectionFromCollection(client: Client, parentCollectionName, collectionName):
logger.debug("sendRemoveCollectionFromCollection %s <- %s", parentCollectionName, collectionName)

buffer = common.encodeString(parentCollectionName) + common.encodeString(collectionName)
Expand All @@ -80,7 +81,7 @@ def buildRemoveCollectionFromCollection(data):
parent.children.unlink(child)


def sendAddObjectToCollection(client: "ClientBlender", collectionName, objName):
def sendAddObjectToCollection(client: Client, collectionName, objName):
logger.debug("sendAddObjectToCollection %s <- %s", collectionName, objName)
buffer = common.encodeString(collectionName) + common.encodeString(objName)
client.addCommand(common.Command(common.MessageType.ADD_OBJECT_TO_COLLECTION, buffer, 0))
Expand All @@ -100,7 +101,7 @@ def buildAddObjectToCollection(data):
collection.objects.link(object_)


def sendRemoveObjectFromCollection(client: "ClientBlender", collectionName, objName):
def sendRemoveObjectFromCollection(client: Client, collectionName, objName):
logger.debug("sendRemoveObjectFromCollection %s <- %s", collectionName, objName)
buffer = common.encodeString(collectionName) + common.encodeString(objName)
client.addCommand(common.Command(common.MessageType.REMOVE_OBJECT_FROM_COLLECTION, buffer, 0))
Expand All @@ -116,7 +117,7 @@ def buildRemoveObjectFromCollection(data):
collection.objects.unlink(object_)


def sendCollectionInstance(client: "ClientBlender", obj):
def sendCollectionInstance(client: Client, obj):
if not obj.instance_collection:
return
instanceName = obj.name_full
Expand Down
13 changes: 6 additions & 7 deletions blender_client/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def encodeBakedMesh(obj):

# Triangulate mesh (before calculating normals)
mesh = obj.data if obj.type == "MESH" else obj.to_mesh()
if mesh == None:
if mesh is None:
# This happens for empty curves
return bytes()

Expand Down Expand Up @@ -319,12 +319,11 @@ def encodeBaseMeshGeometry(mesh_data):

@stats_timer(shareData)
def encodeBaseMesh(obj):
stats_timer = shareData.current_stats_timer

# Temporary for curves and other objects that support to_mesh()
# #todo Implement correct base encoding for these objects
mesh_data = obj.data if obj.type == "MESH" else obj.to_mesh()
if mesh_data == None:
if mesh_data is None:
# This happens for empty curves
# This is temporary, when curves will be fully implemented we will encode something
return bytes()
Expand All @@ -333,7 +332,7 @@ def encodeBaseMesh(obj):

# Shape keys
# source https://blender.stackexchange.com/questions/111661/creating-shape-keys-using-python
if mesh_data.shape_keys == None:
if mesh_data.shape_keys is None:
binary_buffer += common.encodeInt(0) # Indicate 0 key blocks
else:
logger.debug("Writing %d shape keys", len(mesh_data.shape_keys.key_blocks))
Expand Down Expand Up @@ -429,7 +428,7 @@ def encodeMesh(obj, encode_base_mesh, encode_baked_mesh):
# Materials
materials = []
for material in obj.data.materials:
materials.append(material.name_full if material != None else "")
materials.append(material.name_full if material is not None else "")
binary_buffer += common.encodeStringArray(materials)

return binary_buffer
Expand Down Expand Up @@ -488,7 +487,7 @@ def decodeBakedMesh(obj, data, index):
face.loops[0][uv_layer].uv = uvs[i1]
face.loops[1][uv_layer].uv = uvs[i2]
face.loops[2][uv_layer].uv = uvs[i3]
except:
except Exception:
pass

me = obj.data
Expand All @@ -515,7 +514,7 @@ def decodeBaseMesh(client, obj, data, index):

for pos_idx in range(position_count):
co, index = common.decodeVector3(data, index)
vert = bm.verts.new(co)
bm.verts.new(co)

bm.verts.ensure_lookup_table()

Expand Down
3 changes: 2 additions & 1 deletion blender_client/object_.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from ..broadcaster import common
from ..broadcaster.client import Client
from ..shareData import shareData
import logging
import bpy

logger = logging.getLogger(__name__)


def sendObjectVisibility(client: "ClientBlender", object_: bpy.types.Object):
def sendObjectVisibility(client: Client, object_: bpy.types.Object):
logger.debug("sendObjectVisibility %s", object_.name_full)
buffer = (
common.encodeString(object_.name_full)
Expand Down
15 changes: 8 additions & 7 deletions blender_client/scene.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from ..broadcaster import common
from ..broadcaster.client import Client
from ..shareData import shareData
import logging
import bpy

logger = logging.getLogger(__name__)


def sendScene(client: "ClientBlender", scene_name: str):
def sendScene(client: Client, scene_name: str):
logger.debug("sendScene %s", scene_name)
buffer = common.encodeString(scene_name)
client.addCommand(common.Command(common.MessageType.SCENE, buffer, 0))
Expand Down Expand Up @@ -38,7 +39,7 @@ def buildScene(data):
bpy.ops.scene.delete(ctx)


def sendSceneRemoved(client: "ClientBlender", scene_name: str):
def sendSceneRemoved(client: Client, scene_name: str):
logger.debug("sendSceneRemoved %s", scene_name)
buffer = common.encodeString(scene_name)
client.addCommand(common.Command(common.MessageType.SCENE_REMOVED, buffer, 0))
Expand All @@ -56,7 +57,7 @@ def buildSceneRemoved(data):
bpy.ops.scene.delete(ctx)


def sendAddCollectionToScene(client: "ClientBlender", scene_name: str, collection_name: str):
def sendAddCollectionToScene(client: Client, scene_name: str, collection_name: str):
logger.debug("sendAddCollectionToScene %s <- %s", scene_name, collection_name)

buffer = common.encodeString(scene_name) + common.encodeString(collection_name)
Expand All @@ -73,7 +74,7 @@ def buildCollectionToScene(data):
scene.collection.children.link(collection)


def sendRemoveCollectionFromScene(client: "ClientBlender", scene_name: str, collection_name: str):
def sendRemoveCollectionFromScene(client: Client, scene_name: str, collection_name: str):
logger.debug("sendRemoveCollectionFromScene %s <- %s", scene_name, collection_name)

buffer = common.encodeString(scene_name) + common.encodeString(collection_name)
Expand All @@ -89,13 +90,13 @@ def buildRemoveCollectionFromScene(data):
scene.collection.children.unlink(collection)


def sendAddObjectToVRtist(client: "ClientBlender", sceneName: str, objName: str):
def sendAddObjectToVRtist(client: Client, sceneName: str, objName: str):
logger.debug("sendAddObjectToVRtist %s <- %s", sceneName, objName)
buffer = common.encodeString(sceneName) + common.encodeString(objName)
client.addCommand(common.Command(common.MessageType.ADD_OBJECT_TO_VRTIST, buffer, 0))


def sendAddObjectToScene(client: "ClientBlender", sceneName: str, objName: str):
def sendAddObjectToScene(client: Client, sceneName: str, objName: str):
logger.debug("sendAddObjectToScene %s <- %s", sceneName, objName)
buffer = common.encodeString(sceneName) + common.encodeString(objName)
client.addCommand(common.Command(common.MessageType.ADD_OBJECT_TO_SCENE, buffer, 0))
Expand All @@ -114,7 +115,7 @@ def buildAddObjectToScene(data):
scene.collection.objects.link(object_)


def sendRemoveObjectFromScene(client: "ClientBlender", scene_name: str, object_name: str):
def sendRemoveObjectFromScene(client: Client, scene_name: str, object_name: str):
logger.debug("sendRemoveObjectFromScene %s <- %s", scene_name, object_name)
buffer = common.encodeString(scene_name) + common.encodeString(object_name)
client.addCommand(common.Command(common.MessageType.REMOVE_OBJECT_FROM_SCENE, buffer, 0))
Expand Down
1 change: 0 additions & 1 deletion clientBlender.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

_STILL_ACTIVE = 259


logger = logging.getLogger(__name__)


Expand Down
1 change: 1 addition & 0 deletions data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import tempfile
from datetime import datetime
from pathlib import Path

import bpy

Expand Down
2 changes: 1 addition & 1 deletion operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def reparentObjects():

def createVRtistObjects():
"""
VRtist will filter the received messages and handle only the objects that belong to the
VRtist will filter the received messages and handle only the objects that belong to the
same scene as the one initially synchronized
"""
changed = False
Expand Down
9 changes: 4 additions & 5 deletions stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import logging
import copy
import tempfile
from datetime import datetime
from pathlib import Path
import functools

Expand All @@ -15,8 +14,8 @@ class StatsTimer:
def __init__(self, share_data, key, log=None):
assert share_data.current_statistics

if log == None:
if share_data.current_stats_timer == None:
if log is None:
if share_data.current_stats_timer is None:
log = False
else:
log = share_data.current_stats_timer.log
Expand All @@ -29,9 +28,9 @@ def __init__(self, share_data, key, log=None):

if log:
logger.debug(key)
if not "children" in parent_stats_dict:
if "children" not in parent_stats_dict:
parent_stats_dict["children"] = {}
if not key in parent_stats_dict["children"]:
if key not in parent_stats_dict["children"]:
parent_stats_dict["children"][key] = {"time": 0, "max_time": 0, "hit_count": 0}
self.key = key
self.stats_dict = parent_stats_dict["children"][key]
Expand Down
8 changes: 3 additions & 5 deletions tests/grabber.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import sys # nopep8
from pathlib import Path # nopep8
import sys # noqa
from pathlib import Path # noqa

sys.path.append(str(Path(__package__).parent)) # nopep8
sys.path.append(str(Path(__package__).parent)) # noqa

from broadcaster.common import MessageType
from broadcaster.common import Command
from broadcaster.common import readMessage
from broadcaster.common import ClientDisconnectedException
from broadcaster.client import Client
from typing import Mapping, List
import threading
import time


Expand Down
4 changes: 1 addition & 3 deletions tests/test_collection.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import unittest
import testcase
from pathlib import Path
import blender_lib as bl
import logging


Expand Down Expand Up @@ -117,13 +116,12 @@ def test_create_instance_in_collection_after_join(self):
@unittest.skip("Timing problem")
def test_create_instance_in_collection_before_join(self):
"""
This test causes an exception in the second connection in the receiver sharedData.current_statistics
This test causes an exception in the second connection in the receiver sharedData.current_statistics
is not initialized.
"""

# if collection instances are create before join we need to ensure that
# the collection is received before the instance
import time

self._sender.disconnect_dccsync()
self._receiver.disconnect_dccsync()
Expand Down
7 changes: 3 additions & 4 deletions tests/test_scene.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import sys # nopep8
from pathlib import Path # nopep8
import sys # noqa
from pathlib import Path # noqa

sys.path.append(str(Path(__package__).parent)) # nopep8
sys.path.append(str(Path(__package__).parent)) # noqa
from broadcaster.common import MessageType

import unittest
import testcase
from pathlib import Path
import blender_lib as bl


class SceneTestCase(testcase.BlenderTestCase):
Expand Down
10 changes: 4 additions & 6 deletions tests/testcase.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import functools
import hashlib
import logging
from pathlib import Path
Expand All @@ -13,14 +12,13 @@
from grabber import CommandStream
from process import BlenderServer

import sys # nopep8
import sys # noqa

sys.path.append(str(Path(__package__).parent)) # nopep8
sys.path.append(str(Path(__package__).parent)) # noqa
from broadcaster.common import MessageType

logging.basicConfig(stream=sys.stderr, level=logging.INFO)
logger = logging.getLogger(__name__)
# logger.setLevel(logging.INFO)


class Blender:
Expand Down Expand Up @@ -200,8 +198,8 @@ def assertSameFiles(self):
with Path(tempfile.mkdtemp()) as tmp_dir:
sender_file = tmp_dir / "sender"
receiver_file = tmp_dir / "receiver"
self._sender.send_function(blender_lib.save, str(sender_file))
self._receiver.send_function(blender_lib.save, str(receiver_file))
self._sender.send_function(bl.save, str(sender_file))
self._receiver.send_function(bl.save, str(receiver_file))
self._sender.quit()
self._receiver.quit()
self.assertUserSuccess()
Expand Down
2 changes: 1 addition & 1 deletion ui.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import bpy
from . import operators
from .data import get_dcc_sync_props, DCCSyncProperties
from .data import get_dcc_sync_props
from .shareData import shareData

import logging
Expand Down

0 comments on commit e887da1

Please sign in to comment.