@@ -26,20 +26,19 @@ def autotemplate_directive(path, content):
26
26
yield ""
27
27
28
28
29
- def parse_templates (
29
+ def parse_template_paths (
30
30
path : str , filename_filter : Optional [str ] = None
31
31
) -> list [Optional [str ]]:
32
32
if not os .path .isdir (path ):
33
- return [parse_jinja_comment ( path ) ]
33
+ return [path ]
34
34
35
35
filepath_collections = [
36
36
os .path .join (dirpath , filename )
37
37
for dirpath , _ , filenames in os .walk (path )
38
38
for filename in filenames
39
39
if (not filename_filter or re .match (filename_filter , filename ))
40
40
]
41
- template_paths = itertools .chain (filepath_collections )
42
- return [parse_jinja_comment (path ) for path in template_paths ]
41
+ return list (itertools .chain (filepath_collections ))
43
42
44
43
45
44
def parse_jinja_comment (path : str ) -> Optional [str ]:
@@ -63,12 +62,15 @@ class AutojinjaDirective(Directive):
63
62
def make_rst (self ):
64
63
env = self .state .document .settings .env
65
64
path = self .arguments [0 ]
66
- raw_docstrings = parse_templates (
67
- os . path . join ( env . config [ "jinja_template_path" ], path ),
68
- env .config ["jinja_template_pattern" ],
65
+ root_path = os . path . join ( env . config [ "jinja_template_path" ], path )
66
+ template_paths = parse_template_paths (
67
+ root_path , env .config ["jinja_template_pattern" ]
69
68
)
69
+ raw_docstrings = [parse_jinja_comment (path ) for path in template_paths ]
70
70
docstrings = [
71
- prepare_docstring (raw_docstring ) for raw_docstring in raw_docstrings
71
+ prepare_docstring (raw_docstring )
72
+ for raw_docstring in raw_docstrings
73
+ if raw_docstring is not None
72
74
]
73
75
if env .config ["jinja_template_path" ]:
74
76
for docstring in docstrings :
0 commit comments