forked from tox-dev/python-discovery
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_compat.py
More file actions
29 lines (20 loc) · 709 Bytes
/
Copy path_compat.py
File metadata and controls
29 lines (20 loc) · 709 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""Platform compatibility utilities for Python discovery."""
from __future__ import annotations
import functools
import logging
import pathlib
import tempfile
from typing import Final
_LOGGER: Final[logging.Logger] = logging.getLogger(__name__)
@functools.lru_cache(maxsize=1)
def fs_is_case_sensitive() -> bool:
with tempfile.NamedTemporaryFile(prefix="TmP") as tmp_file:
result = not pathlib.Path(tmp_file.name.lower()).exists()
_LOGGER.debug("filesystem is %scase-sensitive", "" if result else "not ")
return result
def fs_path_id(path: str) -> str:
return path.casefold() if not fs_is_case_sensitive() else path
__all__ = [
"fs_is_case_sensitive",
"fs_path_id",
]