


import importlib
import os

import fsspec
import pytest
from fsspec import register_implementation
from fsspec.registry import _registry as _fsspec_registry

from datasets.filesystems import COMPRESSION_FILESYSTEMS, HfFileSystem, extract_path_from_uri, is_remote_filesystem

from .utils import require_lza, require_zstandard
def     __lowerCamelCase						(			UpperCAmelCase_						:		List[str]						):




      """simple docstring"""





      assert "mock" in _fsspec_registry
      assert "bz2" in _fsspec_registry
def     __lowerCamelCase						(			):




      """simple docstring"""





      assert "mock" not in _fsspec_registry
      assert "bz2" in _fsspec_registry
def     __lowerCamelCase						(			):




      """simple docstring"""





      a						:Optional[int]										=	'''mock-s3-bucket'''
      a						:List[Any]										=	F'''s3://{mock_bucket}'''
      a						:int										=	extract_path_from_uri(UpperCAmelCase_						)
      assert dataset_path.startswith('''s3://'''						) is False

      a						:Dict										=	'''./local/path'''
      a						:Optional[int]										=	extract_path_from_uri(UpperCAmelCase_						)
      assert dataset_path == new_dataset_path
def     __lowerCamelCase						(			UpperCAmelCase_						:		int						):




      """simple docstring"""





      a						:Optional[Any]										=	is_remote_filesystem(UpperCAmelCase_						)
      assert is_remote is True

      a						:str										=	fsspec.filesystem('''file'''						)

      a						:Any										=	is_remote_filesystem(UpperCAmelCase_						)
      assert is_remote is False
@pytest.mark.parametrize('''compression_fs_class'''			,  UpperCAmelCase_						)
def     __lowerCamelCase						(			UpperCAmelCase_						:		Dict			,  UpperCAmelCase_						:		Dict			,  UpperCAmelCase_						:		int			,  UpperCAmelCase_						:		Optional[int]			,  UpperCAmelCase_						:		Any			,  UpperCAmelCase_						:		List[str]			,  UpperCAmelCase_						:		Tuple						):




      """simple docstring"""





      a						:Any										=	{'''gzip''': gz_file, '''xz''': xz_file, '''zstd''': zstd_file, '''bz2''': bza_file, '''lz4''': lza_file}
      a						:Union[str, Any]										=	input_paths[compression_fs_class.protocol]
      if input_path is None:
            a						:Optional[Any]										=	F'''for \'{compression_fs_class.protocol}\' compression protocol, '''
            if compression_fs_class.protocol == "lz4":
                  reason += require_lza.kwargs["reason"]
            elif compression_fs_class.protocol == "zstd":
                  reason += require_zstandard.kwargs["reason"]
            pytest.skip(UpperCAmelCase_						)
      a						:Optional[Any]										=	fsspec.filesystem(compression_fs_class.protocol			,  fo=UpperCAmelCase_						)
      assert isinstance(UpperCAmelCase_			,  UpperCAmelCase_						)
      a						:Union[str, Any]										=	os.path.basename(UpperCAmelCase_						)
      a						:int										=	expected_filename[: expected_filename.rindex('''.'''						)]
      assert fs.glob('''*'''						) == [expected_filename]
      with fs.open(UpperCAmelCase_			,  '''r'''			,  encoding='''utf-8'''						) as f, open(UpperCAmelCase_			,  encoding='''utf-8'''						) as expected_file:
            assert f.read() == expected_file.read()
@pytest.mark.parametrize('''protocol'''			,  ['''zip''', '''gzip''']						)
def     __lowerCamelCase						(			UpperCAmelCase_						:		Dict			,  UpperCAmelCase_						:		List[Any]			,  UpperCAmelCase_						:		int						):




      """simple docstring"""





      a						:str										=	{'''zip''': zip_jsonl_path, '''gzip''': jsonl_gz_path}
      a						:Optional[int]										=	compressed_file_paths[protocol]
      a						:Any										=	'''dataset.jsonl'''
      a						:int										=	F'''{protocol}://{member_file_path}::{compressed_file_path}'''
      a						:Tuple										=	fsspec.get_fs_token_paths(UpperCAmelCase_						)
      assert fs.isfile(UpperCAmelCase_						)
      assert not fs.isfile('''non_existing_''' + member_file_path						)
@pytest.mark.integration
def     __lowerCamelCase						(			UpperCAmelCase_						:		Tuple			,  UpperCAmelCase_						:		Tuple			,  UpperCAmelCase_						:		Tuple			,  UpperCAmelCase_						:		Optional[Any]						):




      """simple docstring"""





      a						:List[Any]										=	hf_api.dataset_info(UpperCAmelCase_			,  token=UpperCAmelCase_						)
      a						:List[str]										=	HfFileSystem(repo_info=UpperCAmelCase_			,  token=UpperCAmelCase_						)
      assert sorted(hffs.glob('''*'''						)						) == [".gitattributes", "data"]
      assert hffs.isdir('''data'''						)
      assert hffs.isfile('''.gitattributes'''						) and hffs.isfile('''data/text_data.txt'''						)
      with open(UpperCAmelCase_						) as f:
            assert hffs.open('''data/text_data.txt'''			,  '''r'''						).read() == f.read()






def     __lowerCamelCase						(			):




      """simple docstring"""





      a						:int										=	'''bz2'''

      # Import module
      import datasets.filesystems

      # Overwrite protocol and reload
      register_implementation(UpperCAmelCase_			,  UpperCAmelCase_			,  clobber=UpperCAmelCase_						)
      with pytest.warns(UpperCAmelCase_						) as warning_info:
            importlib.reload(datasets.filesystems						)

      assert len(UpperCAmelCase_						) == 1
      assert (
          str(warning_info[0].message						)
          == F'''A filesystem protocol was already set for {protocol} and will be overwritten.'''
      )









from ...utils import (
    OptionalDependencyNotAvailable,
    is_flax_available,
    is_torch_available,
    is_transformers_available,
)


try:
     if not (is_transformers_available() and is_torch_available()):
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     from ...utils.dummy_torch_and_transformers_objects import *  # noqa F403
else:
     from .multicontrolnet import MultiControlNetModel
     from .pipeline_controlnet import StableDiffusionControlNetPipeline
     from .pipeline_controlnet_imgaimg import StableDiffusionControlNetImgaImgPipeline
     from .pipeline_controlnet_inpaint import StableDiffusionControlNetInpaintPipeline


if is_transformers_available() and is_flax_available():
     from .pipeline_flax_controlnet import FlaxStableDiffusionControlNetPipeline





