Reputation: 83438
I have a package (Skype4Py) which has different dependencies based on the operating system. This is because it relies on the operating system messaging bus to bind itself to Skype.
What is the proper way to declare operating system specific dependencies in Python packages (namely, setup.py)?
Upvotes: 3
Views: 319
Reputation: 18908
Expanding a bit on what I originally left as a comment, what the reply suggested was sensible. I don't think there are clear guides to what practices should this be done, but really, one of the major point of the setup.py
file is to fetch the right dependencies for the agent running that install script and then correctly installs the package in the correct manner, and typically is only going to be run once and it's forgotten until it needs to be reinstalled. That said, would make sense to make that neater, so here's what I would do.
If your package only needs an extra set of dependencies on posix
systems, I would declare something like this near the top of the setup.py
file
system_spec_requires = {
'posix': ['dbus', 'gobjects',],
# ... if others are needed
}
Then declare any hard requirements like so:
requires = [
# just random examples
'requests',
'requests-oauthlib',
# ... and more
]
Then build the full list of requirements by appending the system specific ones to that
import os # assuming you haven't already done that
requires.extend(system_spec_requires.get(os.name, []))
Finally, in the appropriate section in the setup
call in setup.py
:
setup(
...
requires=requires,
...
)
The system_spec_requires
dictionary at the top make it looks like a manifest of system specific requirements of some kind, I mean it looks as clearly stated as possible. Really though, I've seen nastier setup.py
files out but if it does the job (i.e. install the package with its dependencies) correctly (and especially not mess up my system in malicious ways, but you can probably spot that eval
on a string ending with .decode('base64')
somewhere... right?) I couldn't really care less how bad it looks.
Upvotes: 2