hatch-cpp 0.2.2__py3-none-any.whl → 0.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
hatch_cpp/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = "0.2.2"
1
+ __version__ = "0.3.0"
2
2
 
3
3
  from .config import *
4
4
  from .hooks import *
hatch_cpp/config.py CHANGED
@@ -1,10 +1,10 @@
1
1
  from __future__ import annotations
2
2
 
3
- from logging import getLogger
4
3
  from os import system as system_call
5
4
  from pathlib import Path
6
5
  from typing import List, Optional
7
6
 
7
+ from pkn import getSimpleLogger
8
8
  from pydantic import BaseModel, Field, model_validator
9
9
 
10
10
  from .toolchains import BuildType, HatchCppCmakeConfiguration, HatchCppLibrary, HatchCppPlatform, HatchCppVcpkgConfiguration, Toolchain
@@ -15,13 +15,14 @@ __all__ = (
15
15
  )
16
16
 
17
17
 
18
- _log = getLogger(__name__)
18
+ log = getSimpleLogger("hatch_cpp")
19
19
 
20
20
 
21
21
  class HatchCppBuildConfig(BaseModel):
22
22
  """Build config values for Hatch C++ Builder."""
23
23
 
24
24
  verbose: Optional[bool] = Field(default=False)
25
+ skip: Optional[bool] = Field(default=False)
25
26
  name: Optional[str] = Field(default=None)
26
27
  libraries: List[HatchCppLibrary] = Field(default_factory=list)
27
28
  cmake: Optional[HatchCppCmakeConfiguration] = Field(default=None)
@@ -76,7 +77,7 @@ class HatchCppBuildPlan(HatchCppBuildConfig):
76
77
 
77
78
  if "vanilla" in self._active_toolchains:
78
79
  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.")
80
81
 
81
82
  for library in self.libraries:
82
83
  compile_flags = self.platform.get_compile_flags(library, self.build_type)
hatch_cpp/plugin.py CHANGED
@@ -1,7 +1,5 @@
1
1
  from __future__ import annotations
2
2
 
3
- from logging import getLogger
4
- from os import getenv
5
3
  from pathlib import Path
6
4
  from platform import machine as platform_machine
7
5
  from sys import platform as sys_platform, version_info
@@ -10,7 +8,7 @@ from typing import Any
10
8
  from hatch_build import parse_extra_args_model
11
9
  from hatchling.builders.hooks.plugin.interface import BuildHookInterface
12
10
 
13
- from .config import HatchCppBuildConfig, HatchCppBuildPlan
11
+ from .config import HatchCppBuildConfig, HatchCppBuildPlan, log
14
12
  from .utils import import_string
15
13
 
16
14
  __all__ = ("HatchCppBuildHook",)
@@ -20,7 +18,7 @@ class HatchCppBuildHook(BuildHookInterface[HatchCppBuildConfig]):
20
18
  """The hatch-cpp build hook."""
21
19
 
22
20
  PLUGIN_NAME = "hatch-cpp"
23
- _logger = getLogger(__name__)
21
+ _logger = log
24
22
 
25
23
  def initialize(self, version: str, build_data: dict[str, Any]) -> None:
26
24
  """Initialize the plugin."""
@@ -35,12 +33,6 @@ class HatchCppBuildHook(BuildHookInterface[HatchCppBuildConfig]):
35
33
  self._logger.info("ignoring target name %s", self.target_name)
36
34
  return
37
35
 
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
-
44
36
  # Get build config class or use default
45
37
  build_config_class = import_string(self.config["build-config-class"]) if "build-config-class" in self.config else HatchCppBuildConfig
46
38
 
@@ -60,10 +52,14 @@ class HatchCppBuildHook(BuildHookInterface[HatchCppBuildConfig]):
60
52
  build_plan.generate()
61
53
 
62
54
  # Log commands if in verbose mode
63
- if config.verbose:
55
+ if build_plan.verbose:
64
56
  for command in build_plan.commands:
65
57
  self._logger.warning(command)
66
58
 
59
+ if build_plan.skip:
60
+ self._logger.warning("Skipping build")
61
+ return
62
+
67
63
  # Execute build plan
68
64
  build_plan.execute()
69
65
 
@@ -114,4 +110,4 @@ class HatchCppBuildHook(BuildHookInterface[HatchCppBuildConfig]):
114
110
  build_data["force_include"][str(path)] = str(path)
115
111
 
