Setuptools platform specific dependencies

前端 未结 4 1102
悲哀的现实
悲哀的现实 2021-02-08 03:40

Is there any way to tell setuptools or distribute to require a package on a specific platform?

In my specific case, I\'m using readline, which comes as par

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-08 04:31

    While the answer given by Martijn Pieters was totally valid at the time, Python packaging has changed a lot since then.

    The preferred format to distribute packages is using wheels*. Using wheels it is not possible to run Python code during installation.

    Wheel use metadata version two as specified in PEP 0427. Environment markers can be used to specify platform specific dependencies.

    Setuptools allows to specify these environment markers as extras_require keys. The following example script depends on pyreadline for Windows systems and on pyxdg for Linux distributions.

    #!/usr/bin/env python
    from setuptools import setup
    
    setup(
        name='spam',
        version='0.0.1',
        extras_require={
            ':sys_platform == "win32"': [
                'pyreadline'
            ],
            ':"linux" in sys_platform': [
                'pyxdg'
            ]
        })
    

    *Also release an sdist, so platforms which can't use wheel can still install your package.

提交回复
热议问题