Skip to main content

Determine what projects are blocking you from porting to Python 3

Project description

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

Command-line/Web Usage

You can specify your dependencies in multiple ways:

caniusepython3 -r requirements.txt test-requirement.txt
caniusepython3 -m PKG-INFO
caniusepython3 -p numpy scipy ipython
# If your project's setup.py uses setuptools
# (note that setup_requires can't be checked) ...
python setup.py caniusepython3

The output of the script will tell you how many (implicit) dependencies you need to transition to Python 3 in order to allow you to make the same transition. It will also list what projects have no dependencies blocking their transition so you can ask them to start a port to Python 3.

If you prefer a web interface you can use https://caniusepython3.com by Jannis Leidel.

Integrating With Your Tests

If you want to check for Python 3 availability as part of your tests, you can use caniusepython3.check():

def check(requirements_paths=[], metadata=[], projects=[]):
    """Return True if all of the specified dependencies have been ported to Python 3.

    The requirements_paths argument takes a sequence of file paths to
    requirements files. The 'metadata' argument takes a sequence of strings
    representing metadata. The 'projects' argument takes a sequence of project
    names.

    Any project that is not listed on PyPI will be considered ported.
    """

You can then integrate it into your tests like so:

import unittest
import caniusepython3

class DependenciesOnPython3(unittest.TestCase):
  def test_dependencies(self):
    # Will begin to fail when dependencies are no longer blocking you
    # from using Python 3.
    self.assertFalse(caniusepython3.check(projects=['ipython']))

For the change log, how to tell if a project has been ported, as well as help on how to port a project, please see the project website.

Extending pylint --py3k

In Pylint 1.4, a --py3k option was added to the linting tool to turn on checks for Python 2/3 incompatibilities (all other checks are turned off). While great, those checks are a little conservative in order to always be accurate. To fill out those checks with stricter – albeit potentially inaccurate – checkers, caniusepython3.pylint_checker exists. On top of everything pylint --py3k already checks for, it adds checks for:

  1. Uses of open() (in Python3, open() is actually io.open())

  2. String literals that do not have a b/u prefix or from __future__ import unicode_literals

If you wish to use the checker with Pylint, you can add it to your Pylint configuration file, e.g.:

[MASTER]
load-plugins=caniusepython3.pylint_checker

Secret, bonus feature

If you would like to use a different name for the script and setuptools command then set the environment variable CIU_ALT_NAME to what you would like the alternative name to be. Reddit suggests icanhazpython3.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

caniusepython3-3.2.0.tar.gz (18.3 kB view details)

Uploaded Source

Built Distributions

caniusepython3-3.2.0-py2.py3-none-any.whl (29.9 kB view details)

Uploaded Python 2 Python 3

caniusepython3-3.2.0-py2.7.egg (45.9 kB view details)

Uploaded Source

File details

Details for the file caniusepython3-3.2.0.tar.gz.

File metadata

File hashes

Hashes for caniusepython3-3.2.0.tar.gz
Algorithm Hash digest
SHA256 565d4dd1ccdc49b161af45be4f9bab201a6e4f46b257730e6aab78c82dd9815c
MD5 87ff5cc33d69c7b321d82731cb34a70c
BLAKE2b-256 cbf1963fd0260ef3848c6fb9a3c4ececcbe8d6ed3a717d3f2a507b1d406f9c5d

See more details on using hashes here.

Provenance

File details

Details for the file caniusepython3-3.2.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for caniusepython3-3.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 bdec2a86014b2bbf4c6bb1918c33cef14063c961df8d1b83b55f32f15ecc890a
MD5 21ad134f195f56cdcdc0dc7cac18b0ab
BLAKE2b-256 9dae885b1eaf813e82ea263c11bb87b8d2b77f80bed31bfaea668eae61fcaca8

See more details on using hashes here.

Provenance

File details

Details for the file caniusepython3-3.2.0-py2.7.egg.

File metadata

File hashes

Hashes for caniusepython3-3.2.0-py2.7.egg
Algorithm Hash digest
SHA256 424f7d2399be02d3bfc7decdf0ad4942bca78d297a7389ff82ffb70d565e6654
MD5 3ee80d73b59ef648e80bee4c0790653f
BLAKE2b-256 c46d704380c24166cf67de0bf85034c0fae4ceacb2895b16cd8509dab68dc1fa

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page