pip requirement based on available OS library version

Viewed 72

I am developing a python package based on pygit2. pygit2 depends on libgit2.

Ubuntu 18.04 has version libgit2-2.6

Ubuntu 18.10 has version libgit2-2.7

In my requirements.txt/Pipfile, if I have "pygit2" = "==0.26.4", it works in 18.04 (after doing apt-get install libgit2-dev) but not in 18.10. Similarly, depending on "*" or "==0.27" works on 18.10 but not on 18.04. I have not tried on other distros. Is there a way I can specify like,

if os has libgit2-2.6
    pygit2 == 0.26.4
else if os has libgit2-2.7
    pygit2 == 0.27.x

I tried pygit2>=0.26.4, didn't work for 18.04.

1 Answers

You can specify version specific modules by using platform module.

>>> platform.platform().split('-')[6]
'18.04'
>>>

>>> import platform
>>> if "18.04" in platform.platform():
...   print("install 18.04 modules")
... elif "18.10" in platform.platform():
...   print("Install 18.10 modules")
...
install 18.04 modules
>>>

Hope it helps.

Related