Skip to content

Commit b48f4a9

Browse files
committed
Large refactor to be a modular hatchling + meson project
1 parent 33a21cd commit b48f4a9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2694
-3014
lines changed

pyproject.toml

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,30 @@ classifiers = [
1818
"Intended Audience :: Developers",
1919
"License :: OSI Approved :: BSD License",
2020
"Programming Language :: Python :: 3 :: Only",
21-
"Programming Language :: Python :: 3.8",
22-
"Programming Language :: Python :: 3.9",
23-
"Programming Language :: Python :: 3.10",
24-
"Programming Language :: Python :: 3.11",
2521
"Topic :: Software Development",
2622
]
2723
dependencies = [
28-
"setuptools >= 45",
29-
"setuptools_scm >= 6.2, < 8",
24+
"pkgconf",
3025
"sphinxify >= 0.7.3",
3126
"validobj ~= 1.2",
32-
"cxxheaderparser[pcpp] ~= 1.4.1",
27+
"cxxheaderparser[pcpp] ~= 1.5",
3328
"tomli",
3429
"tomli_w",
3530
"toposort",
3631
"typing-extensions",
32+
"validobj",
3733
"pyyaml >= 5.1",
38-
"patch == 1.*",
3934
"pybind11-stubgen ~= 2.5.1",
4035
"delocate; platform_system == 'Darwin'",
4136
"distro; platform_system == 'Linux'",
4237
]
4338

39+
[project.entry-points.hatch]
40+
semiwrap = "semiwrap.hooks"
41+
42+
[project.entry-points.pkg_config]
43+
semiwrap = "semiwrap"
44+
4445
[project.scripts]
4546
semiwrap = "semiwrap.tool.__main__:main"
4647

@@ -50,7 +51,7 @@ semiwrap = "semiwrap.tool.__main__:main"
5051
[tool.hatch.version]
5152
source = "vcs"
5253

53-
[tool.hatch.build.hooks.vcs]
54+
[tool.hatch.build.targets.sdist.hooks.vcs]
5455
version-file = "src/semiwrap/version.py"
5556

5657
[tool.hatch.build.targets.sdist]
@@ -61,13 +62,6 @@ exclude = [
6162
[tool.hatch.build.targets.sdist.force-include]
6263
"./src/semiwrap/pybind11/include" = "./semiwrap/pybind11/include"
6364

64-
[tool.hatch.build.targets.wheel]
65-
packages = ["semiwrap"]
66-
include = [
67-
"/semiwrap/pybind11/include",
68-
"/semiwrap/include",
69-
]
70-
7165

7266
[tool.black]
7367
target-version = ["py38"]

src/semiwrap/autowrap/context.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from dataclasses import dataclass, field
1414
import enum
15+
import pathlib
1516
import typing
1617

1718
from cxxheaderparser.types import Function, PQName
@@ -372,6 +373,9 @@ class ClassContext:
372373

373374
parent: typing.Optional["ClassContext"]
374375

376+
#: lookup key for dat2trampoline
377+
yml_id: str
378+
375379
#: Namespace that this class lives in
376380
namespace: str
377381

@@ -514,6 +518,9 @@ class HeaderContext:
514518
# Name in toml
515519
hname: str
516520

521+
# config file for this
522+
orig_yaml: pathlib.Path
523+
517524
extra_includes_first: typing.List[str]
518525
extra_includes: typing.List[str]
519526
inline_code: typing.Optional[str]
@@ -535,6 +542,9 @@ class HeaderContext:
535542
# same as classes, but only those that have trampolines
536543
classes_with_trampolines: typing.List[ClassContext] = field(default_factory=list)
537544

545+
# for diagnostic purposes
546+
ignored_classes: typing.List[str] = field(default_factory=list)
547+
538548
functions: typing.List[FunctionContext] = field(default_factory=list)
539549

540550
# trampolines

src/semiwrap/autowrap/cxxparser.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
Variable,
5959
)
6060

61+
from ..casters import CastersData
6162
from ..config.autowrap_yml import (
6263
AutowrapConfigYaml,
6364
BufferData,
@@ -87,18 +88,24 @@
8788
TrampolineData,
8889
)
8990

91+
from ..util import relpath_walk_up
92+
9093

9194
class HasSubpackage(Protocol):
92-
subpackage: typing.Optional[str]
95+
@property
96+
def subpackage(self) -> typing.Optional[str]: ...
9397

9498

9599
class HasDoc(Protocol):
96-
doc: str
97-
doc_append: str
100+
@property
101+
def doc(self) -> typing.Optional[str]: ...
102+
@property
103+
def doc_append(self) -> typing.Optional[str]: ...
98104

99105

100106
class HasNameData(Protocol):
101-
rename: str
107+
@property
108+
def rename(self) -> typing.Optional[str]: ...
102109

103110

104111
# TODO: this isn't the best solution
@@ -329,7 +336,7 @@ def __init__(
329336
self,
330337
hctx: HeaderContext,
331338
gendata: GeneratorData,
332-
casters: typing.Dict[str, typing.Dict[str, typing.Any]],
339+
casters: CastersData,
333340
report_only: bool,
334341
) -> None:
335342
self.hctx = hctx
@@ -591,6 +598,7 @@ def on_class_start(self, state: AWClassBlockState) -> typing.Optional[bool]:
591598

