Skip to content

Commit 36f0062

Browse files
committed
more efficient path search with glob
1 parent 21f6a88 commit 36f0062

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

panda/python/core/create_panda_datatypes.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import os
44
import sys
55
import shutil
6+
from glob import glob
7+
from pathlib import Path
68
if sys.version_info[0] < 3:
79
raise RuntimeError('Requires python3')
810

@@ -389,24 +391,15 @@ def main(install=False,recompile=True):
389391

390392
copy_ppp_header("%s/taint2/taint2.h" % PLUGINS_DIR)
391393

394+
# programatically copy anything that ends with _ppp.h
395+
for ppp_file in glob(f"{PLUGINS_DIR}/*/*_ppp.h", recursive=True):
396+
ppp = Path(ppp_file)
397+
copy_ppp_header(ppp_file)
392398

393-
#programtically copy anything that ends with _ppp.h
394-
395-
#for each subdirectory under PLUGINS_DIR
396-
plugin_dirs = [os.path.join(PLUGINS_DIR, f) for f in os.listdir(PLUGINS_DIR) if os.path.isdir(os.path.join(PLUGINS_DIR, f))]
397-
398-
pattern = re.compile(r"_ppp\.h$") #matches strings ending with _ppp.h
399-
for plugin_dir in plugin_dirs:
400-
plugin_files = os.listdir(plugin_dir)
401-
402-
for plugin_file in plugin_files:
403-
if pattern.search(plugin_file):
404-
copy_ppp_header(f"{plugin_dir}/{plugin_file}")
405-
406-
#if the directory with the _ppp.h file also has a [plugin_name].h file, include it
407-
header_filepath = f"{plugin_dir}/{os.path.basename(plugin_dir) + '.h'}"
408-
if os.path.isfile(header_filepath):
409-
create_pypanda_header(header_filepath)
399+
plugin_dir = ppp.parent
400+
header_filepath = Path(plugin_dir, f"{plugin_dir.name}.h")
401+
if header_filepath.exists():
402+
create_pypanda_header(str(header_filepath))
410403

411404
with open(os.path.join(OUTPUT_DIR, "panda_datatypes.py"), "w") as pdty:
412405
pdty.write("""from __future__ import print_function

0 commit comments

Comments
 (0)