-
-
Notifications
You must be signed in to change notification settings - Fork 166
ENH: Add configuration option for parameter cross-referencing #295
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
Add a kwarg to make_xref to toggle the automatic wrapping of every term not in xref_ignore in an :obj: role.
Codecov Report
@@ Coverage Diff @@
## master #295 +/- ##
==========================================
+ Coverage 93.11% 93.57% +0.46%
==========================================
Files 7 7
Lines 1263 1261 -2
==========================================
+ Hits 1176 1180 +4
+ Misses 87 81 -6 |
Another option would be to allow Overall +1 on this idea/PR |
Thanks for the feedback! I gave the I also had to add some input checking for LMK what you think of this alternative. Also, if it makes review easier, I'm happy to submit f2f1867 in a separate PR so that it's easier to compare the two alternatives. |
The two would be https://github.com/numpy/numpydoc/blob/master/numpydoc/numpydoc.py#L237-L240 Maybe we don't need the recursive stuff, not sure. In any case, I don't see any earlier event we could connect to. So feel free to try to make it work with |
I've revisited this a bit and haven't been able to come up with a good way to keep from modifying I'd like to submit this for review in its current form. I did some very crude profiling to make sure the modifications to from numpydoc.tests.test_xref import data, xref_aliases, xref_ignore
from numpydoc.xref import make_xref
param_descrs = [s.split('\n')[0] for s in data.strip().split('\n\n')]
%%timeit
for param in param_descrs:
make_xref(param_descrs[0], xref_aliases, xref_ignore) Which gave: 676a8d4: f2f1867: I also built the numpy documentation with both versions of numpydoc and saw no appreciable difference in build time between the two. |
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.
LGTM, +1 for merge
If nobody else looks in the next couple of days feel free to ping me for a merge!
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 automatic cross-referencing in the
param_type
is a nice feature. However, activating this feature in a large project with many docstring (e.g. numpy) introduces many new broken links as all terms in the parameter-type lines are wrapped in the default:obj:
role if they are not explicitly mentioned in either thenumpydoc_xref_aliases
dict or thenumpydoc_xref_ignore
set. Here's an example from the test suite:Notice how
M
andN
are wrapped in an:obj:
role. If the user wants to prevent this, they have to add 'M' and 'N' tonumpydoc_xref_ignore
(terms_to_ignore
in the above example). For large libraries with many different parameter type descriptions, adding all of the terms that are to be ignored can be a big undertaking that prevents the use of this feature.This PR introduces a new config parameter (tentatively called
numpydoc_xref_wrap_all
- open to suggestions) that toggles the wrapping of "unrecognized" terms in the:obj:
role. If the user sets this value toFalse
, then only values that are explicitly named innumpydoc_xref_aliases
(and not innumpydoc_xref_ignore
) are replaced. This allows for incremental adoption of the cross-referencing feature without requiring that users have fully-specified mappings/sets with terms to replace/ignore to prevent the introduction of broken links. The default value ofnumpydoc_xref_wrap_all=True
keeps the current behavior so that users who are already using this feature are unaffected.