Skip to content

Commit 1b05aa2

Browse files
authored
Fix(doc): Fix DPF operator doc update of the toc.yml (#2647)
1 parent 1299992 commit 1b05aa2

File tree

3 files changed

+36
-41
lines changed

3 files changed

+36
-41
lines changed

src/ansys/dpf/core/documentation/generate_operators_doc.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ def generate_operator_doc(
374374
file.write(output)
375375

376376

377-
def generate_toc_tree(docs_path: Path):
378-
"""Write the global toc.yml file for the DPF documentation based on the operators found.
377+
def update_toc_tree(docs_path: Path):
378+
"""Update the global toc.yml file for the DPF documentation based on the operators found.
379379
380380
Parameters
381381
----------
@@ -391,7 +391,7 @@ def generate_toc_tree(docs_path: Path):
391391
operators = [] # Reset operators for each category
392392
for file in folder.iterdir():
393393
if (
394-
file.is_file() and file.suffix == ".md"
394+
file.is_file() and file.suffix == ".md" and not file.name.endswith("_upd.md")
395395
): # Ensure 'file' is a file with .md extension
396396
file_name = file.name
397397
file_path = f"{category}/{file_name}"
@@ -405,10 +405,18 @@ def generate_toc_tree(docs_path: Path):
405405
template = jinja2.Template(template_file.read())
406406
output = template.render(data=data) # Pass 'data' as a named argument
407407

408-
# Write the rendered output to toc.yml at the operators_doc level
408+
# Update the original toc.yml file with the rendered output for operator_specifications
409409
toc_path = docs_path / Path("toc.yml")
410+
with toc_path.open(mode="r") as file:
411+
original_toc = file.read()
412+
new_toc = re.sub(
413+
pattern=r"- name: Operator specifications\s*.*?(?=- name: Changelog|\Z)",
414+
repl=output,
415+
string=original_toc,
416+
flags=re.DOTALL,
417+
)
410418
with toc_path.open(mode="w") as file:
411-
file.write(output)
419+
file.write(new_toc)
412420

413421

414422
def generate_operators_doc(
@@ -452,7 +460,7 @@ def generate_operators_doc(
452460
for operator_name in operators:
453461
generate_operator_doc(server, operator_name, include_private, output_path)
454462
# Generate the toc tree
455-
generate_toc_tree(output_path)
463+
update_toc_tree(output_path)
456464
# Use update files in output_path
457465
update_operator_descriptions(output_path)
458466

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,3 @@
1-
- name: Introduction
2-
href: index.md
3-
- name: Getting started
4-
items:
5-
- name: Installation
6-
href: getting-started/installation.md
7-
- name: Licensing
8-
href: getting-started/licensing.md
9-
- name: Configuration
10-
href: getting-started/configuration.md
11-
- name: User guide
12-
items:
13-
- name: The server context
14-
href: user-guide/server-context.md
15-
- name: How to use data containers
16-
href: user-guide/using-data-containers.md
17-
- name: How to use operators
18-
href: user-guide/using-operators.md
19-
- name: Workflow examples for beginners
20-
href: user-guide/workflow-examples.md
21-
- name: Build local documentation
22-
href: user-guide/dpf-docs-local-preview.md
23-
- name: Core concepts
24-
items:
25-
- name: Available types
26-
href: core-concepts/dpf-types.md
27-
- name: Operator fundamentals
28-
href: core-concepts/operator.md
291
- name: Operator specifications
302
items:
313
- name: Operator specifications
@@ -36,5 +8,4 @@
368
- name: {{ operator.operator_name }}
379
href: operator-specifications/{{ operator.file_path }}{% endfor %}
3810
{% endfor %}
39-
- name: Changelog
40-
href: changelog/changelog.md
11+

tests/test_documentation.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,33 @@
2727

2828

2929
def test_generate_operators_doc(tmp_path: Path):
30+
specs_path = tmp_path / "operator-specifications"
31+
specs_path.mkdir()
32+
toc_path = tmp_path / "toc.yml"
33+
toc_string = r"""- name: Operator specifications
34+
items:
35+
36+
- name: Changelog
37+
href: changelog/changelog.md"""
38+
with toc_path.open(mode="w") as ff:
39+
ff.write(toc_string)
3040
generate_operators_doc(ansys_path=dpf.SERVER.ansys_path, output_path=tmp_path, verbose=False)
31-
file_to_test = tmp_path / "toc.yml"
32-
assert file_to_test.exists()
33-
file_to_test = tmp_path / "operator-specifications" / "utility" / "forward.md"
41+
assert toc_path.exists()
42+
file_to_test = specs_path / "utility" / "forward.md"
3443
assert file_to_test.exists()
3544

3645

3746
def test_generate_operators_doc_plugin_and_update(tmp_path: Path):
3847
specs_path = tmp_path / "operator-specifications"
3948
specs_path.mkdir()
49+
toc_path = tmp_path / "toc.yml"
50+
toc_string = r"""- name: Operator specifications
51+
items:
52+
53+
- name: Changelog
54+
href: changelog/changelog.md"""
55+
with toc_path.open(mode="w") as ff:
56+
ff.write(toc_string)
4057
utility_path = specs_path / "utility"
4158
utility_path.mkdir()
4259
forward_update_path = utility_path / "forward_upd.md"
@@ -51,8 +68,7 @@ def test_generate_operators_doc_plugin_and_update(tmp_path: Path):
5168
verbose=False,
5269
desired_plugin="core",
5370
)
54-
file_to_test = tmp_path / "toc.yml"
55-
assert file_to_test.exists()
71+
assert toc_path.exists()
5672
file_to_test = utility_path / "forward.md"
5773
assert file_to_test.exists()
5874
with file_to_test.open(mode="r", encoding="utf-8") as ff:

0 commit comments

Comments
 (0)