hatch-cpp 0.2.1__tar.gz → 0.3.0__tar.gz

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.
Files changed (66) hide show
  1. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/PKG-INFO +85 -12
  2. hatch_cpp-0.3.0/README.md +185 -0
  3. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/__init__.py +1 -1
  4. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/config.py +4 -3
  5. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/plugin.py +8 -12
  6. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/toolchains/common.py +21 -13
  7. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/toolchains/vcpkg.py +1 -0
  8. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/pyproject.toml +6 -5
  9. hatch_cpp-0.2.1/README.md +0 -113
  10. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/.gitignore +0 -0
  11. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/LICENSE +0 -0
  12. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/hooks.py +0 -0
  13. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_hatch_build.py +0 -0
  14. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_basic/cpp/project/basic.cpp +0 -0
  15. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_basic/cpp/project/basic.hpp +0 -0
  16. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_basic/project/__init__.py +0 -0
  17. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_basic/pyproject.toml +0 -0
  18. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_cmake/CMakeLists.txt +0 -0
  19. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_cmake/Makefile +0 -0
  20. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_cmake/cpp/project/basic.cpp +0 -0
  21. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_cmake/cpp/project/basic.hpp +0 -0
  22. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_cmake/project/__init__.py +0 -0
  23. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_cmake/project/include/project/basic.hpp +0 -0
  24. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_cmake/pyproject.toml +0 -0
  25. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_cmake_vcpkg/CMakeLists.txt +0 -0
  26. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_cmake_vcpkg/Makefile +0 -0
  27. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_cmake_vcpkg/cpp/project/basic.cpp +0 -0
  28. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_cmake_vcpkg/cpp/project/basic.hpp +0 -0
  29. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_cmake_vcpkg/project/__init__.py +0 -0
  30. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_cmake_vcpkg/project/include/project/basic.hpp +0 -0
  31. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_cmake_vcpkg/pyproject.toml +0 -0
  32. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_cmake_vcpkg/vcpkg.json +0 -0
  33. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_hatch_build/cpp/project/basic.cpp +0 -0
  34. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_hatch_build/cpp/project/basic.hpp +0 -0
  35. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_hatch_build/project/__init__.py +0 -0
  36. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_hatch_build/pyproject.toml +0 -0
  37. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_limited_api/cpp/project/basic.cpp +0 -0
  38. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_limited_api/cpp/project/basic.hpp +0 -0
  39. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_limited_api/project/__init__.py +0 -0
  40. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_limited_api/pyproject.toml +0 -0
  41. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_nanobind/cpp/project/basic.cpp +0 -0
  42. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_nanobind/cpp/project/basic.hpp +0 -0
  43. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_nanobind/project/__init__.py +0 -0
  44. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_nanobind/pyproject.toml +0 -0
  45. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_override_classes/cpp/project/basic.cpp +0 -0
  46. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_override_classes/cpp/project/basic.hpp +0 -0
  47. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_override_classes/project/__init__.py +0 -0
  48. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_override_classes/pyproject.toml +0 -0
  49. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_override_toolchain/cpp/project/basic.cpp +0 -0
  50. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_override_toolchain/cpp/project/basic.hpp +0 -0
  51. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_override_toolchain/project/__init__.py +0 -0
  52. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_override_toolchain/pyproject.toml +0 -0
  53. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_pybind/cpp/project/basic.cpp +0 -0
  54. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_pybind/cpp/project/basic.hpp +0 -0
  55. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_pybind/project/__init__.py +0 -0
  56. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_pybind/pyproject.toml +0 -0
  57. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_pybind_vcpkg/cpp/project/basic.cpp +0 -0
  58. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_pybind_vcpkg/cpp/project/basic.hpp +0 -0
  59. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_pybind_vcpkg/project/__init__.py +0 -0
  60. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_pybind_vcpkg/pyproject.toml +0 -0
  61. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_project_pybind_vcpkg/vcpkg.json +0 -0
  62. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_projects.py +0 -0
  63. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/tests/test_structs.py +0 -0
  64. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/toolchains/__init__.py +0 -0
  65. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/toolchains/cmake.py +0 -0
  66. {hatch_cpp-0.2.1 → hatch_cpp-0.3.0}/hatch_cpp/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hatch-cpp
