Chapter 7. Building and Distributing NumPy Code

In a real-world scenario, you will be writing an application with the intentions of distributing it to the World or reusing it on various other computers. For this purpose, you would like your application to be packed in a standard way so that everyone in the community understands and follows. As you will have noticed by now, Python users mainly use a package manager called pip to automate the installation of modules created by other programmers. Python has a packaging platform called PyPI (Python Package Index), which is an official central repository for more than 50,000 Python packages. Once the package is registered in PyPi aka Cheese Shop, other users across the world can install it after configuring it with package management systems such as pip. Python comes with a number of solutions to help you to build your code ready for distribution to the Cheese Shop and, in this chapter, we will focus on two such tools, setuptools and Distutils. Apart from these two tools, we will be looking into a specific module provided by NumPy called numpy.distutils. This module makes the process of building and distributing NumPy-specific code easier for the programmers. This module also provides added functionalities such as methods for compiling Fortran code, calling f2py, and more. In this chapter, we will be going through the following steps to learn the packaging workflow:

  • We will build a small but working setup
  • We will explain the steps to integrate NumPy modules into your setup
  • We will explain how to register and distribute your application over the Internet

Introducing Distutils and setuptools

Before we begin, first let us understand what these tools are and why we prefer one over another. Distutils is a framework that comes by default with Python, and setuptools builds over the standard Distutils to provide enhanced functionalities and features. In a real-world scenario, you will never use Distutils. The only case where you might want to use Distutils alone is where setuptools is unavailable. (A good setup script should check for the availability of setuptools before proceeding.) In most cases, users will be better off installing setuptools as most packages nowadays are built over them. We will be using setuptools for building Cython code in the following chapters; hence, for our purpose, we will be installing setuptools now and using it extensively from now on.

Next let us start by installing the required tools to build our first dummy (but working) installer. After we have got our installer working, we will dive into more functionalities covering NumPy in a real-world script for the pandas module. We will study the checks made in the scripts to make it more robust and how we provide more information in the event of failures.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.108.112