[TIP] Tox and setup.py enforcing python version

Robert Collins robertc at robertcollins.net
Tue Jun 2 14:36:24 PDT 2015


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. If you have a Linux distribution installed
tox, look for a python3 variant - e.g. python3-tox or something.

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 :)

-Rob


-- 
Robert Collins <rbtcollins at hp.com>
Distinguished Technologist
HP Converged Cloud



More information about the testing-in-python mailing list