5

Kinda followup to this... :)

My project is Python 3-only and my question is basically how I tell distutils/distribute/whoever that this package is Python 3-only?

Community
  • 1
  • 1
dom0
  • 7,356
  • 3
  • 28
  • 50
  • Are you trying to make it so `pip` 2.x will not see your app, or will refuse to install it, or just so that running `python2.7 setup.py install` will give an error? For the latter, bereal's solution is perfect. – abarnert Nov 14 '12 at 19:03
  • I don't really care as long as it's not getting installed some way or the other ;) – dom0 Nov 14 '12 at 19:04
  • Then I'd accept bereal's answer. If you later put the package on PyPI and decide you want to handle `pip` 2 differently, you can always ask for that info later; no need to learn all that now if you don't plan to use it. – abarnert Nov 14 '12 at 19:08
  • Actually I plan to publish it on PyPI ... – dom0 Nov 14 '12 at 19:09
  • In that case, if you're using the `python setup.py register` mechanism, I think a `setup_requires` dependency on `python>=3.0` is enough to make `distribute`/`pip`/`easy_install` refuse to install your package in 2.x, and get the information onto the web page (but also put it in the `long_description` in human-readable terms). But someone who does `python2.7 setup.py install` will see an ugly traceback from a `VersionConflict`, so you'll still want the explicit version check to provide a nice message. (This is all off the top of my head; please research before relying on details.) – abarnert Nov 14 '12 at 19:28
  • 1
    Oh, and you also want to use `Programming Language :: Python :: 3` instead of the default `Programming Language :: Python` classifier. Anyway, all this is really just to prevent `easy_install`, `pip`, or whatever future tool comes out of the `distribute2` project from having to download your package before giving an error. – abarnert Nov 14 '12 at 19:30

1 Answers1

9

Not sure if there's some special setting, but this in the beginning of setup.py might help:

import sys
if sys.version_info.major < 3:
    print("I'm only for 3, please upgrade")
    sys.exit(1)
bereal
  • 32,519
  • 6
  • 58
  • 104
  • 4
    +1. The idiomatic way to check version is `sys.version_info < (3,)` (I believe that's primarily to make it easier to change to `(3, 1)` when you want to drop support for 3.0), but I don't think this is really confusing or less readable. – abarnert Nov 14 '12 at 19:05
  • FWIW I think it's more idiomatic to write it as `.major < 3`, because that immediately assigns meaning to the number. This doesn't really matter in this instance, since it's pretty obvious anyway, though ;) – dom0 Nov 02 '16 at 17:48