



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    _snake_case (       __snake_case    )     ->     Union[str, Any]:






      '''simple docstring'''







      assert "mock" in _fsspec_registry
      assert "bz2" in _fsspec_registry







def    _snake_case (       )     ->     Any:






      '''simple docstring'''







      assert "mock" not in _fsspec_registry
      assert "bz2" in _fsspec_registry







def    _snake_case (       )     ->     Union[str, Any]:






      '''simple docstring'''







      UpperCAmelCase_  :	Dict				      =		"mock-s3-bucket"
      UpperCAmelCase_  :	str				      =		F"""s3://{mock_bucket}"""
      UpperCAmelCase_  :	Dict				      =		extract_path_from_uri(__snake_case    )
      assert dataset_path.startswith("s3://"    ) is False

      UpperCAmelCase_  :	Tuple				      =		"./local/path"
      UpperCAmelCase_  :	List[str]				      =		extract_path_from_uri(__snake_case    )
      assert dataset_path == new_dataset_path







def    _snake_case (       __snake_case    )     ->     List[str]:






      '''simple docstring'''







      UpperCAmelCase_  :	List[str]				      =		is_remote_filesystem(__snake_case    )
      assert is_remote is True

      UpperCAmelCase_  :	List[Any]				      =		fsspec.filesystem("file"    )

      UpperCAmelCase_  :	Optional[Any]				      =		is_remote_filesystem(__snake_case    )
      assert is_remote is False







@pytest.mark.parametrize("compression_fs_class"					,  __snake_case    )
def    _snake_case (       __snake_case					,  __snake_case					,  __snake_case					,  __snake_case					,  __snake_case					,  __snake_case					,  __snake_case    )     ->     List[Any]:






      '''simple docstring'''







      UpperCAmelCase_  :	int				      =		{"gzip": gz_file, "xz": xz_file, "zstd": zstd_file, "bz2": bza_file, "lz4": lza_file}
      UpperCAmelCase_  :	Union[str, Any]				      =		input_paths[compression_fs_class.protocol]
      if input_path is None:
            UpperCAmelCase_  :	List[str]				      =		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(__snake_case    )
      UpperCAmelCase_  :	Dict				      =		fsspec.filesystem(compression_fs_class.protocol					,  fo=__snake_case    )
      assert isinstance(__snake_case					,  __snake_case    )
      UpperCAmelCase_  :	Optional[int]				      =		os.path.basename(__snake_case    )
      UpperCAmelCase_  :	Optional[int]				      =		expected_filename[: expected_filename.rindex("."    )]
      assert fs.glob("*"    ) == [expected_filename]
      with fs.open(__snake_case					,  "r"					,  encoding="utf-8"    ) as f, open(__snake_case					,  encoding="utf-8"    ) as expected_file:
            assert f.read() == expected_file.read()







@pytest.mark.parametrize("protocol"					,  ["zip", "gzip"]    )
def    _snake_case (       __snake_case					,  __snake_case					,  __snake_case    )     ->     Union[str, Any]:






      '''simple docstring'''







      UpperCAmelCase_  :	Union[str, Any]				      =		{"zip": zip_jsonl_path, "gzip": jsonl_gz_path}
      UpperCAmelCase_  :	List[Any]				      =		compressed_file_paths[protocol]
      UpperCAmelCase_  :	Any				      =		"dataset.jsonl"
      UpperCAmelCase_  :	Tuple				      =		F"""{protocol}://{member_file_path}::{compressed_file_path}"""
      UpperCAmelCase_      ,      *UpperCAmelCase_  :	List[Any]				      =		fsspec.get_fs_token_paths(__snake_case    )
      assert fs.isfile(__snake_case    )
      assert not fs.isfile("non_existing_" + member_file_path    )







@pytest.mark.integration
def    _snake_case (       __snake_case					,  __snake_case					,  __snake_case					,  __snake_case    )     ->     List[Any]:






      '''simple docstring'''







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







def    _snake_case (       )     ->     Tuple:






      '''simple docstring'''







      UpperCAmelCase_  :	List[Any]				      =		"bz2"

      # Import module
      import datasets.filesystems

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

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





from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


__lowerCamelCase         =			logging.get_logger(__name__)

__lowerCamelCase         =			{
    '''microsoft/focalnet-tiny''': '''https://huggingface.co/microsoft/focalnet-tiny/resolve/main/config.json''',
}


class   snake_case_ (lowercase__ , lowercase__  ):




       """simple docstring"""






       _lowerCamelCase			    =				"""focalnet"""



       def __init__(     self     ,lowercase=224     ,lowercase=4     ,lowercase=3     ,lowercase=96     ,lowercase=False     ,lowercase=[192, 384, 768, 768]     ,lowercase=[2, 2, 6, 2]     ,lowercase=[2, 2, 2, 2]     ,lowercase=[3, 3, 3, 3]     ,lowercase="gelu"     ,lowercase=4.0     ,lowercase=0.0     ,lowercase=0.1     ,lowercase=False     ,lowercase=1E-4     ,lowercase=False     ,lowercase=False     ,lowercase=False     ,lowercase=0.02     ,lowercase=1E-5     ,lowercase=32     ,lowercase=None     ,lowercase=None     ,**lowercase     ,):

             """simple docstring"""





             super().__init__(**lowercase)

             UpperCAmelCase_  :	int				      =		image_size
             UpperCAmelCase_  :	Optional[Any]				      =		patch_size
             UpperCAmelCase_  :	Dict				      =		num_channels
             UpperCAmelCase_  :	Dict				      =		embed_dim
             UpperCAmelCase_  :	Optional[int]				      =		use_conv_embed
             UpperCAmelCase_  :	int				      =		hidden_sizes
             UpperCAmelCase_  :	Optional[int]				      =		depths
             UpperCAmelCase_  :	Optional[Any]				      =		focal_levels
             UpperCAmelCase_  :	Tuple				      =		focal_windows
             UpperCAmelCase_  :	int				      =		hidden_act
             UpperCAmelCase_  :	Any				      =		mlp_ratio
             UpperCAmelCase_  :	List[Any]				      =		hidden_dropout_prob
             UpperCAmelCase_  :	Tuple				      =		drop_path_rate
             UpperCAmelCase_  :	List[str]				      =		use_layerscale
             UpperCAmelCase_  :	List[str]				      =		layerscale_value
             UpperCAmelCase_  :	List[str]				      =		use_post_layernorm
             UpperCAmelCase_  :	Dict				      =		use_post_layernorm_in_modulation
             UpperCAmelCase_  :	int				      =		normalize_modulator
             UpperCAmelCase_  :	Dict				      =		initializer_range
             UpperCAmelCase_  :	str				      =		layer_norm_eps
             UpperCAmelCase_  :	Union[str, Any]				      =		encoder_stride
             UpperCAmelCase_  :	str				      =		["stem"] + [F"""stage{idx}""" for idx in range(1     ,len(self.depths) + 1)]
             UpperCAmelCase_      ,      UpperCAmelCase_  :	Any				      =		get_aligned_output_features_output_indices(
                 out_features=lowercase     ,out_indices=lowercase     ,stage_names=self.stage_names)
