CLI

In addition to the parsing library, pyproject-parser has a command-line interface for validating and reformatting pyproject.toml files.

New in version 0.2.0.

Attention

This CLI has the following additional requirements:

click>=7.1.2
consolekit>=1.4.1
sdjson>=0.3.1

These can be installed as follows:

python -m pip install pyproject-parser[cli]

Commands

check

Validate the given pyproject.toml file.

pyproject-parser check [OPTIONS] [PYPROJECT_FILE]

Options

-P, --parser-class <parser_class>

The class to parse the ‘pyproject.toml’ file with.

Default

pyproject_parser:PyProject

-T, --traceback

Show the complete traceback on error.

Arguments

PYPROJECT_FILE

The pyproject.toml file.

Optional argument. Default 'pyproject.toml'

The -P / --parser-class and -E / --encoder-class options must be in the form <module_name>:<object_name>. or example, pyproject_parser:PyProject, which corresponds to pyproject_parser.PyProject. The module_name may be any valid Python module, including those containing . .

reformat

Reformat the given pyproject.toml file.

pyproject-parser reformat [OPTIONS] [PYPROJECT_FILE]

Options

-E, --encoder-class <encoder_class>

The class to encode the config to TOML with.

Default

pyproject_parser:PyProjectTomlEncoder

-d, --show-diff

Show a (coloured) diff of changes.

--colour, --no-colour

Whether to use coloured output.

-P, --parser-class <parser_class>

The class to parse the ‘pyproject.toml’ file with.

Default

pyproject_parser:PyProject

-T, --traceback

Show the complete traceback on error.

Arguments

PYPROJECT_FILE

The pyproject.toml file.

Optional argument. Default 'pyproject.toml'

info

New in version 0.5.0.

Extract information from the given pyproject.toml file and print the JSON representation.

pyproject-parser info [OPTIONS] [FIELD]

Options

-r, --resolve

Resolve file key in project.readme and project.license (if present) to retrieve the content of the file.

Default

False

-i, --indent <indent>

Add indentation to the JSON output.

-f, --file <pyproject_file>

The pyproject.toml file.

-P, --parser-class <parser_class>

The class to parse the ‘pyproject.toml’ file with.

Default

pyproject_parser:PyProject

-T, --traceback

Show the complete traceback on error.

Arguments

FIELD

The field to retrieve from the pyproject.toml file.

Optional argument. Default None

Example Usage:

# Print the readme text
echo -e $(python3 -m pyproject_parser info project.readme.text -r | tr -d '"')

# Print the license filename
python3 -m pyproject_parser info project.license.file

# Get one of the project's URLs
python3 -m pyproject_parser info project.urls."Source Code"

# Install the build-system requirements with pip
pip install $(python3 -m pyproject_parser info build-system.requires | jq -r 'join(" ")')

# Dump one of the tool sub-tables
python3 -m pyproject_parser info tool.dependency-dash

As a pre-commit hook

pyproject-parser can also be used as a pre-commit hook. To do so, add the following to your .pre-commit-config.yaml file:

- repo: https://github.com/repo-helper/pyproject-parser
  rev: 0.11.0
  hooks:
  - id: check-pyproject
  - id: reformat-pyproject