Python/Setup.py
From charlesreid1
Contents
Resources
Github: package template
Github sample PyPI project: https://github.com/pypa/sampleproject
- Contains a template setup.py
- Contains README, manifest, other supporting files
- Contains .travis.yml file
My fork: https://github.com/charlesreid1/sampleproject
Python Packaging User Guide
Source code on Github: https://github.com/pypa/python-packaging-user-guide
Tutorial: Packaging and Distributing Projects: https://packaging.python.org/tutorials/distributing-packages/
Guide: Packaging Binary Extensions with Python (example: C code): https://packaging.python.org/guides/packaging-binary-extensions/
Setuptools documentation
Developers guide (list of all available commands in setup.py): https://setuptools.readthedocs.io/en/latest/setuptools.html#developer-s-guide
Setuptools command guide: https://setuptools.readthedocs.io/en/latest/setuptools.html#command-reference
Note on adding commands: https://setuptools.readthedocs.io/en/latest/setuptools.html#adding-commands
- This allows you to add a command like
python setup.py foo - To do this, create a foo class in
mypackage.some_moduleand make it inherit fromsetuptools.Commandsubclass - Now you can add a new setup command into the
distutils.commandsgroup in the setup() call
setup(
# ...
entry_points={
"distutils.commands": [
"foo = mypackage.some_module:foo",
],
},
)
Setup.py Layout
The layout of the setup.py file is as follows:
- Extract information needed for setup process (e.g., extract long description from readme)
- Create a dictionary with setup parameters:
- Project name, description, author info, URL
- Set license
- Set classifiers (maturity, license, categories, versions of Python supported)
- Set modules to be installed
- Install required packages
Setup.py for Packages with C/Fortran
Complicated build package: https://github.com/joe-jordan/complicated_build
Fortran package: boundary value problem solver using Fortran code: https://github.com/jsalvatier/scikits.bvp_solver
Distutils Building Extensions
Building C and C++ Extensions with distutils: https://docs.python.org/3/extending/building.html#building-c-and-c-extensions-with-distutils
To include code in C, C++, or Fortran, we need to create an Extension, and include it using the ext_modules argument when calling setup().
from distutils.core import setup, Extension
module1 = Extension('demo',
sources = ['demo.c'])
setup (name = 'PackageName',
version = '1.0',
description = 'This is a demo package',
ext_modules = [module1])