跳转到主要内容

确定哪些项目阻碍您迁移到Python 3

项目描述

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

我能使用Python 3吗?

此脚本接受一系列依赖项,然后确定其中哪些阻止您迁移到Python 3。

命令行/网络使用

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

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。

如果您喜欢网络界面,可以使用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 版本中,增加了一个 --py3k 选项,用于启用对 Python 2/3 兼容性的检查(其他所有检查都将关闭)。虽然这些检查非常棒,但为了始终确保准确性,它们显得有些保守。为了补充这些检查,并提供更严格的——尽管可能不够准确——检查器,存在一个名为 caniusepython3.pylint_checker 的工具。除了已经检查的内容外,它还增加了以下检查:

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

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

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

[MASTER]
load-plugins=caniusepython3.pylint_checker

秘密,附加功能

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

项目详情


下载文件

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

源代码分发

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

上传时间 源代码

构建分发

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

上传时间 Python 2 Python 3

由以下赞助

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面