Python子包是否可以有setup.py文件?

3
我看到scipy的子包里有setup.py文件。这些setup.py文件是做什么用的?它们用于构建子包吗?
是否有解释这个问题的文档或网页,或者像教程一样的东西?
1个回答

1

一般来说,你不需要任何额外的设置脚本来构建分发。SciPy需要额外的设置脚本主要是为了减少子包特定样板配置代码的数量。SciPy子包中的设置脚本主要用于在构建整个分发时进行配置准备 - 构建和打包仍然是从根设置脚本完成的。如NumPy Distutils - 用户指南所述:

Requirements for SciPy packages

SciPy consists of Python packages, called SciPy packages, that are available to Python users via the scipy namespace. Each SciPy package may contain other SciPy packages. And so on. Therefore, the SciPy directory tree is a tree of packages with arbitrary depth and width. Any SciPy package may depend on NumPy packages but the dependence on other SciPy packages should be kept minimal or zero.

A SciPy package contains, in addition to its sources, the following files and directories:

  • setup.py --- building script
  • __init__.py --- package initializer
  • tests/ --- directory of unittests

Their contents are described below.

The setup.py file

In order to add a Python package to SciPy, its build script (setup.py) must meet certain requirements. The most important requirement is that the package define a configuration(parent_package='',top_path=None) function which returns a dictionary suitable for passing to numpy.distutils.core.setup(..). To simplify the construction of this dictionary, numpy.distutils.misc_util provides the Configuration class, described below.

SciPy pure Python package example

Below is an example of a minimal setup.py file for a pure SciPy package

 #!/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)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接