Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to express a platform-specific dependency in setup.py without building platform-specific versions of my egg?

We have a placeholder egg that contains no code and only exists for the sake of pulling down a list of dependent packages from our PyPi repository.

Most of these dependent packages are platform-agnostic, however some are only used on Win32 platforms.

Is it possible to somehow make the dependency platform-conditional, so that a given dependency in my install_requires list will only get pulled down when installing on Win32?

Alternatively: Is it possible to specify a list of optional dependencies, that will be installed if available, but will not cause easy_install to fail if they are not?

like image 439
Daniel Fortunov Avatar asked Jun 24 '11 14:06

Daniel Fortunov


People also ask

Does pip install use setup py?

@joeforker, pip uses setup.py behind the scenes.

What is Package_data in setup py?

package_data. By default, include_package_data considers all non .py files found inside the package directory ( src/mypkg in this case) as data files, and includes those that satisfy (at least) one of the above two conditions into the source distribution, and consequently in the installation of your package.

What does setup py build do?

The setup.py is a Python script typically included with Python-written libraries or apps. Its objective is to ensure that the program is installed correctly. With the aid of pip , we can use the setup.py to install any module without having to call setup.py directly. The setup.py is a standard Python file.

What is install_requires in setup py?

install_requires is a section within the setup.py file in which you need to input a list of the minimum dependencies needed for a project to run correctly on the target operating system (such as ubuntu). When pip runs setup.py, it will install all of the dependencies listed in install_requires.


2 Answers

For sdist, egg and wheel release from : https://setuptools.readthedocs.io/en/latest/userguide/dependency_management.html#platform-specific-dependencies

Sometimes a project might require a dependency to run on a specific platform. This could to a package that back ports a module so that it can be used in older python versions. Or it could be a package that is required to run on a specific operating system. This will allow a project to work on multiple different platforms without installing dependencies that are not required for a platform that is installing the project.

setup(     name="Project",     ...     install_requires=[         'enum34 ; python_version<"3.4"',         'pywin32 >= 1.0 ; platform_system=="Windows"'     ] ) 
like image 74
wtayyeb Avatar answered Sep 28 '22 22:09

wtayyeb


In setup.py:

from setuptools import setup import sys  setup(     name="...",     install_requires=["This", "That"] + (         ["WinOnly", "AnotherWinOnly"] if sys.platform.startswith("win") else []         ) ) 

distutils.util.get_platform has more information than sys.platform if you need it:

>>> sys.platform 'linux2' >>> distutils.util.get_platform() 'linux-i686' 
like image 41
codeape Avatar answered Sep 28 '22 22:09

codeape