Peter Hoffmann

PyScaffold - Easy setup of a Python project with a bliss

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 a package folder, tests and docs folders, generate the __init__.py files, and setup.py to start. 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 PEP 8 checks. You see where this is going. Before you have coded the first line of your actual project, you spend hours adjusting and configuring 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 then 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, this may seem unimpressive, 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, such as the author, URL, and license, and you can also configure Python console scripts. Have you ever wanted to distribute non-Python data files in your Python package? It is a pain to fiddle with MANIFEST.in and the various options of the setup command. Not so with PyScaffold! In setup.cfg, you can list additional data files, and they will be included in your distribution.

By the way, building your package 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 PEP 440-compliant version number, a package is built whose version number reflects the current Git commit or tag. In practice, this means you no longer need to specify and change a version string inside your package; all that information is taken from your Git history and your tags. This is handled by a sophisticated setup.py that provides many convenience 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. 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 to be called skbrain. Additionally, we want a basic configuration for Travis CI as well as automatic PEP 8 and error checks with the help of pre-commit. The whole project should be New BSD licensed. With PyScaffold, that is 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.