Skip to content

Commit

Permalink
small structure refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
strike-digital committed Jul 7, 2024
1 parent cd2a0ab commit f155e33
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
9 changes: 0 additions & 9 deletions pythonFiles/include/blender_vscode/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from pathlib import Path
import platform

from .utils import is_addon_legacy

python_path = Path(sys.executable)
blender_path = Path(bpy.app.binary_path)
blender_directory = blender_path.parent
Expand All @@ -20,11 +18,4 @@
scripts_folder = blender_path.parent / f"{version[0]}.{version[1]}" / "scripts"


def get_user_addon_directory(source_path: Path):
if is_addon_legacy(source_path):
return Path(bpy.utils.user_resource('SCRIPTS', path="addons"))
else:
return Path(bpy.utils.user_resource("EXTENSIONS", path="user_default"))


addon_directories = tuple(map(Path, addon_utils.paths()))
15 changes: 10 additions & 5 deletions pythonFiles/include/blender_vscode/load_addons.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from . import AddonInfo
from .communication import send_dict_as_json
from .environment import addon_directories, get_user_addon_directory
from .environment import addon_directories
from .utils import is_addon_legacy


Expand Down Expand Up @@ -36,6 +36,14 @@ def setup_addon_links(addons_to_load: list[AddonInfo]):
return path_mappings


def get_user_addon_directory(source_path: Path):
"""Return either the user scripts or user extensions directory depending on the addon type."""
if is_addon_legacy(source_path):
return Path(bpy.utils.user_resource("SCRIPTS", path="addons"))
else:
return Path(bpy.utils.user_resource("EXTENSIONS", path="user_default"))


def load(addons_to_load: list[AddonInfo]):
for addon_info in addons_to_load:
if is_addon_legacy(Path(addon_info.load_dir)):
Expand All @@ -47,8 +55,7 @@ def load(addons_to_load: list[AddonInfo]):
addon_name = "bl_ext.user_default." + addon_info.module_name

try:
# bpy.ops.preferences.addon_enable(module=addon_name)
bpy.ops.dev.update_addon(module_name=addon_name)
bpy.ops.preferences.addon_enable(module=addon_name)
except:
traceback.print_exc()
send_dict_as_json({"type": "enableFailure", "addonPath": str(addon_info.load_dir)})
Expand All @@ -60,12 +67,10 @@ def create_link_in_user_addon_directory(directory, link_path):

if sys.platform == "win32":
import _winapi

_winapi.CreateJunction(str(directory), str(link_path))
else:
os.symlink(str(directory), str(link_path), target_is_directory=True)


def is_in_any_addon_directory(module_path):
for path in addon_directories:
if path == module_path.parent:
Expand Down
3 changes: 2 additions & 1 deletion pythonFiles/launch.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import json
import os
import sys
import json
import traceback
from pathlib import Path
from typing import TYPE_CHECKING

include_dir = Path(__file__).parent / "include"
sys.path.append(str(include_dir))

# Get proper type hinting without impacting runtime
if TYPE_CHECKING:
from .include import blender_vscode
else:
Expand Down

0 comments on commit f155e33

Please sign in to comment.