Kodi Community Forum
Compiling and packaging cross platform pyc/pyo in addon instead of py - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+--- Thread: Compiling and packaging cross platform pyc/pyo in addon instead of py (/showthread.php?tid=181065)



Compiling and packaging cross platform pyc/pyo in addon instead of py - xbmc007 - 2013-12-23

Was wondering if there were any best practices around creating and packaging compiled versions of a python library as part of an addon in a way thats platform independent? e.g. to protect the addon code from being manipulated by end users, is it possible to package only the compiled version of a library w/o the code

I did a small test by including a py file containing a bunch of methods within an addon dir and it seems:
-on OSX it generates a .pyc file. Now if I remove the original py file, the addon still works
-on windows it generates a pyo file. Now if I remove the original py file, the addon still works
-now if I try copying the addon to linux with only the pyc file from above (ie without the py code), it complains "ImportError: Bad magic number in ...pyc" which implies a mismatch in python version

It seems like on each platform it needs the original py for the very first time so I tried a hack where I package the py file and then in the code, on startup, just delete the py file which seems to work on subsequent launches but I'm hoping there is a better way to solve this

Code:
__addon__ = xbmcaddon.Addon(id='plugin.video.someplugin')
os.remove(os.path.join(__addon__.getAddonInfo( 'path' ), 'somelibraryname.py' ))

Disclaimer: This is not for anything that will be packaged in official repo but for personal repo


RE: Compiling and packaging cross platform pyc/pyo in addon instead of py - Hedda - 2013-12-23

(2013-12-23, 05:13)xbmc007 Wrote: Disclaimer: This is not for anything that will be packaged in official repo but for personal repo
Looks like you are already aware why it will not make it into official repo http://wiki.xbmc.org/index.php?title=Add-on_rules


RE: Compiling and packaging cross platform pyc/pyo in addon instead of py - takoi - 2013-12-23

Those are byte code so yes it's cross platform but not cross version. Python version in xbmc can be different for each system so it won't even be portable on the same platform. Best practice? Don't. I have no idea what you're trying to achieve here..


RE: Compiling and packaging cross platform pyc/pyo in addon instead of py - Martijn - 2013-12-23

(2013-12-23, 16:01)Hedda Wrote:
(2013-12-23, 05:13)xbmc007 Wrote: Disclaimer: This is not for anything that will be packaged in official repo but for personal repo
Looks like you are already aware why it will not make it into official repo http://wiki.xbmc.org/index.php?title=Add-on_rules

and it is very bad to even use such a way as you will only get complaining users


RE: Compiling and packaging cross platform pyc/pyo in addon instead of py - davilla - 2013-12-23

obfuscation is what he's trying to do. if you want that, look elsewhere.


RE: Compiling and packaging cross platform pyc/pyo in addon instead of py - xbmc007 - 2013-12-25

Thanks for the replies. I had stumbled across this old post which is why I thought someone might have tried this out in the past
http://forum.xbmc.org/showthread.php?tid=25102&pid=127225#pid127225


RE: Compiling and packaging cross platform pyc/pyo in addon instead of py - Dipti - 2014-05-08

I have a same issue,

I am working on windows .
Please, tell me how to use pyo file of addon's for windows.
If I am removing original py file, addon is not working still there is present pyo files.
Please, guide me what will be process of removing py file and execute pyo file.

Thanks