Skip to content

utils

_normalize_package_name(name)

Implement PyPa specifications for package-name normalization

The name should be lowercased with all runs of the characters ., -, or _ replaced with a single - character. This can be implemented in Python with the re module. (https://packaging.python.org/en/latest/specifications/name-normalization)

Parameters:

Name Type Description Default
name str

The non-normalized package name.

required

Returns:

Type Description
str

The normalized package name.

Source code in fractal_server/tasks/utils.py
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def _normalize_package_name(name: str) -> str:
    """
    Implement PyPa specifications for package-name normalization

    The name should be lowercased with all runs of the characters `.`, `-`,
    or `_` replaced with a single `-` character. This can be implemented in
    Python with the re module.
    (https://packaging.python.org/en/latest/specifications/name-normalization)

    Args:
        name: The non-normalized package name.

    Returns:
        The normalized package name.
    """
    return re.sub(r"[-_.]+", "-", name).lower()

get_absolute_venv_path(venv_path)

If a path is not absolute, make it a relative path of FRACTAL_TASKS_DIR.

Source code in fractal_server/tasks/utils.py
12
13
14
15
16
17
18
19
20
21
def get_absolute_venv_path(venv_path: Path) -> Path:
    """
    If a path is not absolute, make it a relative path of FRACTAL_TASKS_DIR.
    """
    if venv_path.is_absolute():
        package_path = venv_path
    else:
        settings = Inject(get_settings)
        package_path = settings.FRACTAL_TASKS_DIR / venv_path
    return package_path