3
- Version: 0.2.1
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.5,>=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).
@@ -0,0 +1,185 @@
1
+ # hatch-cpp
2
+
3
+ Hatch plugin for C++ builds
4
+
5
+ [![Build Status](https://github.com/python-project-templates/hatch-cpp/actions/workflows/build.yaml/badge.svg?branch=main&event=push)](https://github.com/python-project-templates/hatch-cpp/actions/workflows/build.yaml)
6
+ [![codecov](https://codecov.io/gh/python-project-templates/hatch-cpp/branch/main/graph/badge.svg)](https://codecov.io/gh/python-project-templates/hatch-cpp)
7
+ [![License](https://img.shields.io/github/license/python-project-templates/hatch-cpp)](https://github.com/python-project-templates/hatch-cpp)
8
+ [![PyPI](https://img.shields.io/pypi/v/hatch-cpp.svg)](https://pypi.python.org/pypi/hatch-cpp)
9
+
10
+ ## Overview
11
+
12
+ A simple, extensible C++ build plugin for [hatch](https://hatch.pypa.io/latest/).
13
+
14
+ ```toml
15
+ [tool.hatch.build.hooks.hatch-cpp]
16
+ libraries = [
17
+ {name = "project/extension", sources = ["cpp/project/basic.cpp"], include-dirs = ["cpp"]}
18
+ ]
19
+ ```
20
+
21
+ For more complete systems, see:
22
+
23
+ - [scikit-build-core](https://github.com/scikit-build/scikit-build-core)
24
+ - [setuptools](https://setuptools.pypa.io/en/latest/userguide/ext_modules.html)
25
+
26
+ ## Configuration
27
+
28
+ Configuration is driven from the `[tool.hatch.build.hooks.hatch-cpp]` hatch hook configuration field in a `pyproject.toml`.
29
+ It is designed to closely match existing Python/C/C++ packaging tools.
30
+
31
+ ```toml
32
+ verbose = true
33
+ libraries = { Library Args }
34
+ cmake = { CMake Args }
35
+ platform = { Platform, either "linux", "darwin", or "win32" }
36
+ ```
37
+
38
+ See the [test cases](./hatch_cpp/tests/) for more concrete examples.
39
+
40
+ `hatch-cpp` is driven by [pydantic](https://docs.pydantic.dev/latest/) models for configuration and execution of the build.
41
+ These models can themselves be overridden by setting `build-config-class` / `build-plan-class`.
42
+
43
+ ### Library Arguments
44
+
45
+ ```toml
46
+ name = "mylib"
47
+ sources = [
48
+ "path/to/file.cpp",
49
+ ]
50
+ language = "c++"
51
+
52
+ binding = "cpython" # or "pybind11", "nanobind", "generic"
53
+ std = "" # Passed to -std= or /std:
54
+
55
+ include_dirs = ["paths/to/add/to/-I"]
56
+ library_dirs = ["paths/to/add/to/-L"]
57
+ libraries = ["-llibraries_to_link"]
58
+
59
+ extra_compile_args = ["--extra-compile-args"]
60
+ extra_link_args = ["--extra-link-args"]
61
+ extra_objects = ["extra_objects"]
62
+
63
+ define_macros = ["-Ddefines_to_use"]
64
+ undef_macros = ["-Uundefines_to_use"]
65
+
66
+ py_limited_api = "cp39" # limited API to use
67
+ ```
68
+
69
+ ### CMake Arguments
70
+
71
+ `hatch-cpp` has some convenience integration with CMake.
72
+ Though this is not designed to be as full-featured as e.g. `scikit-build`, it should be satisfactory for many small projects.
73
+
74
+ ```toml
75
+ root = "path/to/cmake/root"
76
+ build = "path/to/cmake/build/folder"
77
+ install = "path/to/cmake/install/folder"
78
+
79
+ cmake_arg_prefix = "MYPROJECT_"
80
+ cmake_args = {} # any other cmake args to pass
81
+ cmake_env_args = {} # env-specific cmake args to pass
82
+
83
+ include_flags = {} # include flags to pass -D
84
+ ```
85
+
86
+ ### CLI
87
+
88
+ `hatch-cpp` is integrated with [`hatch-build`](https://github.com/python-project-templates/hatch-build) to allow easy configuration of options via command line:
89
+
90
+ ```bash
91
+ hatch-build \
92
+ -- \
93
+ --verbose \
94
+ --platform linux \
95
+ --vcpkg.vcpkg a/path/to/vcpkg.json \
96
+ --libraries.0.binding pybind11 \
97
+ --libraries.0.include-dirs cpp,another-dir
98
+ ```
99
+
100
+ This CLI is aware of your `pyproject.toml`-configured setup.
101
+ To display help for this, run (note the passthrough `--`):
102
+
103
+ ```bash
104
+ hatch-build -- --help
105
+ ```
106
+
107
+ For example, for the `test_project_basic` in this project's `tests` folder:
108
+
109
+ ```raw
110
+ hatch-build --hooks-only -- --help
111
+ [sdist]
112
+
113
+ [wheel]
114
+ [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]
115
+ usage: hatch-build-extras-model [-h] [--verbose] [--name NAME] [--libraries.0.name LIBRARIES.0.NAME]
116
+ [--libraries.0.sources.0 LIBRARIES.0.SOURCES.0] [--libraries.0.sources LIBRARIES.0.SOURCES]
117
+ [--libraries.0.language LIBRARIES.0.LANGUAGE] [--libraries.0.binding LIBRARIES.0.BINDING]
118
+ [--libraries.0.std LIBRARIES.0.STD] [--libraries.0.include-dirs.0 LIBRARIES.0.INCLUDE_DIRS.0]
119
+ [--libraries.0.include-dirs LIBRARIES.0.INCLUDE_DIRS]
120
+ [--libraries.0.library-dirs LIBRARIES.0.LIBRARY_DIRS]
121
+ [--libraries.0.libraries LIBRARIES.0.LIBRARIES]
122
+ [--libraries.0.extra-compile-args LIBRARIES.0.EXTRA_COMPILE_ARGS]
123
+ [--libraries.0.extra-link-args LIBRARIES.0.EXTRA_LINK_ARGS]
124
+ [--libraries.0.extra-objects LIBRARIES.0.EXTRA_OBJECTS]
125
+ [--libraries.0.define-macros LIBRARIES.0.DEFINE_MACROS]
126
+ [--libraries.0.undef-macros LIBRARIES.0.UNDEF_MACROS]
127
+ [--libraries.0.export-symbols LIBRARIES.0.EXPORT_SYMBOLS]
128
+ [--libraries.0.depends LIBRARIES.0.DEPENDS]
129
+ [--libraries.0.py-limited-api LIBRARIES.0.PY_LIMITED_API] [--cmake.root CMAKE.ROOT]
130
+ [--cmake.build CMAKE.BUILD] [--cmake.install CMAKE.INSTALL]
131
+ [--cmake.cmake-arg-prefix CMAKE.CMAKE_ARG_PREFIX] [--cmake.cmake-args CMAKE.CMAKE_ARGS]
132
+ [--cmake.include-flags CMAKE.INCLUDE_FLAGS] [--platform.cc PLATFORM.CC]
133
+ [--platform.cxx PLATFORM.CXX] [--platform.ld PLATFORM.LD] [--platform.platform PLATFORM.PLATFORM]
134
+ [--platform.toolchain PLATFORM.TOOLCHAIN] [--platform.disable-ccache] [--vcpkg.vcpkg VCPKG.VCPKG]
135
+ [--vcpkg.vcpkg-root VCPKG.VCPKG_ROOT] [--vcpkg.vcpkg-repo VCPKG.VCPKG_REPO]
136
+ [--vcpkg.vcpkg-triplet VCPKG.VCPKG_TRIPLET] [--build-type BUILD_TYPE] [--commands COMMANDS]
137
+
138
+ options:
139
+ -h, --help show this help message and exit
140
+ --verbose
141
+ --name NAME
142
+ --libraries.0.name LIBRARIES.0.NAME
143
+ --libraries.0.sources.0 LIBRARIES.0.SOURCES.0
144
+ --libraries.0.sources LIBRARIES.0.SOURCES
145
+ --libraries.0.language LIBRARIES.0.LANGUAGE
146
+ --libraries.0.binding LIBRARIES.0.BINDING
147
+ --libraries.0.std LIBRARIES.0.STD
148
+ --libraries.0.include-dirs.0 LIBRARIES.0.INCLUDE_DIRS.0
149
+ --libraries.0.include-dirs LIBRARIES.0.INCLUDE_DIRS
150
+ --libraries.0.library-dirs LIBRARIES.0.LIBRARY_DIRS
151
+ --libraries.0.libraries LIBRARIES.0.LIBRARIES
152
+ --libraries.0.extra-compile-args LIBRARIES.0.EXTRA_COMPILE_ARGS
153
+ --libraries.0.extra-link-args LIBRARIES.0.EXTRA_LINK_ARGS
154
+ --libraries.0.extra-objects LIBRARIES.0.EXTRA_OBJECTS
155
+ --libraries.0.define-macros LIBRARIES.0.DEFINE_MACROS
156
+ --libraries.0.undef-macros LIBRARIES.0.UNDEF_MACROS
157
+ --libraries.0.export-symbols LIBRARIES.0.EXPORT_SYMBOLS
158
+ --libraries.0.depends LIBRARIES.0.DEPENDS
159
+ --libraries.0.py-limited-api LIBRARIES.0.PY_LIMITED_API
160
+ --cmake.root CMAKE.ROOT
161
+ --cmake.build CMAKE.BUILD
162
+ --cmake.install CMAKE.INSTALL
163
+ --cmake.cmake-arg-prefix CMAKE.CMAKE_ARG_PREFIX
164
+ --cmake.cmake-args CMAKE.CMAKE_ARGS
165
+ --cmake.include-flags CMAKE.INCLUDE_FLAGS
166
+ --platform.cc PLATFORM.CC
167
+ --platform.cxx PLATFORM.CXX
168
+ --platform.ld PLATFORM.LD
169
+ --platform.platform PLATFORM.PLATFORM
170
+ --platform.toolchain PLATFORM.TOOLCHAIN
171
+ --platform.disable-ccache
172
+ --vcpkg.vcpkg VCPKG.VCPKG
173
+ --vcpkg.vcpkg-root VCPKG.VCPKG_ROOT
174
+ --vcpkg.vcpkg-repo VCPKG.VCPKG_REPO
175
+ --vcpkg.vcpkg-triplet VCPKG.VCPKG_TRIPLET
176
+ --build-type BUILD_TYPE
177
+ --commands COMMANDS
178
+ ```
179
+
180
+ ### Environment Variables
181
+
182
+ `hatch-cpp` will respect standard environment variables for compiler control, e.g. `CC`, `CXX`, `LD`, `CMAKE_GENERATOR`, `OSX_DEPLOYMENT_TARGET`, etc.
183
+
184
+ > [!NOTE]
185
+ > 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,4 +1,4 @@
1
- __version__ = "0.2.1"
1
+ __version__ = "0.3.0"
2
2
 
3
3
  from .config import *
4
4
  from .hooks import *
@@ -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)
@@ -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
 
@@ -8,7 +8,7 @@ authors = [{name = "the hatch-cpp authors", email = "t.paine154@gmail.com"}]
8
8
  description = "Hatch plugin for C++ builds"
9
9
  readme = "README.md"
10
10
  license = { text = "Apache-2.0" }
11
- version = "0.2.1"
11
+ version = "0.3.0"
12
12
  requires-python = ">=3.10"
13
13
  keywords = [
14
14
  "hatch",
@@ -35,7 +35,8 @@ classifiers = [
35
35
 
36
36
  dependencies = [
37
37
  "hatchling",
38
- "hatch-build>=0.4,<0.5",
38
+ "hatch-build>=0.5,<0.6",
39
+ "pkn",
39
40
  "pydantic",
40
41
  ]
41
42
 
@@ -56,7 +57,7 @@ develop = [
56
57
  "uv",
57
58
  "wheel",
58
59
  # test
59
- "nanobind<2.10.0", # https://github.com/wjakob/nanobind/commit/abd27e3b5565bc95f5091321f0f863fce8b5b95b
60
+ "nanobind<2.12.0", # https://github.com/wjakob/nanobind/commit/abd27e3b5565bc95f5091321f0f863fce8b5b95b
60
61
  "pybind11",
61
62
  "pytest",
62
63
  "pytest-cov",
@@ -74,9 +75,9 @@ Repository = "https://github.com/python-project-templates/hatch-cpp"
74
75
  Homepage = "https://github.com/python-project-templates/hatch-cpp"
75
76
 
76
77
  [tool.bumpversion]
77
- current_version = "0.2.1"
78
+ current_version = "0.3.0"
78
79
  commit = true
79
- tag = false
80
+ tag = true
80
81
  commit_args = "-s"
81
82
 
82
83
  [[tool.bumpversion.files]]
hatch_cpp-0.2.1/README.md DELETED
@@ -1,113 +0,0 @@
1
- # hatch-cpp
2
-
3
- Hatch plugin for C++ builds
4
-
5
- [![Build Status](https://github.com/python-project-templates/hatch-cpp/actions/workflows/build.yaml/badge.svg?branch=main&event=push)](https://github.com/python-project-templates/hatch-cpp/actions/workflows/build.yaml)
6
- [![codecov](https://codecov.io/gh/python-project-templates/hatch-cpp/branch/main/graph/badge.svg)](https://codecov.io/gh/python-project-templates/hatch-cpp)
7
- [![License](https://img.shields.io/github/license/python-project-templates/hatch-cpp)](https://github.com/python-project-templates/hatch-cpp)
8
- [![PyPI](https://img.shields.io/pypi/v/hatch-cpp.svg)](https://pypi.python.org/pypi/hatch-cpp)
9
-
10
- ## Overview
11
-
12
- A simple, extensible C++ build plugin for [hatch](https://hatch.pypa.io/latest/).
13
-
14
- ```toml
15
- [tool.hatch.build.hooks.hatch-cpp]
16
- libraries = [
17
- {name = "project/extension", sources = ["cpp/project/basic.cpp"], include-dirs = ["cpp"]}
18
- ]
19
- ```
20
-
21
- For more complete systems, see:
22
-
23
- - [scikit-build-core](https://github.com/scikit-build/scikit-build-core)
24
- - [setuptools](https://setuptools.pypa.io/en/latest/userguide/ext_modules.html)
25
-
26
- ## Configuration
27
-
28
- Configuration is driven from the `[tool.hatch.build.hooks.hatch-cpp]` hatch hook configuration field in a `pyproject.toml`.
29
- It is designed to closely match existing Python/C/C++ packaging tools.
30
-
31
- ```toml
32
- verbose = true
33
- libraries = { Library Args }
34
- cmake = { CMake Args }
35
- platform = { Platform, either "linux", "darwin", or "win32" }
36
- ```
37
-
38
- See the [test cases](./hatch_cpp/tests/) for more concrete examples.
39
-
40
- `hatch-cpp` is driven by [pydantic](https://docs.pydantic.dev/latest/) models for configuration and execution of the build.
41
- These models can themselves be overridden by setting `build-config-class` / `build-plan-class`.
42
-
43
- ### Library Arguments
44
-
45
- ```toml
46
- name = "mylib"
47
- sources = [
48
- "path/to/file.cpp",
49
- ]
50
- language = "c++"
51
-
52
- binding = "cpython" # or "pybind11", "nanobind", "generic"
53
- std = "" # Passed to -std= or /std:
54
-
55
- include_dirs = ["paths/to/add/to/-I"]
56
- library_dirs = ["paths/to/add/to/-L"]
57
- libraries = ["-llibraries_to_link"]
58
-
59
- extra_compile_args = ["--extra-compile-args"]
60
- extra_link_args = ["--extra-link-args"]
61
- extra_objects = ["extra_objects"]
62
-
63
- define_macros = ["-Ddefines_to_use"]
64
- undef_macros = ["-Uundefines_to_use"]
65
-
66
- py_limited_api = "cp39" # limited API to use
67
- ```
68
-
69
- ### CMake Arguments
70
-
71
- `hatch-cpp` has some convenience integration with CMake.
72
- Though this is not designed to be as full-featured as e.g. `scikit-build`, it should be satisfactory for many small projects.
73
-
74
- ```toml
75
- root = "path/to/cmake/root"
76
- build = "path/to/cmake/build/folder"
77
- install = "path/to/cmake/install/folder"
78
-
79
- cmake_arg_prefix = "MYPROJECT_"
80
- cmake_args = {} # any other cmake args to pass
81
- cmake_env_args = {} # env-specific cmake args to pass
82
-
83
- include_flags = {} # include flags to pass -D
84
- ```
85
-
86
- ### CLI
87
-
88
- `hatch-cpp` is integrated with [`hatch-build`](https://github.com/python-project-templates/hatch-build) to allow easy configuration of options via command line:
89
-
90
- ```bash
91
- hatch-build \
92
- -- \
93
- --verbose \
94
- --platform linux \
95
- --vcpkg.vcpkg a/path/to/vcpkg.json \
96
- --libraries.0.binding pybind11 \
97
- --libraries.0.include-dirs cpp,another-dir
98
- ```
99
-
100
- ### Environment Variables
101
-
102
- `hatch-cpp` will respect standard environment variables for compiler control.
103
-
104
- | Name | Default | Description |
105
- | :------------------------- | :------ | :-------------------- |
106
- | `CC` | | C Compiler override |
107
- | `CXX` | | C++ Compiler override |
108
- | `LD` | | Linker override |
109
- | `HATCH_CPP_PLATFORM` | | Platform to build |
110
- | `HATCH_CPP_DISABLE_CCACHE` | | Disable CCache usage |
111
-
112
- > [!NOTE]
113
- > 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).
File without changes
File without changes
File without changes
File without changes