可以有python子包的setup.py文件吗?

时间:2018-06-05 06:43:07

标签: python numpy scipy setup.py python-packaging

我看到scipy在其子包中有setup.py文件。这些setup.py文件有什么作用?它是用于构建子包吗?

是否有任何文档或网页可以解释这个或者像教程一样?

1 个答案:

答案 0 :(得分:1)

一般来说,您不需要任何其他设置脚本来构建分发版。 SciPy需要额外的设置脚本,主要是为了减少特定于子包的样板配置代码的数量。 SciPy子包中的设置脚本主要用于构建整个分发时的配置准备 - 构建和打包仍然是从根设置脚本完成的。如NumPy Distutils - Users Guide

中所述
  

SciPy包的要求

     

SciPy包含Python包,称为SciPy包   Python用户可以通过scipy命名空间使用。每个SciPy包   可能包含其他SciPy包。等等。因此,SciPy   目录树是具有任意深度和宽度的包树。   任何SciPy包都可能依赖于NumPy包,但依赖于其他包   SciPy包应保持最小或零。

     

SciPy软件包除了其来源之外还包含以下内容   文件和目录:

     
      
  • setup.py ---建筑脚本
  •   
  • __init__.py --- package initializer
  •   
  • tests/ --- unittests目录
  •   
     

他们的内容如下所述。

     

setup.py文件

     

为了向SciPy添加Python包,其构建脚本(setup.py)   必须符合某些要求。最重要的要求是   包定义configuration(parent_package='',top_path=None)函数   它返回一个适合传递的字典   numpy.distutils.core.setup(..)。简化建设   这本字典,numpy.distutils.misc_util提供了   Configuration课程,如下所述。

     

SciPy纯Python包示例

     

以下是纯SciPy包

的最小setup.py文件示例
 #!/usr/bin/env python
 def configuration(parent_package='',top_path=None):
     from numpy.distutils.misc_util import Configuration
     config = Configuration('mypackage',parent_package,top_path)
     return config

 if __name__ == "__main__":
     from numpy.distutils.core import setup
     #setup(**configuration(top_path='').todict())
     setup(configuration=configuration)