pep 420 namespace_packages setup.py 的目的
pep 420 namespace_packages purpose in setup.py
在使用 PEP420 命名空间包(没有 __init__.py 的包)时,setup.py 中的 namespace_packages 参数的目的是什么?
我试了一下,发现是否声明名称空间包没有区别。
"setup.py install" 和 "pip install ." 在任何情况下都有效。
我正在构建一个自动 setup.py 代码生成器,如果没有必要,我很乐意不处理它。
命名空间包是单独的 包,安装在同一个顶级名称下。
通常两个不同的包(例如SQLObject and Cheetah3)安装两个(或更多)不同的顶级包(在我的示例中为sqlobject
和Cheetah
)。
但是,如果我有一个库,我想将其拆分成多个部分并允许安装这些部分而不安装库的其余部分怎么办?我使用命名空间包。示例:这两个包是一个库的两个部分:m_lib and m_lib.defenc. One installs m_lib/defenc.py
which can be used separately, the other installs the rest of the m_lib
library. To install the entire library at once I also provide m_lib.full.
PS。所有提到的包裹都是我的。 Github or my personal git hosting.
提供了源代码
只要你:
- 针对 Python 3.3 和更新版本或安装了
importlib2
依赖项的 Python 2.7(Python 2 的 importlib
向后移植),
- 使用最近版本的
setuptools
打包(我觉得应该是28.8或者更新的)
- 并使用最近的
pip
版本进行安装(9.0 及更新版本可以,8.1.2 可能也可以,但你应该自己测试),
为了安全起见,您可以放心地在设置脚本中省略 namespace_packages
关键字参数。
有个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.
在使用 PEP420 命名空间包(没有 __init__.py 的包)时,setup.py 中的 namespace_packages 参数的目的是什么?
我试了一下,发现是否声明名称空间包没有区别。 "setup.py install" 和 "pip install ." 在任何情况下都有效。
我正在构建一个自动 setup.py 代码生成器,如果没有必要,我很乐意不处理它。
命名空间包是单独的 包,安装在同一个顶级名称下。
通常两个不同的包(例如SQLObject and Cheetah3)安装两个(或更多)不同的顶级包(在我的示例中为sqlobject
和Cheetah
)。
但是,如果我有一个库,我想将其拆分成多个部分并允许安装这些部分而不安装库的其余部分怎么办?我使用命名空间包。示例:这两个包是一个库的两个部分:m_lib and m_lib.defenc. One installs m_lib/defenc.py
which can be used separately, the other installs the rest of the m_lib
library. To install the entire library at once I also provide m_lib.full.
PS。所有提到的包裹都是我的。 Github or my personal git hosting.
提供了源代码只要你:
- 针对 Python 3.3 和更新版本或安装了
importlib2
依赖项的 Python 2.7(Python 2 的importlib
向后移植), - 使用最近版本的
setuptools
打包(我觉得应该是28.8或者更新的) - 并使用最近的
pip
版本进行安装(9.0 及更新版本可以,8.1.2 可能也可以,但你应该自己测试),
为了安全起见,您可以放心地在设置脚本中省略 namespace_packages
关键字参数。
有个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.