def do_translation_override(port_specs, names, rows, opts): if 'name' in opts: names = opts['name'] if names is None: raise ValueError("Must specify name of port to use translation for") if isinstance(names, basestring) or not matplotlib.cbook.iterable(names): names = [names] should_reverse = opts.get('reverse', True) values_only = opts.get('values_only', False) (t, port_type, values) = \ parse_translation(rows, should_reverse) for name in names: print "TRANSLATING", name if name not in port_specs: port_specs[name] = InputPortSpec(name) port_specs[name].entry_types = ['enum'] port_specs[name].values = [values] if not values_only: port_specs[name].translations = t
def parse_artists(artist_types, table_overrides={}): def get_module_name(obj): return obj.__name__ def get_super_name(obj): for base in obj.__bases__: if issubclass(base, Artist): return base.__name__ return "" module_specs = [] for klass in artist_types: (klass, module_name, super_name) = \ get_names(klass, get_module_name, get_super_name, "Mpl", "Properties") port_specs = {} insp = ArtistInspector(klass) klass_name = klass.__name__ klass_qualname = klass.__module__ + "." + klass_name for (s, t) in insp._get_setters_and_targets(): print "** %s **" % s if t.rsplit('.', 1)[0] != klass_qualname: # let inheritance work continue if s in port_specs: raise ValueError('duplicate port "%s"' % s) port_spec = InputPortSpec(s) port_specs[s] = port_spec accepts_raw = insp.get_valid_values(s) (accepts, deflists, tables, call_sigs) = \ parse_docutils_str(accepts_raw) if len(deflists) + len(tables) > 0: raise ValueError("accepts has deflists and/or tables") (port_types, option_strs, default_val, allows_none) = \ parse_description(accepts) if default_val is not None: port_spec.default_val = default_val if len(option_strs) > 0: port_spec.entry_types = ['enum'] port_spec.values = [option_strs] port_spec.hide = False docstring = getattr(insp.o, 'set_' + s).__doc__ if docstring is None: docstring = "" else: docstring = docstring % matplotlib.docstring.interpd.params match = _get_accepts_regex.search(docstring) if match is not None: print "STARTING DOCSTRING:", docstring groups = match.groups() if len(groups) > 2 and groups[2]: docstring = groups[0] + groups[2] else: docstring = groups[0] print "FIXED DOCSTRING:", docstring (cleaned_docstring, args, tables, call_sigs) = \ parse_docutils_str(docstring) port_spec.docstring = cleaned_docstring translations = None for (table_intro, header, rows) in tables: print "TABLE:", table_intro if (klass.__name__, s, table_intro) in table_overrides: (override_type, opts) = \ table_overrides[(klass.__name__, s, table_intro)] if override_type == "translation": do_translation_override(port_specs, s, rows, opts) continue elif override_type == "ports": table_intro = "kwarg" elif override_type == "skip": continue if len(header) != 2: raise ValueError("Table not two columns!") if translations is not None: raise ValueError("Two translations in one attr") (translations, pt2, values) = parse_translation(rows) port_spec.translations = translations port_spec.values = [values] port_types.extend(pt2) resolve_port_type(port_types, port_spec) constructor_port_specs = {} port_specs_list = parse_argspec(klass.__init__) for port_spec in port_specs_list: constructor_port_specs[port_spec.arg] = port_spec constructor_docstring = klass.__init__.__doc__ if constructor_docstring is not None: _, output_port_specs = process_docstring( constructor_docstring, constructor_port_specs, (klass.__name__, '__init__'), table_overrides) for arg, ps in constructor_port_specs.iteritems(): if arg not in port_specs: ps.constructor_arg = True ps.required = False port_specs[arg] = ps module_spec = ModuleSpec(module_name, super_name, klass_qualname, klass.__doc__, port_specs.values()) module_specs.append(module_spec) my_specs = SpecList(module_specs) return my_specs
def parse_artists(artist_types, table_overrides={}): def get_module_name(obj): return obj.__name__ def get_super_name(obj): for base in obj.__bases__: if issubclass(base, Artist): return base.__name__ return "" # if obj.__bases__[0].__name__ != 'object': # return obj.__bases__[0].__name__ # else: # return "" module_specs = [] for klass in artist_types: (klass, module_name, super_name) = \ get_names(klass, get_module_name, get_super_name, "Mpl", "Properties") port_specs = {} insp = ArtistInspector(klass) klass_name = klass.__name__ klass_qualname = klass.__module__ + "." + klass_name for (s, t) in insp._get_setters_and_targets(): print "** %s **" % s if t.rsplit('.',1)[0] != klass_qualname: # let inheritance work continue if s in port_specs: raise ValueError('duplicate port "%s"' % s) port_spec = InputPortSpec(s) port_specs[s] = port_spec accepts_raw = insp.get_valid_values(s) (accepts, deflists, tables, call_sigs) = \ parse_docutils_str(accepts_raw) if len(deflists) + len(tables) > 0: raise ValueError("accepts has deflists and/or tables") (port_types, option_strs, default_val, allows_none) = \ parse_description(accepts) # port_spec.port_type = port_type if default_val is not None: port_spec.default_val = default_val if len(option_strs) > 0: port_spec.entry_types = ['enum'] port_spec.values = [option_strs] port_spec.hide = False docstring = getattr(insp.o, 'set_' + s).__doc__ if docstring is None: docstring = "" else: docstring = docstring % matplotlib.docstring.interpd.params match = _get_accepts_regex.search(docstring) if match is not None: print "STARTING DOCSTRING:", docstring groups = match.groups() if len(groups) > 2 and groups[2]: docstring = groups[0] + groups[2] else: docstring = groups[0] print "FIXED DOCSTRING:", docstring (cleaned_docstring, args, tables, call_sigs) = \ parse_docutils_str(docstring) port_spec.docstring = cleaned_docstring translations = None for (table_intro, header, rows) in tables: print "TABLE:", table_intro if (klass.__name__, s, table_intro) in table_overrides: (override_type, opts) = \ table_overrides[(klass.__name__, s, table_intro)] if override_type == "translation": do_translation_override(port_specs, s, rows, opts) continue elif override_type == "ports": table_intro = "kwarg" elif override_type == "skip": continue if len(header) != 2: raise ValueError("Table not two columns!") if translations is not None: raise ValueError("Two translations in one attr") (translations, pt2, values) = parse_translation(rows) port_spec.translations = translations port_spec.values = [values] port_types.extend(pt2) resolve_port_type(port_types, port_spec) constructor_port_specs = {} port_specs_list = parse_argspec(klass.__init__) for port_spec in port_specs_list: constructor_port_specs[port_spec.arg] = port_spec constructor_docstring = klass.__init__.__doc__ if constructor_docstring is not None: _, output_port_specs = process_docstring(constructor_docstring, constructor_port_specs, (klass.__name__, '__init__'), table_overrides) for arg, ps in constructor_port_specs.iteritems(): if arg not in port_specs: ps.constructor_arg = True ps.required = False port_specs[arg] = ps module_spec = ModuleSpec(module_name, super_name, klass_qualname, klass.__doc__, port_specs.values()) module_specs.append(module_spec) my_specs = SpecList(module_specs) return my_specs