Skip to main content

Lemming

Hits-of-Code Codacy Badge CodeFactor Grade Code style: black semantic-release GitHub PyPI PyPI - Python Version PyPI - Format

Lemming is a tool for formatting and linting your code. With Lemming, everyone will use the same formatters and linters, with the same version.

Installation

Use the package manager pip to install Lemming. Need more help?

pip install python-lemming

Requirements

Lemming requires Python 3.7

Usage

1. Create the config

Lemming's config lives in these places:

  • in the .lemming.toml file
  • in the pyproject.toml file

Please note, that there must be a lemming or tool.lemming key in the config file.

The config looks like this:

fail_fast = false  # OPTIONAL, whether or not immediately quit in case of an error

[[formatters]]
name = "some_example"  # OPTIONAL, used to identify this formatter. Defaults to packages[0]
packages = ["example"]  # REQUIRED, the package(s) to install with pip (might include versions with "==x.y.z")
format_command = "{pyexe} -m example {path}"  # REQUIRED, the command to run to format the code ({pyexe} will be replaced with the python executable, {path} with the path passed to Lemming (usually the current working directory: "."))
check_command = "{pyexe} -m example --check {path}"  # OPTIONAL, the command to run to check the code (stuff will be replaced just like in format_command)
allow_nonzero_on_format = true  # OPTIONAL, if true it is allowed for the format_command to return a non-zero exit status

[[linters]]
name = "other_example"  # OPTIONAL, used to identify this linter. Defaults to packages[0]
packages = ["example"]  # REQUIRED, same as for formatters
command = "{pyexe} -m example {path}"  # REQUIRED, the command to run to lint the code (stuff will be replaced just like in format_command)
run_first = true  # OPTIONAL, if true this linter will be ran BEFORE formatters, and other linters. Defaults to false.

2. Run Lemming

After installing Lemming, run

lemming {format,check} .

If you choose format, the format_commands will be ran, but if you choose check, the check_commands will be ran. Linters will be ran in both cases.

You can also use Lemming as a GitHub workflow, like this.

CLI usage

 Usage: lemming [OPTIONS] COMMAND [ARGS]...

╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --version             -V                                       Print the version of Lemming and exit.                                                              │
│ --install-completion          [bash|zsh|fish|powershell|pwsh]  Install completion for the specified shell. [default: None]                                         │
│ --show-completion             [bash|zsh|fish|powershell|pwsh]  Show completion for the specified shell, to copy it or customize the installation. [default: None]  │
│ --help                                                         Show this message and exit.                                                                         │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ check                        Check the formatting of your code and run linters.                                                                                    │
│ format                       Format your code and run linters.                                                                                                     │
│ pre-commit                   Install a pre-commit git hook which will run Lemming.                                                                                 │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Check

 Usage: lemming check [OPTIONS] PATHS...

 Check the formatting of your code and run linters.

╭─ Arguments ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ *    paths      PATHS...  [default: None] [required]                                                                            │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Options ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --quiet-commands,--qc                If passed the output of the formatters and linters will be hidden.                         │
│ --quiet-pip,--qp                     If passed the output of pip will be hidden.                                                │
│ --verbose              -v            When passed the logger's threshold will be decreased by 10 (may be passed multiple times)  │
│ --quiet                -q            When passed the logger's threshold will be increased by 10 (may be passed multiple times)  │
│ --config                       FILE  The config file to use [default: None]                                                     │
│ --only                         TEXT  Only run these formatters/linters (may be passed multiple times) [default: None]           │
│ --help                               Show this message and exit.                                                                │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Format

Usage: lemming format [OPTIONS] PATHS...

 Format your code and run linters.

╭─ Arguments ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ *    paths      PATHS...  [default: None] [required]                                                                            │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Options ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --quiet-commands,--qc                If passed the output of the formatters and linters will be hidden.                         │
│ --quiet-pip,--qp                     If passed the output of pip will be hidden.                                                │
│ --verbose              -v            When passed the logger's threshold will be decreased by 10 (may be passed multiple times)  │
│ --quiet                -q            When passed the logger's threshold will be increased by 10 (may be passed multiple times)  │
│ --config                       FILE  The config file to use. [default: None]                                                    │
│ --only                         TEXT  Only run these formatters/linters (may be passed multiple times) [default: None]           │
│ --help                               Show this message and exit.                                                                │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Pre-commit

 Usage: lemming pre-commit [OPTIONS]

 Install a pre-commit git hook which will run Lemming.

╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --git-repository          DIRECTORY  The root directory of the git repository to use. Defaults to the current working directory. [default: (dynamic)]      │
│ --verbose         -v                 When passed the logger's threshold will be decreased by 10 (may be passed multiple times)                             │
│ --quiet           -q                 When passed the logger's threshold will be increased by 10 (may be passed multiple times)                             │
│ --help                               Show this message and exit.                                                                                           │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Support

Questions should be asked in the Discussions tab.

Feature requests and bug reports should be reported in the Issues tab.

Security vulnerabilities should be reported as described in our Security policy (in the SECURITY.md file).

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to add entries to the changelog.

For more information, please read the contributing guidelines.

Authors and acknowledgments

A list of nice people who helped this project can be found in the CONTRIBUTORS file.

License

GNU GPLv3+

Metadata

Release files for python-lemming 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-lemming 0.7.0
File Size Uploaded
python_lemming-0.7.0.tar.gz 25.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-lemming 0.7.0
File Interpreter ABI Platform
python_lemming-0.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 49.5 kB

Release files / python_lemming-0.7.0.tar.gz

Download URL python_lemming-0.7.0.tar.gz
Size 25.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0099e216d1b1b93ce0a212ded7cccd662bb2cc7f93751a4d5294631f42bd3583
BLAKE2b-256 checksum
How to use checksums
f537dd8cfa1ecb9ae4051d47f2d80db136874ec3564065fa1a38842cb1b7fb6e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / python_lemming-0.7.0-py3-none-any.whl

Download URL python_lemming-0.7.0-py3-none-any.whl
Size 24.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
566cfe84419aeeb7df4dcca97a547b8e587076e7b3595ffa2c4d0b401fda9786
BLAKE2b-256 checksum
How to use checksums
7c71217a6a78c3c7003af6c5a2ef0ec21c07cae5b24039d846389912c9da5f86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page