Kodi Community Forum
select <requires> platform dependent - 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: select <requires> platform dependent (/showthread.php?tid=162949)



select <requires> platform dependent - lorus11 - 2013-04-21

Hi,

I'm actually on an addon that requires lxml, so I made a second binary addon for it, that I have included in my original addon with <requires> ... now I want to support multiple platforms and wondering how I could select the <requires> dependent on the platform it is running.


cheerz,

lorus


RE: select <requires> platform dependent - amet - 2013-04-21

depend on script.lxml and import it from different binaries depending on teh platform

in script.lxml you have lxml_win, lxml_linux ...

and in xbmc addon you import

Code:
if win:
  import lxml_win as lxml
else if linux:
  import lxml_linux as lxml

you get the idea...


RE: select <requires> platform dependent - lorus11 - 2013-04-21

(2013-04-21, 13:45)amet Wrote: depend on script.lxml and import it from different binaries depending on teh platform

in script.lxml you have lxml_win, lxml_linux ...

and in xbmc addon you import

Code:
if win:
  import lxml_win as lxml
else if linux:
  import lxml_linux as lxml

you get the idea...

But this gives me a very huge all-in-one script.xml then right?

My idea was to split it in one lxml per platform ... so any ideas of doing it in this way?


RE: select <requires> platform dependent - amet - 2013-04-21

no, it will give you a separate lxml addon that you include in your addon, there is no other way that I can think of


RE: select <requires> platform dependent - lorus11 - 2013-04-21

But how would I import submodules with your solution then?
I renamed lxml to lxml_win and tried:

Code:
import lxml_win as lxml
import lxml_win.html as html

but that gives me:
Code:
Traceback (most recent call last):
  File "test.py", line 9, in <module>
    import lxml_win.html as html
  File "C:\Users\Lorus\Documents\python\lxml_win\html\__init__.py", line 42, in <module
    from lxml import etree
ImportError: No module named lxml

So do I also have to rename all imports inside the module? That would mean that this will only work if I rebuild the module from sources ... right?


RE: select <requires> platform dependent - Martijn - 2013-04-21

as an advance warning if you were perhaps thinking of adding it to xbmc repo. we don't allow binary files in our repo so you will have to provide it by yourself.


RE: select <requires> platform dependent - lorus11 - 2013-04-21

(2013-04-21, 18:34)Martijn Wrote: as an advance warning if you were perhaps thinking of adding it to xbmc repo. we don't allow binary files in our repo so you will have to provide it by yourself.

I know and I already have my own repo for that, but still looking for a proper solution around this problem Wink


RE: select <requires> platform dependent - amet - 2013-04-21

I cant say, its standard python... its clear what the issue is you just need to address all the errors you have

from lxml import etree -> from lxml_win import etree maybe?


RE: select <requires> platform dependent - lorus11 - 2013-04-21

that is what I asked, but if I rename lxml to lxml_win everywhere it finally ends up with erros from the binary files ... so I guess this isn't doable without rebuilding the whole module from sources, right?


RE: select <requires> platform dependent - Bstrdsmkr - 2013-04-22

If you renamed it, you'll have to perform a little magic:
Code:
import sys
sys.modules['lxml'] = __import__('lxml_win')
Then everything should be able to reference lxml.parse and etc as normal. Back to your original question though, no you'll have to include all versions in your required dependency and just import the one you need. You're other option is to make each version available in the repo:
script.module.lxml.win
script.module.lxml.mac
and etc, NOT list any of them as a dependency, then download them at run time. That's pretty dirty though


RE: select <requires> platform dependent - lorus11 - 2013-04-24

(2013-04-22, 00:01)Bstrdsmkr Wrote: If you renamed it, you'll have to perform a little magic:
Code:
import sys
sys.modules['lxml'] = __import__('lxml_win')

That does the trick, thanks Smile