Skip to content

Commit d34c424

Browse files
committed
Bugfix for CLI overriding, add skip option
1 parent 0b03e02 commit d34c424

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

hatch_cpp/config.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from __future__ import annotations
22

3-
from logging import getLogger
43
from os import system as system_call
54
from pathlib import Path
65
from typing import List, Optional
76

7+
from pkn import getSimpleLogger
88
from pydantic import BaseModel, Field, model_validator
99

1010
from .toolchains import BuildType, HatchCppCmakeConfiguration, HatchCppLibrary, HatchCppPlatform, HatchCppVcpkgConfiguration, Toolchain
@@ -15,13 +15,14 @@
1515
)
1616

1717

18-
_log = getLogger(__name__)
18+
log = getSimpleLogger("hatch_cpp")
1919

2020

2121
class HatchCppBuildConfig(BaseModel):
2222
"""Build config values for Hatch C++ Builder."""
2323

2424
verbose: Optional[bool] = Field(default=False)
25+
skip: Optional[bool] = Field(default=False)
2526
name: Optional[str] = Field(default=None)
2627
libraries: List[HatchCppLibrary] = Field(default_factory=list)
2728
cmake: Optional[HatchCppCmakeConfiguration] = Field(default=None)
@@ -76,7 +77,7 @@ def generate(self):
7677

7778
if "vanilla" in self._active_toolchains:
7879
if "vcpkg" in self._active_toolchains:
79-
_log.warning("vcpkg toolchain is active; ensure that your compiler is configured to use vcpkg includes and libs.")
80+
log.warning("vcpkg toolchain is active; ensure that your compiler is configured to use vcpkg includes and libs.")
8081

8182
for library in self.libraries:
8283
compile_flags = self.platform.get_compile_flags(library, self.build_type)

hatch_cpp/plugin.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from __future__ import annotations
22

3-
from logging import getLogger
4-
from os import getenv
53
from pathlib import Path
64
from platform import machine as platform_machine
75
from sys import platform as sys_platform, version_info
@@ -10,7 +8,7 @@
108
from hatch_build import parse_extra_args_model
119
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
1210

13-
from .config import HatchCppBuildConfig, HatchCppBuildPlan
11+
from .config import HatchCppBuildConfig, HatchCppBuildPlan, log
1412
from .utils import import_string
1513

1614
__all__ = ("HatchCppBuildHook",)
@@ -20,7 +18,7 @@ class HatchCppBuildHook(BuildHookInterface[HatchCppBuildConfig]):
2018
"""The hatch-cpp build hook."""
2119

2220
PLUGIN_NAME = "hatch-cpp"
23-
_logger = getLogger(__name__)
21+
_logger = log
2422

2523
def initialize(self, version: str, build_data: dict[str, Any]) -> None:
2624
"""Initialize the plugin."""
@@ -35,12 +33,6 @@ def initialize(self, version: str, build_data: dict[str, Any]) -> None:
3533
self._logger.info("ignoring target name %s", self.target_name)
3634
return
3735

38-
# Skip if SKIP_HATCH_CPP is set
39-
# TODO: Support CLI once https://github.com/pypa/hatch/pull/1743
40-
if getenv("SKIP_HATCH_CPP"):
41-
self._logger.info("Skipping the build hook since SKIP_HATCH_CPP was set")
42-
return
43-
4436
# Get build config class or use default
4537
build_config_class = import_string(self.config["build-config-class"]) if "build-config-class" in self.config else HatchCppBuildConfig
4638

@@ -60,10 +52,14 @@ def initialize(self, version: str, build_data: dict[str, Any]) -> None:
6052
build_plan.generate()
6153

6254
# Log commands if in verbose mode
63-
if config.verbose:
55+
if build_plan.verbose:
6456
for command in build_plan.commands:
6557
self._logger.warning(command)
6658

59+
if build_plan.skip:
60+
self._logger.warning("Skipping build")
61+
return
62+
6763
# Execute build plan
6864
build_plan.execute()
6965

@@ -114,4 +110,4 @@ def initialize(self, version: str, build_data: dict[str, Any]) -> None:
114110
build_data["force_include"][str(path)] = str(path)
115111

116112
for path in build_data["force_include"]:
117-
self._logger.warning(f"Force include: {path}")
113+
self._logger.info(f"Force include: {path}")

0 commit comments

Comments
 (0)