# Path: etils/epath/abstract_path.py
# T = TypeVar('T')
# def abstractmethod(fn: T) -> T:
#   def __new__(cls: Type[T], *args: PathLike) -> T:
#   def is_relative_to(self, *other: PathLike) -> bool:
#   def format(self: T, *args: Any, **kwargs: Any) -> T:
#   def exists(self) -> bool:
#   def is_dir(self) -> bool:
#   def is_file(self) -> bool:
#   def iterdir(self: T) -> Iterator[T]:
#   def glob(self: T, pattern: str) -> Iterator[T]:
#   def rglob(self: T, pattern: str) -> Iterator[T]:
#   def expanduser(self: T) -> T:
#   def resolve(self: T, strict: bool = False) -> T:
#   def open(
#       self,
#       mode: str = 'r',
#       encoding: Optional[str] = None,
#       errors: Optional[str] = None,
#       **kwargs: Any,
#   ) -> typing.IO[AnyStr]:
#   def read_bytes(self) -> bytes:
#   def read_text(self, encoding: Optional[str] = None) -> str:
#   def mkdir(
#       self,
#       mode: int = 0o777,
#       parents: bool = False,
#       exist_ok: bool = False,
#   ) -> None:
#   def rmdir(self) -> None:
#   def rmtree(self) -> None:
#   def unlink(self, missing_ok: bool = False) -> None:
#   def write_bytes(self, data: bytes) -> int:
#   def write_text(
#       self,
#       data: str,
#       encoding: Optional[str] = None,
#       errors: Optional[str] = None,
#   ) -> int:
#   def touch(self, mode: int = 0o666, exist_ok: bool = True) -> None:
#   def rename(self: T, target: PathLike) -> T:
#   def replace(self: T, target: PathLike) -> T:
#   def copy(self: T, dst: PathLike, overwrite: bool = False) -> T:
# class Path(pathlib.PurePosixPath):
# 
# Path: etils/epath/gpath.py
# _P = TypeVar('_P')
# URI_PREFIXES = ('gs://', 's3://')
# _URI_SCHEMES = frozenset(('gs', 's3'))
# _URI_MAP_ROOT = {
#     'gs://': '/gs/',
#     's3://': '/s3/',
# }
#   _PATH: ClassVar[types.ModuleType]
#   _PATH = posixpath
#   _PATH = ntpath
# class _GPath(abstract_path.Path):
# class PosixGPath(_GPath):
# class WindowsGPath(pathlib.PureWindowsPath, _GPath):
#   def __new__(cls: Type[_P], *parts: PathLike) -> _P:
#   def _new(self: _P, *parts: PathLike) -> _P:
#   def _uri_scheme(self) -> Optional[str]:
#   def _path_str(self) -> str:
#   def __fspath__(self) -> str:
#   def __str__(self) -> str:  # pylint: disable=invalid-str-returned
#   def __repr__(self) -> str:
#   def exists(self) -> bool:
#   def is_dir(self) -> bool:
#   def iterdir(self: _P) -> Iterator[_P]:
#   def expanduser(self: _P) -> _P:
#   def resolve(self: _P, strict: bool = False) -> _P:
#   def glob(self: _P, pattern: str) -> Iterator[_P]:
#   def mkdir(
#       self,
#       mode: int = 0o777,
#       parents: bool = False,
#       exist_ok: bool = False,
#   ) -> None:
#   def rmdir(self) -> None:
#   def rmtree(self) -> None:
#   def unlink(self, missing_ok: bool = False) -> None:
#   def open(
#       self,
#       mode: str = 'r',
#       encoding: Optional[str] = None,
#       errors: Optional[str] = None,
#       **kwargs: Any,
#   ) -> typing.IO[Union[str, bytes]]:
#   def rename(self: _P, target: PathLike) -> _P:
#   def replace(self: _P, target: PathLike) -> _P:
#   def copy(self: _P, dst: PathLike, overwrite: bool = False) -> _P:
# 
# Path: etils/epath/typing.py



import os
import typing
from typing import Callable, Dict, Tuple, Type, TypeVar
from etils.epath import abstract_path
from etils.epath import gpath
from etils.epath.typing import PathLike  # pylint: disable=g-multiple-import
  else:
    _PATHLIKE_CLS = _PATHLIKE_CLS + (path_cls_or_uri_prefix,)
    return path_cls_or_uri_prefix


def make_path(path: PathLike) -> abstract_path.Path:
  """Create a generic `pathlib.Path`-like abstraction.

  Depending on the input (e.g. `gs://`, `github://`, `ResourcePath`,...), the
  system (Windows, Linux,...), the function will create the right pathlib-like
  abstraction.

  Args:
    path: Pathlike object.

  Returns:
    path: The `pathlib.Path`-like abstraction.
  """
  is_windows = os.name == 'nt'
  if isinstance(path, str):
    uri_splits = path.split('://', maxsplit=1)
    if len(uri_splits) > 1:  # str is URI (e.g. `gs://`, `github://`,...)
      # On windows, `PosixGPath` is created for `gs://` paths
      return _URI_PREFIXES_TO_CLS[uri_splits[0] + '://'](path)  # pytype: disable=bad-return-type
    elif is_windows:
      return gpath.WindowsGPath(path)
    else:
      return gpath.PosixGPath(path)
  elif isinstance(path, _PATHLIKE_CLS):
    return path  # Forward resource path, gpath,... as-is  # pytype: disable=bad-return-type

