hatch-cpp 0.1.6__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 +5 -0
- hatch_cpp/hooks.py +10 -0
- hatch_cpp/plugin.py +91 -0
- hatch_cpp/structs.py +252 -0
- hatch_cpp/tests/test_project_basic/cpp/project/basic.cpp +5 -0
- hatch_cpp/tests/test_project_basic/cpp/project/basic.hpp +17 -0
- hatch_cpp/tests/test_project_basic/project/__init__.py +0 -0
- hatch_cpp/tests/test_project_basic/pyproject.toml +35 -0
- hatch_cpp/tests/test_project_limited_api/cpp/project/basic.cpp +5 -0
- hatch_cpp/tests/test_project_limited_api/cpp/project/basic.hpp +17 -0
- hatch_cpp/tests/test_project_limited_api/project/__init__.py +0 -0
- hatch_cpp/tests/test_project_limited_api/pyproject.toml +35 -0
- hatch_cpp/tests/test_project_nanobind/cpp/project/basic.cpp +2 -0
- hatch_cpp/tests/test_project_nanobind/cpp/project/basic.hpp +7 -0
- hatch_cpp/tests/test_project_nanobind/project/__init__.py +0 -0
- hatch_cpp/tests/test_project_nanobind/pyproject.toml +35 -0
- hatch_cpp/tests/test_project_override_classes/cpp/project/basic.cpp +5 -0
- hatch_cpp/tests/test_project_override_classes/cpp/project/basic.hpp +17 -0
- hatch_cpp/tests/test_project_override_classes/project/__init__.py +0 -0
- hatch_cpp/tests/test_project_override_classes/pyproject.toml +37 -0
- hatch_cpp/tests/test_project_pybind/cpp/project/basic.cpp +6 -0
- hatch_cpp/tests/test_project_pybind/cpp/project/basic.hpp +9 -0
- hatch_cpp/tests/test_project_pybind/project/__init__.py +0 -0
- hatch_cpp/tests/test_project_pybind/pyproject.toml +35 -0
- hatch_cpp/tests/test_projects.py +46 -0
- hatch_cpp/tests/test_structs.py +26 -0
- hatch_cpp/toolchains/__init__.py +0 -0
- hatch_cpp/toolchains/cmake.py +0 -0
- hatch_cpp/utils.py +132 -0
- hatch_cpp-0.1.6.dist-info/METADATA +71 -0
- hatch_cpp-0.1.6.dist-info/RECORD +34 -0
- hatch_cpp-0.1.6.dist-info/WHEEL +4 -0
- hatch_cpp-0.1.6.dist-info/entry_points.txt +2 -0
- hatch_cpp-0.1.6.dist-info/licenses/LICENSE +201 -0
hatch_cpp/__init__.py
ADDED
hatch_cpp/hooks.py
ADDED
hatch_cpp/plugin.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import os
|
|
5
|
+
import platform as sysplatform
|
|
6
|
+
import sys
|
|
7
|
+
import typing as t
|
|
8
|
+
|
|
9
|
+
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
|
10
|
+
|
|
11
|
+
from .structs import HatchCppBuildConfig, HatchCppBuildPlan
|
|
12
|
+
from .utils import import_string
|
|
13
|
+
|
|
14
|
+
__all__ = ("HatchCppBuildHook",)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class HatchCppBuildHook(BuildHookInterface[HatchCppBuildConfig]):
|
|
18
|
+
"""The hatch-cpp build hook."""
|
|
19
|
+
|
|
20
|
+
PLUGIN_NAME = "hatch-cpp"
|
|
21
|
+
_logger = logging.getLogger(__name__)
|
|
22
|
+
|
|
23
|
+
def initialize(self, version: str, build_data: dict[str, t.Any]) -> None:
|
|
24
|
+
"""Initialize the plugin."""
|
|
25
|
+
# Log some basic information
|
|
26
|
+
self._logger.info("Initializing hatch-cpp plugin version %s", version)
|
|
27
|
+
self._logger.info("Running hatch-cpp")
|
|
28
|
+
|
|
29
|
+
# Only run if creating wheel
|
|
30
|
+
# TODO: Add support for specify sdist-plan
|
|
31
|
+
if self.target_name != "wheel":
|
|
32
|
+
self._logger.info("ignoring target name %s", self.target_name)
|
|
33
|
+
return
|
|
34
|
+
|
|
35
|
+
# Skip if SKIP_HATCH_CPP is set
|
|
36
|
+
# TODO: Support CLI once https://github.com/pypa/hatch/pull/1743
|
|
37
|
+
if os.getenv("SKIP_HATCH_CPP"):
|
|
38
|
+
self._logger.info("Skipping the build hook since SKIP_HATCH_CPP was set")
|
|
39
|
+
return
|
|
40
|
+
|
|
41
|
+
# Get build config class or use default
|
|
42
|
+
build_config_class = import_string(self.config["build-config-class"]) if "build-config-class" in self.config else HatchCppBuildConfig
|
|
43
|
+
|
|
44
|
+
# Instantiate build config
|
|
45
|
+
config = build_config_class(**self.config)
|
|
46
|
+
|
|
47
|
+
# Grab libraries and platform
|
|
48
|
+
libraries = config.libraries
|
|
49
|
+
platform = config.platform
|
|
50
|
+
|
|
51
|
+
# Get build plan class or use default
|
|
52
|
+
build_plan_class = import_string(self.config["build-plan-class"]) if "build-plan-class" in self.config else HatchCppBuildPlan
|
|
53
|
+
|
|
54
|
+
# Instantiate builder
|
|
55
|
+
build_plan = build_plan_class(libraries=libraries, platform=platform)
|
|
56
|
+
|
|
57
|
+
# Generate commands
|
|
58
|
+
build_plan.generate()
|
|
59
|
+
|
|
60
|
+
# Log commands if in verbose mode
|
|
61
|
+
if config.verbose:
|
|
62
|
+
for command in build_plan.commands:
|
|
63
|
+
self._logger.warning(command)
|
|
64
|
+
|
|
65
|
+
# Execute build plan
|
|
66
|
+
build_plan.execute()
|
|
67
|
+
|
|
68
|
+
# Perform any cleanup actions
|
|
69
|
+
build_plan.cleanup()
|
|
70
|
+
|
|
71
|
+
# force include libraries
|
|
72
|
+
for library in libraries:
|
|
73
|
+
name = library.get_qualified_name(build_plan.platform.platform)
|
|
74
|
+
build_data["force_include"][name] = name
|
|
75
|
+
|
|
76
|
+
if libraries:
|
|
77
|
+
build_data["pure_python"] = False
|
|
78
|
+
machine = sysplatform.machine()
|
|
79
|
+
version_major = sys.version_info.major
|
|
80
|
+
version_minor = sys.version_info.minor
|
|
81
|
+
# TODO abi3
|
|
82
|
+
if "darwin" in sys.platform:
|
|
83
|
+
os_name = "macosx_11_0"
|
|
84
|
+
elif "linux" in sys.platform:
|
|
85
|
+
os_name = "linux"
|
|
86
|
+
else:
|
|
87
|
+
os_name = "win"
|
|
88
|
+
if all([lib.py_limited_api for lib in libraries]):
|
|
89
|
+
build_data["tag"] = f"cp{version_major}{version_minor}-abi3-{os_name}_{machine}"
|
|
90
|
+
else:
|
|
91
|
+
build_data["tag"] = f"cp{version_major}{version_minor}-cp{version_major}{version_minor}-{os_name}_{machine}"
|
hatch_cpp/structs.py
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from os import environ, system
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from re import match
|
|
6
|
+
from shutil import which
|
|
7
|
+
from sys import executable, platform as sys_platform
|
|
8
|
+
from sysconfig import get_path
|
|
9
|
+
from typing import Any, List, Literal, Optional
|
|
10
|
+
|
|
11
|
+
from pydantic import AliasChoices, BaseModel, Field, field_validator, model_validator
|
|
12
|
+
|
|
13
|
+
__all__ = (
|
|
14
|
+
"HatchCppBuildConfig",
|
|
15
|
+
"HatchCppLibrary",
|
|
16
|
+
"HatchCppPlatform",
|
|
17
|
+
"HatchCppBuildPlan",
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
BuildType = Literal["debug", "release"]
|
|
21
|
+
CompilerToolchain = Literal["gcc", "clang", "msvc"]
|
|
22
|
+
Language = Literal["c", "c++"]
|
|
23
|
+
Binding = Literal["cpython", "pybind11", "nanobind"]
|
|
24
|
+
Platform = Literal["linux", "darwin", "win32"]
|
|
25
|
+
PlatformDefaults = {
|
|
26
|
+
"linux": {"CC": "gcc", "CXX": "g++", "LD": "ld"},
|
|
27
|
+
"darwin": {"CC": "clang", "CXX": "clang++", "LD": "ld"},
|
|
28
|
+
"win32": {"CC": "cl", "CXX": "cl", "LD": "link"},
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class HatchCppLibrary(BaseModel, validate_assignment=True):
|
|
33
|
+
"""A C++ library."""
|
|
34
|
+
|
|
35
|
+
name: str
|
|
36
|
+
sources: List[str]
|
|
37
|
+
language: Language = "c++"
|
|
38
|
+
|
|
39
|
+
binding: Binding = "cpython"
|
|
40
|
+
std: Optional[str] = None
|
|
41
|
+
|
|
42
|
+
include_dirs: List[str] = Field(default_factory=list, alias=AliasChoices("include_dirs", "include-dirs"))
|
|
43
|
+
library_dirs: List[str] = Field(default_factory=list, alias=AliasChoices("library_dirs", "library-dirs"))
|
|
44
|
+
libraries: List[str] = Field(default_factory=list)
|
|
45
|
+
|
|
46
|
+
extra_compile_args: List[str] = Field(default_factory=list, alias=AliasChoices("extra_compile_args", "extra-compile-args"))
|
|
47
|
+
extra_link_args: List[str] = Field(default_factory=list, alias=AliasChoices("extra_link_args", "extra-link-args"))
|
|
48
|
+
extra_objects: List[str] = Field(default_factory=list, alias=AliasChoices("extra_objects", "extra-objects"))
|
|
49
|
+
|
|
50
|
+
define_macros: List[str] = Field(default_factory=list, alias=AliasChoices("define_macros", "define-macros"))
|
|
51
|
+
undef_macros: List[str] = Field(default_factory=list, alias=AliasChoices("undef_macros", "undef-macros"))
|
|
52
|
+
|
|
53
|
+
export_symbols: List[str] = Field(default_factory=list, alias=AliasChoices("export_symbols", "export-symbols"))
|
|
54
|
+
depends: List[str] = Field(default_factory=list)
|
|
55
|
+
|
|
56
|
+
py_limited_api: Optional[str] = Field(default="", alias=AliasChoices("py_limited_api", "py-limited-api"))
|
|
57
|
+
|
|
58
|
+
@field_validator("py_limited_api", mode="before")
|
|
59
|
+
@classmethod
|
|
60
|
+
def check_py_limited_api(cls, value: Any) -> Any:
|
|
61
|
+
if value:
|
|
62
|
+
if not match(r"cp3\d", value):
|
|
63
|
+
raise ValueError("py-limited-api must be in the form of cp3X")
|
|
64
|
+
return value
|
|
65
|
+
|
|
66
|
+
def get_qualified_name(self, platform):
|
|
67
|
+
if platform == "win32":
|
|
68
|
+
suffix = "dll" if self.binding == "none" else "pyd"
|
|
69
|
+
elif platform == "darwin":
|
|
70
|
+
suffix = "dylib" if self.binding == "none" else "so"
|
|
71
|
+
else:
|
|
72
|
+
suffix = "so"
|
|
73
|
+
if self.py_limited_api and platform != "win32":
|
|
74
|
+
return f"{self.name}.abi3.{suffix}"
|
|
75
|
+
return f"{self.name}.{suffix}"
|
|
76
|
+
|
|
77
|
+
@model_validator(mode="after")
|
|
78
|
+
def check_binding_and_py_limited_api(self):
|
|
79
|
+
if self.binding == "pybind11" and self.py_limited_api:
|
|
80
|
+
raise ValueError("pybind11 does not support Py_LIMITED_API")
|
|
81
|
+
return self
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class HatchCppPlatform(BaseModel):
|
|
85
|
+
cc: str
|
|
86
|
+
cxx: str
|
|
87
|
+
ld: str
|
|
88
|
+
platform: Platform
|
|
89
|
+
toolchain: CompilerToolchain
|
|
90
|
+
|
|
91
|
+
@staticmethod
|
|
92
|
+
def default() -> HatchCppPlatform:
|
|
93
|
+
platform = environ.get("HATCH_CPP_PLATFORM", sys_platform)
|
|
94
|
+
CC = environ.get("CC", PlatformDefaults[platform]["CC"])
|
|
95
|
+
CXX = environ.get("CXX", PlatformDefaults[platform]["CXX"])
|
|
96
|
+
LD = environ.get("LD", PlatformDefaults[platform]["LD"])
|
|
97
|
+
if "gcc" in CC and "g++" in CXX:
|
|
98
|
+
toolchain = "gcc"
|
|
99
|
+
elif "clang" in CC and "clang++" in CXX:
|
|
100
|
+
toolchain = "clang"
|
|
101
|
+
elif "cl" in CC and "cl" in CXX:
|
|
102
|
+
toolchain = "msvc"
|
|
103
|
+
else:
|
|
104
|
+
raise Exception(f"Unrecognized toolchain: {CC}, {CXX}")
|
|
105
|
+
|
|
106
|
+
# Customizations
|
|
107
|
+
if which("ccache") and not environ.get("HATCH_CPP_DISABLE_CCACHE"):
|
|
108
|
+
CC = f"ccache {CC}"
|
|
109
|
+
CXX = f"ccache {CXX}"
|
|
110
|
+
|
|
111
|
+
# https://github.com/rui314/mold/issues/647
|
|
112
|
+
# if which("ld.mold"):
|
|
113
|
+
# LD = which("ld.mold")
|
|
114
|
+
# elif which("ld.lld"):
|
|
115
|
+
# LD = which("ld.lld")
|
|
116
|
+
return HatchCppPlatform(cc=CC, cxx=CXX, ld=LD, platform=platform, toolchain=toolchain)
|
|
117
|
+
|
|
118
|
+
def get_compile_flags(self, library: HatchCppLibrary, build_type: BuildType = "release") -> str:
|
|
119
|
+
flags = ""
|
|
120
|
+
|
|
121
|
+
# Python.h
|
|
122
|
+
library.include_dirs.append(get_path("include"))
|
|
123
|
+
|
|
124
|
+
if library.binding == "pybind11":
|
|
125
|
+
import pybind11
|
|
126
|
+
|
|
127
|
+
library.include_dirs.append(pybind11.get_include())
|
|
128
|
+
if not library.std:
|
|
129
|
+
library.std = "c++11"
|
|
130
|
+
elif library.binding == "nanobind":
|
|
131
|
+
import nanobind
|
|
132
|
+
|
|
133
|
+
library.include_dirs.append(nanobind.include_dir())
|
|
134
|
+
if not library.std:
|
|
135
|
+
library.std = "c++17"
|
|
136
|
+
library.sources.append(str(Path(nanobind.include_dir()).parent / "src" / "nb_combined.cpp"))
|
|
137
|
+
library.include_dirs.append(str((Path(nanobind.include_dir()).parent / "ext" / "robin_map" / "include")))
|
|
138
|
+
|
|
139
|
+
if library.py_limited_api:
|
|
140
|
+
if library.binding == "pybind11":
|
|
141
|
+
raise ValueError("pybind11 does not support Py_LIMITED_API")
|
|
142
|
+
library.define_macros.append(f"Py_LIMITED_API=0x0{library.py_limited_api[2]}0{hex(int(library.py_limited_api[3:]))[2:]}00f0")
|
|
143
|
+
|
|
144
|
+
# Toolchain-specific flags
|
|
145
|
+
if self.toolchain == "gcc":
|
|
146
|
+
flags += " " + " ".join(f"-I{d}" for d in library.include_dirs)
|
|
147
|
+
flags += " -fPIC"
|
|
148
|
+
flags += " " + " ".join(library.extra_compile_args)
|
|
149
|
+
flags += " " + " ".join(f"-D{macro}" for macro in library.define_macros)
|
|
150
|
+
flags += " " + " ".join(f"-U{macro}" for macro in library.undef_macros)
|
|
151
|
+
if library.std:
|
|
152
|
+
flags += f" -std={library.std}"
|
|
153
|
+
elif self.toolchain == "clang":
|
|
154
|
+
flags += " ".join(f"-I{d}" for d in library.include_dirs)
|
|
155
|
+
flags += " -fPIC"
|
|
156
|
+
flags += " " + " ".join(library.extra_compile_args)
|
|
157
|
+
flags += " " + " ".join(f"-D{macro}" for macro in library.define_macros)
|
|
158
|
+
flags += " " + " ".join(f"-U{macro}" for macro in library.undef_macros)
|
|
159
|
+
if library.std:
|
|
160
|
+
flags += f" -std={library.std}"
|
|
161
|
+
elif self.toolchain == "msvc":
|
|
162
|
+
flags += " ".join(f"/I{d}" for d in library.include_dirs)
|
|
163
|
+
flags += " " + " ".join(library.extra_compile_args)
|
|
164
|
+
flags += " " + " ".join(library.extra_link_args)
|
|
165
|
+
flags += " " + " ".join(library.extra_objects)
|
|
166
|
+
flags += " " + " ".join(f"/D{macro}" for macro in library.define_macros)
|
|
167
|
+
flags += " " + " ".join(f"/U{macro}" for macro in library.undef_macros)
|
|
168
|
+
flags += " /EHsc /DWIN32"
|
|
169
|
+
if library.std:
|
|
170
|
+
flags += f" /std:{library.std}"
|
|
171
|
+
# clean
|
|
172
|
+
while flags.count(" "):
|
|
173
|
+
flags = flags.replace(" ", " ")
|
|
174
|
+
return flags
|
|
175
|
+
|
|
176
|
+
def get_link_flags(self, library: HatchCppLibrary, build_type: BuildType = "release") -> str:
|
|
177
|
+
flags = ""
|
|
178
|
+
if self.toolchain == "gcc":
|
|
179
|
+
flags += " -shared"
|
|
180
|
+
flags += " " + " ".join(library.extra_link_args)
|
|
181
|
+
flags += " " + " ".join(library.extra_objects)
|
|
182
|
+
flags += " " + " ".join(f"-l{lib}" for lib in library.libraries)
|
|
183
|
+
flags += " " + " ".join(f"-L{lib}" for lib in library.library_dirs)
|
|
184
|
+
flags += f" -o {library.get_qualified_name(self.platform)}"
|
|
185
|
+
if self.platform == "darwin":
|
|
186
|
+
flags += " -undefined dynamic_lookup"
|
|
187
|
+
if "mold" in self.ld:
|
|
188
|
+
flags += f" -fuse-ld={self.ld}"
|
|
189
|
+
elif "lld" in self.ld:
|
|
190
|
+
flags += " -fuse-ld=lld"
|
|
191
|
+
elif self.toolchain == "clang":
|
|
192
|
+
flags += " -shared"
|
|
193
|
+
flags += " " + " ".join(library.extra_link_args)
|
|
194
|
+
flags += " " + " ".join(library.extra_objects)
|
|
195
|
+
flags += " " + " ".join(f"-l{lib}" for lib in library.libraries)
|
|
196
|
+
flags += " " + " ".join(f"-L{lib}" for lib in library.library_dirs)
|
|
197
|
+
flags += f" -o {library.get_qualified_name(self.platform)}"
|
|
198
|
+
if self.platform == "darwin":
|
|
199
|
+
flags += " -undefined dynamic_lookup"
|
|
200
|
+
if "mold" in self.ld:
|
|
201
|
+
flags += f" -fuse-ld={self.ld}"
|
|
202
|
+
elif "lld" in self.ld:
|
|
203
|
+
flags += " -fuse-ld=lld"
|
|
204
|
+
elif self.toolchain == "msvc":
|
|
205
|
+
flags += " " + " ".join(library.extra_link_args)
|
|
206
|
+
flags += " " + " ".join(library.extra_objects)
|
|
207
|
+
flags += " /LD"
|
|
208
|
+
flags += f" /Fe:{library.get_qualified_name(self.platform)}"
|
|
209
|
+
flags += " /link /DLL"
|
|
210
|
+
if (Path(executable).parent / "libs").exists():
|
|
211
|
+
flags += f" /LIBPATH:{str(Path(executable).parent / 'libs')}"
|
|
212
|
+
flags += " " + " ".join(f"{lib}.lib" for lib in library.libraries)
|
|
213
|
+
flags += " " + " ".join(f"/LIBPATH:{lib}" for lib in library.library_dirs)
|
|
214
|
+
# clean
|
|
215
|
+
while flags.count(" "):
|
|
216
|
+
flags = flags.replace(" ", " ")
|
|
217
|
+
return flags
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
class HatchCppBuildPlan(BaseModel):
|
|
221
|
+
build_type: BuildType = "release"
|
|
222
|
+
libraries: List[HatchCppLibrary] = Field(default_factory=list)
|
|
223
|
+
platform: HatchCppPlatform = Field(default_factory=HatchCppPlatform.default)
|
|
224
|
+
commands: List[str] = Field(default_factory=list)
|
|
225
|
+
|
|
226
|
+
def generate(self):
|
|
227
|
+
self.commands = []
|
|
228
|
+
for library in self.libraries:
|
|
229
|
+
compile_flags = self.platform.get_compile_flags(library, self.build_type)
|
|
230
|
+
link_flags = self.platform.get_link_flags(library, self.build_type)
|
|
231
|
+
self.commands.append(
|
|
232
|
+
f"{self.platform.cc if library.language == 'c' else self.platform.cxx} {' '.join(library.sources)} {compile_flags} {link_flags}"
|
|
233
|
+
)
|
|
234
|
+
return self.commands
|
|
235
|
+
|
|
236
|
+
def execute(self):
|
|
237
|
+
for command in self.commands:
|
|
238
|
+
system(command)
|
|
239
|
+
return self.commands
|
|
240
|
+
|
|
241
|
+
def cleanup(self):
|
|
242
|
+
if self.platform.platform == "win32":
|
|
243
|
+
for temp_obj in Path(".").glob("*.obj"):
|
|
244
|
+
temp_obj.unlink()
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
class HatchCppBuildConfig(BaseModel):
|
|
248
|
+
"""Build config values for Hatch C++ Builder."""
|
|
249
|
+
|
|
250
|
+
verbose: Optional[bool] = Field(default=False)
|
|
251
|
+
libraries: List[HatchCppLibrary] = Field(default_factory=list)
|
|
252
|
+
platform: Optional[HatchCppPlatform] = Field(default_factory=HatchCppPlatform.default)
|
|
@@ -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
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.20"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "hatch-cpp-test-project-basic"
|
|
7
|
+
description = "Basic 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
|
+
]
|
|
@@ -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
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.20"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "hatch-cpp-test-project-limtied-api"
|
|
7
|
+
description = "Basic 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"], py-limited-api = "cp39"},
|
|
35
|
+
]
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.20"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "hatch-cpp-test-project-nanobind"
|
|
7
|
+
description = "Basic 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"], binding = "nanobind"},
|
|
35
|
+
]
|
|
@@ -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
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.20"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "hatch-cpp-test-project-override-classes"
|
|
7
|
+
description = "Basic 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
|
+
build-config-class = "hatch_cpp.HatchCppBuildConfig"
|
|
33
|
+
build-plan-class = "hatch_cpp.HatchCppBuildPlan"
|
|
34
|
+
verbose = true
|
|
35
|
+
libraries = [
|
|
36
|
+
{name = "project/extension", sources = ["cpp/project/basic.cpp"], include-dirs = ["cpp"]}
|
|
37
|
+
]
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.20"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "hatch-cpp-test-project-pybind"
|
|
7
|
+
description = "Basic 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"], binding="pybind11"},
|
|
35
|
+
]
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from os import listdir
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from shutil import rmtree
|
|
4
|
+
from subprocess import check_call
|
|
5
|
+
from sys import modules, path, platform
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TestProject:
|
|
11
|
+
@pytest.mark.parametrize(
|
|
12
|
+
"project", ["test_project_basic", "test_project_override_classes", "test_project_pybind", "test_project_nanobind", "test_project_limited_api"]
|
|
13
|
+
)
|
|
14
|
+
def test_basic(self, project):
|
|
15
|
+
# cleanup
|
|
16
|
+
rmtree(f"hatch_cpp/tests/{project}/project/extension.so", ignore_errors=True)
|
|
17
|
+
rmtree(f"hatch_cpp/tests/{project}/project/extension.pyd", ignore_errors=True)
|
|
18
|
+
modules.pop("project", None)
|
|
19
|
+
modules.pop("project.extension", None)
|
|
20
|
+
|
|
21
|
+
# compile
|
|
22
|
+
check_call(
|
|
23
|
+
[
|
|
24
|
+
"hatchling",
|
|
25
|
+
"build",
|
|
26
|
+
"--hooks-only",
|
|
27
|
+
],
|
|
28
|
+
cwd=f"hatch_cpp/tests/{project}",
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
# assert built
|
|
32
|
+
|
|
33
|
+
if project == "test_project_limited_api" and platform != "win32":
|
|
34
|
+
assert "extension.abi3.so" in listdir(f"hatch_cpp/tests/{project}/project")
|
|
35
|
+
else:
|
|
36
|
+
if platform == "win32":
|
|
37
|
+
assert "extension.pyd" in listdir(f"hatch_cpp/tests/{project}/project")
|
|
38
|
+
else:
|
|
39
|
+
assert "extension.so" in listdir(f"hatch_cpp/tests/{project}/project")
|
|
40
|
+
|
|
41
|
+
# import
|
|
42
|
+
here = Path(__file__).parent / project
|
|
43
|
+
path.insert(0, str(here))
|
|
44
|
+
import project.extension
|
|
45
|
+
|
|
46
|
+
assert project.extension.hello() == "A string"
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from pydantic import ValidationError
|
|
3
|
+
|
|
4
|
+
from hatch_cpp.structs import HatchCppLibrary, HatchCppPlatform
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class TestStructs:
|
|
8
|
+
def test_validate_py_limited_api(self):
|
|
9
|
+
with pytest.raises(ValidationError):
|
|
10
|
+
library = HatchCppLibrary(
|
|
11
|
+
name="test",
|
|
12
|
+
sources=["test.cpp"],
|
|
13
|
+
py_limited_api="42",
|
|
14
|
+
)
|
|
15
|
+
library = HatchCppLibrary(
|
|
16
|
+
name="test",
|
|
17
|
+
sources=["test.cpp"],
|
|
18
|
+
py_limited_api="cp39",
|
|
19
|
+
)
|
|
20
|
+
assert library.py_limited_api == "cp39"
|
|
21
|
+
platform = HatchCppPlatform.default()
|
|
22
|
+
flags = platform.get_compile_flags(library)
|
|
23
|
+
assert "-DPy_LIMITED_API=0x030900f0" in flags or "/DPy_LIMITED_API=0x030900f0" in flags
|
|
24
|
+
|
|
25
|
+
with pytest.raises(ValidationError):
|
|
26
|
+
library.binding = "pybind11"
|
|
File without changes
|
|
File without changes
|
hatch_cpp/utils.py
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from functools import lru_cache
|
|
4
|
+
|
|
5
|
+
from pydantic import ImportString, TypeAdapter
|
|
6
|
+
|
|
7
|
+
_import_string_adapter = TypeAdapter(ImportString)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@lru_cache(maxsize=None)
|
|
11
|
+
def import_string(input_string: str):
|
|
12
|
+
return _import_string_adapter.validate_python(input_string)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# import multiprocessing
|
|
16
|
+
# import os
|
|
17
|
+
# import os.path
|
|
18
|
+
# import platform
|
|
19
|
+
# import subprocess
|
|
20
|
+
# import sys
|
|
21
|
+
# from shutil import which
|
|
22
|
+
# from skbuild import setup
|
|
23
|
+
|
|
24
|
+
# CSP_USE_VCPKG = os.environ.get("CSP_USE_VCPKG", "1").lower() in ("1", "on")
|
|
25
|
+
# # Allow arg to override default / env
|
|
26
|
+
# if "--csp-no-vcpkg" in sys.argv:
|
|
27
|
+
# CSP_USE_VCPKG = False
|
|
28
|
+
# sys.argv.remove("--csp-no-vcpkg")
|
|
29
|
+
|
|
30
|
+
# # CMake Options
|
|
31
|
+
# CMAKE_OPTIONS = (
|
|
32
|
+
# ("CSP_BUILD_NO_CXX_ABI", "0"),
|
|
33
|
+
# ("CSP_BUILD_TESTS", "1"),
|
|
34
|
+
# ("CSP_MANYLINUX", "0"),
|
|
35
|
+
# ("CSP_BUILD_KAFKA_ADAPTER", "1"),
|
|
36
|
+
# ("CSP_BUILD_PARQUET_ADAPTER", "1"),
|
|
37
|
+
# ("CSP_BUILD_WS_CLIENT_ADAPTER", "1"),
|
|
38
|
+
# # NOTE:
|
|
39
|
+
# # - omit vcpkg, need to test for presence
|
|
40
|
+
# # - omit ccache, need to test for presence
|
|
41
|
+
# # - omit coverage/gprof, not implemented
|
|
42
|
+
# )
|
|
43
|
+
|
|
44
|
+
# if sys.platform == "linux":
|
|
45
|
+
# VCPKG_TRIPLET = "x64-linux"
|
|
46
|
+
# elif sys.platform == "win32":
|
|
47
|
+
# VCPKG_TRIPLET = "x64-windows-static-md"
|
|
48
|
+
# else:
|
|
49
|
+
# VCPKG_TRIPLET = None
|
|
50
|
+
|
|
51
|
+
# # This will be used for e.g. the sdist
|
|
52
|
+
# if CSP_USE_VCPKG:
|
|
53
|
+
# if not os.path.exists("vcpkg"):
|
|
54
|
+
# subprocess.call(["git", "clone", "https://github.com/Microsoft/vcpkg.git"])
|
|
55
|
+
# if not os.path.exists("vcpkg/ports"):
|
|
56
|
+
# subprocess.call(["git", "submodule", "update", "--init", "--recursive"])
|
|
57
|
+
# if not os.path.exists("vcpkg/buildtrees"):
|
|
58
|
+
# subprocess.call(["git", "pull"], cwd="vcpkg")
|
|
59
|
+
# args = ["install"]
|
|
60
|
+
# if VCPKG_TRIPLET is not None:
|
|
61
|
+
# args.append(f"--triplet={VCPKG_TRIPLET}")
|
|
62
|
+
|
|
63
|
+
# if os.name == "nt":
|
|
64
|
+
# subprocess.call(["bootstrap-vcpkg.bat"], cwd="vcpkg", shell=True)
|
|
65
|
+
# subprocess.call(["vcpkg.bat"] + args, cwd="vcpkg", shell=True)
|
|
66
|
+
# else:
|
|
67
|
+
# subprocess.call(["./bootstrap-vcpkg.sh"], cwd="vcpkg")
|
|
68
|
+
# subprocess.call(["./vcpkg"] + args, cwd="vcpkg")
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
# python_version = f"{sys.version_info.major}.{sys.version_info.minor}"
|
|
72
|
+
# cmake_args = [f"-DCSP_PYTHON_VERSION={python_version}"]
|
|
73
|
+
# vcpkg_toolchain_file = os.path.abspath(
|
|
74
|
+
# os.environ.get(
|
|
75
|
+
# "CSP_VCPKG_PATH",
|
|
76
|
+
# os.path.join("vcpkg/scripts/buildsystems/vcpkg.cmake"),
|
|
77
|
+
# )
|
|
78
|
+
# )
|
|
79
|
+
|
|
80
|
+
# if CSP_USE_VCPKG and os.path.exists(vcpkg_toolchain_file):
|
|
81
|
+
# cmake_args.extend(
|
|
82
|
+
# [
|
|
83
|
+
# "-DCMAKE_TOOLCHAIN_FILE={}".format(vcpkg_toolchain_file),
|
|
84
|
+
# "-DCSP_USE_VCPKG=ON",
|
|
85
|
+
# ]
|
|
86
|
+
# )
|
|
87
|
+
|
|
88
|
+
# if VCPKG_TRIPLET is not None:
|
|
89
|
+
# cmake_args.append(f"-DVCPKG_TARGET_TRIPLET={VCPKG_TRIPLET}")
|
|
90
|
+
# else:
|
|
91
|
+
# cmake_args.append("-DCSP_USE_VCPKG=OFF")
|
|
92
|
+
|
|
93
|
+
# if "CXX" in os.environ:
|
|
94
|
+
# cmake_args.append(f"-DCMAKE_CXX_COMPILER={os.environ['CXX']}")
|
|
95
|
+
|
|
96
|
+
# if "DEBUG" in os.environ:
|
|
97
|
+
# cmake_args.append("-DCMAKE_BUILD_TYPE=Debug")
|
|
98
|
+
|
|
99
|
+
# if platform.system() == "Windows":
|
|
100
|
+
# import distutils.msvccompiler as dm
|
|
101
|
+
|
|
102
|
+
# # https://wiki.python.org/moin/WindowsCompilers#Microsoft_Visual_C.2B-.2B-_14.0_with_Visual_Studio_2015_.28x86.2C_x64.2C_ARM.29
|
|
103
|
+
# msvc = {
|
|
104
|
+
# "12": "Visual Studio 12 2013",
|
|
105
|
+
# "14": "Visual Studio 14 2015",
|
|
106
|
+
# "14.0": "Visual Studio 14 2015",
|
|
107
|
+
# "14.1": "Visual Studio 15 2017",
|
|
108
|
+
# "14.2": "Visual Studio 16 2019",
|
|
109
|
+
# "14.3": "Visual Studio 17 2022",
|
|
110
|
+
# }.get(str(dm.get_build_version()), "Visual Studio 15 2017")
|
|
111
|
+
# cmake_args.extend(
|
|
112
|
+
# [
|
|
113
|
+
# "-G",
|
|
114
|
+
# os.environ.get("CSP_GENERATOR", msvc),
|
|
115
|
+
# ]
|
|
116
|
+
# )
|
|
117
|
+
|
|
118
|
+
# for cmake_option, default in CMAKE_OPTIONS:
|
|
119
|
+
# if os.environ.get(cmake_option, default).lower() in ("1", "on"):
|
|
120
|
+
# cmake_args.append(f"-D{cmake_option}=ON")
|
|
121
|
+
# else:
|
|
122
|
+
# cmake_args.append(f"-D{cmake_option}=OFF")
|
|
123
|
+
|
|
124
|
+
# if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ:
|
|
125
|
+
# os.environ["CMAKE_BUILD_PARALLEL_LEVEL"] = str(multiprocessing.cpu_count())
|
|
126
|
+
|
|
127
|
+
# if platform.system() == "Darwin":
|
|
128
|
+
# os.environ["MACOSX_DEPLOYMENT_TARGET"] = os.environ.get("OSX_DEPLOYMENT_TARGET", "10.15")
|
|
129
|
+
# cmake_args.append(f'-DCMAKE_OSX_DEPLOYMENT_TARGET={os.environ.get("OSX_DEPLOYMENT_TARGET", "10.15")}')
|
|
130
|
+
|
|
131
|
+
# if which("ccache") and os.environ.get("CSP_USE_CCACHE", "") != "0":
|
|
132
|
+
# cmake_args.append("-DCSP_USE_CCACHE=On")
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hatch-cpp
|
|
3
|
+
Version: 0.1.6
|
|
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: twine; extra == 'develop'
|
|
34
|
+
Requires-Dist: wheel; extra == 'develop'
|
|
35
|
+
Description-Content-Type: text/markdown
|
|
36
|
+
|
|
37
|
+
# hatch-cpp
|
|
38
|
+
|
|
39
|
+
Hatch plugin for C++ builds
|
|
40
|
+
|
|
41
|
+
[](https://github.com/python-project-templates/hatch-cpp/actions/workflows/build.yml)
|
|
42
|
+
[](https://codecov.io/gh/python-project-templates/hatch-cpp)
|
|
43
|
+
[](https://github.com/python-project-templates/hatch-cpp)
|
|
44
|
+
[](https://pypi.python.org/pypi/hatch-cpp)
|
|
45
|
+
|
|
46
|
+
## Overview
|
|
47
|
+
|
|
48
|
+
A simple, extensible C++ build plugin for [hatch](https://hatch.pypa.io/latest/).
|
|
49
|
+
|
|
50
|
+
```toml
|
|
51
|
+
[tool.hatch.build.hooks.hatch-cpp]
|
|
52
|
+
libraries = [
|
|
53
|
+
{name = "project/extension", sources = ["cpp/project/basic.cpp"], include-dirs = ["cpp"]}
|
|
54
|
+
]
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
For more complete systems, see:
|
|
58
|
+
- [scikit-build-core](https://github.com/scikit-build/scikit-build-core)
|
|
59
|
+
- [setuptools](https://setuptools.pypa.io/en/latest/userguide/ext_modules.html)
|
|
60
|
+
|
|
61
|
+
## Environment Variables
|
|
62
|
+
| Name | Default | Description |
|
|
63
|
+
|:-----|:--------|:------------|
|
|
64
|
+
|`CC`| | |
|
|
65
|
+
|`CXX`| | |
|
|
66
|
+
|`LD`| | |
|
|
67
|
+
|`HATCH_CPP_PLATFORM`| | |
|
|
68
|
+
|`HATCH_CPP_DISABLE_CCACHE`| | |
|
|
69
|
+
|
|
70
|
+
> [!NOTE]
|
|
71
|
+
> 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,34 @@
|
|
|
1
|
+
hatch_cpp/__init__.py,sha256=GpnnPr3BgwAuiIJ5m9xconjyECZPRPhuZQ9Q7HzWR0o,129
|
|
2
|
+
hatch_cpp/hooks.py,sha256=SQkF5WJIgzw-8rvlTzuQvBqdP6K3fHgnh6CZOZFag50,203
|
|
3
|
+
hatch_cpp/plugin.py,sha256=iEDP6U7T_3G3m2ONCoYcMD3XNLq6ob_s_dn7AbtwnZ8,3238
|
|
4
|
+
hatch_cpp/structs.py,sha256=o_XtXWVs0Zv0IARLY8R3NEbNqT2sAHQf7GNMIFggrKg,10681
|
|
5
|
+
hatch_cpp/utils.py,sha256=topOiT6biVzisNAEKHvYzU-JdA56B3LA61jbU9fjAEQ,4444
|
|
6
|
+
hatch_cpp/tests/test_projects.py,sha256=zE0XOPOuaQPfdvjgZRTPnsZ5gzK2shFPqKaPXkb5oSc,1509
|
|
7
|
+
hatch_cpp/tests/test_structs.py,sha256=Qv2uBHwxf0edR8FIOnA2gj-AJgdsiDKt4vyK8HChAHg,851
|
|
8
|
+
hatch_cpp/tests/test_project_basic/pyproject.toml,sha256=eqM1UVpNmJWDfsuO18ZG_VOV9I4tAWgsM5Dhf49X8Nc,694
|
|
9
|
+
hatch_cpp/tests/test_project_basic/cpp/project/basic.cpp,sha256=gQ2nmdLqIdgaqxSKvkN_vbp6Iv_pAoVIHETXPRnALb0,117
|
|
10
|
+
hatch_cpp/tests/test_project_basic/cpp/project/basic.hpp,sha256=SO5GhPj8k3RzWrfH37lFSDc8w1Vf3yqTUhxmr1hnoko,422
|
|
11
|
+
hatch_cpp/tests/test_project_basic/project/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
|
+
hatch_cpp/tests/test_project_limited_api/pyproject.toml,sha256=k_2y7YpZP5I-KPvKOZLmnHqoKXVE2oVM8fjxtRKoTo0,726
|
|
13
|
+
hatch_cpp/tests/test_project_limited_api/cpp/project/basic.cpp,sha256=gQ2nmdLqIdgaqxSKvkN_vbp6Iv_pAoVIHETXPRnALb0,117
|
|
14
|
+
hatch_cpp/tests/test_project_limited_api/cpp/project/basic.hpp,sha256=SO5GhPj8k3RzWrfH37lFSDc8w1Vf3yqTUhxmr1hnoko,422
|
|
15
|
+
hatch_cpp/tests/test_project_limited_api/project/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
|
+
hatch_cpp/tests/test_project_nanobind/pyproject.toml,sha256=_QV3uW2UWjbiBOKiEfMQKkDyG3VlZui-GE6PSYokdHo,720
|
|
17
|
+
hatch_cpp/tests/test_project_nanobind/cpp/project/basic.cpp,sha256=L4v9AUveWWQX8Z2GMRREsEGLz-A_NCeuX0KiyppDmbc,30
|
|
18
|
+
hatch_cpp/tests/test_project_nanobind/cpp/project/basic.hpp,sha256=AK2FKdlqBwH5jnRUdJXSbWvRr-gSVsUKSG0PiYNsW7A,155
|
|
19
|
+
hatch_cpp/tests/test_project_nanobind/project/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
20
|
+
hatch_cpp/tests/test_project_override_classes/pyproject.toml,sha256=ykoZnutSWLYIZQ0M5K86tcy7P1sHamzRd-R-bJKuxsk,807
|
|
21
|
+
hatch_cpp/tests/test_project_override_classes/cpp/project/basic.cpp,sha256=gQ2nmdLqIdgaqxSKvkN_vbp6Iv_pAoVIHETXPRnALb0,117
|
|
22
|
+
hatch_cpp/tests/test_project_override_classes/cpp/project/basic.hpp,sha256=SO5GhPj8k3RzWrfH37lFSDc8w1Vf3yqTUhxmr1hnoko,422
|
|
23
|
+
hatch_cpp/tests/test_project_override_classes/project/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
24
|
+
hatch_cpp/tests/test_project_pybind/pyproject.toml,sha256=3IVlSprxx8XaC36s6OSgKr-OiSPn6cH6nX8pbp10suM,716
|
|
25
|
+
hatch_cpp/tests/test_project_pybind/cpp/project/basic.cpp,sha256=MT3eCSQKr4guI3XZHV8kw8PoBGC6LEK8ClxnNMBnvnI,78
|
|
26
|
+
hatch_cpp/tests/test_project_pybind/cpp/project/basic.hpp,sha256=LZSfCfhLY_91MBOxtnvDk7DcceO-9GhCHKpMnAjGe18,146
|
|
27
|
+
hatch_cpp/tests/test_project_pybind/project/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
28
|
+
hatch_cpp/toolchains/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
29
|
+
hatch_cpp/toolchains/cmake.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
30
|
+
hatch_cpp-0.1.6.dist-info/METADATA,sha256=xxJ65xK090LytyqWJP48Gy4rQLOGJNIprM5UC2e8_gA,3003
|
|
31
|
+
hatch_cpp-0.1.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
32
|
+
hatch_cpp-0.1.6.dist-info/entry_points.txt,sha256=RgXfjpD4iwomJQK5n7FnPkXzb5fOnF5v3DI5hbkgVcw,30
|
|
33
|
+
hatch_cpp-0.1.6.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
34
|
+
hatch_cpp-0.1.6.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|