/utilities

Common Python utilities and GitHub Actions in Lightning Ecosystem

Primary LanguagePythonApache License 2.0Apache-2.0

Lightning Utilities

UnitTests Apply checks Documentation Status pre-commit.ci status

This repository covers the following use-cases:

  1. GitHub workflows
  2. GitHub actions
  3. CLI lightning_utilities.cli
  4. General Python utilities in lightning_utilities.core

1. Reusable workflows

Usage:

name: Check schema

on: [push]

jobs:
  check-schema:
    uses: Lightning-AI/utilities/.github/workflows/check-schema.yml@main
    with:
      azure-dir: ""

See usage of other workflows in .github/workflows/ci_use-checks.yml.

2. Reusable composite actions

See available composite actions .github/actions/.

Usage:

name: Do something with cache

on: [push]

jobs:
  pytest:
    runs-on: ubuntu-20.04
    steps:
    - uses: actions/checkout@v3
    - uses: actions/setup-python@v4
      with:
        python-version: 3.9
    - uses: Lightning-AI/utilities/.github/actions/cache
      with:
        python-version: 3.9
        requires: oldest
        # requires: latest

3. CLI lightning_utilities.cli

The package provides common CLI commands.

Installation From source:
pip install https://github.com/Lightning-AI/utilities/archive/refs/heads/main.zip

From pypi:

pip install lightning_utilities[cli]

Usage:

python -m lightning_utilities.cli [group] [command]
Example for setting min versions
$ cat requirements/test.txt
coverage>=5.0
codecov>=2.1
pytest>=6.0
pytest-cov
pytest-timeout
$ python -m lightning_utilities.cli requirements set-oldest
$ cat requirements/test.txt
coverage==5.0
codecov==2.1
pytest==6.0
pytest-cov
pytest-timeout

4. General Python utilities lightning_utilities.core

Installation

From pypi:

pip install lightning_utilities

Usage:

Example for optional imports:

from lightning_utilities.core.imports import module_available

if module_available("some_package.something"):
    from some_package import something