9
9
10
10
from pathlib import Path
11
11
12
- # Walk in a directory
13
- # Find all xxx.hpp
14
- # Rename it into xxx-def.hxx
15
- # Update guards
16
- # Remove includes
17
- # Add clangd_hack
18
- # if xxx.hxx associated
19
- # Rename into xxx-decl.hxx
20
- # Update guards
21
- # Remove includes
22
- # Add clangd_hack
23
- # if xxx.txx associated
24
- # Rename into xxx-tpl.hxx
25
- # Update guards
26
- # Remove includes
27
- # Add clangd_hack
28
- # Create xxx.hpp
29
- # Add guards
30
- # Add includes form def, decl and tpl
31
- # include def, decl and tpl
32
-
33
12
GUARD_PATTERN = re .compile ("^#ifndef __(.*)__$" , re .MULTILINE )
34
13
INCLUDE_PATTERN = re .compile (r"^#include ([\"<].*[\">])\n" , re .MULTILINE )
35
14
59
38
// ...
60
39
#endif // ifndef _pinocchio_python_spatial_se3i_hpp__"""
61
40
62
- HPP_MODULE_TPL_GUARD = """
41
+ HPP_MODULE_EXPL_GUARD = """
63
42
/// Explicit template instantiation
64
43
#if PINOCCHIO_ENABLE_TEMPLATE_INSTANTIATION
65
- #include "{module_tpl }"
44
+ #include "{module_expl }"
66
45
#endif // PINOCCHIO_ENABLE_TEMPLATE_INSTANTIATION
67
46
"""
68
47
79
58
// Module headers
80
59
{module_includes}
81
60
82
- {module_tpl_include }
61
+ {module_expl_include }
83
62
84
63
#endif // ifndef {guard}
85
64
"""
@@ -175,13 +154,13 @@ def create_hpp_module(
175
154
guard : str ,
176
155
dependencies_includes : list [str ],
177
156
module_includes : list [str ],
178
- module_tpl_include : str | None ,
157
+ module_expl_include : str | None ,
179
158
) -> str :
180
159
"""Create a module content.
181
160
:ivar guard: Guard name.
182
161
:ivar dependencies_includes: Module dependencies include paths (path with < or ").
183
162
:ivar module_includes: Module internal include paths (path without < or ").
184
- :ivar module_tpl : Module explicit template instantiation (path without < or ").
163
+ :ivar module_expl : Module explicit template instantiation (path without < or ").
185
164
:return: Module content.
186
165
>>> res = create_hpp_module("__pinocchio_python_spatial_se3_hpp__",\
187
166
['<eigenpy/eigenpy.hpp>', '<boost/python/tuple.hpp>', '"pinocchio/spatial/se3.hpp"', '"pinocchio/spatial/explog.hpp"'],\
@@ -212,7 +191,7 @@ def create_hpp_module(
212
191
>>> res = create_hpp_module("__pinocchio_python_spatial_se3_hpp__",\
213
192
['<eigenpy/eigenpy.hpp>', '<boost/python/tuple.hpp>', '"pinocchio/spatial/se3.hpp"', '"pinocchio/spatial/explog.hpp"'],\
214
193
['pinocchio/bindings/python/spatial/se3_decl.hxx', 'pinocchio/bindings/python/spatial/se3_def.hxx'],\
215
- "pinocchio/bindings/python/spatial/se3_tpl .hxx")
194
+ "pinocchio/bindings/python/spatial/se3_expl .hxx")
216
195
>>> print(res)
217
196
//
218
197
// Copyright (c) 2025 INRIA
@@ -234,7 +213,7 @@ def create_hpp_module(
234
213
<BLANKLINE>
235
214
/// Explicit template instantiation
236
215
#if PINOCCHIO_ENABLE_TEMPLATE_INSTANTIATION
237
- #include "pinocchio/bindings/python/spatial/se3_tpl .hxx"
216
+ #include "pinocchio/bindings/python/spatial/se3_expl .hxx"
238
217
#endif // PINOCCHIO_ENABLE_TEMPLATE_INSTANTIATION
239
218
<BLANKLINE>
240
219
<BLANKLINE>
@@ -243,14 +222,14 @@ def create_hpp_module(
243
222
"""
244
223
deps = "\n " .join ([f"#include { d } " for d in dependencies_includes ])
245
224
modules = "\n " .join ([f'#include "{ d } "' for d in module_includes ])
246
- module_tpl = ""
247
- if module_tpl_include is not None :
248
- module_tpl = HPP_MODULE_TPL_GUARD .format (module_tpl = module_tpl_include )
225
+ module_expl = ""
226
+ if module_expl_include is not None :
227
+ module_expl = HPP_MODULE_EXPL_GUARD .format (module_expl = module_expl_include )
249
228
return HPP_MODULE .format (
250
229
guard = guard ,
251
230
dep_includes = deps ,
252
231
module_includes = modules ,
253
- module_tpl_include = module_tpl ,
232
+ module_expl_include = module_expl ,
254
233
)
255
234
256
235
@@ -309,15 +288,15 @@ def update_module(module_path: Path, include_root_path: Path, dry: bool = False)
309
288
310
289
module_path_rel = module_path .relative_to (include_root_path )
311
290
module_old_def = module_path .parent / Path (f"{ module_path .stem } .hxx" )
312
- module_old_tpl = module_path .parent / Path (f"{ module_path .stem } .txx" )
291
+ module_old_expl = module_path .parent / Path (f"{ module_path .stem } .txx" )
313
292
module_decl = module_path .parent / Path (f"{ module_path .stem } -decl.hxx" )
314
293
module_def = module_path .parent / Path (f"{ module_path .stem } -def.hxx" )
315
- module_tpl = module_path .parent / Path (f"{ module_path .stem } -tpl .hxx" )
294
+ module_expl = module_path .parent / Path (f"{ module_path .stem } -expl .hxx" )
316
295
317
296
print (f"\t Convert { module_path } into { module_decl } " )
318
297
dependency_includes = []
319
298
module_includes = [str (module_decl .relative_to (include_root_path ))]
320
- module_tpl_include = None
299
+ module_expl_include = None
321
300
322
301
decl_includes , module_guard = update_content (
323
302
module_path ,
@@ -360,35 +339,35 @@ def update_module(module_path: Path, include_root_path: Path, dry: bool = False)
360
339
)
361
340
module_includes .append (str (module_def .relative_to (include_root_path )))
362
341
363
- if module_old_tpl .exists ():
364
- print (f"\t Convert { module_old_tpl } into { module_tpl } " )
365
- tpl_includes , _ = update_content (
366
- module_old_tpl ,
342
+ if module_old_expl .exists ():
343
+ print (f"\t Convert { module_old_expl } into { module_expl } " )
344
+ expl_includes , _ = update_content (
345
+ module_old_expl ,
367
346
module_path_rel ,
368
- guard_from_path (module_tpl .relative_to (include_root_path )),
347
+ guard_from_path (module_expl .relative_to (include_root_path )),
369
348
dry ,
370
349
)
371
- dependency_includes += tpl_includes
350
+ dependency_includes += expl_includes
372
351
if not dry :
373
352
subprocess .run (
374
353
[
375
354
"git" ,
376
355
"-C" ,
377
356
str (include_root_path ),
378
357
"mv" ,
379
- str (module_old_tpl ),
380
- str (module_tpl ),
358
+ str (module_old_expl ),
359
+ str (module_expl ),
381
360
]
382
361
)
383
- module_tpl_include = str (module_tpl .relative_to (include_root_path ))
362
+ module_expl_include = str (module_expl .relative_to (include_root_path ))
384
363
385
364
print (f"\t Create new module { module_path } " )
386
365
print (f"\t New module guard: { module_guard } " )
387
366
print (f"\t New module dependencies: { ', ' .join (dependency_includes )} " )
388
367
print (f"\t New module includes: { ', ' .join (module_includes )} " )
389
- print (f"\t New module tpl : { module_tpl_include } " )
368
+ print (f"\t New module expl : { module_expl_include } " )
390
369
module_content = create_hpp_module (
391
- module_guard , dependency_includes , module_includes , module_tpl_include
370
+ module_guard , dependency_includes , module_includes , module_expl_include
392
371
)
393
372
if not dry :
394
373
with module_path .open ("w" ) as module_path_desc :
@@ -427,6 +406,28 @@ def argument_parser() -> argparse.ArgumentParser:
427
406
428
407
429
408
def main (args : list [str ]):
409
+ """
410
+ Walk in a directory
411
+ Find all xxx.hpp
412
+ Rename it into xxx-def.hxx
413
+ Update guards
414
+ Remove includes
415
+ Add clangd_hack
416
+ if xxx.hxx associated
417
+ Rename into xxx-decl.hxx
418
+ Update guards
419
+ Remove includes
420
+ Add clangd_hack
421
+ if xxx.txx associated
422
+ Rename into xxx-expl.hxx
423
+ Update guards
424
+ Remove includes
425
+ Add clangd_hack
426
+ Create xxx.hpp
427
+ Add guards
428
+ Add includes form def, decl and expl
429
+ include def, decl and expl
430
+ """
430
431
parser = argument_parser ()
431
432
args = parser .parse_args (args )
432
433
0 commit comments