Skip to main content

Audit for existence and version number of cli tools.

Project description

cli_tool_audit

Verify that a list of cli tools are available. Like a requirements.txt for cli tools, but without an installer component. Intended to work with cli tools regardless to how they were installed, e.g. via pipx, npm, etc.

If 100% of your tools are installed by the same package manager that can install tools from a list with desired versions, then you don't need this tool.

Some useful scenarios:

  • Validating a developer's workstation instead of an "install everything" script.
    • Validating a CI environment and failing the build when configuration has drifted
  • Validating an end user's environment before running an app where you can't install all the dependencies for them.

How it works

You declare a list of cli commands and version ranges.

The tool will run tool --version for each tool and make best efforts to parse the result and compare it to the desired version range.

The tool then can either output a report with warnings or signal failure if something is missing, the wrong version or can't be determined.

There is no universal method for getting a version number from a CLI tool, nor is there a universal orderable version number system, so the outcome of many check may be limited to an existence check or exact version number check.

Here is an example run.

❯ cli_tool_audit audit
+--------+--------------------------+--------+----------+------------+----------+
|  Tool  |          Found           | Parsed | Desired  |   Status   | Modified |
+--------+--------------------------+--------+----------+------------+----------+
|  java  | openjdk version "17.0.6" | 17.0.6 | >=17.0.6 | Compatible | 01/18/23 |
|  make  |      GNU Make 3.81       | 3.81.0 |  >=3.81  | Compatible | 11/24/06 |
|        |       Copyright (        |        |          |            |          |
| python |      Python 3.11.1       | 3.11.1 | >=3.11.1 | Compatible | 01/13/24 |
+--------+--------------------------+--------+----------+------------+----------+

Installation

You will need to install it to your virtual environment if tools you are looking for are in your virtual environment. If all the tools are global then you can pipx install. It is on the roadmap to support a pipx install for all scenarios.

pipx install cli-tool-audit

Usage

Generate minimal config for a few tools.

cli_tool_audit freeze python java make rustc

Copy result of above into your pyproject.toml. Edit as needed, especially if you don't want snapshot versioning, which is probably too strict.

Audit the environment with the current configuration.

cli_tool_audit audit

All commands

❯ cli_tool_audit --help
usage: cli_tool_audit [-h] [-V] [--verbose] [--quiet] [--gui]
                      [--demo {pipx,venv,npm}]
                      {gui,interactive,discover,freeze,audit,single,read,create,update,delete} ...

Audit for existence and version number of cli tools.

positional arguments:
  {gui,interactive,discover,freeze,audit,single,read,create,update,delete}
                        Subcommands.
    gui                 Launch the graphical interface
    interactive         Interactively edit configuration
    discover            Scan project files for CLI tool references
    freeze              Freeze the versions of specified tools
    audit               Audit environment with current configuration
    single              Audit one tool without configuration file
    read                Read and list all tool configurations
    create              Create a new tool configuration
    update              Update an existing tool configuration
    delete              Delete a tool configuration

options:
  -h, --help            show this help message and exit
  -V, --version         Show program's version number and exit.
  --verbose             verbose output
  --quiet               suppress output
  --gui                 Launch the graphical interface
  --demo {pipx,venv,npm}
                        Demo for values of npm, pipx or venv

Note. If you use the create/update commands and specify the --version switch, it must have an equal sign.

GUI

A Tkinter-based graphical interface is included for users who prefer not to use the command line.

cli_tool_audit gui
# or
cli_tool_audit-gui

Auto-Discovery

Scan project files (Makefile, GitHub workflows, package.json, pyproject.toml, Dockerfiles, shell scripts) to find CLI tools referenced in your project:

cli_tool_audit discover

Here is how to generate a freeze, a list of current versions by snapshot, for a lis tof tools. All tools will be check with --version unless they are well known.

cli_tool_audit freeze python java make rustc

This is for programmatic usage.

import cli_tool_audit

print(cli_tool_audit.validate(file_path="pyproject.toml"))

The configuration file lists the tools you expect how hints on how detect the version.

[tool.cli-tools]
# Typical example
pipx = { version = ">=1.0.0", version_switch = "--version" }
# Restrict to specific OS
brew = { version = ">=0.1.0", if_os="darwin" }
# Pin to a snapshot of the output of `poetry --version`
poetry = {version = "Poetry (version 1.5.1)", schema="snapshot"}
# Don't attempt to run `notepad --version`, just check if it is on the path
notepad = { schema = "existence" }
# Any version.
vulture = { version = "*" }
# Supports ^ and ~ version ranges.
shellcheck = { version = "^0.8.0" }
# Uses semver's compatibility logic, which is not the same as an exact match.
rustc = { version = "1.67.0" }

See semver3 for compatibility logic for versions without operators/symbols.

See poetry for version range specifiers.

See stackoverflow for os names.

Demos

Demos will discover a bunch of executables as installed in the local virtual environment, installed by pipx or installed by npm. It will then assume that we want the current or any version and run an audit. Since we know these files already exist, the failures are centered on failing to execute, failing to guess the version switch, failure to parse the switch or the tool's version switch returning a version incompatible to what the package manager reports.

cli_tool_audit --demo=pipx --verbose
cli_tool_audit --demo=venv --verbose
cli_tool_audit --demo=npm --verbose

How does this relate to package managers, e.g. apt, pipx, npm, choco, etc.

Package managers do far more than check for the existence of a tool. They will install it, at the desired version and make sure that tools and their transitive dependencies are compatible.

What they can't do is verify what other package managers have done.

This captures your desired tools, versions and guarantees you have them by installing them.

# list everything available on one machine
pip freeze>requirements.txt
# install it on another.
pip install -r requirements.txt

This is the same thing, but for windows and .net centric apps.

choco export requirements.txt
choco install -y requirements.txt

There are similar patterns, for apt, brew, npm, and so on.

It would be foolish to try to create a package manager that supports other package managers, so features in that vein are out of scope.

Prior Art

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

cli_tool_audit-3.2.0.tar.gz (11.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cli_tool_audit-3.2.0-py3-none-any.whl (54.0 kB view details)

Uploaded Python 3

File details

Details for the file cli_tool_audit-3.2.0.tar.gz.

File metadata

  • Download URL: cli_tool_audit-3.2.0.tar.gz
  • Upload date:
  • Size: 11.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cli_tool_audit-3.2.0.tar.gz
Algorithm Hash digest
SHA256 93c4c3da61f8813887343259bfa915319d2b48ca6d2a0c5c003c48577aad430c
MD5 d2c9d354054e9157a074ae9ff75109b4
BLAKE2b-256 7626a9e538a7b9faccae8eb68c0dfb5828b0d4b9b51b759e2f2cb5f404b40cee

See more details on using hashes here.

Provenance

The following attestation bundles were made for cli_tool_audit-3.2.0.tar.gz:

Publisher: publish_to_pypi.yml on matthewdeanmartin/cli_tool_audit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cli_tool_audit-3.2.0-py3-none-any.whl.

File metadata

  • Download URL: cli_tool_audit-3.2.0-py3-none-any.whl
  • Upload date:
  • Size: 54.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cli_tool_audit-3.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 588ca7a15fc42046872a0478f94e4c3bfe874a3127ee288e756e23a622d0aea1
MD5 6e2e9d663925aa7454cdc1cbc8603a0f
BLAKE2b-256 789b5e3c32618015444f0219ef3270d99fa88733b0b2cd823319b91bdead1616

See more details on using hashes here.

Provenance

The following attestation bundles were made for cli_tool_audit-3.2.0-py3-none-any.whl:

Publisher: publish_to_pypi.yml on matthewdeanmartin/cli_tool_audit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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