-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplugin.py
More file actions
82 lines (62 loc) · 2.72 KB
/
plugin.py
File metadata and controls
82 lines (62 loc) · 2.72 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
from __future__ import annotations
import logging
import os
import platform as sysplatform
import sys
import typing as t
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
from .structs import HatchCppBuildConfig, HatchCppBuildPlan
from .utils import import_string
__all__ = ("HatchCppBuildHook",)
class HatchCppBuildHook(BuildHookInterface[HatchCppBuildConfig]):
"""The hatch-cpp build hook."""
PLUGIN_NAME = "hatch-cpp"
_logger = logging.getLogger(__name__)
def initialize(self, version: str, build_data: dict[str, t.Any]) -> None:
"""Initialize the plugin."""
# Log some basic information
self._logger.info("Initializing hatch-cpp plugin version %s", version)
self._logger.info("Running hatch-cpp")
# Only run if creating wheel
# TODO: Add support for specify sdist-plan
if self.target_name != "wheel":
self._logger.info("ignoring target name %s", self.target_name)
return
build_data["pure_python"] = False
machine = sysplatform.machine()
version_major = sys.version_info.major
version_minor = sys.version_info.minor
# TODO abi3
if "darwin" in sys.platform:
os_name = "macosx_11_0"
elif "linux" in sys.platform:
os_name = "linux"
else:
os_name = "win"
build_data["tag"] = f"cp{version_major}{version_minor}-cp{version_major}{version_minor}-{os_name}_{machine}"
# Skip if SKIP_HATCH_CPP is set
# TODO: Support CLI once https://github.com/pypa/hatch/pull/1743
if os.getenv("SKIP_HATCH_CPP"):
self._logger.info("Skipping the build hook since SKIP_HATCH_CPP was set")
return
# Get build config class or use default
build_config_class = import_string(self.config["build-config-class"]) if "build-config-class" in self.config else HatchCppBuildConfig
# Instantiate build config
config = build_config_class(**self.config)
# Grab libraries and platform
libraries = config.libraries
platform = config.platform
# Get build plan class or use default
build_plan_class = import_string(self.config["build-plan-class"]) if "build-plan-class" in self.config else HatchCppBuildPlan
# Instantiate builder
build_plan = build_plan_class(libraries=libraries, platform=platform)
# Generate commands
build_plan.generate()
# Log commands if in verbose mode
if config.verbose:
for command in build_plan.commands:
self._logger.warning(command)
# Execute build plan
build_plan.execute()
# Perform any cleanup actions
build_plan.cleanup()