Juicy lil' bytes

Automated Python Source Distribution and Wheel Build With Push to PyPI

Here is a script that automates the Python source distribution and wheel release build process, then pushes your release to the Python Package Index.

Automate the Source Distribution Build

The source distribution is built and pushed to PyPI with the command:

1
python setup.py sdist upload

and the script confirms that it succeeded by checking the exit code and displaying an error message for any non-zero exit codes:

1
2
3
4
if (( $? )); then
  echo "Unable to distribute your release to PyPI" >&2
  exit 1
fi

Automate the Wheel Distribution Build

Next, the script builds your wheel release and distributes it to PyPI with :

1
python setup.py bdist_wheel upload

It again confirms that it exited with a success exit code:

1
2
3
4
if (( $? )); then
  echo "Unable to distribute your wheel to PyPI" >&2
  exit 1
fi

and prompts you if there were problems.

The PyPush.sh Script

Here it is in its entirety:

pypush.shSource
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/sh
# Scriptacular - pypush.sh
# Create a Python source distribution and push it to PyPi
# Copyright 2013 Christopher Simpkins
# MIT License

# Build and push to PyPi
python setup.py sdist upload

# Confirm that it worked
if (( $? )); then
  echo "Unable to distribute your release to PyPI" >&2
  exit 1
fi

python setup.py bdist_wheel upload

# Confirm that wheel distribution worked
if (( $? )); then
  echo "Unable to distribute your wheel to PyPI" >&2
  exit 1
fi

# Exit success
exit 0

Drop it in the same directory as your setup.py file, give it executable permission (e.g. chmod 744 pypush.sh), and run it.