0

Hey guys i definitely getting crazy i want to force Python to handle a .pyo like a .py i got kodi xbmc forked and getting crazy

i already tried out and changed multiple lines and nothing changed? i linked them here:

const std::string ADDON_PYTHON_EXT = "*.py"; changed this line to *.pyo

return URIUtils::HasExtension(m_strPath, ".py"); changed this line to. .pyo

i thought that would be enough after compiling, still nothing happens when try to open a add-on

still python does not load .pyo files and does not handle them as .py

btw: i figured out deleting all .py files in the folder and just let the first loaded .py file there so 1 -> .py and the others are all .pyo the add-on works. but when deleting this firstly loaded .py and using this as a .pyo it fails. So what do i have to change that it always use .pyo

First UPDATE:

i tried it out, it does indeed work as a workaround Created a dummy -> include.py with just 1 line import service was enough.

But i want to fix this directly in kodi. in documentions "If there is a current pyc file, this is taken as the compiled version, so no compile step has to be taken before running the command. Otherwise the py file is read, the compiler has to compile it"

So easy said, execute .py if not available check if .pyo but i cannot find where to change / add this method i cannot find even the method right for the execution

Second Update: i added these lines in githublink to file

      //pyoextension == script
  std::string pyoextension = script;

  //Check if the file does exist
  if (!CFile::Exists(script, false))
    {
      //pyoextension append o to get -> .pyo
      pyoextension = script + "o";

      //Check if pyoextension exist -> .pyo
      //if not nothing exist throw error
      if (!CFile::Exists(pyoextension, false)){
        CLog::Log(LOGERROR, "%s - Not executing non-existing script %s", __FUNCTION__, script.c_str());
        return -1;
      }
      LanguageInvokerPtr invoker = GetLanguageInvoker(pyoextension);
      return ExecuteAsync(pyoextension, invoker, addon, arguments);
    }
  LanguageInvokerPtr invoker = GetLanguageInvoker(script);
  return ExecuteAsync(script, invoker, addon, arguments);

Checking if the the add-on does not exist as a .py file checking if the .pyo file is there, and execute that instead. But still the checking does work, but it still throws an error out that it cannot start the script

Human Khoo
  • 135
  • 3
  • 9

2 Answers2

0

Changing such line (const std::string ADDON_PYTHON_EXT = "*.py"; changed this line to *.pyo) is not a good solution

Main reason is that the kodi is configured to use .py extension to be load from addon.xml file which tradition is followed by all the addon. Changing such headers file will only result to work addon only in your custom build kodi and you have to modify all other addon along with it.

The solution I prefer most is you should follow below steps:

  • Create a function in your python script (let's call it as function named service() which execute all the necessary code from your file named service.py)
  • Now create a python file (include.py) to include it in addon.xml containing code as below:

include.py

import service
service.service()
Gahan
  • 4,075
  • 4
  • 24
  • 44
  • thank you, i updated my question. Indeed your workaround work thank you – Human Khoo Jan 07 '18 at 19:30
  • if it helps you you can upvote and accept it as answer – Gahan Jan 08 '18 at 03:30
  • already tried to, sorry got this output "Thanks for the feedback! Votes cast by those with less than 15 reputation are recorded, but do not change the publicly displayed post score." – Human Khoo Jan 09 '18 at 14:34
  • i voted it up, but still this is not the answer i wished to sorry. this is a workaround, but answers not how to accomplish my way that i want CPython check and run the .pyo file if its there. i tried now different ways but still it does not work. I updated my question – Human Khoo Jan 10 '18 at 12:55
  • so being ecsactly , i want to force CPython directly for first execute (the .py file) also execute if its not there without compiling it to byte code using the .pyc / .pyo if its already compiled – Human Khoo Jan 10 '18 at 13:24
  • As I already said if you modify C file you need to build your own kodi for each and every platform, your addon won't support any other or original kodi version. – Gahan Jan 10 '18 at 13:38
0

It might not even be worth it, Kodi is moving to python3 soon, and python3 dropped pyo files. It might use pyc then, but that's not sure right now.

Razze
  • 4,124
  • 3
  • 16
  • 23
  • kodi is moving towards python3 only in new version, also pyo and pyc is nothing but python compiled byte code. As a way i suggested it won't take any affect whether it is python3 or python2 in kodi – Gahan Jan 08 '18 at 03:32
  • not a helping answer, because i want to figure out where does python check for .pyo files that i can edit it like i wish to. Your answer is just say that its not worth lol . – Human Khoo Jan 10 '18 at 12:57
  • Right, but you might not have been aware of the python 3 port and thus your work might have gone to waste. – Razze Jan 10 '18 at 15:38