Dependency Management: Subprocess32 Needed for Python2.7

I have a library ( subx ) that depends on subprocess32 . The subprocess32 library is backport for Python2.7 and provides a kwarg timeout.

My library needs a kwarg timeout.

I need subprocess32 only if the target platform is Python2.x.

How to determine the dependency in my project?

I get this error message if I define the dependency on subprocess32via "install_requires" (setup.py) and I ended up in a python3 virtual file:

===> pip install -e git+https://github.com/guettli/subx.git#egg=subx
Obtaining subx from git+https://github.com/guettli/subx.git#egg=subx
  Cloning https://github.com/guettli/subx.git to ./src/subx
Collecting subprocess32 (from subx)
  Using cached subprocess32-3.2.7.tar.gz
    Complete output from command python setup.py egg_info:
    This backport is for Python 2.x only.

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-lju3nl1y/subprocess32/
+6
source share
2

, afaik setuptools ( , 20.2). , , PEP 508, , .

python : subprocess32, ​​ python2.X. :

install_requires=[
    'subprocess32; python_version<"3"',
]

subx python2.7 :

Processing ./dist/subx-2017.8.0-py2-none-any.whl
Collecting subprocess32; python_version < "3" (from subx==2017.8.0)
Installing collected packages: subprocess32, subx
Successfully installed subprocess32-3.2.7 subx-2017.8.0

python3.X, :

Processing ./dist/subx-2017.8.0-py3-none-any.whl
Installing collected packages: subx
Successfully installed subx-2017.8.0

, subprocess32 .


: , auditwheel Linux delocate MacOS. :

install_requires=[
    ...
    'auditwheel==1.7.0; "linux" in sys_platform',
    'delocate==0.7.1; "darwin" == sys_platform',
]

, Linux , - python, :

$ python2 -c "import sys; print sys.platform"
linux2

$ python3 -c "import sys; print sys.platform"
linux

, , python2.X, "linux2" == sys.platform. python2.X.

+6
import sys

kw = {}
if sys.version_info[0] == 2:
    kw['install_requires'] = ['subprocess32']

setup(
    **kw
)
+5

All Articles