Skip to main content

确定哪些项目阻止您移植到 Python 3

项目描述

** 注意 ** 此项目不再积极开发!

我可以使用 Python 3 吗?

该脚本接受一组依赖项,然后找出它们中的哪些阻碍了您移植到 Python 3。

命令行/Web 使用

您可以通过多种方式指定依赖项:

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

脚本的输出将告诉您需要转换到 Python 3 的(隐式)依赖项,以允许您进行相同的转换。它还将列出哪些项目没有阻止其转换的依赖项,因此您可以要求他们启动到 Python 3 的移植。

如果您更喜欢 Web 界面,可以使用Jannis Leidel 的https://caniusepython3.com

与您的测试集成

如果您想在测试中检查 Python 3 的可用性,可以使用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.
    """

然后,您可以将其集成到您的测试中,如下所示:

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']))

有关更改日志,如何判断项目是否已被移植,以及如何移植项目的帮助,请参阅 项目网站

扩展pylint --py3k

Pylint 1.4 中,向 linting 工具添加了一个--py3k选项,以打开对 Python 2/3 不兼容性的检查(所有其他检查均已关闭)。虽然很棒,但为了始终准确,这些检查有点保守。为了使用更严格(尽管可能不准确)检查器填写这些检查, 存在caniusepython3.pylint_checker除了pylint --py3k已经检查的所有内容之外 ,它还添加了以下检查:

  1. open()的使用(在 Python3 中,open()实际上是io.open()

  2. 没有b / u前缀或 from __future__ import unicode_literals的字符串文字

如果您希望将检查器与 Pylint 一起使用,您可以将其添加到您的 Pylint 配置文件中,例如:

[MASTER]
load-plugins=<s>caniusepython3.pylint_checker</s>

秘密,奖金功能

如果您想为脚本和 setuptools 命令使用不同的名称,请将环境变量CIU_ALT_NAME设置为您希望的替代名称。Reddit 建议icanhazpython3

下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

caniusepython3-7.3.0.tar.gz (25.7 kB 查看哈希

已上传 source

内置分布

caniusepython3-7.3.0-py2.py3-none-any.whl (29.1 kB 查看哈希

已上传 py2 py3