cmdclass在Pythons setuptools中做了什么?

时间:2015-01-07 10:21:51

标签: python setuptools

我最近收到了添加

的拉取请求
class build_ext(_build_ext):
    'to install numpy'
    def finalize_options(self):
        _build_ext.finalize_options(self)
        # Prevent numpy from thinking it is still in its setup process:
        __builtins__.__NUMPY_SETUP__ = False
        import numpy
        self.include_dirs.append(numpy.get_include())

到我的setup.py导致:

from setuptools.command.build_ext import build_ext as _build_ext

try:
    from setuptools import setup
except ImportError:
    from distutils.core import setup


class build_ext(_build_ext):
    'to install numpy'
    def finalize_options(self):
        _build_ext.finalize_options(self)
        # Prevent numpy from thinking it is still in its setup process:
        __builtins__.__NUMPY_SETUP__ = False
        import numpy
        self.include_dirs.append(numpy.get_include())


config = {
    'cmdclass':{'build_txt':build_ext}, #numpy hack
    'setup_requires':['numpy'],         #numpy hack
    'name': 'nntoolkit',
    'version': '0.1.25',
    'author': 'Martin Thoma',
    'author_email': 'info@martin-thoma.de',
    'packages': ['nntoolkit'],
    'scripts': ['bin/nntoolkit'],
    'url': 'https://github.com/MartinThoma/nntoolkit',
    'license': 'MIT',
    'description': 'Neural Network Toolkit',
    'long_description': """...""",
    'install_requires': [
        "argparse",
        "theano",
        "nose",
        "natsort",
        "PyYAML",
        "matplotlib",
        "h5py",
        "numpy",
        "Cython"
    ],
    'keywords': ['Neural Networks', 'Feed-Forward', 'NN', 'MLP'],
    'download_url': 'https://github.com/MartinThoma/nntoolkit',
    'classifiers': ['Development Status :: 3 - Alpha'],
    'zip_safe': False,
    'test_suite': 'nose.collector'
}

setup(**config)

它做了什么?

documentation仅表明:

  

cmdclass:命令名到Command子类(字典)的映射

1 个答案:

答案 0 :(得分:4)

Numpy库是用C / C ++编写的。因此,与其他软件包不同,它需要在实际调用它们之前进行编译。所以'build_ext'只是编译它们。

博客详情:http://www.sadafnoor.com/blog/how-to-automate-numpy-in-setuptool/