textension icon indicating copy to clipboard operation
textension copied to clipboard

Missing plugins directory on linux OS

Open solumath opened this issue 1 year ago • 2 comments

I tried installing the Textension addon on ubuntu 22.04 Blender version 3.6.4 run from source

I notice that you are using os.path.join() which is incompatible with Linux directory paths which then raises error that there is no plugins directory.

I would suggest using pathlib which can handle both linux and windows directories. Because it's used everywhere in your code it's unusable on linux and throws multiple error paths. I would really appreciate compatibility with linux path system.

My suggestion for the get plugins would be:

def get_plugins_dict() -> dict:
    """Return a list of plugin submodules that can be enabled."""
    plugins_path = Path(textension.__path__[0]) / 'plugins'  # Use Path to handle file paths

    if not plugins_path.is_dir():
        print("Textension: missing 'plugins' directory.")
        return
    plugins = {}
    py_path = f"{__package__}.plugins"
    for info in pkgutil.iter_modules([str(plugins_path)]):  # Convert Path to string
        m = __import__(f"{py_path}.{info.name}", fromlist=(info.name,))
        if hasattr(m, "enable") and hasattr(m, "disable"):
            plugins[info.name] = m
    return plugins

Error that initiated this bug hunt.

Read prefs: "/home/solumath/.config/blender/3.6/config/userpref.blend"
Textension: missing 'plugins' directory.
Traceback (most recent call last):
  File "/home/solumath/.config/blender/3.6/scripts/addons/textension/utils.py", line 358, in wrapper
    ret = func(*args, **kw)
  File "/home/solumath/.config/blender/3.6/scripts/addons/textension/__init__.py", line 33, in register
    prefs.init()
  File "/home/solumath/.config/blender/3.6/scripts/addons/textension/prefs.py", line 13, in init
    _init_plugins()
  File "/home/solumath/.config/blender/3.6/scripts/addons/textension/prefs.py", line 58, in _init_plugins
    for name, module in plugins_dict.items():
AttributeError: 'NoneType' object has no attribute 'items'
Exception in module register(): /home/solumath/.config/blender/3.6/scripts/addons/textension/__init__.py
Traceback (most recent call last):
  File "/home/solumath/FIT2/BP/blender-3.6.4-linux-x64/3.6/scripts/modules/addon_utils.py", line 369, in enable
    mod.register()
  File "/home/solumath/.config/blender/3.6/scripts/addons/textension/utils.py", line 358, in wrapper
    ret = func(*args, **kw)
  File "/home/solumath/.config/blender/3.6/scripts/addons/textension/__init__.py", line 33, in register
    prefs.init()
  File "/home/solumath/.config/blender/3.6/scripts/addons/textension/prefs.py", line 13, in init
    _init_plugins()
  File "/home/solumath/.config/blender/3.6/scripts/addons/textension/prefs.py", line 58, in _init_plugins
    for name, module in plugins_dict.items():
AttributeError: 'NoneType' object has no attribute 'items'

solumath avatar Oct 15 '23 18:10 solumath

Appreciate the code! I do indeed use a lot of os.path. For performance reasons, Path objects are not ideal to use everywhere in the addon, but I'll get a copy of ubuntu and work my way through things.

K-410 avatar Oct 15 '23 18:10 K-410

then I would say try to remove "\" in code? just os.path.join(a, b) Thank you anyway for your quick reesponse!

solumath avatar Oct 15 '23 19:10 solumath