Skip to main content

Python Development CLI

Project description

PIB CLI

A batteries included make style CLI for python projects in git repositories.

Project Documentation

Master Branch

pib_cli-automation

Production Branch

pib_cli-automation

Documentation Builds

Documentation Status

Supported Python Versions

Tested to work with the following Python versions:

  • Python 3.7
  • Python 3.8
  • Python 3.9
  • Python 3.10

Installation

To install, simply use:

  • pip install pib_cli
  • pip install pib_cli[docs] (Adds Sphinx support.)
  • pip install pib_cli[docstrings] (Adds pydocstyle support.)
  • pip install pib_cli[types] (Adds mypy support.)

Usage

  • The CLI itself is launched with the dev command.
  • Try dev --help for details.

With Cookiecutter

pib_cli is also baked into this Cookie Cutter template:

License

MPL-2

Included Packages

As it's batteries included, pib_cli ships with a slightly opinionated list of popular development packages. You can customize the exact mix by specifying one or more extras when installing the package.

Core installed packages

package Description
bandit Finds common security issues
commitizen Standardizes commit messages
isort Sorts imports
pre-commit Pre-commit hook manager
pylint Static code analysis
pytest Testing with Python
pytest-cov Coverage support for pytest
pytest-pylint Pylint support for pytest
safety Dependency vulnerability scanning
wheel Package distribution tools
yamllint Lint YAML configuration files
yapf Customizable code formatting

Installed and required by pib_cli

package Description
click Command line interface toolkit
jsonschema JSON Schema validation for Python
GitPython Interact with Git repositories
PyYAML YAML parser and emitter for Python
  • pip install pib_cli to install only these dependencies.
  • These become indirect development dependencies of YOUR project, so it's good to keep that in mind.

'docs' extras

package Description
darglint Sphinx style guide enforcement
sphinx Python documentation generator
sphinx-autopackagesummary Template nested module content
sphinx_rtd_theme The Read the Docs Sphinx theme
  • pip install pib_cli[docs] to add these dependencies to the core installation.

'docstrings' extras

package Description
pydocstyle PEP 257 enforcement
  • pip install[docstrings] to add these dependencies to the core installation.

'types' extras

package Description
mypy Static type checker
  • pip install pib_cli[types] to add these dependencies to the core installation.

'pib_docs' extras

package Description
sphinx Python documentation generator
sphinx-autopackagesummary Templates nested module content
sphinx-click Generates CLI documentation
sphinx-intl Generates documentation translations
sphinx-jsonschema Generates JSON schema documentation
sphinx_rtd_theme The Read the Docs Sphinx theme
  • pip install pib_cli[pib_docs] to add these dependencies to the core installation.
  • These extras exist only to support building pib_cli documentation- they aren't meant to be consumed by user projects.

Installing multiple extras

This is straightforward to do:

  • pip install pib_cli[docs,docstrings,types]

Customizing the Command Line Interface

The most powerful feature of pib_cli is its ability to customize how it interacts with the packages it brings to your project. In this way it's very similar to the standard Linux make command- with the notable difference being that pib_cli is packaged with a suite of Python libraries.

The CLI configuration file is in YAML format, and conforms to this set of JSON schemas.

Creating a '.pib.yml' file

The .pib.yml file is where you can take control, and customize pib_cli behaviour to suit your particular needs. This file should adhere to the specification detailed above- read on for further detail.

The top level of your .pib.yml file should include metadata information. This metadata is used to tell pib_cli where to find your project's codebase and any documentation (Sphinx) definitions.

metadata:
  project_name: "Tell pib_cli the folder your codebase is in."
  documentation_root: "Tell pib_cli where to find your documentation definitions."
cli_definition:
  - [A YAML array of cli command definitions, which are detailed in the next section].
  • The cli_definition section is mandatory, and pib_cli will throw an error if it's missing.
  • The metadata itself though is actually optional, and can also be declared using environment variables.

Understanding pib_cli metadata

Metadata tells pib_cli where to find your project's files, so it's important to set these values appropriately:

  • project_name is your project's name from a Python perspective. It's the top level folder (inside your git repository) that houses your codebase, such that from <project_name> import * would be accessing your codebase.
  • documentation_root is a relative path from your repository's root to a folder containing a Sphinx Makefile. This is purely a convenience definition for any documentation related commands.

