Skip to content

Commit f8989d1

Browse files
authored
Merge pull request jpype-project#1289 from Thrameos/userguide
Userguide update
2 parents 6284ba1 + 331f7fb commit f8989d1

File tree

6 files changed

+4589
-1254
lines changed

6 files changed

+4589
-1254
lines changed

.azure/doc-requirements.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# TODO: consider unpinning these?
2-
Pygments==2.15.0
3-
docutils==0.14
4-
commonmark==0.8.1
5-
recommonmark==0.5.0
2+
Pygments
3+
docutils
4+
commonmark
5+
recommonmark
66
sphinx
77
sphinx-rtd-theme
88
readthedocs-sphinx-ext

doc/add_labels.py

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
import re
2+
3+
def sanitize_label(text):
4+
"""
5+
Sanitize the label text by removing or replacing special characters.
6+
Only allow alphanumeric characters and underscores.
7+
"""
8+
# Replace spaces with underscores
9+
text = text.replace(" ", "_")
10+
# Remove any characters that are not alphanumeric or underscores
11+
text = re.sub(r"[^\w]", "", text)
12+
return text.lower()
13+
14+
15+
def sync_labels(input_file, output_file):
16+
"""
17+
Synchronize labels with headers in an RST file. Labels are generated based on the chapter, header, subheader, and
18+
sub-subheader structure. The script ensures anchors appear immediately before the correct header text, preserves
19+
all section content, and avoids duplicating labels.
20+
21+
Header Hierarchy:
22+
- Chapters are identified by lines underlined with `*`.
23+
- Headers are identified by lines underlined with `=`.
24+
- Subheaders are identified by lines underlined with `-`.
25+
- Sub-subheaders are identified by lines underlined with `~`.
26+
27+
Label Format:
28+
- Labels follow the format: `.. _chapter_header_subheader_subsubheader:`
29+
- Labels are generated dynamically based on the text of the header and its position in the hierarchy.
30+
"""
31+
# Regular expressions to identify underline patterns for different header levels
32+
underline_patterns = {
33+
"*": "chapter",
34+
"=": "header",
35+
"-": "subheader",
36+
"~": "subsubheader",
37+
}
38+
39+
# Variables to track the current hierarchy of headers
40+
current_chapter = None
41+
current_header = None
42+
current_subheader = None
43+
44+
# Read the input file
45+
with open(input_file, "r") as infile:
46+
lines = infile.readlines()
47+
48+
# Initialize output lines
49+
output_lines = []
50+
buffer = None # Holds the previous line to check for headers
51+
last_label = None
52+
line_count = 0
53+
54+
for i, line in enumerate(lines):
55+
# Debugging: Print the current line being processed
56+
print(f"Processing line {i}: {line.strip()}")
57+
58+
if line.startswith(".."):
59+
last_label = line
60+
line_count = 0
61+
62+
# Check if the line is an underline pattern
63+
if re.match(r"^\*+$", line):
64+
# Process chapter
65+
current_chapter = sanitize_label(buffer.strip().lower().replace(" ", "_")) if buffer else None
66+
label = f".. _{current_chapter}:\n\n" if current_chapter else None
67+
if label and not line_count == 2:
68+
print(f"Detected chapter: {current_chapter}, adding label: {label.strip()}")
69+
output_lines.append(label)
70+
if buffer:
71+
print(f"Detected chapter (skip): {current_chapter}, adding label: {label.strip()}")
72+
output_lines.append(buffer) # Add the header text immediately after the label
73+
output_lines.append(line) # Add the underline itself
74+
buffer = None
75+
elif re.match(r"^=+$", line):
76+
# Process header
77+
current_header = sanitize_label(buffer.strip().lower().replace(" ", "_")) if buffer else None
78+
if not current_header: # Fallback for empty buffer
79+
current_header = "unknown_header"
80+
label = f".. _{current_chapter}_{current_header}:\n\n" if current_header else None
81+
if label and not line_count == 2:
82+
print(f"Detected header: {current_header}, adding label: {label.strip()}")
83+
output_lines.append(label)
84+
if buffer:
85+
print(f"Detected header (skip): {current_chapter}, adding label: {label.strip()}")
86+
output_lines.append(buffer) # Add the header text immediately after the label
87+
output_lines.append(line) # Add the underline itself
88+
buffer = None
89+
elif re.match(r"^-+$", line):
90+
# Process subheader
91+
current_subheader = sanitize_label(buffer.strip().lower().replace(" ", "_")) if buffer else None
92+
label = f".. _{current_chapter}_{current_subheader}:\n\n" if current_subheader else None
93+
if label and not line_count == 2:
94+
print(f"Detected subheader: {current_subheader}, adding label: {label.strip()}")
95+
output_lines.append(label)
96+
if buffer:
97+
output_lines.append(buffer) # Add the header text immediately after the label
98+
output_lines.append(line) # Add the underline itself
99+
buffer = None
100+
elif re.match(r"^~+$", line):
101+
# Process sub-subheader
102+
subsubheader_text = sanitize_label(buffer.strip().lower().replace(" ", "_")) if buffer else None
103+
label = f".. _{current_chapter}_{subsubheader_text}:\n\n" if subsubheader_text else None
104+
if label and not line_count == 2:
105+
print(f"Detected sub-subheader: {subsubheader_text}, adding label: {label.strip()}")
106+
output_lines.append(label)
107+
if buffer:
108+
output_lines.append(buffer) # Add the header text immediately after the label
109+
output_lines.append(line) # Add the underline itself
110+
buffer = None
111+
else:
112+
# If the line isn't an underline, store it in the buffer
113+
if buffer:
114+
output_lines.append(buffer) # Add the previous line to the output
115+
buffer = line # Store the current line for processing
116+
if not line.isspace():
117+
line_count += 1
118+
119+
if buffer is not None:
120+
output_lines.append(buffer)
121+
122+
# Write the output to the specified file
123+
with open(output_file, "w") as outfile:
124+
outfile.writelines(output_lines)
125+
126+
print(f"Labels synchronized successfully! Output written to {output_file}")
127+
128+
129+
# Input and output file paths
130+
input_file = "userguide.rst"
131+
output_file = "userguide_with_synced_labels.rst"
132+
133+
# Run the label synchronization
134+
sync_labels(input_file, output_file)

