diff --git a/incipyt/__main__.py b/incipyt/__main__.py index 2c8c9c1..2de8c6b 100644 --- a/incipyt/__main__.py +++ b/incipyt/__main__.py @@ -53,7 +53,7 @@ def choice_callback(_ctx, _param, _choice): required=True, show_default=True, default="Setuptools", - type=click.Choice(["Setuptools", "Flit", "PDM", "Poetry"], case_sensitive=False), + type=click.Choice(["Setuptools", "Flit", "Hatch", "PDM", "Poetry"], case_sensitive=False), callback=choice_callback, help="Build system to use for building wheel and source distributions.", ) diff --git a/incipyt/tools/__init__.py b/incipyt/tools/__init__.py index cee313c..6e7cbc9 100644 --- a/incipyt/tools/__init__.py +++ b/incipyt/tools/__init__.py @@ -1,6 +1,6 @@ from incipyt.tools.base import Tool from incipyt.tools.git import Git from incipyt.tools.license import License -from incipyt.tools.pep517 import PDM, Flit, Setuptools +from incipyt.tools.pep517 import PDM, Flit, Hatch, Setuptools from incipyt.tools.poetry import Poetry from incipyt.tools.venv import Venv diff --git a/incipyt/tools/pep517/__init__.py b/incipyt/tools/pep517/__init__.py index a252d2b..3a4bce0 100644 --- a/incipyt/tools/pep517/__init__.py +++ b/incipyt/tools/pep517/__init__.py @@ -1,4 +1,5 @@ from incipyt.tools.pep517.base import BuildSystem from incipyt.tools.pep517.flit import Flit +from incipyt.tools.pep517.hatch import Hatch from incipyt.tools.pep517.pdm import PDM from incipyt.tools.pep517.setuptools import Setuptools diff --git a/incipyt/tools/pep517/hatch.py b/incipyt/tools/pep517/hatch.py new file mode 100644 index 0000000..fdf36f2 --- /dev/null +++ b/incipyt/tools/pep517/hatch.py @@ -0,0 +1,36 @@ +from incipyt import project, signals +from incipyt._internal.dumpers import Toml +from incipyt.tools import pep517 + + +class Hatch(pep517.BuildSystem): + """Scripts to add Hatch to :class:`incipyt.project._Structure`.""" + + def add_to_structure(self): + """Add hatch configuration to `project.structure`. + + :file:`pyptoject.toml` + + .. code-block:: + + [build-system] + build-backend = "hatchling.build" + requires = ["hatchling>=1.3.0"] + + If this configuration cannot be populate like that, an error is raised. + + :raises RuntimeError: If a build-system is already setup in pyproject.toml. + """ + super().add_to_structure() + + pyproject = project.structure.get_config_dict(Toml("pyproject.toml")) + + if "build-system" in pyproject: + raise RuntimeError("Build system already registered.") + + pyproject["build-system"] = { + "build-backend": "hatchling.build", + "requires": ["hatchling>=1.3.0"], + } + + signals.build_dependency.emit(dep_name="hatch>=1.2.0")