Sal
Peter Hoffmann Director Data Engineering at Blue Yonder. Python Developer, Conference Speaker, Mountaineer

PyScaffold - Easy setup of a Python project with a bliss

PyScaffold helps you to easily setup a new Python project.

Setting up a Python project is usually quite boring, cumbersome and definitely repetitive. This is exactly where PyScaffold excels. You create the structure of your package with package folder, test and docs folder, generate the __init__.py files and setup.py for starters. After that it’s all about tweaking your configuration files like .gitconfig if you are using git (who isn’t these days?), .coveragerc for your coverage reports, conf.py for your Sphinx documentation and of course you want automatic PEP8 checks… you see where this is going. Before you have coded the first line of your actual project, you spent hours to adjust and configure the nuts and bolts of your project’s scaffold. But there is help, and since we want to put up a scaffold for our Python project, it is naturally called PyScaffold! PyScaffold is easy to use and lets you set up a Python project in about 5 seconds. You install it with:

pip install pyscaffold

which takes about 3 seconds and create your project named my_project in about 2 seconds:

putup my_project

This neat little command creates a folder my_project with the usual project layout of a Python project. You’ll have a my_project package folder inside as well as docs and tests folders and the files setup.py, setup.cfg, AUTHORS.txt, README.txt and LICENSE.txt. So far, unimpressive, you might say but here comes the cool part. All configuration of your project is done in setup.cfg instead of setup.py. There you can change all settings related to your package like the author, url, license and you can even configure Python console scripts. Ever wanted to distribute non-Python data files in your Python package? Yep, it is a pain to fiddle with MANIFEST.in and the various options of the setup command. But not so with PyScaffold! Within setup.cfg we can just name additional data files and they will be included in our distribution.

By the way, building your package just works out of the box with python setup.py sdist. Since the my_project folder is already an initialized git repository and git is used to retrieve a PEP440 compliant version number, a package is built whose version number reflects the current git commit or tag. In practice that means, no longer you need to specify and change a version string inside your package, all that information is just taken from your git history and your tags. Responsible for this magic is a sophisticated setup.py that provides a lot of comfort features. You can print the current version with python setup.py version, run your unit tests with python setup.py test, build your documentation with python setup.py docs and so forth. And that’s not even all, there are many more goodies in PyScaffold.

Let’s say our project is called Scikit-Brain but we want the package itself called skbrain. Additionally we want a basic configuration for Travis as well as automatic PEP8 and error checks with the help of pre-commit. The whole project should be new-BSD licensed. With PyScaffold that’s just:

putup Scikit-Brain -p skbrain --license new-bsd --with-pre-commit --with-travis

Check out the homepage of PyScaffold for more details, it will save you a lot of time.