Metadata-Version: 2.1
Name: pytoolconfig
Version: 1.3.1
Summary: Python tool configuration
Author-Email: bageljr <bageljr897@protonmail.com>
License: LGPL-3.0-or-later
Project-URL: Homepage, https://github.com/bageljrkhanofemus/pytoolconfig
Requires-Python: >=3.10
Requires-Dist: tomli>=2.0.1; python_version < "3.11"
Requires-Dist: packaging>=23.2
Provides-Extra: validation
Requires-Dist: pydantic>=2.5.3; extra == "validation"
Provides-Extra: global
Requires-Dist: platformdirs>=3.11.0; extra == "global"
Provides-Extra: doc
Requires-Dist: tabulate>=0.9.0; extra == "doc"
Requires-Dist: sphinx>=7.1.2; extra == "doc"
Provides-Extra: gendocs
Requires-Dist: sphinx>=7.1.2; extra == "gendocs"
Requires-Dist: sphinx-autodoc-typehints>=1.25.2; extra == "gendocs"
Requires-Dist: sphinx-rtd-theme>=2.0.0; extra == "gendocs"
Requires-Dist: pytoolconfig[doc]; extra == "gendocs"
Description-Content-Type: text/markdown

# Pytoolconfig

**Py**thon **Tool** **Config**uration

Pytoolconfig manages the configuration of Python tools, such as rope. It
reads the settings of a tool from the `[tool.<name>]` table of
`pyproject.toml` and maps them onto a dataclass.

See the [documentation](https://pytoolconfig.readthedocs.io/en/latest/) for
details.

## Features

- Configuration from `pyproject.toml`, with optional custom sources such as
  `setup.cfg` or other INI files.
- Optional global configuration from `pytool.toml` in the user configuration
  directory (requires `platformdirs`).
- Command line overrides through `argparse`.
- Universal settings shared by all tools, such as the supported Python
  versions read from `requires-python`.
- Documentation of the configuration options for Sphinx.

## Requirements

Python 3.10 or later.

## Usage

```python
import sys
from argparse import ArgumentParser
from pathlib import Path

from pytoolconfig import PyToolConfig, UniversalKey, dataclass, field


@dataclass
class MyToolConfig:
    verbose: bool = field(
        default=False,
        description="Print more output",
        command_line=("--verbose",),
    )
    min_py: tuple[int, ...] | None = field(
        default=None,
        description="Oldest supported Python version",
        universal_config=UniversalKey.min_py_version,
    )


config = PyToolConfig(
    "mytool",
    Path.cwd(),
    MyToolConfig,
    arg_parser=ArgumentParser(),
    global_config=True,
).parse(sys.argv[1:])
```

With this `pyproject.toml`, `config.verbose` is `True` and `config.min_py`
is `(3, 10)`; running the tool with `--verbose false` overrides `verbose`:

```toml
[project]
requires-python = ">=3.10"

[tool.mytool]
verbose = true
```

## Development

Run `pdm install --dev -G :all` to set up the development environment and
`pdm run pytest` to run the tests.

## Alternatives

[Maison](https://dbatten5.github.io/maison/) is a similar library.
