-
-
Notifications
You must be signed in to change notification settings - Fork 166
ENH: Added support for multiple functions+description in a See Also block #172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Under Py3.6 nosetests passes, but the latexpdf fails with Under Py 2.7, one nosetest test fails with Implication: Inserting a Unicode character into the output, either as Unicode or UTF-8, breaks downstream processing. @jnothman suggests using ".." instead and that seems to behave better. |
Also closes gh-28 |
Summary:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pvanmulbregt can you rebase to get rid of the merge conflict?
Also remove the zero-width space \u200B when comparing test output.
This seems like a useful extension/bugfix to me, and it sounds like using I rebuilt MNE doc with this and things still looked okay. I also rebuilt SciPy and things looked okay. And when I modified this:
To be this:
It looked good: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've not really managed to review for correctness yet.
numpydoc/tests/test_docscrape.py
Outdated
@@ -331,13 +331,15 @@ def _strip_blank_lines(s): | |||
|
|||
|
|||
def line_by_line_compare(a, b): | |||
empty_description = '..' | |||
rgx = re.compile(r"^\s+" + re.escape(empty_description) + "$") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rgx is a terrible name for something that matches an empty description. But I'm also not sure why it's important to disregard these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to empty_description_rgx
.
numpydoc/docscrape.py
Outdated
ml = self._line_rgx.match(line) | ||
description = None | ||
if ml: | ||
if 'description' in ml.groupdict(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
description = ml.group('desc')
will suffice here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -236,10 +236,30 @@ def _parse_param_list(self, content): | |||
|
|||
return params | |||
|
|||
_role = r":(?P<role>\w+):" | |||
_funcbacktick = r"`(?P<name>(?:~\w+\.)?[a-zA-Z0-9_.-]+)`" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's confusing to mix the use of \w
and explicit character classes:
_funcbacktick = r"`(?P<name>(?:~\w+\.)?[a-zA-Z0-9_.-]+)`" | |
_funcbacktick = r"`(?P<name>(?:~\w+\.)?[\w.-]+)`" |
Actually, I don't think the ~
or .
should be obligatory.
_funcbacktick = r"`(?P<name>(?:~\w+\.)?[a-zA-Z0-9_.-]+)`" | |
_funcbacktick = r"`(?P<name>(?:~?\w+\.)?[\w.-]+|\w+)`" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regexes appearing in these patterns were taken from the original regex.
_name_rgx = re.compile(r"^\s*(:(?P<role>\w+):"
r"`(?P<name>(?:~\w+\.)?[a-zA-Z0-9_.-]+)`|"
r" (?P<name2>[a-zA-Z0-9_.-]+))\s*", re.X)
The patterns can be changed but I'd prefer that to be in a separate PR, since that will change the meaning.
@@ -236,10 +236,30 @@ def _parse_param_list(self, content): | |||
|
|||
return params | |||
|
|||
_role = r":(?P<role>\w+):" | |||
_funcbacktick = r"`(?P<name>(?:~\w+\.)?[a-zA-Z0-9_.-]+)`" | |||
_funcplain = r"(?P<name2>[a-zA-Z0-9_.-]+)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_funcplain = r"(?P<name2>[a-zA-Z0-9_.-]+)" | |
_funcplain = r"(?P<name2>[a-zA-Z0-9_.-]+)" |
_funcplain = r"(?P<name2>[a-zA-Z0-9_.-]+)" | |
_funcplain = r"(?P<name2>[\w.-]+)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above regarding original _name_rgx
.
_funcplain = r"(?P<name2>[a-zA-Z0-9_.-]+)" | ||
_funcname = r"(" + _role + _funcbacktick + r"|" + _funcplain + r")" | ||
_funcnamenext = _funcname.replace('role', 'rolenext').replace('name', 'namenext') | ||
_description = r"(?P<description>\s*:(\s+(?P<desc>\S+.*))?)?\s*$" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I think we'd like to make the space before the colon obligatory, for consistency with param lists, but I don't think the current code requires it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that the original _name_rgx
did not require it.
numpydoc/docscrape.py
Outdated
if not text.strip(): | ||
break | ||
name, role, m2 = parse_item_name(text) | ||
# m2 = self._func_rgx.match(text) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove this commented section
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
numpydoc/docscrape.py
Outdated
while True: | ||
if not text.strip(): | ||
break | ||
name, role, m2 = parse_item_name(text) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be cleaner to have parse_item_name
return the end
than the match. especially if you're going to call it the inscrutable m2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
numpydoc/tests/test_docscrape.py
Outdated
'~baz.obj_r'): | ||
assert (not desc), str([func, desc]) | ||
elif func in ('func_f2', 'func_g2', 'func_h2', 'func_j2'): | ||
assert (desc), str([func, desc]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rm parentheses
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
numpydoc/tests/test_docscrape.py
Outdated
elif func in ('func_f2', 'func_g2', 'func_h2', 'func_j2'): | ||
assert (desc), str([func, desc]) | ||
else: | ||
assert(desc), str([func, desc]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rm parentheses
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks reasonable in terms of functionality and tests. Just could be neater code.
Added the spec used by NumpyDocString._parse_see_also. Added a warning whenever an unexpected trailing comma appears in a See Also function list. Removed unnecessary re.X qualifiers from some regular expressions. Renamed some variables with more descriptive names. Removed some unused/commented-out code. Removed some unnneeded parentheses. Shortened some lines to keep under 80 characters.
numpydoc/docscrape.py
Outdated
# <FUNCNAME> ( COMMA SPACE+ <FUNCNAME>)* SPACE* COLON SPACE+ <DESC> SPACE* | ||
|
||
# <FUNCNAME> is: | ||
# A legal function name, optionally enclosed in backticks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currently a function name enclosed in backticks requires a role.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated doc.
numpydoc/docscrape.py
Outdated
if not m: | ||
raise ParseError("%s is not a item name" % text) | ||
role = m.group('role') | ||
name = (m.group('name') if role else m.group('name2')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant parentheses
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
numpydoc/docscrape.py
Outdated
else: | ||
out[-1] += ", %s" % link | ||
for funcs, desc in self['See Also']: | ||
assert isinstance(funcs, (list, tuple)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we allow a tuple?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only allow lists.
numpydoc/tests/test_docscrape.py
Outdated
@@ -331,10 +331,16 @@ def _strip_blank_lines(s): | |||
|
|||
|
|||
def line_by_line_compare(a, b): | |||
empty_description = NumpyDocString.empty_description # '..' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it's important that these are inserted, why do we want to disregard them in testing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the disregarding of these lines and updated the expected output to account for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you forgotten to commit this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise LGTM
Thanks, @pvanmulbregt. I'd appreciate if this could also be mentioned in the docs. another pr? |
Addresses gh-170. Extended capabilities of See Also blocks. No longer silently drops descriptions from lines with multiple functions.
Supports
<FUNCNAME>
<FUNCNAME> <SPACE>* COLON SPACE+ <DESCRIPTION> SPACE*
<FUNCNAME> ( COMMA SPACE+ <FUNCNAME>)* SPACE*
<FUNCNAME> ( COMMA SPACE+ <FUNCNAME>)* SPACE* COLON SPACE+ <DESCRIPTION> SPACE*
Empty
<DESCRIPTION>
elements are replaced with a Unicode ZERO-WIDTH SPACE" \u200B"
in the output ofdocscrape.py
. That is sufficient to convince the subsequent processing that the definition is present for the purposes of continuing the definition list. Further processing replaces the string" \u200B"
with""
, so that teh zero-width space doesn't appear in the generated HTML.Closes #28