





import os
from pathlib import Path
from unittest.mock import patch

import pytest
import zstandard as zstd

from datasets.download.download_config import DownloadConfig
from datasets.utils.file_utils import (
    OfflineModeIsEnabled,
    cached_path,
    fsspec_get,
    fsspec_head,
    ftp_get,
    ftp_head,
    get_from_cache,
    http_get,
    http_head,
)


_a						=   "\\n    Text data.\n    Second line of data."

_a						=   "file"





@pytest.fixture(scope='''session'''							)
def lowerCAmelCase__(__snake_case							)       ->   List[str]:







	'''simple docstring'''







	lowerCamelCase__              =	tmp_path_factory.mktemp('''data'''							) / (FILE_PATH + '''.zstd''')
	lowerCamelCase__              =	bytes(__snake_case ,'''utf-8'''							)
	with zstd.open(__snake_case ,'''wb'''							) as f:
		f.write(__snake_case							)
	return path





@pytest.fixture
def lowerCAmelCase__(__snake_case							)       ->   Dict:







	'''simple docstring'''







	with open(os.path.join(tmpfs.local_root_dir ,__snake_case							) ,'''w'''							) as f:
		f.write(__snake_case							)
	return FILE_PATH





@pytest.mark.parametrize('''compression_format''' ,['''gzip''', '''xz''', '''zstd''']							)
def lowerCAmelCase__(__snake_case ,__snake_case ,__snake_case ,__snake_case ,__snake_case ,__snake_case							)       ->   Union[str, Any]:







	'''simple docstring'''







	lowerCamelCase__              =	{'''gzip''': gz_file, '''xz''': xz_file, '''zstd''': zstd_path}
	lowerCamelCase__              =	input_paths[compression_format]
	lowerCamelCase__              =	tmp_path / '''cache'''
	lowerCamelCase__              =	DownloadConfig(cache_dir=__snake_case ,extract_compressed_file=__snake_case							)
	lowerCamelCase__              =	cached_path(__snake_case ,download_config=__snake_case							)
	with open(__snake_case							) as f:
		lowerCamelCase__              =	f.read()
	with open(__snake_case							) as f:
		lowerCamelCase__              =	f.read()
	assert extracted_file_content == expected_file_content





@pytest.mark.parametrize('''default_extracted''' ,[True, False]							)
@pytest.mark.parametrize('''default_cache_dir''' ,[True, False]							)
def lowerCAmelCase__(__snake_case ,__snake_case ,__snake_case ,__snake_case ,__snake_case							)       ->   Tuple:







	'''simple docstring'''







	lowerCamelCase__              =	'''custom_cache'''
	lowerCamelCase__              =	'''custom_extracted_dir'''
	lowerCamelCase__              =	tmp_path / '''custom_extracted_path'''
	if default_extracted:
		lowerCamelCase__              =	('''downloads''' if default_cache_dir else custom_cache_dir, '''extracted''')
	else:
		monkeypatch.setattr('''datasets.config.EXTRACTED_DATASETS_DIR''' ,__snake_case							)
		monkeypatch.setattr('''datasets.config.EXTRACTED_DATASETS_PATH''' ,str(__snake_case							)							)
		lowerCamelCase__              =	custom_extracted_path.parts[-2:] if default_cache_dir else (custom_cache_dir, custom_extracted_dir)

	lowerCamelCase__              =	xz_file
	lowerCamelCase__              =	(
	    DownloadConfig(extract_compressed_file=__snake_case							)
	    if default_cache_dir
	    else DownloadConfig(cache_dir=tmp_path / custom_cache_dir ,extract_compressed_file=__snake_case							)
	)
	lowerCamelCase__              =	cached_path(__snake_case ,download_config=__snake_case							)
	assert Path(__snake_case							).parent.parts[-2:] == expected





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







	'''simple docstring'''







	lowerCamelCase__              =	str(Path(__snake_case							).resolve()							)
	assert cached_path(__snake_case							) == text_file
	# relative path
	lowerCamelCase__              =	str(Path(__snake_case							).resolve().relative_to(Path(os.getcwd()							)							)							)
	assert cached_path(__snake_case							) == text_file





