-
Notifications
You must be signed in to change notification settings - Fork 210
ENH: Add CSS classes for backrefs #581
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| import codecs | ||
| import collections | ||
| from html import escape | ||
| import inspect | ||
| import os | ||
| import re | ||
| import warnings | ||
|
|
@@ -67,9 +68,18 @@ def get_mapping(self): | |
| if local_name in self.imported_names: | ||
| # Join import path to relative path | ||
| full_name = self.imported_names[local_name] + remainder | ||
| yield name, full_name, class_attr | ||
| if local_name in self.global_variables: | ||
| obj = self.global_variables[local_name] | ||
| if remainder: | ||
| for level in remainder[1:].split('.'): | ||
| obj = getattr(obj, level) | ||
|
Comment on lines
+74
to
+75
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be missing something but why is a for loop needed here? Won't
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In some case doing ...but fortunately I was so annoyed by it that I wrote a test to capture it, and if I just do Which is probably because of this somewhat unexpected behavior:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I am suggesting
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoops
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I get it now. Sorry and thanks for explaining.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No problem, hopefully it's not too bad to add your changes from #584 on top once this is in -- then it will be my turn to be confused during review :)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apparently you are allowed to have
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hope never to encounter such code :) |
||
| is_class = inspect.isclass(obj) | ||
| else: | ||
| is_class = False | ||
| yield name, full_name, class_attr, is_class | ||
| elif local_name in self.global_variables: | ||
| obj = self.global_variables[local_name] | ||
| is_class = inspect.isclass(obj) | ||
| if remainder and remainder[0] == '.': # maybe meth or attr | ||
| method = [remainder[1:]] | ||
| class_attr = True | ||
|
|
@@ -91,7 +101,7 @@ def get_mapping(self): | |
| for depth in range(len(module), 0, -1): | ||
| full_name = '.'.join( | ||
| module[:depth] + [class_name] + method) | ||
| yield name, full_name, class_attr | ||
| yield name, full_name, class_attr, is_class | ||
|
|
||
|
|
||
| def _from_import(a, b): | ||
|
|
@@ -157,10 +167,10 @@ def identify_names(script_blocks, global_variables=None, node=''): | |
| names = list(finder.get_mapping()) | ||
| # Get matches from docstring inspection | ||
| text = '\n'.join(txt for kind, txt, _ in script_blocks if kind == 'text') | ||
| names.extend((x, x, False) for x in re.findall(_regex, text)) | ||
| names.extend((x, x, False, False) for x in re.findall(_regex, text)) | ||
| example_code_obj = collections.OrderedDict() # order is important | ||
| fill_guess = dict() | ||
| for name, full_name, class_like in names: | ||
| for name, full_name, class_like, is_class in names: | ||
| if name in example_code_obj: | ||
| continue # if someone puts it in the docstring and code | ||
| # name is as written in file (e.g. np.asarray) | ||
|
|
@@ -178,7 +188,7 @@ def identify_names(script_blocks, global_variables=None, node=''): | |
| # get shortened module name | ||
| module_short = _get_short_module_name(module, attribute) | ||
| cobj = {'name': attribute, 'module': module, | ||
| 'module_short': module_short} | ||
| 'module_short': module_short, 'is_class': is_class} | ||
| if module_short is not None: | ||
| example_code_obj[name] = cobj | ||
| elif name not in fill_guess: | ||
|
|
||
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
!importanthere? It makes it hard to override by package developers, I think (I'm no CSS expert so please bear with me :-))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.
This is just for building the SG docs, it shouldn't affect actual use of SG by downstream libraries. The one CSS change that will is in gallery.css