-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
34 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,31 @@ | ||
import tomllib | ||
from pathlib import Path | ||
from typing import Any | ||
|
||
from hatchling.builders.config import BuilderConfig | ||
from hatchling.builders.hooks.plugin.interface import BuildHookInterface | ||
from hatchling.plugin import hookimpl | ||
|
||
from hatch_una import util | ||
|
||
class BuildConfig(BuilderConfig): | ||
pass | ||
|
||
|
||
class UnaHook(BuildHookInterface[BuildConfig]): | ||
class UnaBuildHook(BuildHookInterface[BuilderConfig]): | ||
PLUGIN_NAME = "una-build" | ||
|
||
def initialize(self, version: str, build_data: dict[str, Any]) -> None: | ||
print("una: Injecting internal dependencies") | ||
root = Path(self.root) | ||
with (root / "pyproject.toml").open("rb") as fp: | ||
conf = tomllib.load(fp) | ||
conf = util.load_conf(root) | ||
|
||
int_deps: dict[str, str] = conf["tool"]["una"]["libs"] | ||
found = {k: v for k, v in int_deps.items() if (root / k).exists()} | ||
found = [Path(k) for k in int_deps if (root / k).exists()] | ||
if not int_deps or not found: | ||
# should I raise here? | ||
return | ||
build_data["force_include"] = {**build_data["force_include"], **int_deps} | ||
|
||
add_pyproj = {str(f.parents[1] / util.PYPROJ): str(util.EXTRA_PYPROJ / f.name / util.PYPROJ) for f in found} | ||
build_data["force_include"] = {**build_data["force_include"], **int_deps, **add_pyproj} | ||
|
||
|
||
@hookimpl | ||
def hatch_register_build_hook(): | ||
return UnaHook | ||
def hatch_register_build_hook() -> type[UnaBuildHook]: | ||
return UnaBuildHook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import tomllib | ||
from pathlib import Path | ||
from typing import Any | ||
|
||
PYPROJ = "pyproject.toml" | ||
EXTRA_PYPROJ = Path("extra_pyproj") | ||
|
||
|
||
def load_conf(path: Path) -> dict[str, Any]: | ||
with (path / PYPROJ).open("rb") as fp: | ||
return tomllib.load(fp) |