Search code examples
pythonsetuptoolspython-wheel

Can I make a python package depend on different packages by OS?


I'm working on a package that requires sh. This package is not supported on Windows. For Windows, I use the old package sh was forked from, pbs, and rename it to sh in my namespace.

How can I create a setup.py that will properly install pbs on Windows and sh on other platforms?

EDIT: After some research, it turns out my question was specific to the new wheel format as my answer reflects. I'll ask a different question in the future if I can't figure out how wheels are supposed to work.


Solution

  • Ok, it turns out my original solution was correct:

    # setup.py
    ...
    setup(
    ...
    
        install_requires=["pbs" if os.name == 'nt' else "sh"]
    ...
    )
    

    The reason this recently broke was due to releasing in the new wheel format. My understanding is that this new format does not ship a setup.py with your package and handles dependencies using some other means.

    Until I understand how to ship a wheel with conditional dependencies, I just won't produce wheels for this project.