Metadata-Version: 2.4
Name: hatch-build
Version: 0.5.0
Summary: A minimal CLI wrapper around hatchling build
Project-URL: Repository, https://github.com/python-project-templates/hatch-build
Project-URL: Homepage, https://github.com/python-project-templates/hatch-build
Author-email: the hatch-build authors <t.paine154@gmail.com>
License: Apache-2.0
License-File: LICENSE
Keywords: build,hatch,packaging
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Python: >=3.10
Requires-Dist: hatchling<1.28,>=1.14.1
Requires-Dist: p2a<0.2,>=0.1.1
Requires-Dist: pkn<0.4,>=0.3
Provides-Extra: develop
Requires-Dist: build; extra == 'develop'
Requires-Dist: bump-my-version; extra == 'develop'
Requires-Dist: check-manifest; extra == 'develop'
Requires-Dist: codespell<2.5,>=2.4; extra == 'develop'
Requires-Dist: hatchling; extra == 'develop'
Requires-Dist: mdformat-tables>=1; extra == 'develop'
Requires-Dist: mdformat<1.1,>=0.7.22; extra == 'develop'
Requires-Dist: pydantic<3,>=2; extra == 'develop'
Requires-Dist: pytest; extra == 'develop'
Requires-Dist: pytest-cov; extra == 'develop'
Requires-Dist: ruff<0.15,>=0.9; extra == 'develop'
Requires-Dist: twine; extra == 'develop'
Requires-Dist: uv; extra == 'develop'
Requires-Dist: wheel; extra == 'develop'
Description-Content-Type: text/markdown

# hatch build

A minimal CLI wrapper around hatchling build

[![Build Status](https://github.com/python-project-templates/hatch-build/actions/workflows/build.yaml/badge.svg?branch=main&event=push)](https://github.com/python-project-templates/hatch-build/actions/workflows/build.yaml)
[![codecov](https://codecov.io/gh/python-project-templates/hatch-build/branch/main/graph/badge.svg)](https://codecov.io/gh/python-project-templates/hatch-build)
[![License](https://img.shields.io/github/license/python-project-templates/hatch-build)](https://github.com/python-project-templates/hatch-build)
[![PyPI](https://img.shields.io/pypi/v/hatch-build.svg)](https://pypi.python.org/pypi/hatch-build)

## Overview

This library provides a minimal CLI `hatch-build`, equivalent to [`hatchling build`](https://hatch.pypa.io/latest/) except for [the enablement of passthrough arguments](https://github.com/pypa/hatch/pull/1743).

```bash
hatch-build -- --my-custom-plugin-arg
```

As a convenience, we provide an `argparse` wrapper to extract the extra args:

```python
from hatch_build import parse_extra_args

args, extras = parse_extra_args(my_argparse_parser)
```

### Configuration

If you manage your hatch plugin config as a pydantic model, a function is provided to automatically expose fields as command line arguments.

```python
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
from pydantic import BaseModel


from hatch_build import parse_extra_args_model


class MyPluginConfig(BaseModel, validate_assignment=True):
    extra_arg: bool = False
    extra_arg_with_value: str = "default"
    extra_arg_literal: Literal["a", "b", "c"] = "a"

class MyHatchPlugin(BuildHookInterface[MyPluginConfig]):
    PLUGIN_NAME = "my-hatch-plugin"

    def initialize(self, version: str, build_data: dict[str, Any]) -> None:
        my_config_model = MyPluginConfig(**self.config)
        parse_extra_args_model(my_config_model)

        print(f"{my_config_model.extra_arg} {my_config_model.extra_arg_with_value} {my_config_model.extra_arg_literal}")

# > hatch-build -- --extra-arg --extra-arg-with-value "test" --extra-arg-literal b
# True test b
```

> [!NOTE]
> This library was generated using [copier](https://copier.readthedocs.io/en/stable/) from the [Base Python Project Template repository](https://github.com/python-project-templates/base).
