19

I have several python projects with different set of dependencies listed in pip requirements files. I've started to think about porting the code to python 3, but I need to know if my dependencies are already there.

Is it possible to check what packages from a requirements.txt file support python 3 and what don't?

Example requirements.txt contents:

mysql-python==1.2.5
lxml==3.3.4
Fabric==1.8.0

From this list, only lxml supports python 3.


Just a side note.

There is a Python 3 Wall of Superpowers (python3wos project) that shows python 3 support of popular python packages.

As far as I understand, python3wos periodically parses the Python Package Index html pages and checks for the Programming Language :: Python :: 3 text to define whether a packages supports python 3rd branch or not. Isn't there anything simpler than scraping the html on PyPI?

TuringTux
  • 559
  • 1
  • 12
  • 26
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • 3
    http://py3readiness.org/ can also be used to check the python 3 compatibility of popular packages. – thefourtheye Apr 09 '14 at 02:02
  • 1
    @thefourtheye this is really a good point from you. I've discovered `py3readiness.org` sources and I think I found exactly what I need. I'm going to proceed with answering my own question, but it would be fair to give credits to you - just let me know if you're going to answer. Thank you! – alecxe Apr 09 '14 at 02:10
  • 1
    Your answer is elaborate and good. I ll just settle with upvoting yours :) – thefourtheye Apr 09 '14 at 02:47
  • 1
    One would assume that something in the lines of 1. activate a py3 virtualenv 2. pip install would work if the package supports python 3 or fail if not. I tried to install Fabric==1.8.0 on a py3 venv, and it installed like a charm. only when i did `from fabric.context_managers import *` it broke. pypi and pip needs to fix this. you won't know until runtime that your package doesnt play well with your python version. – srj Oct 08 '14 at 14:51
  • @srj strictly speaking, you are right. But that `Python :: 3x` classifier on the package home page was designed to be smth we can rely on. You would not really know if it truly 3.x compatible until you start using it. Thank you. – alecxe Oct 08 '14 at 14:56

1 Answers1

26

With the help of @thefourtheye and py3readiness.org sources, I've found exactly what I needed.

caniusepython3 module by Brett Cannon:

Determine what projects are blocking you from porting to Python 3

This script takes in a set of dependencies and then figures out which of them are holding you up from porting to Python 3.

Example (for the requirements.txt from the question):

$ caniusepython3 -r requirements.txt 
Finding and checking dependencies ...

You need 2 projects to transition to Python 3.
Of those 2 projects, 2 have no direct dependencies blocking their transition:

  fabric
  mysql-python

I should note that it still uses the same approach as python3wos - looking for Programming Language :: Python :: 3x classifiers on the package page.

There is also a web-interface where you can type your dependencies or drop a requirements.txt file.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195