Skip to content
Snippets Groups Projects
Commit 19a79ef5 authored by Andrew Maclean's avatar Andrew Maclean
Browse files

Make the globbing recursive

parent 61046fbc
No related branches found
No related tags found
1 merge request!226Add vtk modules for cxx
...@@ -46,29 +46,29 @@ def get_available_modules(jpath): ...@@ -46,29 +46,29 @@ def get_available_modules(jpath):
return sorted(res) return sorted(res)
def get_classes_constants(path): def get_classes_constants(paths):
""" """
Extract the vtk class names and constants from the path. Extract the vtk class names and constants from the path.
:param path: The path to the Python file. :param paths: The path(s) to the Python file(s).
:return: The file name, the VTK classes and any VTK constants. :return: The file name, the VTK classes and any VTK constants.
""" """
res = collections.defaultdict(set) res = collections.defaultdict(set)
content = path.read_text().split('\n') for path in paths:
for line in content: content = path.read_text().split('\n')
vtk_class_pattern = re.compile(r'(vtk[a-zA-Z]+\S+\()') for line in content:
vtk_class_pattern1 = re.compile(r'[^\(]+') vtk_class_pattern = re.compile(r'(vtk[a-zA-Z]+\S+\()')
vtk_constants_pattern = re.compile(r'(VTK_[A-Z_]+)') vtk_class_pattern1 = re.compile(r'[^\(]+')
m = vtk_class_pattern.search(line) vtk_constants_pattern = re.compile(r'(VTK_[A-Z_]+)')
if m: m = vtk_class_pattern.search(line)
for g in m.groups(): if m:
m1 = vtk_class_pattern1.match(g) for g in m.groups():
res[path.stem].add(m1.group()) m1 = vtk_class_pattern1.match(g)
m = vtk_constants_pattern.search(line) res[str(path)].add(m1.group())
if m: m = vtk_constants_pattern.search(line)
for g in m.groups(): if m:
res[path.stem].add(g) for g in m.groups():
res[str(path)].add(g)
return res return res
...@@ -107,7 +107,6 @@ def format_imports(imports): ...@@ -107,7 +107,6 @@ def format_imports(imports):
res.append(preface) res.append(preface)
res.append(f'# import vtkmodules.{module}') res.append(f'# import vtkmodules.{module}')
res.append('') res.append('')
return res return res
...@@ -131,7 +130,7 @@ def main(json_path, src_paths, ofn): ...@@ -131,7 +130,7 @@ def main(json_path, src_paths, ofn):
if path.is_file() and path.suffix == '.py': if path.is_file() and path.suffix == '.py':
paths.append(path) paths.append(path)
elif path.is_dir(): elif path.is_dir():
path_list = list(Path(fn).glob('*.py')) path_list = list(Path(fn).rglob('*.py'))
program_path = Path(__file__) program_path = Path(__file__)
for path in path_list: for path in path_list:
if path.resolve() != program_path.resolve(): if path.resolve() != program_path.resolve():
...@@ -139,13 +138,11 @@ def main(json_path, src_paths, ofn): ...@@ -139,13 +138,11 @@ def main(json_path, src_paths, ofn):
else: else:
print(f'Non existent path: {path}') print(f'Non existent path: {path}')
classes_constants = collections.defaultdict(set) classes_constants = get_classes_constants(paths)
for path in paths:
classes_constants.update(get_classes_constants(path))
if not classes_constants: if not classes_constants:
print('No classes or constants were present.') print('No classes or constants were present.')
return return
if use_json: if use_json:
vtk_modules = get_available_modules(jpath) vtk_modules = get_available_modules(jpath)
else: else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment