trial guy
trial guy

Reputation: 601

Can there be setup.py files for python subpackages?

I saw that scipy had setup.py files inside its sub packages. What do these setup.py files do? Is it used to build the sub packages?

Is there any documentation or a webpage where this is explained or like a tutorial?

Upvotes: 3

Views: 678

Answers (1)

hoefling
hoefling

Reputation: 66331

Generally speaking, you don't need any additional setup scripts to build the distribution. SciPy requires additional setup scripts mainly to reduce the amount of subpackage-specific boilerplate configuration code. The setup scripts in SciPy subpackages are mainly used for configuration preparation when building the whole distribution - the building and packaging still being done from the root setup script. As described in NumPy Distutils - Users Guide:

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)

Upvotes: 1

Related Questions