Skip to content

utils

load_plugin_template(template_name)

Loads a jinja template for a plugin (currently only airflow) from the jinja_templates folder.

Source code in lineapy/plugins/utils.py
16
17
18
19
20
21
22
23
24
25
26
def load_plugin_template(template_name: str) -> Template:
    """
    Loads a jinja template for a plugin (currently only airflow) from the jinja_templates folder.
    """
    template_loader = FileSystemLoader(
        searchpath=str(
            (Path(lineapy.__file__) / "../plugins/jinja_templates").resolve()
        )
    )
    template_env = Environment(loader=template_loader)
    return template_env.get_template(template_name)

slugify(value, allow_unicode=False)

Taken from https://github.com/django/django/blob/master/django/utils/text.py

Convert to ASCII if 'allow_unicode' is False. Convert spaces or repeated dashes to single dashes. Remove characters that aren't alphanumerics, underscores, or hyphens. Convert to lowercase. Also strip leading and trailing whitespace, dashes, and underscores. Lastly, replace all dashes with underscores.

Copyright (c) Django Software Foundation and individual contributors. All rights reserved.

Source code in lineapy/plugins/utils.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
def slugify(value, allow_unicode=False):
    """
    Taken from
    https://github.com/django/django/blob/master/django/utils/text.py

    Convert to ASCII if 'allow_unicode' is False. Convert spaces or repeated
    dashes to single dashes. Remove characters that aren't alphanumerics,
    underscores, or hyphens. Convert to lowercase. Also strip leading and
    trailing whitespace, dashes, and underscores.
    Lastly, replace all dashes with underscores.

    Copyright (c) Django Software Foundation and individual contributors.
    All rights reserved.
    """
    value = str(value)
    if allow_unicode:
        value = unicodedata.normalize("NFKC", value)
    else:
        value = (
            unicodedata.normalize("NFKD", value)
            .encode("ascii", "ignore")
            .decode("ascii")
        )
    value = re.sub(r"[^\w\s-]", "", value.lower())
    value = re.sub(r"[-\s]+", "_", value).strip("-_")
    value = re.sub("-", "_", value)
    return value

Was this helpful?

Help us improve docs with your feedback!