doc/boilerplate.txt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
Today, we are working on modifying the JPype documentation. The document I
2+
have provided is in reStructuredText (RST) format. All responses must adhere
3+
to the following guidelines:
4+
5+
1. **Line Length**:
6+
- All responses must maintain an 80-character line length limit.
7+
8+
2. **Formatting**:
9+
- Match the existing format in terms of anchors, linkage, and overall
10+
structure.
11+
- Header levels must follow the established hierarchy:
12+
- ****** Chapter Level
13+
- ====== Header Level
14+
- ------ Subheader Level
15+
- ~~~~~~ Subheader Level
16+
17+
3. **Content Style**:
18+
- When revisions are presented, they must match the header levels and
19+
formatting of the existing text.
20+
- Use descriptive text instead of bullet lists to ensure the document
21+
reads as a cohesive narrative rather than an outline.
22+
23+
4. **Sphinx Compatibility**:
24+
- The resulting RST file must conform to Sphinx's interpretation of RST.
25+
- Ensure proper use of directives, roles, and syntax supported by Sphinx
26+
to avoid processing errors.
27+
- Test the RST file with Sphinx to verify compatibility and correctness
28+
before finalizing revisions.
29+
30+
5. **Avoid Speculative Material**:
31+
- Ensure all revisions are based on verified information, authoritative
32+
sources, or established best practices.
33+
- Avoid unverified claims, ambiguous statements, or unsupported examples.
34+
- Do not include predictions or assumptions about future behavior unless
35+
explicitly supported by authoritative sources or documentation.
36+
- Provide sufficient context and explanation for all claims, examples,
37+
and workflows to ensure clarity and reliability.
38+
39+
By following these guidelines, all revisions will align with the existing
40+
style and structure of the JPype documentation.
41+
42+
43+
44+
45+
Typical prompts:
46+
47+
Please review the document for consistency of style between the different
48+
sections. Identify sections that no longer fit the description of a narrative
49+
(excluding sections in which a narrative would not be expected such as
50+
glossary)
51+

doc/conf.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,13 @@ def patch(self, key):
207207
#html_theme_options = {}
208208

209209
# Add any paths that contain custom themes here, relative to this directory.
210-
#html_theme_path = []
211210

212211
# on_rtd is whether we are on readthedocs.org, this line of code grabbed from docs.readthedocs.org
213212
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
214213

215214
if not on_rtd: # only import and set the theme if we're building docs locally
216215
import sphinx_rtd_theme
217216
html_theme = 'sphinx_rtd_theme'
218-
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
219217

220218
# otherwise, readthedocs.org uses their theme by default, so no need to specify it
221219

0 commit comments

Comments
 (0)