Brian E Johnson A personal website

Learning Cookiecutter

Brian Johnson

2022-11-01

I have known for some time that cookiecutter is a nice tool for scaffolding development projects. Today I reviewed the documentation and a few of the project templates referenced in the documentation. The reference templates for python have a ton of great stuff in them. However, for my needs at the moment, I don't need setup for testing in tox, CI/CD, and all the other requirements for a public open source project. I decided to start from scratch and incrementally enhance my cookiecutter template as I grow in my development journey.

The initial template structure is:

    {{cookiecutter.project_name}}
    |
    |-{{cookiecutter.package_name}}
    |  |
    |  |-__init__.py
    |  |-{{cookiecutter.package_name}}.py
    |-.gitignore
    |-README.md

I have not decided if the package_name and project_name should be the same. Posting to GitHub should yield an answer and a decision. Additionally, I am reading that some developers use a src directory in lieu of having the project root contain all the packages. I need to research this more to understand the implications of either way.

README.md

I started with some basic content.

Overview

{{ cookiecutter.project_short_description }}

Features

Setup

Installation

Install it into an activated virtual environment:

$ pip install {{ cookiecutter.project_name }}

Usage

$ python
>>> import {{ cookiecutter.package_name }}
>>> {{ cookiecutter.package_name }}.__version__

.gitignore

I used the default content from GitHub.

init.py

"""Top-level package for {{ cookiecutter.project_name }}."""

{{cookiecutter.package_name}}.py

"""Main module."""


def main():
    """Execute the module."""
    ...


if __name__ == "__main__":
    main()

Next Steps

There are a few directions I can go. I'll probably start with fleshing out the main package content and how testing should go. It may be good to include some instructions (or a post-processing hook) about other project initialization tasks like setting up a virtual environment, git init, logging (log2d?), and Visual Studio Code settings. Other items include the packaging set up files like pyproject.toml, setting up a CLI entry point and script, and documentation. I think CD/CI workflows are likely not in my future.

Some other cookiecutter ideas are: