PHP 8.2.30
Preview: _path.py Size: 2.91 KB
/opt/cloudlinux/venv/lib/python3.11/site-packages/setuptools/_path.py

from __future__ import annotations

import contextlib
import os
import sys
from typing import TYPE_CHECKING, TypeVar, Union

from more_itertools import unique_everseen

if TYPE_CHECKING:
    from typing_extensions import TypeAlias

StrPath: TypeAlias = Union[str, os.PathLike[str]]  #  Same as _typeshed.StrPath
StrPathT = TypeVar("StrPathT", bound=Union[str, os.PathLike[str]])


def ensure_directory(path):
    """Ensure that the parent directory of `path` exists"""
    dirname = os.path.dirname(path)
    os.makedirs(dirname, exist_ok=True)


def same_path(p1: StrPath, p2: StrPath) -> bool:
    """Differs from os.path.samefile because it does not require paths to exist.
    Purely string based (no comparison between i-nodes).
    >>> same_path("a/b", "./a/b")
    True
    >>> same_path("a/b", "a/./b")
    True
    >>> same_path("a/b", "././a/b")
    True
    >>> same_path("a/b", "./a/b/c/..")
    True
    >>> same_path("a/b", "../a/b/c")
    False
    >>> same_path("a", "a/b")
    False
    """
    return normpath(p1) == normpath(p2)


def _cygwin_patch(filename: StrPath):  # pragma: nocover
    """
    Contrary to POSIX 2008, on Cygwin, getcwd (3) contains
    symlink components. Using
    os.path.abspath() works around this limitation. A fix in os.getcwd()
    would probably better, in Cygwin even more so, except
    that this seems to be by design...
    """
    return os.path.abspath(filename) if sys.platform == 'cygwin' else filename


def normpath(filename: StrPath) -> str:
    """Normalize a file/dir name for comparison purposes."""
    return os.path.normcase(os.path.realpath(os.path.normpath(_cygwin_patch(filename))))


@contextlib.contextmanager
def paths_on_pythonpath(paths):
    """
    Add the indicated paths to the head of the PYTHONPATH environment
    variable so that subprocesses will also see the packages at
    these paths.

    Do this in a context that restores the value on exit.

    >>> getfixture('monkeypatch').setenv('PYTHONPATH', 'anything')
    >>> with paths_on_pythonpath(['foo', 'bar']):
    ...     assert 'foo' in os.environ['PYTHONPATH']
    ...     assert 'anything' in os.environ['PYTHONPATH']
    >>> os.environ['PYTHONPATH']
    'anything'

    >>> getfixture('monkeypatch').delenv('PYTHONPATH')
    >>> with paths_on_pythonpath(['foo', 'bar']):
    ...     assert 'foo' in os.environ['PYTHONPATH']
    >>> os.environ.get('PYTHONPATH')
    """
    nothing = object()
    orig_pythonpath = os.environ.get('PYTHONPATH', nothing)
    current_pythonpath = os.environ.get('PYTHONPATH', '')
    try:
        prefix = os.pathsep.join(unique_everseen(paths))
        to_join = filter(None, [prefix, current_pythonpath])
        new_path = os.pathsep.join(to_join)
        if new_path:
            os.environ['PYTHONPATH'] = new_path
        yield
    finally:
        if orig_pythonpath is nothing:
            os.environ.pop('PYTHONPATH', None)
        else:
            os.environ['PYTHONPATH'] = orig_pythonpath

Directory Contents

Dirs: 7 × Files: 43

Name Size Perms Modified Actions
command DIR
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
compat DIR
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
config DIR
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
tests DIR
- drwxr-xr-x 2026-02-06 08:01:49
Edit Download
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
_vendor DIR
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
- drwxr-xr-x 2026-02-06 08:05:34
Edit Download
7.18 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
19.50 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
11.50 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
14.00 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
13.50 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
11.50 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
5.83 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
20.76 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
43.83 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
2.95 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
6.53 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
5.92 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
11.50 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
14.00 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
13.50 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
11.50 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
4.97 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
820 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
1.23 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
568 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
3.63 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
40.66 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
3.10 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
218 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
138 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
3.11 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
161 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
3.71 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
9.25 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
726 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
11.70 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
836 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
2.41 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
2.38 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
223 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
657 B lrw-r--r-- 2026-01-20 13:01:47
Edit Download
5.61 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
2.91 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
1.35 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
10.98 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
1.54 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
4.74 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download
8.79 KB lrw-r--r-- 2026-01-20 13:01:47
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).