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 .copier-answers.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier
_commit: ebb6e1c
_commit: '4372075'
_src_path: https://github.com/python-project-templates/base.git
add_docs: false
add_extension: python
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ lint-py: ## lint python with ruff
python -m ruff format --check hatch_build

lint-docs: ## lint docs with mdformat and codespell
python -m mdformat --check README.md
python -m codespell_lib README.md
python -m mdformat --check README.md $(wildcard docs/src)
python -m codespell_lib README.md $(wildcard docs/src)

fix-py: ## autoformat python code with ruff
python -m ruff check --fix hatch_build
python -m ruff format hatch_build

fix-docs: ## autoformat docs with mdformat and codespell
python -m mdformat README.md
python -m codespell_lib --write README.md
python -m mdformat README.md $(wildcard docs/src)
python -m codespell_lib --write README.md $(wildcard docs/src)

lint: lint-py lint-docs ## run all linters
lints: lint
Expand All @@ -52,7 +52,7 @@ check-dist: ## check python sdist and wheel with check-dist
check-types: ## check python types with ty
ty check --python $$(which python)

checks: check-dist
checks: check-dist check-types

# Alias
check: checks
Expand Down
14 changes: 8 additions & 6 deletions hatch_build/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from argparse import ArgumentParser
from collections.abc import Callable
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Any, TypeVar, cast

from hatchling.cli.build import build_command
from p2a import parse_extra_args_model as base_parse_extra_args_model
Expand All @@ -13,21 +13,22 @@
"parse_extra_args",
"parse_extra_args_model",
)
_extras = None
_extras: list[str] | None = None
ModelT = TypeVar("ModelT", bound="BaseModel")


def parse_extra_args(subparser: ArgumentParser | None = None) -> list[str]:
def parse_extra_args(subparser: ArgumentParser | None = None) -> tuple[dict[str, Any], list[str]]:
if subparser is None:
subparser = ArgumentParser(prog="hatch-build-extras", allow_abbrev=False)
kwargs, extras = subparser.parse_known_args(_extras or [])
return vars(kwargs), extras


def parse_extra_args_model(model: "BaseModel"):
return base_parse_extra_args_model(model, _extras)
def parse_extra_args_model(model: ModelT) -> tuple[ModelT, list[str]]:
return cast(tuple[ModelT, list[str]], base_parse_extra_args_model(model, _extras or []))


def _hatchling_internal() -> tuple[Callable | None, dict | None, list[str]]:
def _hatchling_internal() -> tuple[Callable | None, dict | None, list[str] | None]:
parser = ArgumentParser(prog="hatch-build", allow_abbrev=False)
subparsers = parser.add_subparsers()

Expand Down Expand Up @@ -64,6 +65,7 @@ def hatchling() -> int:
command, kwargs, extras = _hatchling_internal()
if command is None:
return 1
assert kwargs is not None

# Set so plugins can reference
_extras = extras
Expand Down
3 changes: 2 additions & 1 deletion hatch_build/tests/test_cli_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class MyTopLevelModel(BaseModel, validate_assignment=True):
dict_enum_key_model_value: dict[MyEnum, SubModel] = {MyEnum.OPTION_A: SubModel()}

submodel: SubModel
submodel2: SubModel = SubModel(sub_args=84, sub_arg_with_value="predefined", sub_arg_enum=MyEnum.OPTION_B, sub_arg_literal="z")
submodel2: SubModel = SubModel(sub_arg=84, sub_arg_with_value="predefined", sub_arg_enum=MyEnum.OPTION_B, sub_arg_literal="z")
submodel3: RuntimeOptional[SubModel] = None

submodel_list_instanced: list[SubModel] = [SubModel()]
Expand Down Expand Up @@ -171,6 +171,7 @@ def test_get_arg_from_model(self):
assert model.submodel2.sub_arg_enum == MyEnum.OPTION_B
assert model.submodel2.sub_arg_literal == "z"

assert model.submodel3 is not None
assert model.submodel3.sub_arg == 300
assert model.submodel_list_instanced[0].sub_arg == 400
assert model.submodel_list_instanced[0].sub_arg_with_value == "list_value"
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ develop = [
"codespell",
"hatchling",
"mdformat",
"mdformat-frontmatter",
"mdformat-tables>=1",
"pydantic>=2,<3",
"pytest",
Expand Down Expand Up @@ -83,7 +84,7 @@ replace = 'version = "{new_version}"'
[tool.coverage.run]
branch = true
omit = [
"hatch_build/tests/integration/",
"hatch_build/tests/integration/*",
]

[tool.coverage.report]
Expand Down