Skip to content

Commit 72547d7

Browse files
committed
Add dynamic skip in conf.py of tutorials requiring a higher version of DPF
1 parent 155632c commit 72547d7

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

doc/source/conf.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,29 @@
5555
)
5656
server_version = server_instance.version
5757
server.shutdown_all_session_servers()
58-
print(f"DPF version: {server_version}")
58+
print("".rjust(40, '*'))
59+
print(f"Doc built for DPF server version {server_version} at:\n{server_instance.ansys_path}")
60+
print("".rjust(40, '*'))
61+
62+
def get_tutorial_version_requirements(tutorial_path: str) -> str:
63+
note_flag = r".. note::"
64+
version_flag = "This tutorial requires DPF"
65+
previous_line_is_note = False
66+
minimum_version = "0.0"
67+
tutorial_path = Path(tutorial_path)
68+
with tutorial_path.open("r") as f:
69+
for line in f:
70+
if (version_flag in line) and previous_line_is_note:
71+
minimum_version = line.strip(version_flag).split()[0]
72+
break
73+
if note_flag in line:
74+
previous_line_is_note = True
75+
else:
76+
previous_line_is_note = False
77+
return minimum_version
5978

6079
# Build ignore pattern
6180
ignored_pattern = r"(ignore"
62-
header_flag = "\"\"\""
63-
note_flag = r".. note::"
6481
for example in glob(r"../../examples/**/*.py"):
6582
minimum_version_str = get_example_required_minimum_dpf_version(example)
6683
if float(server_version) - float(minimum_version_str) < -0.05:
@@ -71,6 +88,15 @@
7188
ignored_pattern += "|06-distributed_stress_averaging.py"
7289
ignored_pattern += r")"
7390

91+
exclude_patterns = []
92+
for tutorial_file in glob(r"user_guide/tutorials/**/*.rst"):
93+
if Path(tutorial_file).name == "index.rst":
94+
continue
95+
minimum_version_str = get_tutorial_version_requirements(tutorial_file)
96+
if float(server_version) - float(minimum_version_str) < -0.05:
97+
print(f"Tutorial {Path(tutorial_file).name} skipped as it requires DPF {minimum_version_str}.")
98+
exclude_patterns.append(tutorial_file)
99+
74100
# Autoapi ignore pattern
75101
autoapi_ignore_list = [
76102
"*/log.py",
@@ -159,7 +185,7 @@
159185
# List of patterns, relative to source directory, that match files and
160186
# directories to ignore when looking for source files.
161187
# This pattern also affects html_static_path and html_extra_path.
162-
exclude_patterns = ["links_and_refs.rst"]
188+
exclude_patterns.extend(["links_and_refs.rst"])
163189

164190
# make rst_epilog a variable, so you can add other epilog parts to it
165191
rst_epilog = ""

0 commit comments

Comments
 (0)