Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions autogen/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"""

from __future__ import unicode_literals

import re
import subprocess


leading_ws = re.compile("^( +)", re.MULTILINE)
trailing_ws = re.compile("( +)$", re.MULTILINE)
double_space = re.compile(" +")
Expand All @@ -20,7 +20,9 @@
verb_loop = re.compile("^( .*)@\[[a-z]*\]", re.MULTILINE)

dollars = re.compile(r"@\[dollar\]\s*(.*?)\s*@\[dollar\]", re.DOTALL)
doubledollars = re.compile(r"@\[doubledollar\]\s*(.*?)\s*@\[doubledollar\] *", re.DOTALL)
doubledollars = re.compile(
r"@\[doubledollar\]\s*(.*?)\s*@\[doubledollar\] *", re.DOTALL
)

math_loop = re.compile(r"(@\[start[A-Z]*MATH\][^@]*)@\[[a-z]*\]")
math_backslash = re.compile(r"(@\[start[A-Z]*MATH\][^@]*)=BACKSLASH=")
Expand Down Expand Up @@ -101,6 +103,8 @@ def raw_to_rest(doc):
dividing :math:`\#E`.
"""
doc = doc.decode("utf-8")
if not doc:
return ""

# Work around a specific problem with doc of "component"
doc = doc.replace("[@[dollar]@[dollar]]", "[]")
Expand Down Expand Up @@ -242,8 +246,8 @@ def raw_to_rest(doc):
i = doc.index("@")
except ValueError:
return doc
ilow = max(0, i-30)
ihigh = min(len(doc), i+30)
ilow = max(0, i - 30)
ihigh = min(len(doc), i + 30)
raise SyntaxError("@ found: " + doc[ilow:ihigh])


Expand All @@ -269,9 +273,19 @@ def get_raw_doc(function):
...
RuntimeError: no help found for 'abcde'
"""
doc = subprocess.check_output(["gphelp", "-raw", function])
try:
doc = subprocess.check_output(["gphelp", "-raw", function])
except (subprocess.CalledProcessError, FileNotFoundError) as error:
print(
f"""
Error calling gphelp: {error}.
This is most likely because your PARI installation doesn't include the documentation.
As a result, the generated function will not have a docstring.
""".strip()
)
return b""
if doc.endswith(b"""' not found !\n"""):
raise RuntimeError("no help found for '{}'".format(function))
raise RuntimeError(f"no help found for '{function}'")
return doc


Expand Down Expand Up @@ -328,7 +342,7 @@ def get_rest_doc(function):

>>> print(get_rest_doc("bitor"))
bitwise (inclusive)
:literal:`or` of two integers :math:`x` and :math:`y`, that is the integer
:literal:`or` of two integers :math:`x` and :math:`y`, that is the integer
<BLANKLINE>
.. MATH::
<BLANKLINE>
Expand Down
Loading