select <requires> platform dependent
#1
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
Reply
#2
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...
Reply
#3
(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?
Reply
#4
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
Reply
#5
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?
Reply
#6
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.
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
#7
(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
Reply
#8
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?
Reply
#9
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?
Reply
#10
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
Reply
#11
(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
Reply

Logout Mark Read Team Forum Stats Members Help
select <requires> platform dependent0