hatch-cpp 0.1.7__tar.gz → 0.1.8__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 (48) hide show
  1. hatch_cpp-0.1.8/.gitignore +159 -0
  2. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/LICENSE +4 -0
  3. hatch_cpp-0.1.8/PKG-INFO +144 -0
  4. hatch_cpp-0.1.8/README.md +99 -0
  5. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/__init__.py +1 -1
  6. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/structs.py +34 -5
  7. hatch_cpp-0.1.8/hatch_cpp/tests/test_project_override_classes/cpp/project/basic.hpp +17 -0
  8. hatch_cpp-0.1.8/hatch_cpp/tests/test_project_override_toolchain/cpp/project/basic.cpp +5 -0
  9. hatch_cpp-0.1.8/hatch_cpp/tests/test_project_override_toolchain/cpp/project/basic.hpp +17 -0
  10. hatch_cpp-0.1.8/hatch_cpp/tests/test_project_override_toolchain/pyproject.toml +38 -0
  11. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_projects.py +3 -2
  12. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_structs.py +8 -0
  13. hatch_cpp-0.1.8/hatch_cpp/toolchains/cmake.py +0 -0
  14. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/pyproject.toml +18 -9
  15. hatch_cpp-0.1.7/.gitignore +0 -170
  16. hatch_cpp-0.1.7/PKG-INFO +0 -72
  17. hatch_cpp-0.1.7/README.md +0 -35
  18. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/hooks.py +0 -0
  19. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/plugin.py +0 -0
  20. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_basic/cpp/project/basic.cpp +0 -0
  21. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_basic/cpp/project/basic.hpp +0 -0
  22. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_basic/project/__init__.py +0 -0
  23. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_basic/pyproject.toml +0 -0
  24. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_cmake/CMakeLists.txt +0 -0
  25. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_cmake/Makefile +0 -0
  26. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_cmake/cpp/project/basic.cpp +0 -0
  27. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_cmake/cpp/project/basic.hpp +0 -0
  28. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_cmake/project/__init__.py +0 -0
  29. {hatch_cpp-0.1.7/hatch_cpp/tests/test_project_limited_api/cpp → hatch_cpp-0.1.8/hatch_cpp/tests/test_project_cmake/project/include}/project/basic.hpp +0 -0
  30. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_cmake/pyproject.toml +0 -0
  31. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_limited_api/cpp/project/basic.cpp +0 -0
  32. {hatch_cpp-0.1.7/hatch_cpp/tests/test_project_override_classes → hatch_cpp-0.1.8/hatch_cpp/tests/test_project_limited_api}/cpp/project/basic.hpp +0 -0
  33. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_limited_api/project/__init__.py +0 -0
  34. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_limited_api/pyproject.toml +0 -0
  35. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_nanobind/cpp/project/basic.cpp +0 -0
  36. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_nanobind/cpp/project/basic.hpp +0 -0
  37. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_nanobind/project/__init__.py +0 -0
  38. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_nanobind/pyproject.toml +0 -0
  39. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_override_classes/cpp/project/basic.cpp +0 -0
  40. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_override_classes/project/__init__.py +0 -0
  41. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_override_classes/pyproject.toml +0 -0
  42. {hatch_cpp-0.1.7/hatch_cpp/tests/test_project_pybind → hatch_cpp-0.1.8/hatch_cpp/tests/test_project_override_toolchain}/project/__init__.py +0 -0
  43. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_pybind/cpp/project/basic.cpp +0 -0
  44. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_pybind/cpp/project/basic.hpp +0 -0
  45. {hatch_cpp-0.1.7/hatch_cpp/toolchains → hatch_cpp-0.1.8/hatch_cpp/tests/test_project_pybind/project}/__init__.py +0 -0
  46. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/tests/test_project_pybind/pyproject.toml +0 -0
  47. /hatch_cpp-0.1.7/hatch_cpp/toolchains/cmake.py → /hatch_cpp-0.1.8/hatch_cpp/toolchains/__init__.py +0 -0
  48. {hatch_cpp-0.1.7 → hatch_cpp-0.1.8}/hatch_cpp/utils.py +0 -0
