HEX
Server: Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/8.4.25
System: Windows NT DESKTOP-4TAV2RJ 10.0 build 19045 (Windows 10) AMD64
User: fred (0)
PHP: 8.4.25
Disabled: NONE
Upload Files
File: C:/Users/fred/anaconda3/Lib/site-packages/binstar_client/utils/paths.py
# -*- coding: utf8 -*-

"""Utilities to manage file paths."""

from __future__ import annotations

__all__ = ['expandvars', 'normalize']

import os
import string
import typing

from . import conda


def expandvars(path: str) -> str:
    """
    Expand environment variables in :code:`path`.

    Missing conda-related variables might be injected from :data:`~binstar_client.utils.conda.CONDA_INFO`.
    """
    mapping: typing.Dict[str, str] = {
        **typing.cast(typing.Mapping[str, str], conda.CONDA_INFO),
        **os.environ,
    }
    return string.Template(path).safe_substitute(mapping)


def normalize(path: str) -> str:
    """Normalize file :code:`path`."""
    return os.path.abspath(os.path.expanduser(expandvars(path)))