Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

python-project-templates/hatch-build

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

94 Commits
94 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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[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 from the Base Python Project Template repository.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.