Skip to content

woernerm/luxury_python_template

Repository files navigation

The Luxury Python Template

Maximum Coding Convenience from Day One

IntroductionExample ReportQuick Guide


Introduction

There are great tools available to automatically style, analyze, and build your code. They help you deliver better products faster. However, you have to learn how they work, configure them, and clean up after them. It’s easy to forgo this tedious work in the beginning when all you can think about is the bright idea behind your new Python package. Will you do that later on? Probably not, because then chances are high that you get hundreds of complaints from these tools, and fixing them all will likely set you back for weeks. It's way more fun to focus on new features anyway.

Writing better code would be so much easier if any new project, regardless of whether it starts out as an afternoon experiment or the next big thing, already included all of the bells and whistles that professional packages use. For free and without having to register yourself for yet another online service.

With the luxury Python template, you can have all that right from the start! It is very opinionated, meaning the only thing you have to think about is the project name. It comes with a single, zero-configuration command-line tool. Its options are intentionally limited and therefore easy to remember.

Quick Guide

Make sure you have the uv package manager installed. Then, you get everything with a single call of:

uv run package.py build

That's it! You don't have to create a virtual environment. You don't even have to install Python! The above command takes care of that (thanks to uv). It performs the following tasks for you:

  • Discovering an installed Python version or downloading one on the fly to satisfy the Python version requirement defined in pyproject.toml.
  • Creating a virtual environment.
  • Installing all needed dependencies.
  • Formatting and linting your code with ruff.
  • Static type analysis with MyPy.
  • Checking for security issues with Bandit.
  • Running tests with Pytest and evaluating test coverage with Coverage.py
  • Generating documentation with Sphinx and markdown support from MySt.
  • Checking for undocumented code (built into package.py).
  • Generating a single, beautiful report for all of the above with Pico.css.
  • Generate a cov.xml file so that your IDE can visualize what lines are (not) covered. For this, you can use tools like Coverage Gutters for VSCode.
  • Building wheel files and incrementing the version number according to calendar versioning.
  • Generating badges with the most important metrics for your repository like the ones shown above using shields.io
  • Removing temporary files and folders.

Specialized Commands

Report Only - Generate the report without building the package:

uv run package.py report

Documentation Only - Generate the documentation without building the package or generating a report:

uv run package.py doc

Remove Generated Files - Remove all generated files and folders including the wheel files, documentation, and report:

uv run package.py remove

Get Help - If you want to see all available commands and options, run:

uv run package.py --help

Example Report

The package.py tool that comes with the template can generate a single, beautiful report that summarizes the results of the above-mentioned tools. Want an example? Have a look at the following, problematic code:

import hashlib
import subprocess

from django.db.models import Model


def getHash(password: str):
    """
    This is an example function for encrypting passwords.

    Args:
        password: The password to be encrypted.
    """

    return hashlib.md5(str(password).encode("utf-8"))


print(getHash(12345))

In this example, the code is stored in src/bad_example.py. If you run python package.py build you will get the report. Have a look!

License

The package is distributed under Apache License 2.0. You can use it for anything you want! Attribution would be nice, but you do not have to.

About

Maximum coding convenience from day one.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •