[TIP] Tox and setup.py enforcing python version
Florian Bruhin
me at the-compiler.org
Tue Jun 2 23:12:46 PDT 2015
* Robert Collins <robertc at robertcollins.net> [2015-06-03 09:36:24 +1200]:
> On 3 June 2015 at 07:14, Roy Wright <roy at wright.org> wrote:
> > Howdy,
> >
> > For my python3 apps I've been including the following to prevent them from being installed on python2:
> >
> > import sys
> > if sys.version_info < (3, 3):
> > print("appname requires python 3.3 or newer")
> > exit(-1)
> >
> > Now my system python is 2.7 (Ubuntu 14.04) so running tox will immediately fail even with:
> >
> > [tox]
> > envlist = py33,py34
> >
> > Removing the exit allows tox to run.
> >
> > I'm just curious what is the best practice here? Run tox from python3 virtualenv? Let the user beware? Depend on classifiers?
>
> So you've got two related things here. One is how to get tox to work
> when your project is syntax incompatible with python2: answer (AIUI) -
> install tox using Python3.
Note only the setup.py has to be syntax-compatible! After running it,
a python2-tox can run a python3-only application just fine (when you
tell it to use a python3 for the virtualenvs, of course).
IMHO it's worthwile to make the setup.py compatible with python2, so
using tox is easier for everyone.
This is all it took for me:
https://github.com/The-Compiler/qutebrowser/commit/513fbb1539ce1a0b5547901357e9c7afaedefc3c
But for simpler setup.py's, it should work out of the box unless you
actively prevent it ;)
> If you have a Linux distribution installed tox, look for a python3
> variant - e.g. python3-tox or something.
Note neither Debian nor Ubuntu have a package for a python3 tox:
http://packages.ubuntu.com/search?keywords=python3-tox&searchon=names&suite=all§ion=all
https://packages.debian.org/search?keywords=python3-tox&searchon=names&suite=all§ion=all
> The other, is how to stop your things being installed on python2.
> There, I think you're overthinking it.
>
> Make sure your classifiers are correct for the cheeseshop, and get on
> with other more interesting things. Version checking like you've done
> is very non-duck-typing, and Python is largely about duck typing :)
I disagree with you here. How is it related to duck typing?
In the #python IRC channel, often there are people who wonder why
something doesn't run, because they are running a python2 application
with python3, or vice-versa.
Ideally a python2 or python3 classifier on PyPI would be enforced and
pip would refuse (unless --force'd) to install something with a
python2 classifier on python3 (and vice-versa).
But since that's not the case, I think a clear error message (at least
when attempting to *use* the application) can help users a lot.
Florian
--
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20150603/26ef4427/attachment.pgp>
More information about the testing-in-python
mailing list