Skip to content

Latest commit

 

History

History
56 lines (33 loc) · 1.99 KB

python-application-structure.md

File metadata and controls

56 lines (33 loc) · 1.99 KB

Structuring a Python application

Starter, scaffold, or boilerplate code for projects developed mainly in Python. The note was inspired by a Real Python tutorial.

Common task — capture dependencies for both tests and code:

$ pip install -r requirements.txt

LICENSE information: if no license (file?) is included with the code, the code is fully copyrighted by default in most jurisdictions. This means no one has a right to use it or copy it in any fashion! I'm using MIT License for my Python templates.

One-off script

This template is for a single-file Python program, often called a script. It works both for code with or without dependencies.

To begin, generate a new repository using python-template-oneoff template repository.

To manage dependencies, create a virtual environment.

To run the unit test suite for the script:

$ python -m unittest tests.py

Installable single package

This template steps up in complexity. It is a multi-file Python module.

  • Now there are multiple Python files, grouped into a module.
  • Now there are multiple test files. The test coverage is checked as well.
  • Another tool useful for larger programs is a linter (pyflake, pep8).

To begin, generate a new repository using python-template-single-package template repository.

To run the tests, there is a runtests.sh bash script:

  • it runs the tests;
  • it runs the test coverage tool from PyPI coverage suite;
  • it can be made to run a linter at the end, as well.

Flask

TODO this template is an example of a multi-module Python program.

Django

TODO