Skip to content

Commit

Permalink
fixed circular import
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-Morgan committed Jul 6, 2023
1 parent 70ee09b commit ee1715f
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 58 deletions.
29 changes: 0 additions & 29 deletions bpy_speckle/convert/__init__.py
Original file line number Diff line number Diff line change
@@ -1,29 +0,0 @@
from typing import Union
from bpy_speckle.convert.to_native import convert_to_native
from specklepy.objects.base import Base

def get_speckle_subobjects(attr: Union[dict, Base], scale: float, name: str) -> list:
subobjects = []
keys = attr.keys() if isinstance(attr, dict) else attr.get_dynamic_member_names()
for key in keys:
if isinstance(attr[key], dict):
subtype = attr[key].get("type", None)
if subtype:
name = f"{name}.{key}"
subobject = convert_to_native(attr[key], name)

subobjects.append(subobject)
props = attr[key].get("properties", None)
if props:
subobjects.extend(get_speckle_subobjects(props, scale, name))
elif hasattr(attr[key], "type"):
subtype = attr[key].type
if subtype:
name = "{}.{}".format(name, key)
subobject = convert_to_native(attr[key], name)

subobjects.append(subobject)
props = attr[key].get("properties", None)
if props:
subobjects.extend(get_speckle_subobjects(props, scale, name))
return subobjects
4 changes: 2 additions & 2 deletions bpy_speckle/convert/to_native.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import math
from typing import Any, Dict, Iterable, List, Optional, Tuple, Union, Collection, cast
from typing import Any, Dict, Iterable, List, Optional, Union, Collection, cast
from bpy_speckle.convert.constants import DISPLAY_VALUE_PROPERTY_ALIASES, ELEMENTS_PROPERTY_ALIASES, OBJECT_NAME_MAX_LENGTH, OBJECT_NAME_SEPERATOR, SPECKLE_ID_LENGTH
from bpy_speckle.convert.to_speckle import ConversionSkippedException
from bpy_speckle.functions import get_default_traversal_func, get_scale_length, _report
from bpy_speckle.convert.util import ConversionSkippedException
from mathutils import (
Matrix as MMatrix,
Vector as MVector,
Expand Down
5 changes: 2 additions & 3 deletions bpy_speckle/convert/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import math
from typing import Any, Dict, Optional, Tuple, Union, cast
from typing import Any, Dict, Optional, Tuple, Union
from bmesh.types import BMesh
import bpy, struct, idprop

Expand All @@ -9,7 +9,6 @@
from bpy_speckle.convert.constants import IGNORED_PROPERTY_KEYS
from bpy_speckle.functions import _report
from bpy.types import Material, Object, Collection as BCollection
from mathutils import Matrix as MMatrix

from bpy_speckle.specklepy_extras.traversal import TraversalContext

Expand Down Expand Up @@ -421,7 +420,7 @@ def link_object_to_collection_nested(obj: Object, col: BCollection):
for child in obj.children: #type: ignore
link_object_to_collection_nested(child, col)

def add_to_heirarchy(converted: Union[Object, BCollection], traversalContext : TraversalContext, converted_objects: Dict[str, Union[Object, BCollection]], preserve_transform: bool) -> None:
def add_to_heirarchy(converted: Union[Object, BCollection], traversalContext : 'TraversalContext', converted_objects: Dict[str, Union[Object, BCollection]], preserve_transform: bool) -> None:
nextParent = traversalContext.parent

# Traverse up the tree to find a direct parent object, and a containing collection
Expand Down
12 changes: 2 additions & 10 deletions bpy_speckle/functions.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
from typing import Callable, Dict, Optional, Set, Union
import bpy

from bpy.types import Object, Context, Collection as BCollection
from typing import Callable
from specklepy.objects.base import Base
from specklepy.objects.other import Instance
from bpy_speckle.convert.constants import ELEMENTS_PROPERTY_ALIASES
from bpy_speckle.properties.scene import SpeckleSceneSettings

from bpy_speckle.specklepy_extras.traversal import GraphTraversal, TraversalContext, TraversalRule
from bpy_speckle.specklepy_extras.traversal import GraphTraversal, TraversalRule

"""
Speckle functions
Expand Down Expand Up @@ -79,6 +74,3 @@ def get_default_traversal_func(can_convert_to_native: Callable[[Base], bool]) ->
)

return GraphTraversal([ignore_rule, convertable_rule, default_rule])

def get_speckle(context: Context) -> 'SpeckleSceneSettings':
return context.scene.speckle #type: ignore
4 changes: 1 addition & 3 deletions bpy_speckle/operators/commit.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"""
Commit operators
"""
from typing import cast
import bpy
from bpy.props import BoolProperty
from bpy_speckle.functions import _report, get_speckle
from bpy_speckle.clients import speckle_clients
from bpy_speckle.properties.scene import SpeckleSceneSettings
from bpy_speckle.properties.scene import get_speckle


class DeleteCommit(bpy.types.Operator):
Expand Down
7 changes: 2 additions & 5 deletions bpy_speckle/operators/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Stream operators
"""
from math import radians
from typing import Any, Callable, Dict, Iterable, List, Optional, Union, cast
from typing import Callable, Dict, Optional, Union, cast
import webbrowser
import bpy
from bpy.props import (
Expand All @@ -29,11 +29,10 @@
get_default_traversal_func,
_report,
get_scale_length,
get_speckle,
)
from bpy_speckle.clients import speckle_clients
from bpy_speckle.operators.users import add_user_stream
from bpy_speckle.properties.scene import SpeckleSceneSettings, SpeckleUserObject
from bpy_speckle.properties.scene import SpeckleSceneSettings, SpeckleUserObject, get_speckle
from bpy_speckle.convert.util import ConversionSkippedException, add_to_heirarchy
from specklepy.api.models import Commit
from specklepy.api import operations, host_applications
Expand All @@ -45,8 +44,6 @@
from specklepy.logging.exceptions import SpeckleException
from specklepy.logging import metrics

from bpy_speckle.specklepy_extras.traversal import TraversalContext

ObjectCallback = Optional[Callable[[bpy.types.Context, Object, Base], Object]]
ReceiveCompleteCallback = Optional[Callable[[bpy.types.Context, Dict[str, Union[Object, Collection]]], None]]

Expand Down
4 changes: 2 additions & 2 deletions bpy_speckle/operators/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from typing import cast
import bpy
from bpy.types import Context
from bpy_speckle.functions import _report, get_speckle
from bpy_speckle.functions import _report
from bpy_speckle.clients import speckle_clients
from bpy_speckle.properties.scene import SpeckleCommitObject, SpeckleSceneSettings, SpeckleUserObject
from bpy_speckle.properties.scene import SpeckleCommitObject, SpeckleSceneSettings, SpeckleUserObject, get_speckle
from specklepy.api.client import SpeckleClient
from specklepy.api.models import Stream
from specklepy.api.credentials import get_local_accounts
Expand Down
6 changes: 4 additions & 2 deletions bpy_speckle/properties/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
PointerProperty,
)


class SpeckleSceneObject(bpy.types.PropertyGroup):
name: bpy.props.StringProperty(default="")

Expand Down Expand Up @@ -191,4 +190,7 @@ def validate_commit_selection(self) ->Tuple[SpeckleUserObject, SpeckleStreamObje
return (user, stream, branch, commit)

class SelectionException(Exception):
pass
pass

def get_speckle(context: bpy.types.Context) -> SpeckleSceneSettings:
return context.scene.speckle #type: ignore
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "Apache-2.0"

[tool.poetry.dependencies]
python = ">=3.8, <4.0.0"
specklepy = "^2.15.0"
specklepy = "^2.15.1"
attrs = "^23.1.0"

# [tool.poetry.group.local_specklepy.dependencies]
Expand Down

0 comments on commit ee1715f

Please sign in to comment.