Automation for python package logic
This a small post presenting how to build a simple executable for your python project.
PS : after stumbling upon this cookicutter repo, I believe this is probably the go-to when you want to build a new python package.
Why do I need that ?
Easy launch of command line jobs
Get your executable, launch your logic with something like my_exec -m my_package --arg1 value1
.
Job is done.
On top of that, you can store all the previous executables from earlier version of your job and run regressions tests.
What tool to use ?
pex
It offers the packaging feature that we want.
At the end of the build, we get a *.pex file that we can later use as myproject.pex -m my_package --arg1 value1
.
A boilerplate code
Available here, it gives the basic blocks to build a pex with your python package.
In short, run the following commands to see how your project can be built as an executable
tox
./dist/app.pex -m my_project
What this does is :
- Build the package requirements in a virtual env
- Install your custom package
- Create a zip that will be the .pex file
- you can launch your __main__.py with the second line of the command line