Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does cmdclass do in Pythons setuptools?

Tags:

I've recently got a pull request which added

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())

to my setup.py resulting in:

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_ext':build_ext}, #numpy hack
    'setup_requires':['numpy'],         #numpy hack
    'name': 'nntoolkit',
    'version': '0.1.25',
    'author': 'Martin Thoma',
    'author_email': '[email protected]',
    '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)

What does it do?

The documentation only states:

cmdclass: A mapping of command names to Command subclasses (a dictionary)

like image 569
Martin Thoma Avatar asked Jan 07 '15 10:01

Martin Thoma


People also ask

What is Cmdclass in setup py?

cmdclass: A mapping of command names to Command subclasses (a dictionary) python setuptools. Follow this question to receive notifications. edited Dec 15, 2020 at 9:32. Martin Thoma.

What does setuptools do Python?

Setuptools is a package development process library designed to facilitate packaging Python projects by enhancing the Python standard library distutils (distribution utilities). It includes: Python package and module definitions. Distribution package metadata.

What is distutils Python?

Distutils is a mechanism to distribute Python packages and extensions provided in the Python standard library since Python 1.6.


1 Answers

Numpy libraries are written in C/C++. So unlike other packages, it needs to be compiled before actually calling them. So 'build_ext' just compiles them.

Details in blog: http://sadafnoor.me/blog/how-to-automate-numpy-installation-in-your-project-using-setuptool/

like image 61
sadaf2605 Avatar answered Oct 17 '22 01:10

sadaf2605