Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Blender 4.2 extension loading bug #67

Merged
merged 4 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/addons/send2ue/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
bl_info = {
"name": "Send to Unreal",
"author": "Epic Games Inc (now a community fork)",
"version": (2, 4, 8),
"version": (2, 4, 9),
"blender": (3, 6, 0),
"location": "Header > Pipeline > Send to Unreal",
"description": "Sends an asset to the first open Unreal Editor instance on your machine.",
Expand Down
2 changes: 1 addition & 1 deletion src/addons/send2ue/blender_manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ schema_version = "1.0.0"
id = "send2ue"
name = "Send to Unreal"
tagline = "Send assets directly to an open Unreal Editor on your machine"
version = "2.4.8"
version = "2.4.9"
type = "add-on"
tags = [ "Pipeline" ]
blender_version_min = "4.2.0"
Expand Down
24 changes: 10 additions & 14 deletions src/addons/send2ue/core/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import bpy
import sys
import ast
import importlib.util
import tempfile
from . import settings
from abc import abstractmethod
from ..constants import ToolInfo, Extensions, ExtensionTasks
from . import utilities
from .. import __package__ as base_package
from pathlib import Path
from importlib.machinery import SourceFileLoader
from importlib.util import module_from_spec, spec_from_loader


def run_extension_filters(armature_objects, mesh_objects, hair_objects):
Expand Down Expand Up @@ -266,9 +267,9 @@ def __init__(self, file_path):
super(ExtensionCollector, self).__init__()

# Todo: Remove this when extensions don't need base classes
addons_folder = str(Path(__file__).parent.parent.parent)
if addons_folder not in sys.path:
sys.path.insert(0, addons_folder)
addons_folder = Path(__file__).parent.parent.parent
if addons_folder not in [Path(i) for i in sys.path]:
sys.path.insert(0, str(addons_folder))

self._extension_module = self.get_module(file_path)
self._extension_classes = []
Expand All @@ -282,15 +283,10 @@ def get_module(file_path):
"""
Gets the module from the file path.
"""
path = os.path.dirname(file_path)
name, file_extension = os.path.splitext(os.path.basename(file_path))
if path not in sys.path:
sys.path.insert(0, path)
module = importlib.import_module(name)
importlib.reload(module)

# remove to prevent root module naming conflicts
sys.path.remove(path)
name = f'send2ue_extension_{Path(file_path).name}'
spec = spec_from_loader(name, SourceFileLoader(name, str(file_path)))
module = module_from_spec(spec) # type: ignore
spec.loader.exec_module(module) # type: ignore
return module

def get_extension_classes(self):
Expand All @@ -307,7 +303,7 @@ def visit_ClassDef(self, node):
"""
extension_class = getattr(self._extension_module, node.name)

if issubclass(extension_class, ExtensionBase):
if ExtensionBase.__name__ in [i.__name__ for i in extension_class.__bases__]:
self._extension_classes.append(extension_class)


Expand Down
3 changes: 1 addition & 2 deletions src/addons/send2ue/dependencies/rpc/validations.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ def get_source_file_path(function):
:param callable function: A callable.
:return str: A file path.
"""
client_module = inspect.getmodule(function)
return client_module.__file__
return inspect.getsourcefile(function)


def get_line_link(function):
Expand Down
Loading