116
112
  for path in build_data["force_include"]:
117
- self._logger.warning(f"Force include: {path}")
113
+ self._logger.info(f"Force include: {path}")
@@ -96,13 +96,13 @@ class HatchCppPlatform(BaseModel):
96
96
  ld: str
97
97
  platform: Platform
98
98
  toolchain: CompilerToolchain
99
+ disable_ccache: bool = False
99
100
 
100
101
  @staticmethod
101
102
  def default() -> HatchCppPlatform:
102
- platform = environ.get("HATCH_CPP_PLATFORM", sys_platform)
103
- CC = environ.get("CC", PlatformDefaults[platform]["CC"])
104
- CXX = environ.get("CXX", PlatformDefaults[platform]["CXX"])
105
- LD = environ.get("LD", PlatformDefaults[platform]["LD"])
103
+ CC = environ.get("CC", PlatformDefaults[sys_platform]["CC"])
104
+ CXX = environ.get("CXX", PlatformDefaults[sys_platform]["CXX"])
105
+ LD = environ.get("LD", PlatformDefaults[sys_platform]["LD"])
106
106
  if "gcc" in CC and "g++" in CXX:
107
107
  toolchain = "gcc"
108
108
  elif "clang" in CC and "clang++" in CXX:
@@ -110,26 +110,34 @@ class HatchCppPlatform(BaseModel):
110
110
  elif "cl" in CC and "cl" in CXX:
111
111
  toolchain = "msvc"
112
112
  # Fallback to platform defaults
113
- elif platform == "linux":
113
+ elif sys_platform == "linux":
114
114
  toolchain = "gcc"
115
- elif platform == "darwin":
115
+ elif sys_platform == "darwin":
116
116
  toolchain = "clang"
117
- elif platform == "win32":
117
+ elif sys_platform == "win32":
118
118
  toolchain = "msvc"
119
119
  else:
120
120
  toolchain = "gcc"
121
121
 
122
- # Customizations
123
- if which("ccache") and not environ.get("HATCH_CPP_DISABLE_CCACHE"):
124
- CC = f"ccache {CC}"
125
- CXX = f"ccache {CXX}"
126
-
122
+ # TODO:
127
123
  # https://github.com/rui314/mold/issues/647
128
124
  # if which("ld.mold"):
129
125
  # LD = which("ld.mold")
130
126
  # elif which("ld.lld"):
131
127
  # LD = which("ld.lld")
132
- return HatchCppPlatform(cc=CC, cxx=CXX, ld=LD, platform=platform, toolchain=toolchain)
128
+ return HatchCppPlatform(cc=CC, cxx=CXX, ld=LD, platform=sys_platform, toolchain=toolchain)
129
+
130
+ @model_validator(mode="wrap")
131
+ @classmethod
132
+ def validate_model(cls, data, handler):
133
+ model = handler(data)
134
+ if which("ccache") and not model.disable_ccache:
135
+ if model.toolchain in ["gcc", "clang"]:
136
+ if not model.cc.startswith("ccache "):
137
+ model.cc = f"ccache {model.cc}"
138
+ if not model.cxx.startswith("ccache "):
139
+ model.cxx = f"ccache {model.cxx}"
140
+ return model
133
141
 
134
142
  @staticmethod
135
143
  def platform_for_toolchain(toolchain: CompilerToolchain) -> HatchCppPlatform:
@@ -33,6 +33,7 @@ VcpkgPlatformDefaults = {
33
33
  ("darwin", "x86_64"): "x64-osx",
34
34
  ("darwin", "arm64"): "arm64-osx",
35
35
  ("win32", "x86_64"): "x64-windows-static-md",
36
+ ("win32", "AMD64"): "x64-windows-static-md",
36
37
  ("win32", "arm64"): "arm64-windows-static-md",
37
38
  }
38
39
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hatch-cpp
3
- Version: 0.2.2
3
+ Version: 0.3.0
4
4
  Summary: Hatch plugin for C++ builds
5
5
  Project-URL: Repository, https://github.com/python-project-templates/hatch-cpp
6
6
  Project-URL: Homepage, https://github.com/python-project-templates/hatch-cpp
@@ -20,8 +20,9 @@ Classifier: Programming Language :: Python :: 3.14
20
20
  Classifier: Programming Language :: Python :: Implementation :: CPython
21
21
  Classifier: Programming Language :: Python :: Implementation :: PyPy
