Python Development Workflow

What is Python Development Workflow

There are a lots of common process in a Python project development life cycle, for instances:

  1. create / remove dev virtual environment

  2. install dependencies

  3. unit test, code coverage test, matrix test

  4. build document, preview document

  5. build and publish to PyPI.

These common processes natively are just combination of CLI command. You may need to resolve some directory or file path issue, and run different commands conditionally. pygitrepo simplified those process, and provide a consistent development experience for all developer.

1. Display useful information

Display important information you need to know in this workflow.

pgr info

2. Create / Remove virtual environment

Create virtual environment. It locate at ${HOME}/venvs/python/${PYTHON_VERSION}/${PROJECT_NAME}_venv, example ${HOME}/venvs/python/3.8.11/pygitrepo_venv. We try to isolate the venv dir from GitHub repository dir, avoid committing to the git. dir_venv().

pgr venv-up

Remove virtual environment. Remove the venv folder.

pgr venv-remove

3. Install Dependencies

Install dependencies and the python package you are developing itself to virtual environment, if force to uninstall existing python package, make sure it meets the definition in requirements.txt file.

pgr pip-dev-install

Remove the python package you are developing from virtual environment, keep other dependencies

pgr pip-uninstall

Pip Install requirements-dev.txt

pgr req-dev

Pip Install requirements-doc.txt

pgr req-doc

Pip Install requirements-test.txt

pgr req-test

4. Run Test

Run all unit test with pytest, don’t reuse any cache

pgr test # another version is ``pgr test-only``, it reuse cache.

Run code coverage test with pytest-cov, don’t reuse any cache

pgr cov # another version is ``pgr cov-only``, it reuse cache.

Run matrix test with tox, don’t reuse any cache

pgr tox # another version is ``pgr tox-only``, it reuse cache.

5. Normalize your Python Code Style

Normalize your Python Code Style in your python source code dir and tests dir

pgr pep8

6. Build and Publish Documents

Build docs on local with sphinx-doc

pgr build-doc # another version is ``pgr build-doc-only``, it reuse cache.

Preview recently built local documents

pgr view-doc

Remove recently built doc

pgr clean-doc

Deploy recently built docs as versioned doc to AWS S3

pgr deploy-doc-to-versioned

Deploy recently built docs as latest doc to AWS S3

pgr deploy-doc-to-latest

Deploy recently built docs as versioned doc and also latest doc to AWS S3

pgr deploy-doc

7. Publish to PyPI

Publish current version to PyPI

pgr publish

Summary

All Done.