[IPython-dev] How should requirements be listed in setup.py post-4.0?

Erik Bray erik.m.bray at gmail.com
Tue Aug 18 14:03:12 EDT 2015


On Thu, Aug 13, 2015 at 5:48 PM, Matt Craig <mattwcraig at gmail.com> wrote:
> Hi,
>
> I actually have two questions, both related to a widget-based package I'm
> about release a new version of that is compatible with both IPython 3 and
> IPython 4/jupyter.
>
> 1. What is the "best" thing to list as a requirement for the widget
> bits...jupyter? ipywidgets?something else?
>
> 2. Anyone know a way to express in install_requires that either IPython v3
> or jupyter/ipywidgets/whatever-the-answer-to1-is meets the install
> requirements? I could fudge this by doing two separate releases, but would
> rather not.

This might be a good question for distutils-sig.  But I don't think
there's currently a great way currently to specify a requirement that
may be satisfied. PEP-426 provides for this, but that isn't currently
implemented in any practically usable way.

One kind of hacky approach would be to specify each dependency as an
extras_require [2].  Something like:

extras_require = {
    'IPython': ['IPython>=3.0'],
    'ipywidgets': ['ipywidgets'],
    'jupyter': ['juptyter']
}

This is sort of an abuse of the extras system since is actually a
*required* dependency (to have at least one).  But you could put
something in your setup.py that tries importing each one of them in
turn (or better, use pkg_resources.get_distribution or the like), and
if none of the required dependencies are found raise an exception
stating that at least one of IPython, ipywidgets, or jupyter must be
installed with the package, and you can select which one you want
using the syntax:

    $ pip install "MyPackage[jupyter]"

for example.

So this can be read sort of as "MyPackage with Jupyter support".  This
is similar to, but perhaps slightly nicer than having multiple
distributions for each possible dependency.

Erik

[1] https://www.python.org/dev/peps/pep-0426/#id40
[2] https://pythonhosted.org/setuptools/setuptools.html#declaring-extras-optional-features-with-their-own-dependencies



More information about the IPython-dev mailing list