Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hatch_build/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "0.3.1"

from .cli import parse_extra_args
from .cli import *
7 changes: 4 additions & 3 deletions hatch_build/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
__all__ = (
"hatchling",
"parse_extra_args",
"parse_extra_args_model",
)
_extras = None

Expand All @@ -20,7 +21,7 @@ def parse_extra_args(subparser: Optional[ArgumentParser] = None) -> List[str]:
return vars(kwargs), extras


def recurse_add_fields(parser: ArgumentParser, model: "BaseModel", prefix: str = ""):
def _recurse_add_fields(parser: ArgumentParser, model: "BaseModel", prefix: str = ""):
from pydantic import BaseModel

for field_name, field in model.__class__.model_fields.items():
Expand All @@ -30,7 +31,7 @@ def recurse_add_fields(parser: ArgumentParser, model: "BaseModel", prefix: str =
parser.add_argument(arg_name, action="store_true", default=field.default)
elif isinstance(field_type, Type) and issubclass(field_type, BaseModel):
# Nested model, add its fields with a prefix
recurse_add_fields(parser, getattr(model, field_name), prefix=f"{field_name}.")
_recurse_add_fields(parser, getattr(model, field_name), prefix=f"{field_name}.")
elif get_origin(field_type) in (list, List):
# TODO: if list arg is complex type, raise as not implemented for now
if get_args(field_type) and get_args(field_type)[0] not in (str, int, float, bool):
Expand Down Expand Up @@ -61,7 +62,7 @@ def parse_extra_args_model(model: "BaseModel"):
# Recursively parse fields from a pydantic model and its sub-models
# and create an argument parser to parse extra args
parser = ArgumentParser(prog="hatch-build-extras-model", allow_abbrev=False)
parser = recurse_add_fields(parser, model)
parser = _recurse_add_fields(parser, model)

# Parse the extra args and update the model
args, kwargs = parse_extra_args(parser)
Expand Down