def setUp(self): self.maxDiff = None class TestClass(param.Parameterized): u = param.Number(4) v = param.Number(4, constant=True) w = param.Number(4, readonly=True) x = param.String(None, allow_None=True) y = param.Number(4, bounds=(-1, None)) z = param.Number(4, bounds=(-1, 100), softbounds=(-100, -200)) self.TestClass = TestClass self.pager = ParamPager()
def setUp(self): super(TestParamPager, self).setUp() self.maxDiff = None class TestClass(param.Parameterized): u = param.Number(4, precedence=0) w = param.Number(4, readonly=True, precedence=1) v = param.Number(4, constant=True, precedence=2) x = param.String(None, allow_None=True, precedence=3) y = param.Number(4, bounds=(-1, None), precedence=4) z = param.Number(4, bounds=(-1, 100), softbounds=(-100, -200), precedence=5) self.TestClass = TestClass self.pager = ParamPager()
class InfoPrinter(object): """ Class for printing other information related to an object that is of use to the user. """ headings = ['\x1b[1;35m%s\x1b[0m', '\x1b[1;32m%s\x1b[0m'] ansi_escape = re.compile(r'\x1b[^m]*m') ppager = ParamPager() store = None elements = [] @classmethod def get_parameter_info(cls, obj, ansi=False, show_values=True, pattern=None, max_col_len=40): """ Get parameter information from the supplied class or object. """ if cls.ppager is None: return '' if pattern is not None: obj = ParamFilter(obj, ParamFilter.regexp_filter(pattern)) if len(obj.params()) <= 1: return None param_info = cls.ppager.get_param_info(obj) param_list = cls.ppager.param_docstrings(param_info) if not show_values: retval = cls.ansi_escape.sub( '', param_list) if not ansi else param_list return cls.highlight(pattern, retval) else: info = cls.ppager(obj) if ansi is False: info = cls.ansi_escape.sub('', info) return cls.highlight(pattern, info) @classmethod def heading(cls, heading_text, char='=', level=0, ansi=False): """ Turn the supplied heading text into a suitable heading with optional underline and color. """ heading_color = cls.headings[level] if ansi else '%s' if char is None: return heading_color % '%s\n' % heading_text else: heading_ul = char * len(heading_text) return heading_color % '%s\n%s\n%s' % (heading_ul, heading_text, heading_ul) @classmethod def highlight(cls, pattern, string): if pattern is None: return string return re.sub(pattern, '\033[43;1;30m\g<0>\x1b[0m', string, flags=re.IGNORECASE) @classmethod def info(cls, obj, ansi=False, backend='matplotlib', visualization=True, pattern=None, elements=[]): """ Show information about an object in the given category. ANSI color codes may be enabled or disabled. """ cls.elements = elements ansi_escape = re.compile(r'\x1b[^m]*m') isclass = isinstance(obj, type) name = obj.__name__ if isclass else obj.__class__.__name__ backend_registry = cls.store.registry.get(backend, {}) plot_class = backend_registry.get(obj if isclass else type(obj), None) # Special case to handle PlotSelectors if hasattr(plot_class, 'plot_classes'): plot_class = list(plot_class.plot_classes.values())[0] if visualization is False or plot_class is None: if pattern is not None: obj = ParamFilter(obj, ParamFilter.regexp_filter(pattern)) if len(obj.params()) <= 1: return ( 'No %r parameters found matching specified pattern %r' % (name, pattern)) info = param.ipython.ParamPager()(obj) if ansi is False: info = ansi_escape.sub('', info) return cls.highlight(pattern, info) heading = name if isclass else '{name}: {group} {label}'.format( name=name, group=obj.group, label=obj.label) prefix = heading lines = [ prefix, cls.object_info(obj, name, backend=backend, ansi=ansi) ] if not isclass: lines += ['', cls.target_info(obj, ansi=ansi)] if plot_class is not None: lines += ['', cls.options_info(plot_class, ansi, pattern=pattern)] return "\n".join(lines) @classmethod def get_target(cls, obj): objtype = obj.__class__.__name__ group = group_sanitizer(obj.group) label = ('.' + label_sanitizer(obj.label) if obj.label else '') target = '{objtype}.{group}{label}'.format(objtype=objtype, group=group, label=label) return (None, target) if hasattr(obj, 'values') else (target, None) @classmethod def target_info(cls, obj, ansi=False): if isinstance(obj, type): return '' targets = obj.traverse(cls.get_target) elements, containers = zip(*targets) element_set = set(el for el in elements if el is not None) container_set = set(c for c in containers if c is not None) element_info = None if len(element_set) == 1: element_info = 'Element: %s' % list(element_set)[0] elif len(element_set) > 1: element_info = 'Elements:\n %s' % '\n '.join( sorted(element_set)) container_info = None if len(container_set) == 1: container_info = 'Container: %s' % list(container_set)[0] elif len(container_set) > 1: container_info = 'Containers:\n %s' % '\n '.join( sorted(container_set)) heading = cls.heading('Target Specifications', ansi=ansi, char="-") target_header = '\nTargets in this object available for customization:\n' if element_info and container_info: target_info = '%s\n\n%s' % (element_info, container_info) else: target_info = element_info if element_info else container_info target_footer = ( "\nTo see the options info for one of these target specifications," "\nwhich are of the form {type}[.{group}[.{label}]], do holoviews.help({type})." ) return '\n'.join([heading, target_header, target_info, target_footer]) @classmethod def object_info(cls, obj, name, backend, ansi=False): element = not getattr(obj, '_deep_indexable', False) element_url = 'http://holoviews.org/reference/elements/{backend}/{obj}.html' container_url = 'http://holoviews.org/reference/containers/{backend}/{obj}.html' url = element_url if element else container_url link = url.format(obj=name, backend=backend) link = None if element and (name not in cls.elements) else link msg = ("\nOnline example: {link}" if link else '' + "\nHelp for the data object: holoviews.help({obj})" + " or holoviews.help(<{lower}_instance>)") return '\n'.join([msg.format(obj=name, lower=name.lower(), link=link)]) @classmethod def options_info(cls, plot_class, ansi=False, pattern=None): if plot_class.style_opts: backend_name = plot_class.backend style_info = ( "\n(Consult %s's documentation for more information.)" % backend_name) style_keywords = '\t%s' % ', '.join(plot_class.style_opts) style_msg = '%s\n%s' % (style_keywords, style_info) else: style_msg = '\t<No style options available>' param_info = cls.get_parameter_info(plot_class, ansi=ansi, pattern=pattern) lines = [ cls.heading('Style Options', ansi=ansi, char="-"), '', style_msg, '', cls.heading('Plot Options', ansi=ansi, char="-"), '' ] if param_info is not None: lines += [ "The plot options are the parameters of the plotting class:\n", param_info ] elif pattern is not None: lines += [ 'No %r parameters found matching specified pattern %r.' % (plot_class.__name__, pattern) ] else: lines += ['No %r parameters found.' % plot_class.__name__] return '\n'.join(lines)
class InfoPrinter(object): """ Class for printing other information related to an object that is of use to the user. """ headings = ['\x1b[1;35m%s\x1b[0m', '\x1b[1;32m%s\x1b[0m'] ansi_escape = re.compile(r'\x1b[^m]*m') ppager = ParamPager() store = None @classmethod def get_parameter_info(cls, obj, ansi=False, show_values=True, max_col_len=40): """ Get parameter information from the supplied class or object. """ if cls.ppager is None: return '' param_info = cls.ppager.get_param_info(obj) param_list = cls.ppager.param_docstrings(param_info) if not show_values: return cls.ansi_escape.sub('', param_list) if not ansi else param_list else: info = cls.ppager(obj) if ansi is False: info = cls.ansi_escape.sub('', info) return info @classmethod def heading(cls, heading_text, char='=', level=0, ansi=False): """ Turn the supplied heading text into a suitable heading with optional underline and color. """ heading_color = cls.headings[level] if ansi else '%s' if char is None: return heading_color % '%s\n' % heading_text else: heading_ul = char * len(heading_text) return heading_color % '%s\n%s\n%s' % (heading_ul, heading_text, heading_ul) @classmethod def info(cls, obj, ansi=False): """ Show information about an object in the given category. ANSI color codes may be enabled or disabled. """ isclass = isinstance(obj, type) name = obj.__name__ if isclass else obj.__class__.__name__ plot_class = cls.store.registry.get(obj if isclass else type(obj), None) heading = name if isclass else '{name}: {group} {label}'.format( name=name, group=obj.group, label=obj.label) prefix = heading lines = [prefix, cls.object_info(obj, name, ansi=ansi)] if not isclass: lines += ['', cls.target_info(obj, ansi=ansi)] if plot_class is not None: lines += ['', cls.options_info(plot_class, ansi)] return "\n".join(lines) @classmethod def get_target(cls, obj): objtype = obj.__class__.__name__ group = sanitize_identifier(obj.group) label = ('.' + sanitize_identifier(obj.label) if obj.label else '') target = '{objtype}.{group}{label}'.format(objtype=objtype, group=group, label=label) return (None, target) if hasattr(obj, 'values') else (target, None) @classmethod def target_info(cls, obj, ansi=False): if isinstance(obj, type): return '' # < TEST targets = obj.traverse(cls.get_target) elements, containers = zip(*targets) element_set = set(el for el in elements if el is not None) container_set = set(c for c in containers if c is not None) element_info = None if len(element_set) == 1: element_info = 'Element: %s' % list(element_set)[0] elif len(element_set) > 1: element_info = 'Elements:\n %s' % '\n '.join( sorted(element_set)) container_info = None if len(container_set) == 1: container_info = 'Container: %s' % list(container_set)[0] elif len(container_set) > 1: container_info = 'Containers:\n %s' % '\n '.join( sorted(container_set)) heading = cls.heading('Target Specifications', ansi=ansi, char="-") target_header = '\nTargets in this object available for customization:\n' if element_info and container_info: target_info = '%s\n\n%s' % (element_info, container_info) else: target_info = element_info if element_info else container_info target_footer = ( "\nTo see the options info for one of these target specifications," "\nwhich are of the form {type}[.{group}[.{label}]], do holoviews.help({type})." ) return '\n'.join([heading, target_header, target_info, target_footer]) @classmethod def object_info(cls, obj, name, ansi=False): element = not getattr(obj, '_deep_indexable', False) url = ( 'https://ioam.github.io/holoviews/Tutorials/Elements.html#{obj}' if element else 'https://ioam.github.io/holoviews/Tutorials/Containers.html#{obj}') link = url.format(obj=name) msg = ("\nOnline example: {link}" + "\nHelp for the data object: holoviews.help({obj})" + " or holoviews.help(<{lower}_instance>)") return '\n'.join([msg.format(obj=name, lower=name.lower(), link=link)]) @classmethod def options_info(cls, plot_class, ansi=False): if plot_class.style_opts: style_info = "\n(Consult matplotlib's documentation for more information.)" style_keywords = '\t%s' % ', '.join(plot_class.style_opts) style_msg = '%s\n%s' % (style_keywords, style_info) else: style_msg = '\t<No style options available>' param_info = cls.get_parameter_info(plot_class, ansi=ansi) return '\n'.join([ cls.heading('Style Options', ansi=ansi, char="-"), '', style_msg, '', cls.heading('Plot Options', ansi=ansi, char="-"), '', "The plot options are the parameters of the plotting class:\n", param_info ])