[MRG] Fixes cross-reference and no reference issues in sphinx#13000
[MRG] Fixes cross-reference and no reference issues in sphinx#13000adrinjalali merged 25 commits intoscikit-learn:masterfrom
Conversation
|
Hmmm... are you sure this is what you mean? This will override the global default role so that only |
|
Yea, I wanted to change the priority order. It looks like the order for |
|
I'm happy for us to customise the default role but last time I tried to do
it it looked too messy so I just went with any
|
|
This PR was updated to override the default
Codewise, it adds the following few lines to the default with suppress(KeyError):
py_domain = self.env.domains['py']
results.extend(py_domain.resolve_any_xref(
self.env, refdoc, self.app.builder, target, node, contnode))and removes the logging that has to do with more than one reference. |
|
This PR was updated with a refactor to clean up the code and make it easier to review. If a reference is found, it will immediately be processed into a node and returned. |
|
Can you help by pointing to links that this improves/changes? Thanks
|
|
It prioritizes references in class docstrings to reference itself. Here are a few examples:
On master the links point to the glossary. With this PR, they point to the class methods. |
|
Looks nice (not looked at code yet)! I have a small concern about referencing base estimator methods in meta-estimator documentation where, if you want a link at all, it is not to the local |
This is true, this PR's ColumnTransformer, links |
| target = node['reftarget'] | ||
|
|
||
| # first, try resolving as :doc: | ||
| doc_ref = stddomain.resolve_xref(self.env, refdoc, self.app.builder, |
There was a problem hiding this comment.
I'm not sure we really ever want to link to :doc:, do we?
| @@ -0,0 +1,83 @@ | |||
| """Adapted from | |||
| sphinx.transforms.post_transforms.ReferencesResolver.resolve_anyref | |||
There was a problem hiding this comment.
Please include any relevant licensing information to avoid breach of terms.
| return self.create_node(('doc', doc_ref)) | ||
|
|
||
| # process 'py' domain first for python classes | ||
| if "py:class" in node: |
|
|
||
| def create_node(self, result): | ||
| res_role, newnode = result | ||
| # Override "any" class with the actual role type to get the styling |
There was a problem hiding this comment.
Nice!! One confusing thing is that :term: does not generally require monospace, but some terms are explicitly formatted with double backticks in the glossary (but the link target does not include backticks). I assume we're not really able to make that work nicely. No big deal.
I can't see what code controls styling when there's no match.
There was a problem hiding this comment.
When the reference is missing the missing-reference event is called. This is handled in another PR: https://github.com/scikit-learn/scikit-learn/pull/12970/files. In that PR, the single backticks are treated as double backticks when there are not matches.
|
This PR was updated to address the "no reference" case. If no reference is found, the single backticked strings will be displayed as |
|
This PR was updated to address the "no reference" case. Codewise, the following was added: def resolve_anyref(self, refdoc, node, contnode):
...
# no results considered to be <code>
contnode['classes'] = []
return contnodeIf no reference is found, the single backticked strings will be displayed as |
jnothman
left a comment
There was a problem hiding this comment.
I like this, but I'm not sure if we should continue calling this 'any'. Is it easy to rename the default role to show maintainers that it's different?
| post_transforms[i] = CustomReferencesResolver | ||
| break | ||
| else: | ||
| raise RuntimeError |
There was a problem hiding this comment.
Might add a message: ReferencesResolver not found
|
If we wish to change the default role's name, we would most likely need to create a custom role and a corresponding domain. This would require a different approach than this PR. A comment was added to the |
|
@amueller This PR enables the following:
|
| By setting ``remainder`` to be an estimator, the remaining | ||
| non-specified columns will use the ``remainder`` estimator. The | ||
| estimator must support `fit` and `transform`. | ||
| estimator must support :term:`fit` and :term:`transform`. |
…earn#13000) * DOC: Fixes cross references * RFC: Minimizes diffs * REV: Removes default-role * ENH: Process python domain first * ENH: Support sphinx 1.6.2 * RFC: Only reorder for python classes * RFC: Adds early exit * DOC: Uses term for ColumnTransformer * REV: Removes styling from term * ENH: Handle no references case * ENH: Adds RuntimeError * RFC: Adds runtime error message * DOC: Adds comment on default_role * CLN Removes term
…cikit-learn#13000)" This reverts commit e52752b.
…cikit-learn#13000)" This reverts commit e52752b.
…earn#13000) * DOC: Fixes cross references * RFC: Minimizes diffs * REV: Removes default-role * ENH: Process python domain first * ENH: Support sphinx 1.6.2 * RFC: Only reorder for python classes * RFC: Adds early exit * DOC: Uses term for ColumnTransformer * REV: Removes styling from term * ENH: Handle no references case * ENH: Adds RuntimeError * RFC: Adds runtime error message * DOC: Adds comment on default_role * CLN Removes term
Reference Issues/PRs
Fixes #12802
What does this implement/fix? Explain your changes.
Overrides the default
ReferencesResolverwith aCustomReferencesResolver. The custom resolver does two things:pydomain above thestddomain, allowing class methods to be referenced first.Any other comments?
This together with #12970 should resolve most of the warnings that appear in sphinx when we switched the default role to "any".