Specifying additional dependencies in setup.py script based on implementation (PyPy / CPython support)

Viewed 440

Preface

I have a package with PyPy support and for CPython users it has mypy as an additional dependency which I specify as

import platform

from setuptools import setup
...
install_requires = [...]
if platform.python_implementation() != 'PyPy':
    install_requires.append('mypy>=0.630')
setup(...,
      install_requires=install_requires)

and locally it works fine, but when I create source distribution via CPython like

> python setup.py sdist

and try to install it via PyPy

> pypy3 -m pip install path/to/package.tar.gz

it tries to install mypy (and fails since mypy uses CPython-specific packages), so it looks like dependencies are taken for CPython version (for which distribution was created).

Problem

How can I specify dependencies and create source distribution once so it will work for both CPython & PyPy versions (and upload to PyPI afterwards)?

1 Answers
Related