What does cmdclass do in Pythons setuptools settings?

I recently received a transfer request that 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_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) 

What is he doing?

The documentation only states:

cmdclass: display command names in Command subclasses (dictionary)

+10
source share
1 answer

Numpy libraries are written in C / C ++. Therefore, unlike other packages, it must be compiled before calling it. So build_ext just compiles them.

Details on the blog: http://blog.sadafnoor.me/blog/how-to-automate-numpy-in-setuptool/

+5
source

Source: https://habr.com/ru/post/1210540/


All Articles