Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional dependency with Python Wheels

I have a Python package that I would like to make into a wheel. On Python 2, the package uses the ipaddr library. On Python 3, it uses the built-in ipaddress library. For the sdist package, I check the sys.version_info in setup.py to set the requirements based on the Python version. Unfortunately, this does not seem to work with wheels. Is it possible to do a conditional dependency based on the Python version with a wheel?

like image 222
Greg Oschwald Avatar asked Oct 01 '22 22:10

Greg Oschwald


1 Answers

As of Wheel 0.24.0, this is support using extra_require. For instance

setup(
    ...,
    extras_require={':python_version=="2.6"':: ['ipaddr']},
    ...
)

This is documented in the "Defining Conditional Dependencies" of the Wheel documentation and follows PEP 426.

like image 195
Greg Oschwald Avatar answered Oct 10 '22 03:10

Greg Oschwald