@@ -0,0 +1,159 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.a
8
+ *.so
9
+ *.obj
10
+ *.dll
11
+ *.exp
12
+ *.lib
13
+
14
+ # Distribution / packaging
15
+ .Python
16
+ build/
17
+ develop-eggs/
18
+ dist/
19
+ downloads/
20
+ eggs/
21
+ .eggs/
22
+ lib/
23
+ lib64/
24
+ parts/
25
+ sdist/
26
+ var/
27
+ wheels/
28
+ pip-wheel-metadata/
29
+ share/python-wheels/
30
+ *.egg-info/
31
+ .installed.cfg
32
+ *.egg
33
+ MANIFEST
34
+
35
+ # PyInstaller
36
+ *.manifest
37
+ *.spec
38
+
39
+ # Installer logs
40
+ pip-log.txt
41
+ pip-delete-this-directory.txt
42
+
43
+ # Unit test / coverage reports
44
+ htmlcov/
45
+ .tox/
46
+ .nox/
47
+ .coverage
48
+ .coverage.*
49
+ .cache
50
+ nosetests.xml
51
+ coverage.xml
52
+ junit.xml
53
+ *.cover
54
+ *.py,cover
55
+ .hypothesis/
56
+ .pytest_cache/
57
+
58
+ # Translations
59
+ *.mo
60
+ *.pot
61
+
62
+ # Django stuff:
63
+ *.log
64
+ local_settings.py
65
+ db.sqlite3
66
+ db.sqlite3-journal
67
+
68
+ # Flask stuff:
69
+ instance/
70
+ .webassets-cache
71
+
72
+ # Scrapy stuff:
73
+ .scrapy
74
+
75
+ # PyBuilder
76
+ target/
77
+
78
+ # IPython
79
+ profile_default/
80
+ ipython_config.py
81
+
82
+ # pyenv
83
+ .python-version
84
+
85
+ # pipenv
86
+ Pipfile.lock
87
+
88
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
89
+ __pypackages__/
90
+
91
+ # Celery stuff
92
+ celerybeat-schedule
93
+ celerybeat.pid
94
+
95
+ # SageMath parsed files
96
+ *.sage.py
97
+
98
+ # Environments
99
+ .env
100
+ .venv
101
+ env/
102
+ venv/
103
+ ENV/
104
+ env.bak/
105
+ venv.bak/
106
+
107
+ # Spyder project settings
108
+ .spyderproject
109
+ .spyproject
110
+
111
+ # Rope project settings
112
+ .ropeproject
113
+
114
+ # mkdocs documentation
115
+ /site
116
+
117
+ # mypy
118
+ .mypy_cache/
119
+ .dmypy.json
120
+ dmypy.json
121
+
122
+ # Pyre type checker
123
+ .pyre/
124
+
125
+ # Documentation
126
+ /site
127
+ index.md
128
+ docs/_build/
129
+ docs/src/_build/
130
+ docs/api
131
+ docs/index.md
132
+ docs/html
133
+ docs/jupyter_execute
134
+ index.md
135
+
136
+ # JS
137
+ js/coverage
138
+ js/dist
139
+ js/lib
140
+ js/node_modules
141
+ js/test-results
142
+ js/playwright-report
143
+ js/*.tgz
144
+ hatch_cpp/extension
145
+
146
+ # Jupyter
147
+ .ipynb_checkpoints
148
+ .autoversion
149
+ Untitled*.ipynb
150
+ !hatch_cpp/extension/hatch_cpp.json
151
+ !hatch_cpp/extension/install.json
152
+ hatch_cpp/nbextension
153
+ hatch_cpp/labextension
154
+
155
+ # Mac
156
+ .DS_Store
157
+
158
+ # Rust
159
+ target
@@ -186,7 +186,11 @@
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
+ <<<<<<< before updating
189
190
  Copyright [yyyy] [name of copyright owner]
191
+ =======
192
+ Copyright 2025 the hatch-cpp authors
193
+ >>>>>>> after updating
190
194
 
191
195
  Licensed under the Apache License, Version 2.0 (the "License");
192
196
  you may not use this file except in compliance with the License.
@@ -0,0 +1,144 @@
1
+ Metadata-Version: 2.4
2
+ Name: hatch-cpp
3
+ Version: 0.1.8
4
+ Summary: Hatch plugin for C++ builds
5
+ Project-URL: Repository, https://github.com/python-project-templates/hatch-cpp
6
+ Project-URL: Homepage, https://github.com/python-project-templates/hatch-cpp
7
+ Author-email: the hatch-cpp authors <t.paine154@gmail.com>
8
+ License: Apache-2.0
9
+ License-File: LICENSE
10
+ Keywords: build,c++,cmake,cpp,hatch,python
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Programming Language :: Python
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Programming Language :: Python :: Implementation :: CPython
22
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
23
+ Requires-Python: >=3.9
24
+ Requires-Dist: hatchling>=1.20
25
+ Requires-Dist: pydantic
26
+ Provides-Extra: develop
27
+ Requires-Dist: build; extra == 'develop'
28
+ Requires-Dist: bump-my-version; extra == 'develop'
29
+ Requires-Dist: check-manifest; extra == 'develop'
30
+ Requires-Dist: codespell<2.5,>=2.4; extra == 'develop'
31
+ Requires-Dist: hatch-build; extra == 'develop'
32
+ Requires-Dist: hatchling; extra == 'develop'
33
+ Requires-Dist: mdformat-tables>=1; extra == 'develop'
34
+ Requires-Dist: mdformat<0.8,>=0.7.22; extra == 'develop'
35
+ Requires-Dist: nanobind<2.10.0; extra == 'develop'
36
+ Requires-Dist: pybind11; extra == 'develop'
37
+ Requires-Dist: pytest; extra == 'develop'
38
+ Requires-Dist: pytest-cov; extra == 'develop'
39
+ Requires-Dist: ruff; extra == 'develop'
40
+ Requires-Dist: toml; extra == 'develop'
41
+ Requires-Dist: twine; extra == 'develop'
42
+ Requires-Dist: uv; extra == 'develop'
43
+ Requires-Dist: wheel; extra == 'develop'
44
+ Description-Content-Type: text/markdown
45
+
46
+ # hatch-cpp
47
+
48
+ Hatch plugin for C++ builds
49
+
50
+ [![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)
51
+ [![codecov](https://codecov.io/gh/python-project-templates/hatch-cpp/branch/main/graph/badge.svg)](https://codecov.io/gh/python-project-templates/hatch-cpp)
52
+ [![License](https://img.shields.io/github/license/python-project-templates/hatch-cpp)](https://github.com/python-project-templates/hatch-cpp)
53
+ [![PyPI](https://img.shields.io/pypi/v/hatch-cpp.svg)](https://pypi.python.org/pypi/hatch-cpp)
54
+
55
+ ## Overview
56
+
57
+ A simple, extensible C++ build plugin for [hatch](https://hatch.pypa.io/latest/).
58
+
59
+ ```toml
60
+ [tool.hatch.build.hooks.hatch-cpp]
61
+ libraries = [
62
+ {name = "project/extension", sources = ["cpp/project/basic.cpp"], include-dirs = ["cpp"]}
63
+ ]
64
+ ```
65
+
66
+ For more complete systems, see:
67
+
68
+ - [scikit-build-core](https://github.com/scikit-build/scikit-build-core)
69
+ - [setuptools](https://setuptools.pypa.io/en/latest/userguide/ext_modules.html)
70
+
71
+ ## Configuration
72
+
73
+ Configuration is driven from the `[tool.hatch.build.hooks.hatch-cpp]` hatch hook configuration field in a `pyproject.toml`.
74
+ It is designed to closely match existing Python/C/C++ packaging tools.
75
+
76
+ ```toml
77
+ verbose = true
78
+ libraries = { Library Args }
79
+ cmake = { CMake Args }
80
+ platform = { Platform, either "linux", "darwin", or "win32" }
81
+ ```
82
+
83
+ See the [test cases](./hatch_cpp/tests/) for more concrete examples.
84
+
85
+ `hatch-cpp` is driven by [pydantic](https://docs.pydantic.dev/latest/) models for configuration and execution of the build.
86
+ These models can themselves be overridden by setting `build-config-class` / `build-plan-class`.
87
+
88
+ ### Library Arguments
89
+
90
+ ```toml
91
+ name = "mylib"
92
+ sources = [
93
+ "path/to/file.cpp",
94
+ ]
95
+ language = "c++"
96
+
97
+ binding = "cpython" # or "pybind11", "nanobind", "generic"
98
+ std = "" # Passed to -std= or /std:
99
+
100
+ include_dirs = ["paths/to/add/to/-I"]
101
+ library_dirs = ["paths/to/add/to/-L"]
102
+ libraries = ["-llibraries_to_link"]
103
+
104
+ extra_compile_args = ["--extra-compile-args"]
105
+ extra_link_args = ["--extra-link-args"]
106
+ extra_objects = ["extra_objects"]
107
+
108
+ define_macros = ["-Ddefines_to_use"]
109
+ undef_macros = ["-Uundefines_to_use"]
110
+
111
+ py_limited_api = "cp39" # limited API to use
112
+ ```
113
+
114
+ ### CMake Arguments
115
+
116
+ `hatch-cpp` has some convenience integration with CMake.
117
+ Though this is not designed to be as full-featured as e.g. `scikit-build`, it should be satisfactory for many small projects.
118
+
119
+ ```toml
120
+ root = "path/to/cmake/root"
121
+ build = "path/to/cmake/build/folder"
122
+ install = "path/to/cmake/install/folder"
123
+
124
+ cmake_arg_prefix = "MYPROJECT_"
125
+ cmake_args = {} # any other cmake args to pass
126
+ cmake_env_args = {} # env-specific cmake args to pass
127
+
128
+ include_flags = {} # include flags to pass -D
129
+ ```
130
+
131
+ ### Environment Variables
132
+
133
+ `hatch-cpp` will respect standard environment variables for compiler control.
134
+
135
+ | Name | Default | Description |
136
+ | :------------------------- | :------ | :-------------------- |
137
+ | `CC` | | C Compiler override |
138
+ | `CXX` | | C++ Compiler override |
139
+ | `LD` | | Linker override |
140
+ | `HATCH_CPP_PLATFORM` | | Platform to build |
141
+ | `HATCH_CPP_DISABLE_CCACHE` | | Disable CCache usage |
142
+
143
+ > [!NOTE]
144
+ > 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,99 @@
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
+ ### Environment Variables
87
+
88
+ `hatch-cpp` will respect standard environment variables for compiler control.
89
+
90
+ | Name | Default | Description |
91
+ | :------------------------- | :------ | :-------------------- |
92
+ | `CC` | | C Compiler override |
93
+ | `CXX` | | C++ Compiler override |
94
+ | `LD` | | Linker override |
95
+ | `HATCH_CPP_PLATFORM` | | Platform to build |
96
+ | `HATCH_CPP_DISABLE_CCACHE` | | Disable CCache usage |
97
+
98
+ > [!NOTE]
99
+ > 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.1.7"
1
+ __version__ = "0.1.8"
2
2
 
3
3
  from .hooks import hatch_register_build_hook
4
4
  from .plugin import HatchCppBuildHook
@@ -102,8 +102,15 @@ class HatchCppPlatform(BaseModel):
102
102
  toolchain = "clang"
103
103
  elif "cl" in CC and "cl" in CXX:
104
104
  toolchain = "msvc"
105
+ # Fallback to platform defaults
106
+ elif platform == "linux":
107
+ toolchain = "gcc"
108
+ elif platform == "darwin":
109
+ toolchain = "clang"
110
+ elif platform == "win32":
111
+ toolchain = "msvc"
105
112
  else:
106
- raise Exception(f"Unrecognized toolchain: {CC}, {CXX}")
113
+ toolchain = "gcc"
107
114
 
108
115
  # Customizations
109
116
  if which("ccache") and not environ.get("HATCH_CPP_DISABLE_CCACHE"):
@@ -117,6 +124,12 @@ class HatchCppPlatform(BaseModel):
117
124
  # LD = which("ld.lld")
118
125
  return HatchCppPlatform(cc=CC, cxx=CXX, ld=LD, platform=platform, toolchain=toolchain)
119
126
 
127
+ @staticmethod
128
+ def platform_for_toolchain(toolchain: CompilerToolchain) -> HatchCppPlatform:
129
+ platform = HatchCppPlatform.default()
130
+ platform.toolchain = toolchain
131
+ return platform
132
+
120
133
  def get_compile_flags(self, library: HatchCppLibrary, build_type: BuildType = "release") -> str:
121
134
  flags = ""
122
135
 
@@ -241,11 +254,27 @@ class HatchCppBuildConfig(BaseModel):
241
254
  cmake: Optional[HatchCppCmakeConfiguration] = Field(default=None)
242
255
  platform: Optional[HatchCppPlatform] = Field(default_factory=HatchCppPlatform.default)
243
256
 
244
- @model_validator(mode="after")
245
- def check_toolchain_matches_args(self):
246
- if self.cmake and self.libraries:
257
+ @model_validator(mode="wrap")
258
+ @classmethod
259
+ def validate_model(cls, data, handler):
260
+ if "toolchain" in data:
261
+ data["platform"] = HatchCppPlatform.platform_for_toolchain(data["toolchain"])
262
+ data.pop("toolchain")
263
+ elif "platform" not in data:
264
+ data["platform"] = HatchCppPlatform.default()
265
+ if "cc" in data:
266
+ data["platform"].cc = data["cc"]
267
+ data.pop("cc")
268
+ if "cxx" in data:
269
+ data["platform"].cxx = data["cxx"]
270
+ data.pop("cxx")
271
+ if "ld" in data:
272
+ data["platform"].ld = data["ld"]
273
+ data.pop("ld")
274
+ model = handler(data)
275
+ if model.cmake and model.libraries:
247
276
  raise ValueError("Must not provide libraries when using cmake toolchain.")
248
- return self
277
+ return model
249
278
 
250
279
 
251
280
  class HatchCppBuildPlan(HatchCppBuildConfig):
@@ -0,0 +1,17 @@
1
+ #pragma once
2
+ #include "Python.h"
3
+
4
+ PyObject* hello(PyObject*, PyObject*);
5
+
6
+ static PyMethodDef extension_methods[] = {
7
+ {"hello", (PyCFunction)hello, METH_NOARGS},
8
+ {nullptr, nullptr, 0, nullptr}
9
+ };
10
+
11
+ static PyModuleDef extension_module = {
12
+ PyModuleDef_HEAD_INIT, "extension", "extension", -1, extension_methods};
13
+
14
+ PyMODINIT_FUNC PyInit_extension(void) {
15
+ Py_Initialize();
16
+ return PyModule_Create(&extension_module);
17
+ }
@@ -0,0 +1,5 @@
1
+ #include "project/basic.hpp"
2
+
3
+ PyObject* hello(PyObject*, PyObject*) {
4
+ return PyUnicode_FromString("A string");
5
+ }
@@ -0,0 +1,17 @@
1
+ #pragma once
2
+ #include "Python.h"
3
+
4
+ PyObject* hello(PyObject*, PyObject*);
5
+
6
+ static PyMethodDef extension_methods[] = {
7
+ {"hello", (PyCFunction)hello, METH_NOARGS},
8
+ {nullptr, nullptr, 0, nullptr}
9
+ };
10
+
11
+ static PyModuleDef extension_module = {
12
+ PyModuleDef_HEAD_INIT, "extension", "extension", -1, extension_methods};
13
+
14
+ PyMODINIT_FUNC PyInit_extension(void) {
15
+ Py_Initialize();
16
+ return PyModule_Create(&extension_module);
17
+ }
@@ -0,0 +1,38 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.20"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "hatch-cpp-test-project-toolchain"
7
+ description = "Toolchain override test project for hatch-cpp"
8
+ version = "0.1.0"
9
+ requires-python = ">=3.9"
10
+ dependencies = [
11
+ "hatchling>=1.20",
12
+ "hatch-cpp",
13
+ ]
14
+
15
+ [tool.hatch.build]
16
+ artifacts = [
17
+ "project/*.dll",
18
+ "project/*.dylib",
19
+ "project/*.so",
20
+ ]
21
+
22
+ [tool.hatch.build.sources]
23
+ src = "/"
24
+
25
+ [tool.hatch.build.targets.sdist]
26
+ packages = ["project"]
27
+
28
+ [tool.hatch.build.targets.wheel]
29
+ packages = ["project"]
30
+
31
+ [tool.hatch.build.hooks.hatch-cpp]
32
+ verbose = true
33
+ libraries = [
34
+ {name = "project/extension", sources = ["cpp/project/basic.cpp"], include-dirs = ["cpp"]}
35
+ ]
36
+ toolchain = "gcc"
37
+ cc = "clang"
38
+ cxx = "clang++"
@@ -13,6 +13,8 @@ class TestProject:
13
13
  [
14
14
  "test_project_basic",
15
15
  "test_project_override_classes",
16
+ "test_project_override_classes",
17
+ "test_project_override_toolchain",
16
18
  "test_project_pybind",
17
19
  "test_project_nanobind",
18
20
  "test_project_limited_api",
@@ -29,8 +31,7 @@ class TestProject:
29
31
  # compile
30
32
  check_call(
31
33
  [
32
- "hatchling",
33
- "build",
34
+ "hatch-build",
34
35
  "--hooks-only",
35
36
  ],
36
37
  cwd=f"hatch_cpp/tests/{project}",
@@ -46,3 +46,11 @@ class TestStructs:
46
46
  assert f"-DHATCH_CPP_TEST_PROJECT_BASIC_PYTHON_VERSION=3.{version_info.minor}" in hatch_build_plan.commands[0]
47
47
  if hatch_build_plan.platform.platform == "darwin":
48
48
  assert "-DCMAKE_OSX_DEPLOYMENT_TARGET=11" in hatch_build_plan.commands[0]
49
+
50
+ def test_platform_toolchain_override(self):
51
+ txt = (Path(__file__).parent / "test_project_override_toolchain" / "pyproject.toml").read_text()
52
+ toml = loads(txt)
53
+ hatch_build_config = HatchCppBuildConfig(name=toml["project"]["name"], **toml["tool"]["hatch"]["build"]["hooks"]["hatch-cpp"])
54
+ assert "clang" in hatch_build_config.platform.cc
55
+ assert "clang++" in hatch_build_config.platform.cxx
56
+ assert hatch_build_config.platform.toolchain == "gcc"
File without changes
@@ -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.1.7"
11
+ version = "0.1.8"
12
12
  requires-python = ">=3.9"
13
13
  keywords = [
14
14
  "hatch",
@@ -20,6 +20,7 @@ keywords = [
20
20
  ]
21
21
  classifiers = [
22
22
  "Development Status :: 3 - Alpha",
23
+ "License :: OSI Approved :: Apache Software License",
23
24
  "Programming Language :: Python",
24
25
  "Programming Language :: Python :: Implementation :: CPython",
25
26
  "Programming Language :: Python :: Implementation :: PyPy",
@@ -28,7 +29,8 @@ classifiers = [
28
29
  "Programming Language :: Python :: 3.10",
29
30
  "Programming Language :: Python :: 3.11",
30
31
  "Programming Language :: Python :: 3.12",
31
- "License :: OSI Approved :: Apache Software License",
32
+ "Programming Language :: Python :: 3.13",
33
+ "Programming Language :: Python :: 3.14",
32
34
  ]
33
35
 
34
36
  dependencies = [
@@ -41,11 +43,19 @@ develop = [
41
43
  "build",
42
44
  "bump-my-version",
43
45
  "check-manifest",
44
- "ruff>=0.3,<0.9",
46
+ "codespell>=2.4,<2.5",
47
+ "hatchling",
48
+ "hatch-build",
49
+ "mdformat>=0.7.22,<0.8",
50
+ "mdformat-tables>=1",
51
+ "pytest",
52
+ "pytest-cov",
53
+ "ruff",
45
54
  "twine",
55
+ "uv",
46
56
  "wheel",
47
57
  # test
48
- "nanobind",
58
+ "nanobind<2.10.0", # https://github.com/wjakob/nanobind/commit/abd27e3b5565bc95f5091321f0f863fce8b5b95b
49
59
  "pybind11",
50
60
  "pytest",
51
61
  "pytest-cov",
@@ -63,9 +73,10 @@ Repository = "https://github.com/python-project-templates/hatch-cpp"
63
73
  Homepage = "https://github.com/python-project-templates/hatch-cpp"
64
74
 
65
75
  [tool.bumpversion]
66
- current_version = "0.1.7"
76
+ current_version = "0.1.8"
67
77
  commit = true
68
78
  tag = false
79
+ commit_args = "-s"
69
80
 
70
81
  [[tool.bumpversion.files]]
71
82
  filename = "hatch_cpp/__init__.py"
@@ -79,9 +90,8 @@ replace = 'version = "{new_version}"'
79
90
 
80
91
  [tool.check-manifest]
81
92
  ignore = [
82
- ".copier-answers.yml",
93
+ ".copier-answers.yaml",
83
94
  "Makefile",
84
- "setup.py",
85
95
  "docs/**/*",
