コード例 #1
0
ファイル: graph_objs.py プロジェクト: kiwiroy/python-api
 def _get_valid_attributes(self):
     """See `graph_reference.get_valid_attributes`."""
     if self._valid_attributes is None:
         parent_object_names = self._get_parent_object_names()
         valid_attributes = graph_reference.get_valid_attributes(
             self._name, parent_object_names)
         self.__dict__['_valid_attributes'] = valid_attributes
     return self._valid_attributes
コード例 #2
0
ファイル: graph_objs.py プロジェクト: yabloki/python-api
 def _get_valid_attributes(self):
     """See `graph_reference.get_valid_attributes`."""
     if self._valid_attributes is None:
         parent_object_names = self._get_parent_object_names()
         valid_attributes = graph_reference.get_valid_attributes(
             self._name, parent_object_names
         )
         self.__dict__['_valid_attributes'] = valid_attributes
     return self._valid_attributes
コード例 #3
0
def _dict_object_help(object_name, path, parent_object_names):
    """See get_help()."""
    attributes = graph_reference.get_valid_attributes(object_name,
                                                      parent_object_names)
    lines = textwrap.wrap(repr(list(attributes)), width=LINE_SIZE - TAB_SIZE)

    help_dict = {
        'object_name': object_name,
        'path_string': '[' + ']['.join(repr(k) for k in path) + ']',
        'parent_object_names': parent_object_names,
        'attributes_string': '\t' + '\n\t'.join(lines)
    }

    return (
        "Valid attributes for '{object_name}' at path {path_string} under "
        "parents {parent_object_names}:\n\n{attributes_string}\n\n"
        "Run `<{object_name}-object>.help('attribute')` on any of the above.\n"
        "'<{object_name}-object>' is the object at {path_string}".format(
            **help_dict))
コード例 #4
0
ファイル: graph_objs_tools.py プロジェクト: AltxSF/plotly.py
def _dict_object_help(object_name, path, parent_object_names):
    """See get_help()."""
    attributes = graph_reference.get_valid_attributes(object_name,
                                                      parent_object_names)
    lines = textwrap.wrap(repr(list(attributes)), width=LINE_SIZE-TAB_SIZE)

    help_dict = {
        'object_name': object_name,
        'path_string': '[' + ']['.join(repr(k) for k in path) + ']',
        'parent_object_names': parent_object_names,
        'attributes_string': '\t' + '\n\t'.join(lines)
    }

    return (
        "Valid attributes for '{object_name}' at path {path_string} under "
        "parents {parent_object_names}:\n\n{attributes_string}\n\n"
        "Run `<{object_name}-object>.help('attribute')` on any of the above.\n"
        "'<{object_name}-object>' is the object at {path_string}"
        .format(**help_dict)
    )
コード例 #5
0
    def test_get_help_does_not_raise(self):

        msg = None
        try:
            for object_name in gr.OBJECTS:
                msg = object_name
                got.get_help(object_name)

            for object_name in gr.ARRAYS:
                msg = object_name
                got.get_help(object_name)

            for object_name in gr.OBJECTS:
                attributes = gr.get_valid_attributes(object_name)
                for attribute in attributes:
                    msg = (object_name, attribute)
                    got.get_help(object_name, attribute=attribute)
                fake_attribute = 'fake attribute'
                msg = (object_name, fake_attribute)
                got.get_help(object_name, attribute=fake_attribute)
        except:
            self.fail(msg=msg)
コード例 #6
0
    def test_get_help_does_not_raise(self):

        msg = None
        try:
            for object_name in gr.OBJECTS:
                msg = object_name
                got.get_help(object_name)

            for object_name in gr.ARRAYS:
                msg = object_name
                got.get_help(object_name)

            for object_name in gr.OBJECTS:
                attributes = gr.get_valid_attributes(object_name)
                for attribute in attributes:
                    msg = (object_name, attribute)
                    got.get_help(object_name, attribute=attribute)
                fake_attribute = 'fake attribute'
                msg = (object_name, fake_attribute)
                got.get_help(object_name, attribute=fake_attribute)
        except:
            self.fail(msg=msg)
コード例 #7
0
ファイル: graph_objs_tools.py プロジェクト: aczapata/twitter
def _dict_attribute_help(object_name, path, parent_object_names, attribute):
    """
    Get general help information or information on a specific attribute.

    See get_help().

    :param (str|unicode) attribute: The attribute we'll get info for.

    """
    help_dict = {
        'object_name': object_name,
        'path_string': '[' + ']['.join(repr(k) for k in path) + ']',
        'parent_object_names': parent_object_names,
        'attribute': attribute
    }

    valid_attributes = graph_reference.get_valid_attributes(
        object_name, parent_object_names
    )

    help_string = (
        "Current path: {path_string}\n"
        "Current parent object_names: {parent_object_names}\n\n")

    if attribute not in valid_attributes:
        help_string += "'{attribute}' is not allowed here.\n"
        return help_string.format(**help_dict)

    attributes_dicts = graph_reference.get_attributes_dicts(
        object_name, parent_object_names
    )

    attribute_definitions = []
    additional_definition = None
    meta_keys = graph_reference.GRAPH_REFERENCE['defs']['metaKeys']
    trace_names = graph_reference.TRACE_NAMES
    for key, attribute_dict in attributes_dicts.items():
        if attribute in attribute_dict:
            if object_name in trace_names and attribute == 'type':
                d = {'role': 'info'}
            else:
                d = {k: v for k, v in attribute_dict[attribute].items()
                     if k in meta_keys and not k.startswith('_')}
        elif attribute in attribute_dict.get('_deprecated', {}):
            deprecate_attribute_dict = attribute_dict['_deprecated'][attribute]
            d = {k: v for k, v in deprecate_attribute_dict.items()
                 if k in meta_keys and not k.startswith('_')}
            d['deprecated'] = True
        else:
            continue

        if key == 'additional_attributes':
            additional_definition = d
            continue

        new_definition = True
        for item in attribute_definitions:
            if item['definition'] == d:
                item['paths'].append(key)
                new_definition = False
        if new_definition:
            attribute_definitions.append({'paths': [key], 'definition': d})

    if attribute_definitions:
        help_string += ("With the current parents, '{attribute}' can be "
                        "used as follows:\n\n")

    help_string = help_string.format(**help_dict)

    for item in attribute_definitions:
        valid_parents_objects_names = [
            graph_reference.attribute_path_to_object_names(definition_path)
            for definition_path in item['paths']
        ]

        if len(valid_parents_objects_names) == 1:
            valid_parent_objects_names = valid_parents_objects_names[0]
            help_string += 'Under {}:\n\n'.format(
                str(valid_parent_objects_names)
            )
        else:
            help_string += 'Under any of:\n\t\t* {}\n\n'.format(
                '\n\t\t* '.join(str(tup) for tup in valid_parents_objects_names)
            )

        for meta_key, val in sorted(item['definition'].items()):
            help_string += '\t{}: '.format(meta_key)
            if meta_key == 'description':

                # TODO: https://github.com/plotly/streambed/issues/3950
                if isinstance(val, list) and attribute == 'showline':
                    val = val[0]

                lines = textwrap.wrap(val, width=LINE_SIZE)
                help_string += '\n\t\t'.join(lines)
            else:
                help_string += '{}'.format(val)
            help_string += '\n'
        help_string += '\n\n'

    if additional_definition:
        help_string += 'Additionally:\n\n'
        for item in sorted(additional_definition.items()):
            help_string += '\t{}: {}\n'.format(*item)
        help_string += '\n'

    return help_string