def class_link(cls, text):
    """ Generates an intra-document link for the given class. Example:
        >>> from labelbox import Project
        >>> class_link(Project, "blah")
        >>> <a href="#class_labelbox_schema_project">blah</a>
    """
    header_id = "class_" + snake_case(qual_class_name(cls).replace(".", "_"))
    return header_link(text, header_id)
Ejemplo n.º 2
0
 def create_labeler_performance(client, result):
     result["user"] = Entity.User(client, result["user"])
     result["lastActivityTime"] = datetime.fromtimestamp(
         result["lastActivityTime"] / 1000, timezone.utc)
     return LabelerPerformance(**{
         utils.snake_case(key): value
         for key, value in result.items()
     })
Ejemplo n.º 3
0
 def create_labeler_performance(client, result):
     result["user"] = Entity.User(client, result["user"])
     # python isoformat doesn't accept Z as utc timezone
     result["lastActivityTime"] = datetime.fromisoformat(
         result["lastActivityTime"].replace('Z', '+00:00'))
     return LabelerPerformance(**{
         utils.snake_case(key): value
         for key, value in result.items()
     })
def generate_class(cls):
    """ Generates HelpDocs style documentation for the given class.
    Args:
        cls (type): The class to generate docs for.
    Return:
        HelpDocs style documentation for `cls` containing class description,
        methods and fields and relationships if `schema_class`.
    """
    text = []
    schema_class = issubclass(cls, Entity)

    text.append(header(2, cls.__name__, snake_case(cls.__name__)))

    package_and_superclasses = "Class " + cls.__module__ + "." + cls.__name__
    if schema_class:
        superclasses = [
            plugin.__name__
            for plugin in (Updateable, Deletable, BulkDeletable)
            if issubclass(cls, plugin)
        ]
        if superclasses:
            package_and_superclasses += " (%s)" % ", ".join(superclasses)
    package_and_superclasses += "."
    text.append(paragraph(package_and_superclasses, False))

    text.append(preprocess_docstring(cls.__doc__))

    constants = generate_constants(cls)
    if constants:
        text.append(header(3, "Constants"))
        text.append(constants)

    if schema_class:
        text.append(header(3, "Fields"))
        text.append(generate_fields(cls))
        text.append(header(3, "Relationships"))
        text.append(generate_relationships(cls))

    for name, predicate in (("Static Methods",
                             lambda attr: type(attr) == staticmethod),
                            ("Class Methods",
                             lambda attr: type(attr) == classmethod),
                            ("Object Methods", is_method)):
        functions = generate_functions(cls, predicate).strip()
        if len(functions):
            text.append(header(3, name))
            text.append(functions)

    return "\n".join(text)
Ejemplo n.º 5
0
 def invite_limit(self) -> InviteLimit:
     """ Retrieve invite limits for the org
     This already accounts for users currently in the org
     Meaining that  `used = users + invites, remaining = limit - (users + invites)`
    
     Returns:
         InviteLimit
 
     """
     org_id_param = "organizationId"
     res = self.client.execute("""query InvitesLimitPyApi($%s: ID!) {
         invitesLimit(where: {id: $%s}) { used limit remaining }
     }""" % (org_id_param, org_id_param), {org_id_param: self.uid},
                               experimental=True)
     return InviteLimit(
         **{utils.snake_case(k): v
            for k, v in res['invitesLimit'].items()})
def inject_class_links(text):
    """ Finds all occurences of known class names in the given text and
    replaces them with relative links to those classes.
    """
    pattern_link_pairs = [(r"\b(%s.)?%ss?\b" % (cls.__module__, cls.__name__),
                           "#" + snake_case(cls.__name__))
                          for cls in _ALL_CLASSES]
    pattern_link_pairs.append(
        (r"\bPaginatedCollection\b", "general-concepts#pagination"))

    for pattern, link in pattern_link_pairs:
        matches = list(re.finditer(pattern, text))
        for match in reversed(matches):
            start, end = match.span()
            link = tag(match.group(), "a", {"href": link})
            text = text[:start] + link + text[end:]
    return text
Ejemplo n.º 7
0
    def __init__(self,
                 relationship_type,
                 destination_type_name,
                 filter_deleted=True,
                 name=None,
                 graphql_name=None):
        self.relationship_type = relationship_type
        self.destination_type_name = destination_type_name
        self.filter_deleted = filter_deleted

        if name is None:
            name = utils.snake_case(destination_type_name) + (
                "s" if relationship_type == Relationship.Type.ToMany else "")
        self.name = name

        if graphql_name is None:
            graphql_name = utils.camel_case(name)
        self.graphql_name = graphql_name
def header(level, text, header_id=None):
    """ Wraps `text` into a <h> (header) tag ov the given level.
    Automatically increases the level by 2 to be inline with HelpDocs
    standards (h1 -> h3).

    Example:
        >>> header(2, "My Chapter")
        >>> "<h4>My Chapter</h4>

    Args:
        level (int): Level of header.
        text (str): Header text.
        header_id (str or None): The ID of the header. If None it's
            generated from text by converting to snake_case and
            replacing all whitespace with "_".
    """
    if header_id == None:
        header_id = snake_case(text).replace(" ", "_")
    # Convert to level + 2 for HelpDocs standard.
    return tag(text, "h" + str(level + 2), {"id": header_id})
Ejemplo n.º 9
0
def test_snake():
    assert utils.snake_case(SNAKE) == SNAKE
    assert utils.snake_case(TITLE) == SNAKE
    assert utils.snake_case(CAMEL) == SNAKE
    assert utils.snake_case(MIXED) == SNAKE