def lowerCAmelCase__(__snake_case							)       ->   int:







	'''simple docstring'''







	lowerCamelCase__              =	str(tmp_path.resolve() / '''__missing_file__.txt'''							)
	with pytest.raises(__snake_case							):
		cached_path(__snake_case							)
	# relative path
	lowerCamelCase__              =	'''./__missing_file__.txt'''
	with pytest.raises(__snake_case							):
		cached_path(__snake_case							)





def lowerCAmelCase__(__snake_case							)       ->   Optional[Any]:







	'''simple docstring'''







	lowerCamelCase__              =	get_from_cache(F'tmp://{tmpfs_file}'							)
	with open(__snake_case							) as f:
		lowerCamelCase__              =	f.read()
	assert output_file_content == FILE_CONTENT





@patch('''datasets.config.HF_DATASETS_OFFLINE''' ,__snake_case							)
def lowerCAmelCase__()       ->   str:







	'''simple docstring'''







	with pytest.raises(__snake_case							):
		cached_path('''https://huggingface.co'''							)





@patch('''datasets.config.HF_DATASETS_OFFLINE''' ,__snake_case							)
def lowerCAmelCase__(__snake_case							)       ->   Dict:







	'''simple docstring'''







	lowerCamelCase__              =	tmp_path_factory.mktemp('''data'''							) / '''file.html'''
	with pytest.raises(__snake_case							):
		http_get('''https://huggingface.co''' ,temp_file=__snake_case							)
	with pytest.raises(__snake_case							):
		http_head('''https://huggingface.co'''							)





@patch('''datasets.config.HF_DATASETS_OFFLINE''' ,__snake_case							)
def lowerCAmelCase__(__snake_case							)       ->   Optional[Any]:







	'''simple docstring'''







	lowerCamelCase__              =	tmp_path_factory.mktemp('''data'''							) / '''file.html'''
	with pytest.raises(__snake_case							):
		ftp_get('''ftp://huggingface.co''' ,temp_file=__snake_case							)
	with pytest.raises(__snake_case							):
		ftp_head('''ftp://huggingface.co'''							)





@patch('''datasets.config.HF_DATASETS_OFFLINE''' ,__snake_case							)
def lowerCAmelCase__(__snake_case							)       ->   Optional[Any]:







	'''simple docstring'''







	lowerCamelCase__              =	tmp_path_factory.mktemp('''data'''							) / '''file.html'''
	with pytest.raises(__snake_case							):
		fsspec_get('''s3://huggingface.co''' ,temp_file=__snake_case							)
	with pytest.raises(__snake_case							):
		fsspec_head('''s3://huggingface.co'''							)










from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_flax_available, is_torch_available


_a						=   {
    "configuration_gpt_neo": ["GPT_NEO_PRETRAINED_CONFIG_ARCHIVE_MAP", "GPTNeoConfig", "GPTNeoOnnxConfig"],
}

try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_a						=   [
			    "GPT_NEO_PRETRAINED_MODEL_ARCHIVE_LIST",
			    "GPTNeoForCausalLM",
			    "GPTNeoForQuestionAnswering",
			    "GPTNeoForSequenceClassification",
			    "GPTNeoForTokenClassification",
			    "GPTNeoModel",
			    "GPTNeoPreTrainedModel",
			    "load_tf_weights_in_gpt_neo",
			]

try:
			if not is_flax_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_a						=   [
			    "FlaxGPTNeoForCausalLM",
			    "FlaxGPTNeoModel",
			    "FlaxGPTNeoPreTrainedModel",
			]


if TYPE_CHECKING:
			from .configuration_gpt_neo import GPT_NEO_PRETRAINED_CONFIG_ARCHIVE_MAP, GPTNeoConfig, GPTNeoOnnxConfig

			try:
						if not is_torch_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_gpt_neo import (
						    GPT_NEO_PRETRAINED_MODEL_ARCHIVE_LIST,
						    GPTNeoForCausalLM,
						    GPTNeoForQuestionAnswering,
						    GPTNeoForSequenceClassification,
						    GPTNeoForTokenClassification,
						    GPTNeoModel,
						    GPTNeoPreTrainedModel,
						    load_tf_weights_in_gpt_neo,
						)

			try:
						if not is_flax_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_flax_gpt_neo import FlaxGPTNeoForCausalLM, FlaxGPTNeoModel, FlaxGPTNeoPreTrainedModel


else:
			import sys

			_a						=   _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)