# Path: etils/epath/abstract_path.py
# T = TypeVar('T')
# def abstractmethod(fn: T) -> T:
#   def __new__(cls: Type[T], *args: PathLike) -> T:
#   def is_relative_to(self, *other: PathLike) -> bool:
#   def format(self: T, *args: Any, **kwargs: Any) -> T:
#   def exists(self) -> bool:
#   def is_dir(self) -> bool:
#   def is_file(self) -> bool:
#   def iterdir(self: T) -> Iterator[T]:
#   def glob(self: T, pattern: str) -> Iterator[T]:
#   def rglob(self: T, pattern: str) -> Iterator[T]:
#   def expanduser(self: T) -> T:
#   def resolve(self: T, strict: bool = False) -> T:
#   def open(
#       self,
#       mode: str = 'r',
#       encoding: Optional[str] = None,
#       errors: Optional[str] = None,
#       **kwargs: Any,
#   ) -> typing.IO[AnyStr]:
#   def read_bytes(self) -> bytes:
#   def read_text(self, encoding: Optional[str] = None) -> str:
#   def mkdir(
#       self,
#       mode: int = 0o777,
#       parents: bool = False,
#       exist_ok: bool = False,
#   ) -> None:
#   def rmdir(self) -> None:
#   def rmtree(self) -> None:
#   def unlink(self, missing_ok: bool = False) -> None:
#   def write_bytes(self, data: bytes) -> int:
#   def write_text(
#       self,
#       data: str,
#       encoding: Optional[str] = None,
#       errors: Optional[str] = None,
#   ) -> int:
#   def touch(self, mode: int = 0o666, exist_ok: bool = True) -> None:
#   def rename(self: T, target: PathLike) -> T:
#   def replace(self: T, target: PathLike) -> T:
#   def copy(self: T, dst: PathLike, overwrite: bool = False) -> T:
# class Path(pathlib.PurePosixPath):
# 
# Path: etils/epath/gpath.py
# _P = TypeVar('_P')
# URI_PREFIXES = ('gs://', 's3://')
# _URI_SCHEMES = frozenset(('gs', 's3'))
# _URI_MAP_ROOT = {
#     'gs://': '/gs/',
#     's3://': '/s3/',
# }
#   _PATH: ClassVar[types.ModuleType]
#   _PATH = posixpath
#   _PATH = ntpath
# class _GPath(abstract_path.Path):
# class PosixGPath(_GPath):
# class WindowsGPath(pathlib.PureWindowsPath, _GPath):
#   def __new__(cls: Type[_P], *parts: PathLike) -> _P:
#   def _new(self: _P, *parts: PathLike) -> _P:
#   def _uri_scheme(self) -> Optional[str]:
#   def _path_str(self) -> str:
#   def __fspath__(self) -> str:
#   def __str__(self) -> str:  # pylint: disable=invalid-str-returned
#   def __repr__(self) -> str:
#   def exists(self) -> bool:
#   def is_dir(self) -> bool:
#   def iterdir(self: _P) -> Iterator[_P]:
#   def expanduser(self: _P) -> _P:
#   def resolve(self: _P, strict: bool = False) -> _P:
#   def glob(self: _P, pattern: str) -> Iterator[_P]:
#   def mkdir(
#       self,
#       mode: int = 0o777,
#       parents: bool = False,
#       exist_ok: bool = False,
#   ) -> None:
#   def rmdir(self) -> None:
#   def rmtree(self) -> None:
#   def unlink(self, missing_ok: bool = False) -> None:
#   def open(
#       self,
#       mode: str = 'r',
#       encoding: Optional[str] = None,
#       errors: Optional[str] = None,
#       **kwargs: Any,
#   ) -> typing.IO[Union[str, bytes]]:
#   def rename(self: _P, target: PathLike) -> _P:
#   def replace(self: _P, target: PathLike) -> _P:
#   def copy(self: _P, dst: PathLike, overwrite: bool = False) -> _P:
# 
# Path: etils/epath/typing.py



# Path: etils/epath/register.py
import os
import typing
from typing import Callable, Dict, Tuple, Type, TypeVar
from etils.epath import abstract_path
from etils.epath import gpath
from etils.epath.typing import PathLike  # pylint: disable=g-multiple-import

  else:
    _PATHLIKE_CLS = _PATHLIKE_CLS + (path_cls_or_uri_prefix,)
    return path_cls_or_uri_prefix


def make_path(path: PathLike) -> abstract_path.Path:
  """Create a generic `pathlib.Path`-like abstraction.

  Depending on the input (e.g. `gs://`, `github://`, `ResourcePath`,...), the
  system (Windows, Linux,...), the function will create the right pathlib-like
  abstraction.

  Args:
    path: Pathlike object.

  Returns:
    path: The `pathlib.Path`-like abstraction.
  """
  is_windows = os.name == 'nt'
  if isinstance(path, str):
    uri_splits = path.split('://', maxsplit=1)
    if len(uri_splits) > 1:  # str is URI (e.g. `gs://`, `github://`,...)
      # On windows, `PosixGPath` is created for `gs://` paths
      return _URI_PREFIXES_TO_CLS[uri_splits[0] + '://'](path)  # pytype: disable=bad-return-type
    elif is_windows:
      return gpath.WindowsGPath(path)
    else:
      return gpath.PosixGPath(path)
  elif isinstance(path, _PATHLIKE_CLS):
    return path  # Forward resource path, gpath,... as-is  # pytype: disable=bad-return-type

  elif isinstance(path, os.PathLike):  # Other `os.fspath` compatible objects