-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplugin.py
More file actions
88 lines (70 loc) · 3.41 KB
/
plugin.py
File metadata and controls
88 lines (70 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from __future__ import annotations
import logging
import os
import typing as t
from dataclasses import fields
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
from .structs import HatchCppBuildConfig, HatchCppBuildPlan, HatchCppLibrary, HatchCppPlatform
__all__ = ("HatchCppBuildHook",)
class HatchCppBuildHook(BuildHookInterface[HatchCppBuildConfig]):
"""The hatch-cpp build hook."""
PLUGIN_NAME = "hatch-cpp"
_logger = logging.getLogger(__name__)
def initialize(self, version: str, _: dict[str, t.Any]) -> None:
"""Initialize the plugin."""
self._logger.info("Running hatch-cpp")
if self.target_name != "wheel":
self._logger.info("ignoring target name %s", self.target_name)
return
if os.getenv("SKIP_HATCH_CPP"):
self._logger.info("Skipping the build hook since SKIP_HATCH_CPP was set")
return
kwargs = {k.replace("-", "_"): v if not isinstance(v, bool) else str(v) for k, v in self.config.items()}
available_fields = [f.name for f in fields(HatchCppBuildConfig)]
for key in list(kwargs):
if key not in available_fields:
del kwargs[key]
config = HatchCppBuildConfig(**kwargs)
library_kwargs = [
{k.replace("-", "_"): v if not isinstance(v, bool) else str(v) for k, v in library_kwargs.items()} for library_kwargs in config.libraries
]
libraries = [HatchCppLibrary(**library_kwargs) for library_kwargs in library_kwargs]
platform = HatchCppPlatform.default()
if config.toolchain == "raw":
build_plan = HatchCppBuildPlan(libraries=libraries, platform=platform)
build_plan.generate()
if config.verbose:
for command in build_plan.commands:
self._logger.info(command)
build_plan.execute()
# build_kwargs = config.build_kwargs
# if version == "editable":
# build_kwargs = config.editable_build_kwargs or build_kwargs
# should_skip_build = False
# if not config.build_function:
# log.warning("No build function found")
# should_skip_build = True
# elif config.skip_if_exists and version == "standard":
# should_skip_build = should_skip(config.skip_if_exists)
# if should_skip_build:
# log.info("Skip-if-exists file(s) found")
# # Get build function and call it with normalized parameter names.
# if not should_skip_build and config.build_function:
# build_func = get_build_func(config.build_function)
# build_kwargs = normalize_kwargs(build_kwargs)
# log.info("Building with %s", config.build_function)
# log.info("With kwargs: %s", build_kwargs)
# try:
# build_func(self.target_name, version, **build_kwargs)
# except Exception as e:
# if version == "editable" and config.optional_editable_build.lower() == "true":
# warnings.warn(f"Encountered build error:\n{e}", stacklevel=2)
# else:
# raise e
# else:
# log.info("Skipping build")
# # Ensure targets in distributable dists.
# if version == "standard":
# ensure_targets(config.ensured_targets)
self._logger.info("Finished running hatch-cpp")
return