Skip to content

Instantly share code, notes, and snippets.

@decatur
Last active July 26, 2021 17:54
Show Gist options
  • Save decatur/4218c17a95011a2b6bf5784ee2d38cdb to your computer and use it in GitHub Desktop.
Save decatur/4218c17a95011a2b6bf5784ee2d38cdb to your computer and use it in GitHub Desktop.
A definition of what constitutes a Python Application

What is a Python Application

A Python Application describes required packages, entry point and constraints for the operation and development process.

Operation

  1. An entry point, e.g. my_app.my_module:App
  2. Constraints for required packages AppR, e.g. {my_app=1.2.3, my_util=0.1.2, pandas=1.2.5, ...}

Development

  1. A set of development packages Dev = {my_app, pytest, ...}
  2. [Optional] Constraints for required development packages DevR = {my_app=1.2.3, pytest=6.1.2, nose=3.2.1, ...}
    ┌───────────────────────┐     ┌──────────────────────┐
    │                       │     │                      │
    │          App          │     │       Dev            │
    │                       │     │                      │
    │  my_app.my_module:App │     │ my_app, pytest, ...  │
    │      constraints      │     │     constraints      │
    │                       │     │                      │
    └───────────┬───────────┘     └──────────┬───────────┘
                │                            │
                │                            │
                │ generate                   │ generate
                │                            │
                │                            │
                │                            │
    ┌───────────▼───────────┐     ┌──────────▼───────────┐
    │                       │     │                      │
    │        AppR           │     │        DevR          │
    │                       │     │                      │
    │  App Requirements     │     │  Dev Requirements    │
    │                       │     │                      │
    └───────────────────────┘     └──────────────────────┘

Process Requirements

  1. From App definition (1)-(2), generate a set of fixed required packages AppR.
  2. Being able to install set AppR incrementally.
  3. From Dev definition (1)-(2), generate a set of fixed required packages DevR.
  4. Being able to install set DevR incrementally.

Design Decision

  • Do not devops with a git deploy workflow.
  • Use pip-compile to resolve dependencies and generate an initial requirements.txt. Version control and curate this file: It is your App!
  • Use flit to build (and deploy) packages.
  • When building packages, inject the build version into pyproject.toml from the current git tag.

Notes

@decatur
Copy link
Author

decatur commented Jul 2, 2021

👍pip-compile both has dependency resolution without install and supports layered requirements workflow.
👎pip-sync only works in the context of a venv.

@decatur
Copy link
Author

decatur commented Jul 2, 2021

poetry has issues in cooperate firewall settings...

@decatur
Copy link
Author

decatur commented Jul 26, 2021

flit currently seems to be the best bet for building wheels: modern, strictly static config, and it supports PEP 621 -- Storing project metadata in pyproject.toml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment