pep 420 setup.py中的namespace_packages用途 [英] pep 420 namespace_packages purpose in setup.py

查看:72
本文介绍了pep 420 setup.py中的namespace_packages用途的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用PEP420名称空间软件包(不含__init__.py的软件包)时,setup.py中的 namespace_packages 参数的用途是什么?

What is the purpose of the namespace_packages argument in setup.py when working with PEP420 namespace packages (the ones without __init__.py)?

我玩了一下,发现是否声明了命名空间包,都没有区别."setup.py install"和"pip install".无论如何都可以工作.

I played with it and saw no difference whether I declared the namespace packages or not. "setup.py install" and "pip install ." worked in any case.

我正在构建一个自动的setup.py代码生成器,如果不需要的话,很乐意不进行处理.

I am building an automatic setup.py code generator and would be happy not to handle this if this is not necessary.

推荐答案

只要您:

  • 针对安装了 importlib2 依赖项(针对Python 2的 importlib 的反向端口)的Python 3.3及更高版本或Python 2.7,
  • 使用最新版本的 setuptools 进行包装(我认为应该为28.8或更高版本)
  • 并使用最新的 pip 版本进行安装(9.0或更高版本可以,8.1.2可能也可以,但您应该自己进行测试),
  • aim for Python 3.3 and newer or Python 2.7 with importlib2 dependency installed (a backport of importlib for Python 2),
  • use a recent version of setuptools for packaging (I think it should be 28.8 or newer)
  • and use a recent pip version for installing (9.0 and newer will be fine, 8.1.2 will probably also work, but you should test that yourself),

您很安全,可以安全地在设置脚本中省略 namespace_packages 关键字arg.

you are on the safe side and can safely omit the namespace_packages keyword arg in your setup scripts.

有一个 PyPA的官方存储库,名为 sample-namespace-packages 在GitHub 上,其中包含针对已安装的发行版的不同可能场景的一组测试,其中包含每种名称空间包.如您所见,使用隐式命名空间包的示例包在其安装脚本中未使用 namespace_packages arg(此处为完整的结果表.

There is a PyPA's official repository named sample-namespace-packages on GitHub that contains a suite of tests for different possible scenarios of distributions installed that contain namespace packages of each kind. As you can see, the sample packages using the implicit namespace packages don't use namespace_packages arg in their setup scripts (here is one of the scripts) and all of the tests of types pep420 and cross_pep420_pkgutil pass on Python 3; here is the complete results table.

这篇关于pep 420 setup.py中的namespace_packages用途的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