Environment variables and pib_cli

You may also define your project's metadata by setting environment variables. This would allow you to reuse the same CLI configuration for multiple projects:

  • project_name can also be defined by PIB_PROJECT_NAME environment variable
  • documentation_root can also be defined by the PIB_DOCUMENTATION_ROOT environment variable

When configuration AND environment variables exist, pib_cli will prefer to use environment variable values.

Environment variables and pib_cli commands

Regardless of whether you have used configuration or environment variables, when your CLI commands are executed, the environment variables will be available in the shell:

  • PIB_PROJECT_NAME will always be defined and accessible from inside the shell
  • PIB_DOCUMENTATION_ROOT will always be defined and accessible from inside the shell

Adding a CLI definition to a '.pib.yml' file

The cli_definition YAML key, should contain a list of definitions for CLI commands you wish to use.

Each command should adhere to this format (and you can have many commands for whatever tasks you need to perform):

    - name: "command-name"
      description: "A description of the command."
      container_only: false # Optional restriction of the command to a PIB container
      path: "repo_root"
      commands:
        - "one or more"
        - "shell commands"
        - "each run in a discrete environment"
        - "The ${PIB_DOCUMENTATION_ROOT} environment variable is also available if you need to navigate to that folder."
        - "The ${PIB_PROJECT_NAME} environment variable is available if you need to navigate to that folder."
        - "Any extra arguments passed are stored in the ${PIB_OVERLOAD_ARGUMENTS} environment variable."
      success: "Success Message"
      failure: "Failure Message"

Notes on this configuration format:

  • container_only restricts the command to working only inside a Python-in-a-Box container environment. (Completely optional key to include, defaults to false.)
  • path must be one of:
    • repo_root (The root folder of your code repository.)
    • documentation_root (Defaults to the folder documentation, can be customized with metadata or environment variables.)
    • project_root (The project_name folder as defined with metadata or environment variables.)

Validating a '.pib.yml' file

Use pib_cli to validate new configuration files before activating them:

  • dev @pib config -c <path to your file> validate

Activating a '.pib.yml' file

To activate your configuration, use one of the following methods:

  1. You can set the environment variable PIB_CONFIG_FILE_LOCATION to the absolute path where the file is located.
  2. Or just move your new .pib.yml file to the top level folder (the repository root) of your project.

Use the command dev @pib config where to confirm it's been activated.

If a .pib.yml file cannot be found with either of these methods, then the default config will be used.

Development Guide for pib_cli

Please see the documentation here.

Environment Variable Summary

This table summarizes the environment variables that can be used with pib_cli:

Name Purpose
PIB_CONFIG_FILE_LOCATION The absolute path to the configuration file that should be used.
PIB_DOCUMENTATION_ROOT A relative path from the repository root where a Sphinx Makefile lives.
PIB_OVERLOAD_ARGUMENTS Reserved to pass arguments to customized CLI commands.
PIB_PROJECT_NAME The top level folder in the repository where the codebase is found.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pib_cli-1.2.0.tar.gz (37.0 kB view details)

Uploaded Source

Built Distribution

pib_cli-1.2.0-py3-none-any.whl (54.1 kB view details)

Uploaded Python 3

File details

Details for the file pib_cli-1.2.0.tar.gz.

File metadata

  • Download URL: pib_cli-1.2.0.tar.gz
  • Upload date:
  • Size: 37.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.7.13 Linux/5.11.0-1028-azure

File hashes

Hashes for pib_cli-1.2.0.tar.gz
Algorithm Hash digest
SHA256 bbc0a51f4847f1eb9112574ef60d9a3e43c60f1a214d0f170548f27b784aa928
MD5 10ac7a7709dbeac43bd23937e2b40e35
BLAKE2b-256 5233e092db0d9862baba9aabb6681fde3916c28c7802bdb9c62d08aa388e1451

See more details on using hashes here.

File details

Details for the file pib_cli-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: pib_cli-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 54.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.7.13 Linux/5.11.0-1028-azure

File hashes

Hashes for pib_cli-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c0b7926adb80fad211dc1c355ed56e5f0aa30cb89d35955b46eb20dab971881
MD5 5c886f25393d6791b1b2ce651bedb360
BLAKE2b-256 966f833ed03adf124d952efb45d4ecc449db19d66a1538028ef9619863fde11a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page