22
22
  Requires-Python: >=3.10
23
- Requires-Dist: hatch-build<0.6,>=0.4
23
+ Requires-Dist: hatch-build<0.6,>=0.5
24
24
  Requires-Dist: hatchling
25
+ Requires-Dist: pkn
25
26
  Requires-Dist: pydantic
26
27
  Provides-Extra: develop
27
28
  Requires-Dist: build; extra == 'develop'
@@ -32,7 +33,7 @@ Requires-Dist: hatch-build>=0.3.2; extra == 'develop'
32
33
  Requires-Dist: hatchling; extra == 'develop'
33
34
  Requires-Dist: mdformat-tables>=1; extra == 'develop'
34
35
  Requires-Dist: mdformat<1.1,>=0.7.22; extra == 'develop'
35
- Requires-Dist: nanobind<2.10.0; extra == 'develop'
36
+ Requires-Dist: nanobind<2.12.0; extra == 'develop'
36
37
  Requires-Dist: pybind11; extra == 'develop'
37
38
  Requires-Dist: pytest; extra == 'develop'
38
39
  Requires-Dist: pytest-cov; extra == 'develop'
@@ -142,17 +143,89 @@ hatch-build \
142
143
  --libraries.0.include-dirs cpp,another-dir
143
144
  ```
144
145
 
145
- ### Environment Variables
146
+ This CLI is aware of your `pyproject.toml`-configured setup.
147
+ To display help for this, run (note the passthrough `--`):
148
+
149
+ ```bash
150
+ hatch-build -- --help
151
+ ```
146
152
 
147
- `hatch-cpp` will respect standard environment variables for compiler control.
153
+ For example, for the `test_project_basic` in this project's `tests` folder:
154
+
155
+ ```raw
156
+ hatch-build --hooks-only -- --help
157
+ [sdist]
158
+
159
+ [wheel]
160
+ [2025-11-11T17:31:06-0500][p2a][WARNING]: Only dicts with str, int, float, bool, or enum values are supported - field `cmake_env_args` got value type typing.Dict[str, str]
161
+ usage: hatch-build-extras-model [-h] [--verbose] [--name NAME] [--libraries.0.name LIBRARIES.0.NAME]
162
+ [--libraries.0.sources.0 LIBRARIES.0.SOURCES.0] [--libraries.0.sources LIBRARIES.0.SOURCES]
163
+ [--libraries.0.language LIBRARIES.0.LANGUAGE] [--libraries.0.binding LIBRARIES.0.BINDING]
164
+ [--libraries.0.std LIBRARIES.0.STD] [--libraries.0.include-dirs.0 LIBRARIES.0.INCLUDE_DIRS.0]
165
+ [--libraries.0.include-dirs LIBRARIES.0.INCLUDE_DIRS]
166
+ [--libraries.0.library-dirs LIBRARIES.0.LIBRARY_DIRS]
167
+ [--libraries.0.libraries LIBRARIES.0.LIBRARIES]
168
+ [--libraries.0.extra-compile-args LIBRARIES.0.EXTRA_COMPILE_ARGS]
169
+ [--libraries.0.extra-link-args LIBRARIES.0.EXTRA_LINK_ARGS]
170
+ [--libraries.0.extra-objects LIBRARIES.0.EXTRA_OBJECTS]
171
+ [--libraries.0.define-macros LIBRARIES.0.DEFINE_MACROS]
172
+ [--libraries.0.undef-macros LIBRARIES.0.UNDEF_MACROS]
173
+ [--libraries.0.export-symbols LIBRARIES.0.EXPORT_SYMBOLS]
174
+ [--libraries.0.depends LIBRARIES.0.DEPENDS]
175
+ [--libraries.0.py-limited-api LIBRARIES.0.PY_LIMITED_API] [--cmake.root CMAKE.ROOT]
176
+ [--cmake.build CMAKE.BUILD] [--cmake.install CMAKE.INSTALL]
177
+ [--cmake.cmake-arg-prefix CMAKE.CMAKE_ARG_PREFIX] [--cmake.cmake-args CMAKE.CMAKE_ARGS]
178
+ [--cmake.include-flags CMAKE.INCLUDE_FLAGS] [--platform.cc PLATFORM.CC]
179
+ [--platform.cxx PLATFORM.CXX] [--platform.ld PLATFORM.LD] [--platform.platform PLATFORM.PLATFORM]
180
+ [--platform.toolchain PLATFORM.TOOLCHAIN] [--platform.disable-ccache] [--vcpkg.vcpkg VCPKG.VCPKG]
181
+ [--vcpkg.vcpkg-root VCPKG.VCPKG_ROOT] [--vcpkg.vcpkg-repo VCPKG.VCPKG_REPO]
182
+ [--vcpkg.vcpkg-triplet VCPKG.VCPKG_TRIPLET] [--build-type BUILD_TYPE] [--commands COMMANDS]
183
+
184
+ options:
185
+ -h, --help show this help message and exit
186
+ --verbose
187
+ --name NAME
188
+ --libraries.0.name LIBRARIES.0.NAME
189
+ --libraries.0.sources.0 LIBRARIES.0.SOURCES.0
190
+ --libraries.0.sources LIBRARIES.0.SOURCES
191
+ --libraries.0.language LIBRARIES.0.LANGUAGE
192
+ --libraries.0.binding LIBRARIES.0.BINDING
193
+ --libraries.0.std LIBRARIES.0.STD
194
+ --libraries.0.include-dirs.0 LIBRARIES.0.INCLUDE_DIRS.0
195
+ --libraries.0.include-dirs LIBRARIES.0.INCLUDE_DIRS
196
+ --libraries.0.library-dirs LIBRARIES.0.LIBRARY_DIRS
197
+ --libraries.0.libraries LIBRARIES.0.LIBRARIES
198
+ --libraries.0.extra-compile-args LIBRARIES.0.EXTRA_COMPILE_ARGS
199
+ --libraries.0.extra-link-args LIBRARIES.0.EXTRA_LINK_ARGS
200
+ --libraries.0.extra-objects LIBRARIES.0.EXTRA_OBJECTS
201
+ --libraries.0.define-macros LIBRARIES.0.DEFINE_MACROS
202
+ --libraries.0.undef-macros LIBRARIES.0.UNDEF_MACROS
203
+ --libraries.0.export-symbols LIBRARIES.0.EXPORT_SYMBOLS
204
+ --libraries.0.depends LIBRARIES.0.DEPENDS
205
+ --libraries.0.py-limited-api LIBRARIES.0.PY_LIMITED_API
206
+ --cmake.root CMAKE.ROOT
207
+ --cmake.build CMAKE.BUILD
208
+ --cmake.install CMAKE.INSTALL
209
+ --cmake.cmake-arg-prefix CMAKE.CMAKE_ARG_PREFIX
210
+ --cmake.cmake-args CMAKE.CMAKE_ARGS
211
+ --cmake.include-flags CMAKE.INCLUDE_FLAGS
212
+ --platform.cc PLATFORM.CC
213
+ --platform.cxx PLATFORM.CXX
214
+ --platform.ld PLATFORM.LD
215
+ --platform.platform PLATFORM.PLATFORM
216
+ --platform.toolchain PLATFORM.TOOLCHAIN
217
+ --platform.disable-ccache
218
+ --vcpkg.vcpkg VCPKG.VCPKG
219
+ --vcpkg.vcpkg-root VCPKG.VCPKG_ROOT
220
+ --vcpkg.vcpkg-repo VCPKG.VCPKG_REPO
221
+ --vcpkg.vcpkg-triplet VCPKG.VCPKG_TRIPLET
222
+ --build-type BUILD_TYPE
223
+ --commands COMMANDS
224
+ ```
225
+
226
+ ### Environment Variables
148
227
 
149
- | Name | Default | Description |
150
- | :------------------------- | :------ | :-------------------- |
151
- | `CC` | | C Compiler override |
152
- | `CXX` | | C++ Compiler override |
153
- | `LD` | | Linker override |
154
- | `HATCH_CPP_PLATFORM` | | Platform to build |
155
- | `HATCH_CPP_DISABLE_CCACHE` | | Disable CCache usage |
228
+ `hatch-cpp` will respect standard environment variables for compiler control, e.g. `CC`, `CXX`, `LD`, `CMAKE_GENERATOR`, `OSX_DEPLOYMENT_TARGET`, etc.
156
229
 
157
230
  > [!NOTE]
158
231
  > This library was generated using [copier](https://copier.readthedocs.io/en/stable/) from the [Base Python Project Template repository](https://github.com/python-project-templates/base).
@@ -1,7 +1,7 @@
1
- hatch_cpp/__init__.py,sha256=K9MSlud8adPKmDzkJWwPGoEVanTCIFGjZM-UI5yKkGE,114
2
- hatch_cpp/config.py,sha256=8UIdlc6fHEBNgjmLZ1op3x-16BARxx4GJHPwAFQlOUw,3641
1
+ hatch_cpp/__init__.py,sha256=72Jl9ttvsEB_8_pmXYxv4QjBn3bfuIq9oBLqQvI9c0Q,114
2
+ hatch_cpp/config.py,sha256=LlwDBmD1nir08Y5GOl4wa29h2iJBtNRSzYMGHRVFJUo,3698
3
3
  hatch_cpp/hooks.py,sha256=SQkF5WJIgzw-8rvlTzuQvBqdP6K3fHgnh6CZOZFag50,203
4
- hatch_cpp/plugin.py,sha256=pywarl9lNXMMYmYa0OMT2Q3VQGvViusaa0-tZbMA1W4,4523
4
+ hatch_cpp/plugin.py,sha256=NcIDi7c9KH-_RkPeeCgWKoH5InIjw2eECswazwvGl_c,4304
5
5
  hatch_cpp/utils.py,sha256=lxd3U3aMYsTS6DYMc1y17MR16LzgRzv92f_xh87LSg8,297
6
6
  hatch_cpp/tests/test_hatch_build.py,sha256=q2IKTFi3Pq99UsOyL84V-C9VtFUs3ZcA9UlA8lpRW54,1553
7
7
  hatch_cpp/tests/test_projects.py,sha256=vs-kHdiHM7pCqM3oGQsSryq5blRi0HyK5QFfHxlJDi8,1773
@@ -56,10 +56,10 @@ hatch_cpp/tests/test_project_pybind_vcpkg/cpp/project/basic.hpp,sha256=LZSfCfhLY
56
56
  hatch_cpp/tests/test_project_pybind_vcpkg/project/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
57
57
  hatch_cpp/toolchains/__init__.py,sha256=anza4tXKxauobWMOUrxX3sEO0qs7sp6VdLXhLae3vkY,64
58
58
  hatch_cpp/toolchains/cmake.py,sha256=VQYYqiOu0ZEF0IBuep35Xad7jryWy04-dHYYf7c0XgY,3331
59
- hatch_cpp/toolchains/common.py,sha256=nBAGQ9B5a7yNgOgohUCsbnDAJACrdQ8lt5dFyb7IXMs,10076
60
- hatch_cpp/toolchains/vcpkg.py,sha256=fx9lo5EH3HVqg9Fnh5EO67gNsAXcza9eZz4S-Y8piJ0,2097
61
- hatch_cpp-0.2.2.dist-info/METADATA,sha256=df6Svm6GGIBwpNFEb1825-E4gEsbh07AAjJsrcBm62Y,5900
62
- hatch_cpp-0.2.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
63
- hatch_cpp-0.2.2.dist-info/entry_points.txt,sha256=RgXfjpD4iwomJQK5n7FnPkXzb5fOnF5v3DI5hbkgVcw,30
64
- hatch_cpp-0.2.2.dist-info/licenses/LICENSE,sha256=FWyFTpd5xXEz50QpGDtsyIv6dgR2z_dHdoab_Nq_KMw,11452
65
- hatch_cpp-0.2.2.dist-info/RECORD,,
59
+ hatch_cpp/toolchains/common.py,sha256=I3wF-Xduf9TMI1EKpV6E9HE7uSDynj6r6tGnLki07b0,10391
60
+ hatch_cpp/toolchains/vcpkg.py,sha256=Gwv3YNXBngpdebvRuYuUcWCzPyDbmDvy8c0K7uV4k38,2146
61
+ hatch_cpp-0.3.0.dist-info/METADATA,sha256=27ovNRF_l5FQxI0-nsVH6Pr7nJS4R_MRHABab6uHojc,9896
62
+ hatch_cpp-0.3.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
63
+ hatch_cpp-0.3.0.dist-info/entry_points.txt,sha256=RgXfjpD4iwomJQK5n7FnPkXzb5fOnF5v3DI5hbkgVcw,30
64
+ hatch_cpp-0.3.0.dist-info/licenses/LICENSE,sha256=FWyFTpd5xXEz50QpGDtsyIv6dgR2z_dHdoab_Nq_KMw,11452
65
+ hatch_cpp-0.3.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.27.0
2
+ Generator: hatchling 1.28.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any