Skip to content

Commit ecba2dc

Browse files
committed
refactor: minor refactoring
1 parent 36e25f7 commit ecba2dc

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

jinja_autodoc/autotemplate.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,19 @@ def autotemplate_directive(path, content):
2626
yield ""
2727

2828

29-
def parse_templates(
29+
def parse_template_paths(
3030
path: str, filename_filter: Optional[str] = None
3131
) -> list[Optional[str]]:
3232
if not os.path.isdir(path):
33-
return [parse_jinja_comment(path)]
33+
return [path]
3434

3535
filepath_collections = [
3636
os.path.join(dirpath, filename)
3737
for dirpath, _, filenames in os.walk(path)
3838
for filename in filenames
3939
if (not filename_filter or re.match(filename_filter, filename))
4040
]
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))
4342

4443

4544
def parse_jinja_comment(path: str) -> Optional[str]:
@@ -63,12 +62,15 @@ class AutojinjaDirective(Directive):
6362
def make_rst(self):
6463
env = self.state.document.settings.env
6564
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"]
6968
)
69+
raw_docstrings = [parse_jinja_comment(path) for path in template_paths]
7070
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
7274
]
7375
if env.config["jinja_template_path"]:
7476
for docstring in docstrings:

0 commit comments

Comments
 (0)