_compat.py 709 B

1234567891011121314151617181920212223242526272829
  1. """Platform compatibility utilities for Python discovery."""
  2. from __future__ import annotations
  3. import functools
  4. import logging
  5. import pathlib
  6. import tempfile
  7. from typing import Final
  8. _LOGGER: Final[logging.Logger] = logging.getLogger(__name__)
  9. @functools.lru_cache(maxsize=1)
  10. def fs_is_case_sensitive() -> bool:
  11. with tempfile.NamedTemporaryFile(prefix="TmP") as tmp_file:
  12. result = not pathlib.Path(tmp_file.name.lower()).exists()
  13. _LOGGER.debug("filesystem is %scase-sensitive", "" if result else "not ")
  14. return result
  15. def fs_path_id(path: str) -> str:
  16. return path.casefold() if not fs_is_case_sensitive() else path
  17. __all__ = [
  18. "fs_is_case_sensitive",
  19. "fs_path_id",
  20. ]