99import sys
1010
1111from .casters import TypeCasterJsonData , TypeCasterJsonHeader , save_typecaster_json_data
12+ from .mkpc import make_pc_file
1213from .pyproject import PyProject
1314
1415
@@ -22,40 +23,31 @@ def main():
2223 project = PyProject (pathlib .Path (pyproject_toml ))
2324 cfg = project .project .export_type_casters [caster_name ]
2425
25- # determine the include directory location relative to the pc directory
26- # .. needs to be the pc install directory, not the output file
27- includedir = project .root / pathlib .Path (cfg .includedir )
28- if not includedir .exists ():
29- print (f"ERROR: { includedir } does not exist" , file = sys .stderr )
30- print (
31- f"- specified at [tool.semiwrap.export_type_casters.{ caster_name } ].includedir" ,
32- file = sys .stderr ,
33- )
34- sys .exit (1 )
26+ # make sure the include directories actually exist
27+ include_dirs = []
28+ for inc in cfg .includedir :
29+ includedir = project .root / pathlib .Path (inc )
30+ include_dirs .append (includedir )
31+ if not includedir .exists ():
32+ print (f"ERROR: { includedir } does not exist" , file = sys .stderr )
33+ print (
34+ f"- specified at [tool.semiwrap.export_type_casters.{ caster_name } ].includedir" ,
35+ file = sys .stderr ,
36+ )
37+ sys .exit (1 )
3538
3639 pc_install_path = project .package_root / pathlib .Path (* cfg .pypackage .split ("." ))
37- rel_includedir = includedir .relative_to (pc_install_path )
38-
39- # Write the pc file
40- pc_content = [
41- "# automatically generated by semiwrap" ,
42- "prefix=${pcfiledir}" ,
43- f"includedir=${{prefix}}/{ rel_includedir .as_posix ()} " ,
44- "" ,
45- f"Name: { caster_name } " ,
46- "Description: pybind11 type casters" ,
47- "Version:" , # TODO put in correct version
48- "Cflags: -I${includedir}" ,
49- ]
50-
51- if cfg .requires :
52- requires = " " .join (cfg .requires )
53- pc_content .append (f"Requires: { requires } " )
54-
55- pc_content .append ("" )
56-
57- with open (output_pc , "w" ) as fp :
58- fp .write ("\n " .join (pc_content ))
40+ make_pc_file (
41+ project_root = project .root ,
42+ pcfile = pathlib .Path (output_pc ),
43+ pc_install_path = pc_install_path ,
44+ name = caster_name ,
45+ desc = "pybind11 type casters" ,
46+ version = "" ,
47+ includes = cfg .includedir ,
48+ depends = cfg .requires ,
49+ libinit_py = None ,
50+ )
5951
6052 #
6153 # Gather the data and write it next to the pc file
@@ -65,13 +57,22 @@ def main():
6557 for hdr in cfg .headers :
6658
6759 # Ensure the published header actually exists
68- full_hdr = includedir / hdr .header
69- if not full_hdr .exists ():
70- print (f"ERROR: { full_hdr } does not exist" , file = sys .stderr )
60+ searched = []
61+ for inc in include_dirs :
62+ full_hdr = inc / hdr .header
63+ if full_hdr .exists ():
64+ break
65+
66+ searched .append (full_hdr )
67+ else :
68+
69+ print (f"ERROR: { hdr .header } does not exist" , file = sys .stderr )
7170 print (
7271 f"- specified at [[tool.semiwrap.export_type_casters.{ caster_name } .headers]].header" ,
7372 file = sys .stderr ,
7473 )
74+ for s in searched :
75+ print (f"- searched '{ s } '" )
7576 sys .exit (1 )
7677
7778 data .headers .append (
0 commit comments