Skip to main content

hatch build

A minimal CLI wrapper around hatchling build

Build Status codecov License PyPI

Overview

This library provides a minimal CLI hatch-build, equivalent to hatchling build except for the enablement of passthrough arguments.

hatch-build -- --my-custom-plugin-arg

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

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.

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):
    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

Metadata

Release files for hatch-build 0.5.1

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

Source distribution (sdist)

Source distribution for hatch-build 0.5.1
File Size Uploaded
hatch_build-0.5.1.tar.gz 10.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hatch-build 0.5.1
File Interpreter ABI Platform
hatch_build-0.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 21.3 kB

Release files / hatch_build-0.5.1.tar.gz

Download URL hatch_build-0.5.1.tar.gz
Size 10.4 kB
Tags Source
SHA-256 checksum
How to use checksums
a6b1628d6483a5728ffc8abde4fd083cc8a2f91ccf939787df5635b7ed33f3bb
BLAKE2b-256 checksum
How to use checksums
0373463fe1c61e59aa3c34c4eb222a772a9d5baeec3eb45b51124a417e58d99e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.15

Release files / hatch_build-0.5.1-py3-none-any.whl

Download URL hatch_build-0.5.1-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5d72df4a26f49551a2b85272e092f91a844ff318bab9cee8fd678b408b168def
BLAKE2b-256 checksum
How to use checksums
e037a70af24e5c21f8cc01f2908f68ef4c2ecf81047639a44649db14eedede37
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.15

Release history Release notifications | RSS feed

This release

0.5.1 This release

2 release files

0.5.0

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.0

1 release file

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