99
1010from pathlib import Path
1111
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-
3312GUARD_PATTERN = re .compile ("^#ifndef __(.*)__$" , re .MULTILINE )
3413INCLUDE_PATTERN = re .compile (r"^#include ([\"<].*[\">])\n" , re .MULTILINE )
3514
5938// ...
6039#endif // ifndef _pinocchio_python_spatial_se3i_hpp__"""
6140
62- HPP_MODULE_TPL_GUARD = """
41+ HPP_MODULE_EXPL_GUARD = """
6342/// Explicit template instantiation
6443#if PINOCCHIO_ENABLE_TEMPLATE_INSTANTIATION
65- #include "{module_tpl }"
44+ #include "{module_expl }"
6645#endif // PINOCCHIO_ENABLE_TEMPLATE_INSTANTIATION
6746"""
6847
7958// Module headers
8059{module_includes}
8160
82- {module_tpl_include }
61+ {module_expl_include }
8362
8463#endif // ifndef {guard}
8564"""
@@ -175,13 +154,13 @@ def create_hpp_module(
175154 guard : str ,
176155 dependencies_includes : list [str ],
177156 module_includes : list [str ],
178- module_tpl_include : str | None ,
157+ module_expl_include : str | None ,
179158) -> str :
180159 """Create a module content.
181160 :ivar guard: Guard name.
182161 :ivar dependencies_includes: Module dependencies include paths (path with < or ").
183162 :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 ").
185164 :return: Module content.
186165 >>> res = create_hpp_module("__pinocchio_python_spatial_se3_hpp__",\
187166 ['<eigenpy/eigenpy.hpp>', '<boost/python/tuple.hpp>', '"pinocchio/spatial/se3.hpp"', '"pinocchio/spatial/explog.hpp"'],\
@@ -212,7 +191,7 @@ def create_hpp_module(
212191 >>> res = create_hpp_module("__pinocchio_python_spatial_se3_hpp__",\
213192 ['<eigenpy/eigenpy.hpp>', '<boost/python/tuple.hpp>', '"pinocchio/spatial/se3.hpp"', '"pinocchio/spatial/explog.hpp"'],\
214193 ['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")
216195 >>> print(res)
217196 //
218197 // Copyright (c) 2025 INRIA
@@ -234,7 +213,7 @@ def create_hpp_module(
234213 <BLANKLINE>
235214 /// Explicit template instantiation
236215 #if PINOCCHIO_ENABLE_TEMPLATE_INSTANTIATION
237- #include "pinocchio/bindings/python/spatial/se3_tpl .hxx"
216+ #include "pinocchio/bindings/python/spatial/se3_expl .hxx"
238217 #endif // PINOCCHIO_ENABLE_TEMPLATE_INSTANTIATION
239218 <BLANKLINE>
240219 <BLANKLINE>
@@ -243,14 +222,14 @@ def create_hpp_module(
243222 """
244223 deps = "\n " .join ([f"#include { d } " for d in dependencies_includes ])
245224 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 )
249228 return HPP_MODULE .format (
250229 guard = guard ,
251230 dep_includes = deps ,
252231 module_includes = modules ,
253- module_tpl_include = module_tpl ,
232+ module_expl_include = module_expl ,
254233 )
255234
256235
@@ -309,15 +288,15 @@ def update_module(module_path: Path, include_root_path: Path, dry: bool = False)
309288
310289 module_path_rel = module_path .relative_to (include_root_path )
311290 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" )
313292 module_decl = module_path .parent / Path (f"{ module_path .stem } -decl.hxx" )
314293 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" )
316295
317296 print (f"\t Convert { module_path } into { module_decl } " )
318297 dependency_includes = []
319298 module_includes = [str (module_decl .relative_to (include_root_path ))]
320- module_tpl_include = None
299+ module_expl_include = None
321300
322301 decl_includes , module_guard = update_content (
323302 module_path ,
@@ -360,35 +339,35 @@ def update_module(module_path: Path, include_root_path: Path, dry: bool = False)
360339 )
361340 module_includes .append (str (module_def .relative_to (include_root_path )))
362341
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 ,
367346 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 )),
369348 dry ,
370349 )
371- dependency_includes += tpl_includes
350+ dependency_includes += expl_includes
372351 if not dry :
373352 subprocess .run (
374353 [
375354 "git" ,
376355 "-C" ,
377356 str (include_root_path ),
378357 "mv" ,
379- str (module_old_tpl ),
380- str (module_tpl ),
358+ str (module_old_expl ),
359+ str (module_expl ),
381360 ]
382361 )
383- module_tpl_include = str (module_tpl .relative_to (include_root_path ))
362+ module_expl_include = str (module_expl .relative_to (include_root_path ))
384363
385364 print (f"\t Create new module { module_path } " )
386365 print (f"\t New module guard: { module_guard } " )
387366 print (f"\t New module dependencies: { ', ' .join (dependency_includes )} " )
388367 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 } " )
390369 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
392371 )
393372 if not dry :
394373 with module_path .open ("w" ) as module_path_desc :
@@ -427,6 +406,28 @@ def argument_parser() -> argparse.ArgumentParser:
427406
428407
429408def 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+ """
430431 parser = argument_parser ()
431432 args = parser .parse_args (args )
432433
0 commit comments