Python Packaging
and Releasing
Outline
Some terms...
More terms… (Python specific)
More terms...
And more terms...
Why package?
~$ echo $PYTHONPATH
/usr/local/lib/python2.7:/usr/local/lib/python2.7/site-packages:/usr/lib/python2.7/mystuff:~/program_from_bob:~/temp/numpy‑1.8.1:/home/embray/my_code/test_program:/home/embray/my_code/astropy:/home/embray/mycode/astropy_old:/opt/python3.4/lib/python3.4:/opt/python3.3/lib/python3.4/site-packages…
Why package?
More reasons to package?
But I just write code for myself / one-off scripts
But I just write code for myself / one-off scripts
History: distutils
setuptools
setuptools (cont.)
easy_install
pip
pip (cont.)
Tumult
More tumult
Other Python packaging projects
Summary
How to
How to (cont.)
Start by making a directory for your distribution
Make a directory
Make an empty setup.py in the directory, set it executable
Bare minimum setup.py
#!/usr/bin/env python
from setuptools import setup
setup()
Try it out
First we need some actual code to install
Let’s add some bare minimum metadata to our setup
Essential metadata
Go ahead and put a name and version in your setup.py
#!/usr/bin/env python
from setuptools import setup
setup(
name=‘MakeUpAUniqueName’,
version=‘0.1’
)
Now try
Other metadata
Now tell setup() what actual code is part of our distribution
Adding single modules
py_modules=[
‘name_of_module’,
‘another_module’
]
# without the .py
Adding packages
packages=[‘name_of_package’]
from setuptools import find_packages
setup(…
packages=find_packages()
)
Adding scripts
console_scripts
console_scripts syntax
setup(
...
entry_points = {
‘console_scripts’: [
‘simcluster = simcluster:main’
]
},
...
)
__version__ convention
Version de-duplication
Put version in __init__
How to manage version number
Two broad categories of releases
Version schemes
X.Y scheme
Dev versions
Releasing Python distributions
Prepare for release
Changelog format
Test source dist
sdist output
sdist testing
Make a MANIFEST.in
Register on PyPI
PyPI authentication still sucks
.pypirc contents (for testpypi)
[distutils]
index-servers=
pypitest
[pypitest]
repository = https://testpypi.python.org/pypi
username = erik
password = <your password goes here>
Now run the register command
Now run the register command
Build dist and upload
Congrats!