86
96
  ]
87
97
 
@@ -97,7 +107,7 @@ exclude_also = [
97
107
  "@(abc\\.)?abstractmethod",
98
108
  ]
99
109
  ignore_errors = true
100
- fail_under = 70
110
+ fail_under = 50
101
111
 
102
112
  [tool.hatch.build]
103
113
  artifacts = []
@@ -113,7 +123,6 @@ packages = ["hatch_cpp"]
113
123
 
114
124
  [tool.pytest.ini_options]
115
125
  addopts = ["-vvv", "--junitxml=junit.xml"]
116
- asyncio_mode = "strict"
117
126
  testpaths = "hatch_cpp/tests"
118
127
 
119
128
  [tool.ruff]
@@ -1,170 +0,0 @@
1
- # Byte-compiled / optimized / DLL files
2
- __pycache__/
3
- *.py[cod]
4
- *$py.class
5
-
6
- # C extensions
7
- *.a
8
- *.so
9
- *.obj
10
- *.dll
11
- *.exp
12
- *.lib
13
-
14
- # Distribution / packaging
15
- .Python
16
- env/
17
- build/
18
- develop-eggs/
19
- dist/
20
- downloads/
21
- eggs/
22
- .eggs/
23
- include/
24
- lib/
25
- lib64/
26
- parts/
27
- sdist/
28
- var/
29
- *.egg-info/
30
- .installed.cfg
31
- *.egg
32
-
33
- # PyInstaller
34
- # Usually these files are written by a python script from a template
35
- # before PyInstaller builds the exe, so as to inject date/other infos into it.
36
- *.manifest
37
- *.spec
38
-
39
- # Installer logs
40
- pip-log.txt
41
- pip-delete-this-directory.txt
42
-
43
- # Unit test / coverage reports
44
- htmlcov/
45
- .tox/
46
- .coverage
47
- .coverage.*
48
- .cache
49
- python_junit.xml
50
- junit.xml
51
- nosetests.xml
52
- coverage.xml
53
- *,cover
54
- .hypothesis/
55
- .pytest_cache
56
- .ruff_cache
57
- js/playwright-report
58
-
59
- # Translations
60
- *.mo
61
- *.pot
62
-
63
- # Django stuff:
64
- *.log
65
- local_settings.py
66
-
67
- # Flask instance folder
68
- instance/
69
-
70
- # Scrapy stuff:
71
- .scrapy
72
-
73
- # Sphinx documentation
74
- docs/_build/
75
- docs/source
76
-
77
- # PyBuilder
78
- target/
79
-
80
- # IPython Notebook
81
- .ipynb_checkpoints
82
- *.ipynb
83
- .autoversion
84
-
85
- # pyenv
86
- .python-version
87
-
88
- # celery beat schedule file
89
- celerybeat-schedule
90
-
91
- # dotenv
92
- .env
93
-
94
- # virtualenv
95
- venv/
96
- ENV/
97
-
98
- # Spyder project settings
99
- .spyderproject
100
-
101
- # Rope project settings
102
- .ropeproject
103
-
104
- # =========================
105
- # Operating System Files
106
- # =========================
107
-
108
- # OSX
109
- # =========================
110
-
111
- .DS_Store
112
- .AppleDouble
113
- .LSOverride
114
-
115
- # Thumbnails
116
- ._*
117
-
118
- # Files that might appear in the root of a volume
119
- .DocumentRevisions-V100
120
- .fseventsd
121
- .Spotlight-V100
122
- .TemporaryItems
123
- .Trashes
124
- .VolumeIcon.icns
125
-
126
- # Directories potentially created on remote AFP share
127
- .AppleDB
128
- .AppleDesktop
129
- Network Trash Folder
130
- Temporary Items
131
- .apdisk
132
-
133
- # Windows
134
- # =========================
135
-
136
- # Windows image file caches
137
- Thumbs.db
138
- ehthumbs.db
139
-
140
- # Folder config file
141
- Desktop.ini
142
-
143
- # Recycle Bin used on file shares
144
- $RECYCLE.BIN/
145
-
146
- # Windows Installer files
147
- *.cab
148
- *.msi
149
- *.msm
150
- *.msp
151
-
152
- # Windows shortcuts
153
- *.lnk
154
-
155
-
156
- # NPM
157
- # ----
158
- **/node_modules/
159
-
160
- # Coverage data
161
- # -------------
162
- **/coverage/
163
-
164
- # Notebook and lab extensions
165
-
166
- nbprint/extension/*
167
- nbprint/templates/nbprint/static/*
168
- nbprint/voila/static/*
169
- tmp.html
170
- examples/output/
hatch_cpp-0.1.7/PKG-INFO DELETED
@@ -1,72 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: hatch-cpp
3
- Version: 0.1.7
4
- Summary: Hatch plugin for C++ builds
5
- Project-URL: Repository, https://github.com/python-project-templates/hatch-cpp
6
- Project-URL: Homepage, https://github.com/python-project-templates/hatch-cpp
7
- Author-email: the hatch-cpp authors <t.paine154@gmail.com>
8
- License: Apache-2.0
9
- License-File: LICENSE
10
- Keywords: build,c++,cmake,cpp,hatch,python
11
- Classifier: Development Status :: 3 - Alpha
12
- Classifier: License :: OSI Approved :: Apache Software License
13
- Classifier: Programming Language :: Python
14
- Classifier: Programming Language :: Python :: 3
15
- Classifier: Programming Language :: Python :: 3.9
16
- Classifier: Programming Language :: Python :: 3.10
17
- Classifier: Programming Language :: Python :: 3.11
18
- Classifier: Programming Language :: Python :: 3.12
19
- Classifier: Programming Language :: Python :: Implementation :: CPython
20
- Classifier: Programming Language :: Python :: Implementation :: PyPy
21
- Requires-Python: >=3.9
22
- Requires-Dist: hatchling>=1.20
23
- Requires-Dist: pydantic
24
- Provides-Extra: develop
25
- Requires-Dist: build; extra == 'develop'
26
- Requires-Dist: bump-my-version; extra == 'develop'
27
- Requires-Dist: check-manifest; extra == 'develop'
28
- Requires-Dist: nanobind; extra == 'develop'
29
- Requires-Dist: pybind11; extra == 'develop'
30
- Requires-Dist: pytest; extra == 'develop'
31
- Requires-Dist: pytest-cov; extra == 'develop'
32
- Requires-Dist: ruff<0.9,>=0.3; extra == 'develop'
33
- Requires-Dist: toml; extra == 'develop'
34
- Requires-Dist: twine; extra == 'develop'
35
- Requires-Dist: wheel; extra == 'develop'
36
- Description-Content-Type: text/markdown
37
-
38
- # hatch-cpp
39
-
40
- Hatch plugin for C++ builds
41
-
42
- [![Build Status](https://github.com/python-project-templates/hatch-cpp/actions/workflows/build.yml/badge.svg?branch=main&event=push)](https://github.com/python-project-templates/hatch-cpp/actions/workflows/build.yml)
43
- [![codecov](https://codecov.io/gh/python-project-templates/hatch-cpp/branch/main/graph/badge.svg)](https://codecov.io/gh/python-project-templates/hatch-cpp)
44
- [![License](https://img.shields.io/github/license/python-project-templates/hatch-cpp)](https://github.com/python-project-templates/hatch-cpp)
45
- [![PyPI](https://img.shields.io/pypi/v/hatch-cpp.svg)](https://pypi.python.org/pypi/hatch-cpp)
46
-
47
- ## Overview
48
-
49
- A simple, extensible C++ build plugin for [hatch](https://hatch.pypa.io/latest/).
50
-
51
- ```toml
52
- [tool.hatch.build.hooks.hatch-cpp]
53
- libraries = [
54
- {name = "project/extension", sources = ["cpp/project/basic.cpp"], include-dirs = ["cpp"]}
55
- ]
56
- ```
57
-
58
- For more complete systems, see:
59
- - [scikit-build-core](https://github.com/scikit-build/scikit-build-core)
60
- - [setuptools](https://setuptools.pypa.io/en/latest/userguide/ext_modules.html)
61
-
62
- ## Environment Variables
63
- | Name | Default | Description |
64
- |:-----|:--------|:------------|
65
- |`CC`| | |
66
- |`CXX`| | |
67
- |`LD`| | |
68
- |`HATCH_CPP_PLATFORM`| | |
69
- |`HATCH_CPP_DISABLE_CCACHE`| | |
70
-
71
- > [!NOTE]
72
- > 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).
hatch_cpp-0.1.7/README.md DELETED
@@ -1,35 +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.yml/badge.svg?branch=main&event=push)](https://github.com/python-project-templates/hatch-cpp/actions/workflows/build.yml)
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
- - [scikit-build-core](https://github.com/scikit-build/scikit-build-core)
23
- - [setuptools](https://setuptools.pypa.io/en/latest/userguide/ext_modules.html)
24
-
25
- ## Environment Variables
26
- | Name | Default | Description |
27
- |:-----|:--------|:------------|
28
- |`CC`| | |
29
- |`CXX`| | |
30
- |`LD`| | |
31
- |`HATCH_CPP_PLATFORM`| | |
32
- |`HATCH_CPP_DISABLE_CCACHE`| | |
33
-
34
- > [!NOTE]
35
- > 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