Declaring Linux Dependent Dependencies in setup.py

I have a package (Skype4Py) that has different dependencies based on the operating system. This is because it uses the operating system's messaging bus to bind to Skype.

What is the correct way to declare operating system dependent dependencies in Python packages (namely setup.py)?

https://github.com/ProgVal/skype4py/commit/06aff9202e5fa8ad90a7bacc6ee1882ce10663dd#commitcomment-7377819

+3


source to share


1 answer


Expanding a bit on what I originally left as a comment, what the answer suggested was reasonable. I don't think there are clear instructions on what to do, but actually one of the highlights of the file setup.py

is picking the correct dependencies for the agent running the script installation, then installing the package correctly in the correct order, and usually it will only run once and it will forget it until it is reinstalled. That said, it would be wise to make this neat, so here's what I'll do.

If your package only needs an additional set of dependencies on the systems posix

, I would declare something like this at the top of the filesetup.py

system_spec_requires = {
    'posix': ['dbus', 'gobjects',],
    # ... if others are needed
}

      

Then declare any hard requirements like this:

requires = [
    # just random examples
    'requests',
    'requests-oauthlib',
    # ... and more
]

      



Then create a complete list of requirements by adding system to this

import os  # assuming you haven't already done that
requires.extend(system_spec_requires.get(os.name, []))

      

Finally, in the relevant section of the call setup

to setup.py

:

setup(
    ...
    requires=requires,
    ...
)

      

The dictionary system_spec_requires

at the top makes it look like a manifestation of some specific system requirement, I mean it looks as clear as possible. In fact, I've seen the nastier files setup.py

, but if it does the job correctly (i.e. installs the package with its dependencies) (and especially hasn't messed up my system in malicious ways, but you can probably notice that eval

on the line ending with .decode('base64')

where- then ... right?) I wouldn't care how bad it looks.

+2


source







All Articles