When releasing a Python egg with support for both Python 2 and 3, can you specify dependencies that change depending on which version you're using? For example, if you use dnspython
for Python 2, there is a Python 3 version that is called dnspython3
.
Can you write your setuptools.setup()
function in such a way that your egg is useable to both versions if that is the only roadblock, i.e., if you have run 2to3
to ensure that the rest of your library is compatible with both versions.
I have looked through these documents and can't seem to find the answer this question:
Bogdan's comment helped point me on my way. I thought I'd post what I did in case anyone else has my problem.
For the example in the question, I did exactly what Bogdan suggested:
setup.py
However, this still has the issue of pip-style dependencies for Travis and
tox
(I'm not sure why, given Bogdan's second comment). To work around this problem, I created two extra requirements files, as shown below:requirements-py2.txt
requirements-py3.txt
Then for Travis, I made use of some environment variables that I gleaned from the tornado .travis.yml:
.travis.yml
Lastly, for
tox
, I had to use a rather hackish method of using these multiple requirements files.tox.ini
The setup.py portion of the answer by @Harold did not work for me: pip install distribution.whl still installs the dependency that the if code says it shouldn't. I will further update this answer in a few days when I have this issue resolved.
Here are some links that may provide additional ways to deal with this ():
For something mostly related but not exactly to the point see my answer https://stackoverflow.com/a/25078063/302521 and this script: https://gist.github.com/pombredanne/72130ee6f202e89c13bb