确定哪些项目阻止您移植到python 3
caniusepython3的Python项目详细描述
这个脚本接受一组依赖项,然后计算出 其中的一个阻碍了您移植到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界面,可以使用https://caniusepython3.comby 詹尼斯·莱德尔。
与您的测试集成
如果您想在测试中检查python 3的可用性,可以 使用caniusepython3.check():
defcheck(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. """
然后,您可以将其集成到您的测试中,如下所示:
importunittestimportcaniusepython3classDependenciesOnPython3(unittest.TestCase):deftest_dependencies(self):# Will begin to fail when dependencies are no longer blocking you# from using Python 3.self.assertFalse(caniusepython3.check(projects=['ipython']))
对于更改日志,如何判断项目是否已被移植,以及 如何移植项目,请参见 project website。
扩展pylint --py3k
在Pylint1.4中,--py3k选项是 添加到linting工具以启用python 2/3的检查 不兼容(关闭所有其他检查)。虽然很棒, 这些支票有点保守,以便总是准确的。填补 用更严格的——尽管可能不准确的——跳棋检查, {TT4} $存在。在一切之上pylint --py3k 已经检查过,它会添加检查:
- 使用open()(在python3中,open()实际上是io.open())
- 没有前缀b/u或 from __future__ import unicode_literals
如果您想将检查器与pylint一起使用,可以将其添加到pylint中 配置文件,例如:
[MASTER]load-plugins=caniusepython3.pylint_checker
秘密,奖励功能
如果您想对脚本使用不同的名称, setuptools命令然后将环境变量CIU_ALT_NAME设置为 你想要另一个名字。reddit建议使用icanhazpython3。