2013-12-23, 05:13
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
Disclaimer: This is not for anything that will be packaged in official repo but for personal repo
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