romanvm / kodi.six

20 stars 9 forks source link

Best Practice for referencing the script.module.kodi-six library #9

Open garycnew opened 7 months ago

garycnew commented 7 months ago

Roman,

I am running into issues referencing the script.module.kodi-six library and wondering what is the best practice for referencing it?

It doesn't seem to matter whether I reference it within the PYTHONPATH or sys.path. It still runs into issues.

export PYTHONPATH=/Kodi/addons/script.module.kodi-six/libs:/Kodi/addons/script.module.kodi-six/libs/kodi_six

OR

import sys sys.path.append("/Kodi/addons/script.module.kodi-six/libs") sys.path.append("/Kodi/addons/script.module.kodi-six/libs/kodi_six") print(sys.path)

Kodi/addons/script.module.kodi-six/libs/kodi_six/xbmc.py", line 10, in from .utils import PY2 as _PY2, ModuleWrapper as _ModuleWrapper ImportError: attempted relative import with no known parent package

It seems to get further, if I more explicitly define the .util module as kodi_six.util.

cd Kodi/addons/script.module.kodi-six/libs/kodi_six/

sed "s/.utils/kodi_six.utils/g" xbmc*.py | grep "utils" from kodi_six.utils import PY2 as _PY2, ModuleWrapper as _ModuleWrapper from kodi_six.utils import PY2 as _PY2, ModuleWrapper as _ModuleWrapper from kodi_six.utils import PY2 as _PY2, ModuleWrapper as _ModuleWrapper from kodi_six.utils import PY2 as _PY2, ModuleWrapper as _ModuleWrapper from kodi_six.utils import PY2 as _PY2, ModuleWrapper as _ModuleWrapper from kodi_six.utils import PY2 as _PY2, ModuleWrapper as _ModuleWrapper

sed -i.orig "s/.utils/kodi_six.utils/g" xbmc*.py

However, I still run into issues further down the line.

Kodi/addons/plugin.video.scrubsv2/resources/lib/modules/control.py", line 28, in addon = xbmcaddon.Addon AttributeError: module 'kodi_six.xbmcaddon' has no attribute 'Addon'

Do you have any guidance on the best practice for referencing the script.module.kodi-six library?

Thank You.

Gary

romanvm commented 7 months ago

I don't understand what you are trying to achieve. If you want to use the library in your addon inside Kodi then you need to add it to addon.xml as a dependency. If you want to use it in your development environment, then you can install it into your virtual environment with pip install git+https://github.com/romanvm/kodi.six.git command. The repo does have setup.py file for regular installation.

garycnew commented 7 months ago

I'm attempting to fix a broken Scrubs python script within my existing kodi installation. Initially, the python script I am working on couldn't find the referenced modules, but I found it was because they weren't in the PYTHONPATH or sys.path. However, even after adding the script.modules.kodi-six library to the PYTHONPATH or sys.path, it continues to have the issues that I referenced in the original post; while, the non-kodi-six libraries work without issue.

romanvm commented 7 months ago

Still don't understand what you are talking about. Normally, you don't need to manipulate sys.path for addon dependencies. They are added automatically if correctly referenced in addon.xml. An example is in the project's Readme. There is no other "secret" way to use the library in your addon.

romanvm commented 7 months ago

In any case this library is no longer relevant. Current Kodi versions use Python 3 runtime for addons and you should use idiomatic Python 3 for your addons. As for a specific Python version, 3.8 is a safe bet for all platforms.

garycnew commented 7 months ago

Still don't understand what you are talking about. Normally, you don't need to manipulate sys.path for addon dependencies. They are added automatically if correctly referenced in addon.xml. An example is in the project's Readme. There is no other "secret" way to use the library in your addon.

@romanvm Scrubs v2 is an older add-on developed by @jewbmx that still incorporates script.module.kodi-six.

It is referenced correctly in plugin.video.scrubsv2/addon.xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

I'm simply trying to fix one of the components of Scrubs v2 and test it at the command-line. $ python3 fmovies_vision.py Which is where I run into various module "ModuleNotFoundError" errors, etc. Thank you for your time and assistance. Respectfully, Gary
romanvm commented 7 months ago

You shoul have mentioned from the start that you are trying to run this outside Kodi. For a development environment you should creare a proper Python virtual environment and then install this library with pip install git+https://github.com/romanvm/kodi.six.git command. However it will work only for development purposes, e.g. code completion in your IDE and such. This library is a wrapper for Kodi Python API that does not exist ouside Kodi, so your script will not work anyway. You can run only those parts of your addon that do not interact with Kodi Python API.