How to build/generate .pyo files for addon
#1
In root directory of my addon I see only the My_very_big_addon.py file of my addon (among other files).

In the \resources\lib directory I get after each run also .pyo files of .py files that live there.

How can I generate a My_very_big_addon.pyo file in the root dir?

Reason I ask this is that I have a very big addon that takes 8 seconds to start. Precompiling the addon (at install) would hopefully lower that time.
Add-on : Bluray iso utils Rewrite of BR_iso_enhancements
Add-on : BR_iso_Enhancements Give theatrical & directors cut from the same bluray iso each their own library entry, use bluray iso's of tv shows as if they are already ripped.
Reply
#2
Create a very small service.py and move most of the code to another file.
Precompile is not recommended
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#3
(2017-07-02, 09:20)Martijn Wrote: Create a very small service.py and move most of the code to another file.

That could work. Thanks!

(2017-07-02, 09:20)Martijn Wrote: Precompile is not recommended

Precompile would offcourse need to be done on install, because intel/windows precompile isn't compatible with ARM/android precompile.

But other than that, why isn't it recommend?
Add-on : Bluray iso utils Rewrite of BR_iso_enhancements
Add-on : BR_iso_Enhancements Give theatrical & directors cut from the same bluray iso each their own library entry, use bluray iso's of tv shows as if they are already ripped.
Reply
#4
Normally, you don't need to mess with bytecode .pyc/.pyo files. But, as it was said above, If you want to speed up launching your addon, you may move most of your logic into imported modules. However, I doubt that speed gain will be significant, because compiling to bytecode is done very fast.

Quote:Precompile would offcourse need to be done on install, because intel/windows precompile isn't compatible with ARM/android precompile.

As to my knowledge, Python bytecode is not platform dependent.
Reply
#5
(2017-07-02, 18:33)Roman_V_M Wrote: As to my knowledge, Python bytecode is not platform dependent.
You can't share them on similar platforms if you spread your code across multiple files. Every import you make results in an absolute path in your bytecode. If the path of the imported module differs (because of the user name, userdir path, ...), the import would fail.

Bytecode may be incompatible across different versions of python - Kodi updates could break the add-on.

I think that a short waiting time is ok for the first run of the add-on. Ideally, this would be done at install time (but this is just a minor nitpick).
Reply
#6
IMO I'd take the long compile time as a sign to compartmentalize your code into modules. Forcing compiling seems like the wrong solution?

Sent from my SM-G935T
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#7
event though it is not recommmended, as mentioned above
and this is not gonna help much to solve your problem afaik,

for the sake of discussion, you can use compile module to generate bytecodes.

https://docs.python.org/2/library/compileall.html

you have to launch your compiling python intepreter with -o flag to create "optimized" outputs.

be aware, bytecode is version dependant.
Reply
#8
@membrane

Quote:You can't share them on similar platforms if you spread your code across multiple files. Every import you make results in an absolute path in your bytecode. If the path of the imported module differs (because of the user name, userdir path, ...), the import would fail.

Yes, totally forgot about that.

@boogiepop

Quote:for the sake of discussion, you can use compile module to generate bytecodes.

Yes, in case of a separate interpreter executable it is possible, but you cannot control how a Python script is launched from Kodi.

Quote:be aware, bytecode is version dependant.

IIRC, bytecode is compatible only between minor versions.
Reply
#9
Thanks all

I'll see if I can compartmentalize the addon.

Maybe it does/doesn't make a difference, I'll see...
Add-on : Bluray iso utils Rewrite of BR_iso_enhancements
Add-on : BR_iso_Enhancements Give theatrical & directors cut from the same bluray iso each their own library entry, use bluray iso's of tv shows as if they are already ripped.
Reply

Logout Mark Read Team Forum Stats Members Help
How to build/generate .pyo files for addon0