592599
# Ignore explicitly ignored classes (including default-ignore)
593600
if class_data.ignore:
601+
self.hctx.ignored_classes.append(cls_key)
594602
return False
595603

596604
if missing and not self.report_only:
@@ -721,6 +729,7 @@ def on_class_start(self, state: AWClassBlockState) -> typing.Optional[bool]:
721729

722730
ctx = ClassContext(
723731
parent=parent_ctx,
732+
yml_id=cls_key,
724733
namespace=cls_namespace,
725734
cpp_name=cls_name,
726735
full_cpp_name=cls_qualname,
@@ -1897,8 +1906,8 @@ def _add_default_arg_cast(
18971906
typename = _fmt_nameonly(ntype.typename)
18981907
if typename:
18991908
ccfg = self.casters.get(typename)
1900-
if ccfg and ccfg.get("darg"):
1901-
found_typename = ccfg["typename"]
1909+
if ccfg and ccfg.default_arg_cast:
1910+
found_typename = ccfg.typename
19021911
name = f"({found_typename}){name}"
19031912

19041913
return name
@@ -1974,7 +1983,7 @@ def _set_type_caster_includes(self):
19741983
for typename in self.types:
19751984
ccfg = casters.get(typename)
19761985
if ccfg:
1977-
includes.add(ccfg["hdr"])
1986+
includes.add(ccfg.header)
19781987

19791988
self.hctx.type_caster_includes = sorted(includes)
19801989

@@ -1985,18 +1994,19 @@ def parse_header(
19851994
header_root: pathlib.Path,
19861995
gendata: GeneratorData,
19871996
parser_options: ParserOptions,
1988-
casters: typing.Dict[str, typing.Dict[str, typing.Any]],
1997+
casters: CastersData,
19891998
report_only: bool,
19901999
) -> HeaderContext:
19912000
user_cfg = gendata.data
19922001

19932002
# Initialize the header context with user configuration
19942003
hctx = HeaderContext(
19952004
hname=name,
2005+
orig_yaml=gendata.data_fname,
19962006
extra_includes_first=user_cfg.extra_includes_first,
19972007
extra_includes=user_cfg.extra_includes,
19982008
inline_code=user_cfg.inline_code,
1999-
rel_fname=str(header_path.relative_to(header_root)),
2009+
rel_fname=relpath_walk_up(header_path, header_root).as_posix(),
20002010
)
20012011

20022012
# Parse the header using a custom visitor

src/semiwrap/autowrap/generator_data.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
from cxxheaderparser.types import Function
1414

1515
import dataclasses
16-
from typing import Dict, List, Optional, Tuple
16+
import pathlib
17+
from typing import Any, Dict, List, Optional, Tuple
1718

1819

1920
@dataclasses.dataclass
@@ -66,7 +67,7 @@ class GeneratorData:
6667

6768
data: AutowrapConfigYaml
6869

69-
def __init__(self, data: AutowrapConfigYaml, data_fname: str):
70+
def __init__(self, data: AutowrapConfigYaml, data_fname: pathlib.Path):
7071
self.data = data
7172
self.data_fname = data_fname
7273

@@ -202,7 +203,7 @@ def get_prop_data(self, name) -> PropData:
202203

203204
return data
204205

205-
def report_missing(self, name: str, reporter: "MissingReporter"):
206+
def report_missing(self, name: pathlib.Path, reporter: "MissingReporter"):
206207
"""
207208
Generate a structure that can be copy/pasted into the generation
208209
data yaml and print it out if there's missing data
@@ -356,6 +357,9 @@ class MissingReporter:
356357
def __init__(self):
357358
self.reports = {}
358359

360+
def __bool__(self) -> bool:
361+
return len(self.reports) > 0
362+
359363
def _merge(self, src, dst):
360364
for k, v in src.items():
361365
if isinstance(v, dict):

src/semiwrap/autowrap/render_cls_prologue.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def render_class_prologue(r: RenderBuffer, hctx: HeaderContext):
66
# fmt: off
77
r.writeln(
88
"// This file is autogenerated. DO NOT EDIT\n"
9-
"#include <robotpy_build.h>"
9+
"#include <semiwrap.h>"
1010
)
1111
# fmt: on
1212

@@ -36,6 +36,6 @@ def render_class_prologue(r: RenderBuffer, hctx: HeaderContext):
3636
for cls in hctx.classes_with_trampolines:
3737
r.writeln()
3838
r.writeln(
39-
f"#define RPYGEN_ENABLE_{cls.full_cpp_name_identifier}_PROTECTED_CONSTRUCTORS"
39+
f"#define SWGEN_ENABLE_{cls.full_cpp_name_identifier}_PROTECTED_CONSTRUCTORS"
4040
)
41-
r.writeln(f"#include <rpygen/{cls.full_cpp_name_identifier}.hpp>")
41+
r.writeln(f"#include <trampolines/{cls.full_cpp_name_identifier}.hpp>")

0 commit comments

Comments
 (0)