




"""simple docstring"""





import contextlib
import csv
import json
import os
import sqlitea
import tarfile
import textwrap
import zipfile

import pyarrow as pa
import pyarrow.parquet as pq
import pytest

import datasets
import datasets.config

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			)			->			int:


			"""simple docstring"""
			__UpperCAmelCase	: List[str]		=					10
			__UpperCAmelCase	: List[str]		=					datasets.Features(
			    {
			        "tokens": datasets.Sequence(datasets.Value("string"							)							),
			        "labels": datasets.Sequence(datasets.ClassLabel(names=["negative", "positive"]							)							),
			        "answers": datasets.Sequence(
			            {
			                "text": datasets.Value("string"							),
			                "answer_start": datasets.Value("int32"							),
			            }							),
			        "id": datasets.Value("int64"							),
			    }							)
			__UpperCAmelCase	: int		=					datasets.Dataset.from_dict(
			    {
			        "tokens": [["foo"] * 5] * n,
			        "labels": [[1] * 5] * n,
			        "answers": [{"answer_start": [97], "text": ["1976"]}] * 10,
			        "id": list(range(UpperCamelCase							)							),
			    }				,       features=UpperCamelCase				,       )
			return dataset

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase				,       UpperCamelCase							)			->			Optional[int]:


			"""simple docstring"""
			__UpperCAmelCase	: int		=					str(tmp_path_factory.mktemp("data"							) / "file.arrow"							)
			dataset.map(cache_file_name=UpperCamelCase							)
			return filename


# FILE_CONTENT + files


A   =       """\
    Text data.
    Second line of data."""

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase							)			->			Union[str, Any]:


			"""simple docstring"""
			__UpperCAmelCase	: Tuple		=					tmp_path_factory.mktemp("data"							) / "file.txt"
			__UpperCAmelCase	: int		=					FILE_CONTENT
			with open(UpperCamelCase				,       "w"							) as f:
						f.write(UpperCamelCase							)
			return filename

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase							)			->			Any:


			"""simple docstring"""
			import bza

			__UpperCAmelCase	: Tuple		=					tmp_path_factory.mktemp("data"							) / "file.txt.bz2"
			__UpperCAmelCase	: Dict		=					bytes(UpperCamelCase				,       "utf-8"							)
			with bza.open(UpperCamelCase				,       "wb"							) as f:
						f.write(UpperCamelCase							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase							)			->			int:


			"""simple docstring"""
			import gzip

			__UpperCAmelCase	: Dict		=					str(tmp_path_factory.mktemp("data"							) / "file.txt.gz"							)
			__UpperCAmelCase	: Tuple		=					bytes(UpperCamelCase				,       "utf-8"							)
			with gzip.open(UpperCamelCase				,       "wb"							) as f:
						f.write(UpperCamelCase							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase							)			->			Optional[Any]:


			"""simple docstring"""
			if datasets.config.LZ4_AVAILABLE:
						import lza.frame

						__UpperCAmelCase	: Optional[Any]		=					tmp_path_factory.mktemp("data"							) / "file.txt.lz4"
						__UpperCAmelCase	: Tuple		=					bytes(UpperCamelCase				,       "utf-8"							)
						with lza.frame.open(UpperCamelCase				,       "wb"							) as f:
									f.write(UpperCamelCase							)
						return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase				,       UpperCamelCase							)			->			List[Any]:


			"""simple docstring"""
			if datasets.config.PY7ZR_AVAILABLE:
						import pyazr

						__UpperCAmelCase	: int		=					tmp_path_factory.mktemp("data"							) / "file.txt.7z"
						with pyazr.SevenZipFile(UpperCamelCase				,       "w"							) as archive:
									archive.write(UpperCamelCase				,       arcname=os.path.basename(UpperCamelCase							)							)
						return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase				,       UpperCamelCase							)			->			Optional[int]:


			"""simple docstring"""
			import tarfile

			__UpperCAmelCase	: Optional[Any]		=					tmp_path_factory.mktemp("data"							) / "file.txt.tar"
			with tarfile.TarFile(UpperCamelCase				,       "w"							) as f:
						f.add(UpperCamelCase				,       arcname=os.path.basename(UpperCamelCase							)							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase							)			->			Optional[int]:


			"""simple docstring"""
			import lzma

			__UpperCAmelCase	: Dict		=					tmp_path_factory.mktemp("data"							) / "file.txt.xz"
			__UpperCAmelCase	: Optional[int]		=					bytes(UpperCamelCase				,       "utf-8"							)
			with lzma.open(UpperCamelCase				,       "wb"							) as f:
						f.write(UpperCamelCase							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase				,       UpperCamelCase							)			->			int:


			"""simple docstring"""
			import zipfile

			__UpperCAmelCase	: Dict		=					tmp_path_factory.mktemp("data"							) / "file.txt.zip"
			with zipfile.ZipFile(UpperCamelCase				,       "w"							) as f:
						f.write(UpperCamelCase				,       arcname=os.path.basename(UpperCamelCase							)							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase							)			->			int:


			"""simple docstring"""
			if datasets.config.ZSTANDARD_AVAILABLE:
						import zstandard as zstd

						__UpperCAmelCase	: int		=					tmp_path_factory.mktemp("data"							) / "file.txt.zst"
						__UpperCAmelCase	: Dict		=					bytes(UpperCamelCase				,       "utf-8"							)
						with zstd.open(UpperCamelCase				,       "wb"							) as f:
									f.write(UpperCamelCase							)
						return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase							)			->			Dict:


			"""simple docstring"""
			__UpperCAmelCase	: Tuple		=					tmp_path_factory.mktemp("data"							) / "file.xml"
			__UpperCAmelCase	: str		=					textwrap.dedent(
			    "\\n    <?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n    <tmx version=\"1.4\">\n      <header segtype=\"sentence\" srclang=\"ca\" />\n      <body>\n        <tu>\n          <tuv xml:lang=\"ca\"><seg>Contingut 1</seg></tuv>\n          <tuv xml:lang=\"en\"><seg>Content 1</seg></tuv>\n        </tu>\n        <tu>\n          <tuv xml:lang=\"ca\"><seg>Contingut 2</seg></tuv>\n          <tuv xml:lang=\"en\"><seg>Content 2</seg></tuv>\n        </tu>\n        <tu>\n          <tuv xml:lang=\"ca\"><seg>Contingut 3</seg></tuv>\n          <tuv xml:lang=\"en\"><seg>Content 3</seg></tuv>\n        </tu>\n        <tu>\n          <tuv xml:lang=\"ca\"><seg>Contingut 4</seg></tuv>\n          <tuv xml:lang=\"en\"><seg>Content 4</seg></tuv>\n        </tu>\n        <tu>\n          <tuv xml:lang=\"ca\"><seg>Contingut 5</seg></tuv>\n          <tuv xml:lang=\"en\"><seg>Content 5</seg></tuv>\n        </tu>\n      </body>\n    </tmx>"							)
			with open(UpperCamelCase				,       "w"							) as f:
						f.write(UpperCamelCase							)
			return filename


A   =       [
    {"""col_1""": """0""", """col_2""": 0, """col_3""": 0.0},
    {"""col_1""": """1""", """col_2""": 1, """col_3""": 1.0},
    {"""col_1""": """2""", """col_2""": 2, """col_3""": 2.0},
    {"""col_1""": """3""", """col_2""": 3, """col_3""": 3.0},
]
A   =       [
    {"""col_1""": """4""", """col_2""": 4, """col_3""": 4.0},
    {"""col_1""": """5""", """col_2""": 5, """col_3""": 5.0},
]
A   =       {
    """col_1""": ["""0""", """1""", """2""", """3"""],
    """col_2""": [0, 1, 2, 3],
    """col_3""": [0.0, 1.0, 2.0, 3.0],
}

A   =       [
    {"""col_3""": 0.0, """col_1""": """0""", """col_2""": 0},
    {"""col_3""": 1.0, """col_1""": """1""", """col_2""": 1},
]

A   =       [
    {"""col_1""": """s0""", """col_2""": 0, """col_3""": 0.0},
    {"""col_1""": """s1""", """col_2""": 1, """col_3""": 1.0},
    {"""col_1""": """s2""", """col_2""": 2, """col_3""": 2.0},
    {"""col_1""": """s3""", """col_2""": 3, """col_3""": 3.0},
]

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			)			->			List[str]:


			"""simple docstring"""
			return DATA_DICT_OF_LISTS

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase							)			->			str:


			"""simple docstring"""
			__UpperCAmelCase	: Any		=					datasets.Dataset.from_dict(UpperCamelCase							)
			__UpperCAmelCase	: List[str]		=					str(tmp_path_factory.mktemp("data"							) / "dataset.arrow"							)
			dataset.map(cache_file_name=UpperCamelCase							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase							)			->			Optional[Any]:


			"""simple docstring"""
			__UpperCAmelCase	: List[Any]		=					str(tmp_path_factory.mktemp("data"							) / "dataset.sqlite"							)
			with contextlib.closing(sqlitea.connect(UpperCamelCase							)							) as con:
						__UpperCAmelCase	: Optional[Any]		=					con.cursor()
						cur.execute("CREATE TABLE dataset(col_1 text, col_2 int, col_3 real)"							)
						for item in DATA:
									cur.execute("INSERT INTO dataset(col_1, col_2, col_3) VALUES (?, ?, ?)"				,       tuple(item.values()							)							)
						con.commit()
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase							)			->			Optional[Any]:


			"""simple docstring"""
			__UpperCAmelCase	: List[str]		=					str(tmp_path_factory.mktemp("data"							) / "dataset.csv"							)
			with open(UpperCamelCase				,       "w"				,       newline=""							) as f:
						__UpperCAmelCase	: Dict		=					csv.DictWriter(UpperCamelCase				,       fieldnames=["col_1", "col_2", "col_3"]							)
						writer.writeheader()
						for item in DATA:
									writer.writerow(UpperCamelCase							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase							)			->			List[Any]:


			"""simple docstring"""
			__UpperCAmelCase	: int		=					str(tmp_path_factory.mktemp("data"							) / "dataset2.csv"							)
			with open(UpperCamelCase				,       "w"				,       newline=""							) as f:
						__UpperCAmelCase	: str		=					csv.DictWriter(UpperCamelCase				,       fieldnames=["col_1", "col_2", "col_3"]							)
						writer.writeheader()
						for item in DATA:
									writer.writerow(UpperCamelCase							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase				,       UpperCamelCase							)			->			Any:


			"""simple docstring"""
			import bza

			__UpperCAmelCase	: List[str]		=					tmp_path_factory.mktemp("data"							) / "dataset.csv.bz2"
			with open(UpperCamelCase				,       "rb"							) as f:
						__UpperCAmelCase	: Any		=					f.read()
			# data = bytes(FILE_CONTENT, "utf-8")
			with bza.open(UpperCamelCase				,       "wb"							) as f:
						f.write(UpperCamelCase							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase				,       UpperCamelCase				,       UpperCamelCase							)			->			Optional[Any]:


			"""simple docstring"""
			__UpperCAmelCase	: Union[str, Any]		=					tmp_path_factory.mktemp("data"							) / "dataset.csv.zip"
			with zipfile.ZipFile(UpperCamelCase				,       "w"							) as f:
						f.write(UpperCamelCase				,       arcname=os.path.basename(UpperCamelCase							)							)
						f.write(UpperCamelCase				,       arcname=os.path.basename(UpperCamelCase							)							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase				,       UpperCamelCase				,       UpperCamelCase							)			->			int:


			"""simple docstring"""
			__UpperCAmelCase	: Optional[int]		=					tmp_path_factory.mktemp("data"							) / "dataset.csv.zip"
			with zipfile.ZipFile(UpperCamelCase				,       "w"							) as f:
						f.write(UpperCamelCase				,       arcname=os.path.basename(csv_path.replace(".csv"				,       ".CSV"							)							)							)
						f.write(UpperCamelCase				,       arcname=os.path.basename(csva_path.replace(".csv"				,       ".CSV"							)							)							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase				,       UpperCamelCase				,       UpperCamelCase							)			->			int:


			"""simple docstring"""
			__UpperCAmelCase	: Union[str, Any]		=					tmp_path_factory.mktemp("data"							) / "dataset_with_dir.csv.zip"
			with zipfile.ZipFile(UpperCamelCase				,       "w"							) as f:
						f.write(UpperCamelCase				,       arcname=os.path.join("main_dir"				,       os.path.basename(UpperCamelCase							)							)							)
						f.write(UpperCamelCase				,       arcname=os.path.join("main_dir"				,       os.path.basename(UpperCamelCase							)							)							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase							)			->			Tuple:


			"""simple docstring"""
			__UpperCAmelCase	: Tuple		=					str(tmp_path_factory.mktemp("data"							) / "dataset.parquet"							)
			__UpperCAmelCase	: Tuple		=					pa.schema(
			    {
			        "col_1": pa.string(),
			        "col_2": pa.intaa(),
			        "col_3": pa.floataa(),
			    }							)
			with open(UpperCamelCase				,       "wb"							) as f:
						__UpperCAmelCase	: str		=					pq.ParquetWriter(UpperCamelCase				,       schema=UpperCamelCase							)
						__UpperCAmelCase	: Union[str, Any]		=					pa.Table.from_pydict({k: [DATA[i][k] for i in range(len(UpperCamelCase							)							)] for k in DATA[0]}				,       schema=UpperCamelCase							)
						writer.write_table(UpperCamelCase							)
						writer.close()
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase							)			->			str:


			"""simple docstring"""
			__UpperCAmelCase	: Optional[int]		=					str(tmp_path_factory.mktemp("data"							) / "dataset.json"							)
			__UpperCAmelCase	: int		=					{"data": DATA}
			with open(UpperCamelCase				,       "w"							) as f:
						json.dump(UpperCamelCase				,       UpperCamelCase							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase							)			->			int:


			"""simple docstring"""
			__UpperCAmelCase	: List[Any]		=					str(tmp_path_factory.mktemp("data"							) / "dataset.json"							)
			__UpperCAmelCase	: List[Any]		=					{"data": DATA_DICT_OF_LISTS}
			with open(UpperCamelCase				,       "w"							) as f:
						json.dump(UpperCamelCase				,       UpperCamelCase							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase							)			->			int:


			"""simple docstring"""
			__UpperCAmelCase	: Any		=					str(tmp_path_factory.mktemp("data"							) / "dataset.jsonl"							)
			with open(UpperCamelCase				,       "w"							) as f:
						for item in DATA:
									f.write(json.dumps(UpperCamelCase							) + "\n"							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase							)			->			List[str]:


			"""simple docstring"""
			__UpperCAmelCase	: str		=					str(tmp_path_factory.mktemp("data"							) / "dataset2.jsonl"							)
			with open(UpperCamelCase				,       "w"							) as f:
						for item in DATA:
									f.write(json.dumps(UpperCamelCase							) + "\n"							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase							)			->			Any:


			"""simple docstring"""
			__UpperCAmelCase	: str		=					str(tmp_path_factory.mktemp("data"							) / "dataset_312.jsonl"							)
			with open(UpperCamelCase				,       "w"							) as f:
						for item in DATA_312:
									f.write(json.dumps(UpperCamelCase							) + "\n"							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase							)			->			Dict:


			"""simple docstring"""
			__UpperCAmelCase	: List[Any]		=					str(tmp_path_factory.mktemp("data"							) / "dataset-str.jsonl"							)
			with open(UpperCamelCase				,       "w"							) as f:
						for item in DATA_STR:
									f.write(json.dumps(UpperCamelCase							) + "\n"							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase				,       UpperCamelCase							)			->			Dict:


			"""simple docstring"""
			import gzip

			__UpperCAmelCase	: Optional[Any]		=					str(tmp_path_factory.mktemp("data"							) / "dataset.txt.gz"							)
			with open(UpperCamelCase				,       "rb"							) as orig_file:
						with gzip.open(UpperCamelCase				,       "wb"							) as zipped_file:
									zipped_file.writelines(UpperCamelCase							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase				,       UpperCamelCase							)			->			str:


			"""simple docstring"""
			import gzip

			__UpperCAmelCase	: List[Any]		=					str(tmp_path_factory.mktemp("data"							) / "dataset.jsonl.gz"							)
			with open(UpperCamelCase				,       "rb"							) as orig_file:
						with gzip.open(UpperCamelCase				,       "wb"							) as zipped_file:
									zipped_file.writelines(UpperCamelCase							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase				,       UpperCamelCase				,       UpperCamelCase							)			->			int:


			"""simple docstring"""
			__UpperCAmelCase	: List[str]		=					tmp_path_factory.mktemp("data"							) / "dataset.jsonl.zip"
			with zipfile.ZipFile(UpperCamelCase				,       "w"							) as f:
						f.write(UpperCamelCase				,       arcname=os.path.basename(UpperCamelCase							)							)
						f.write(UpperCamelCase				,       arcname=os.path.basename(UpperCamelCase							)							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase				,       UpperCamelCase				,       UpperCamelCase				,       UpperCamelCase							)			->			Any:


			"""simple docstring"""
			__UpperCAmelCase	: Optional[int]		=					tmp_path_factory.mktemp("data"							) / "dataset_nested.jsonl.zip"
			with zipfile.ZipFile(UpperCamelCase				,       "w"							) as f:
						f.write(UpperCamelCase				,       arcname=os.path.join("nested"				,       os.path.basename(UpperCamelCase							)							)							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase				,       UpperCamelCase				,       UpperCamelCase							)			->			Any:


			"""simple docstring"""
			__UpperCAmelCase	: str		=					tmp_path_factory.mktemp("data"							) / "dataset_with_dir.jsonl.zip"
			with zipfile.ZipFile(UpperCamelCase				,       "w"							) as f:
						f.write(UpperCamelCase				,       arcname=os.path.join("main_dir"				,       os.path.basename(UpperCamelCase							)							)							)
						f.write(UpperCamelCase				,       arcname=os.path.join("main_dir"				,       os.path.basename(UpperCamelCase							)							)							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase				,       UpperCamelCase				,       UpperCamelCase							)			->			str:


			"""simple docstring"""
			__UpperCAmelCase	: Optional[int]		=					tmp_path_factory.mktemp("data"							) / "dataset.jsonl.tar"
			with tarfile.TarFile(UpperCamelCase				,       "w"							) as f:
						f.add(UpperCamelCase				,       arcname=os.path.basename(UpperCamelCase							)							)
						f.add(UpperCamelCase				,       arcname=os.path.basename(UpperCamelCase							)							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase				,       UpperCamelCase				,       UpperCamelCase				,       UpperCamelCase							)			->			Optional[Any]:


			"""simple docstring"""
			__UpperCAmelCase	: List[Any]		=					tmp_path_factory.mktemp("data"							) / "dataset_nested.jsonl.tar"
			with tarfile.TarFile(UpperCamelCase				,       "w"							) as f:
						f.add(UpperCamelCase				,       arcname=os.path.join("nested"				,       os.path.basename(UpperCamelCase							)							)							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase							)			->			Tuple:


			"""simple docstring"""
			__UpperCAmelCase	: Any		=					["0", "1", "2", "3"]
			__UpperCAmelCase	: Union[str, Any]		=					str(tmp_path_factory.mktemp("data"							) / "dataset.txt"							)
			with open(UpperCamelCase				,       "w"							) as f:
						for item in data:
									f.write(item + "\n"							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase							)			->			Union[str, Any]:


			"""simple docstring"""
			__UpperCAmelCase	: Optional[int]		=					["0", "1", "2", "3"]
			__UpperCAmelCase	: Any		=					str(tmp_path_factory.mktemp("data"							) / "dataset2.txt"							)
			with open(UpperCamelCase				,       "w"							) as f:
						for item in data:
									f.write(item + "\n"							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase							)			->			str:


			"""simple docstring"""
			__UpperCAmelCase	: Any		=					["0", "1", "2", "3"]
			__UpperCAmelCase	: List[Any]		=					tmp_path_factory.mktemp("data"							) / "dataset.abc"
			with open(UpperCamelCase				,       "w"							) as f:
						for item in data:
									f.write(item + "\n"							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase				,       UpperCamelCase				,       UpperCamelCase							)			->			Optional[int]:


			"""simple docstring"""
			__UpperCAmelCase	: str		=					tmp_path_factory.mktemp("data"							) / "dataset.text.zip"
			with zipfile.ZipFile(UpperCamelCase				,       "w"							) as f:
						f.write(UpperCamelCase				,       arcname=os.path.basename(UpperCamelCase							)							)
						f.write(UpperCamelCase				,       arcname=os.path.basename(UpperCamelCase							)							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase				,       UpperCamelCase				,       UpperCamelCase							)			->			Dict:


			"""simple docstring"""
			__UpperCAmelCase	: Any		=					tmp_path_factory.mktemp("data"							) / "dataset_with_dir.text.zip"
			with zipfile.ZipFile(UpperCamelCase				,       "w"							) as f:
						f.write(UpperCamelCase				,       arcname=os.path.join("main_dir"				,       os.path.basename(UpperCamelCase							)							)							)
						f.write(UpperCamelCase				,       arcname=os.path.join("main_dir"				,       os.path.basename(UpperCamelCase							)							)							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase				,       UpperCamelCase				,       UpperCamelCase							)			->			str:


			"""simple docstring"""
			__UpperCAmelCase	: List[Any]		=					tmp_path_factory.mktemp("data"							) / "dataset.ext.zip"
			with zipfile.ZipFile(UpperCamelCase				,       "w"							) as f:
						f.write(UpperCamelCase				,       arcname=os.path.basename("unsupported.ext"							)							)
						f.write(UpperCamelCase				,       arcname=os.path.basename("unsupported_2.ext"							)							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase							)			->			int:


			"""simple docstring"""
			__UpperCAmelCase	: Optional[Any]		=					"\n".join(["First", "Second\u2029with Unicode new line", "Third"]							)
			__UpperCAmelCase	: int		=					str(tmp_path_factory.mktemp("data"							) / "dataset_with_unicode_new_lines.txt"							)
			with open(UpperCamelCase				,       "w"				,       encoding="utf-8"							) as f:
						f.write(UpperCamelCase							)
			return path

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			)			->			Dict:


			"""simple docstring"""
			return os.path.join("tests"				,       "features"				,       "data"				,       "test_image_rgb.jpg"							)

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			)			->			Optional[Any]:


			"""simple docstring"""
			return os.path.join("tests"				,       "features"				,       "data"				,       "test_audio_44100.wav"							)

@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase				,       UpperCamelCase							)			->			List[Any]:


			"""simple docstring"""
			__UpperCAmelCase	: str		=					tmp_path_factory.mktemp("data"							) / "dataset.img.zip"
			with zipfile.ZipFile(UpperCamelCase				,       "w"							) as f:
						f.write(UpperCamelCase				,       arcname=os.path.basename(UpperCamelCase							)							)
						f.write(UpperCamelCase				,       arcname=os.path.basename(UpperCamelCase							).replace(".jpg"				,       "2.jpg"							)							)
			return path





@pytest.fixture(scope="session"							)
def 					_UpperCamelCase    (			UpperCamelCase							)			->			Optional[Any]:


			"""simple docstring"""
			__UpperCAmelCase	: List[Any]		=					tmp_path_factory.mktemp("data_dir"							)

			(data_dir / "subdir").mkdir()
			with open(data_dir / "subdir" / "train.txt"				,       "w"							) as f:
						f.write("foo\n" * 10							)
			with open(data_dir / "subdir" / "test.txt"				,       "w"							) as f:
						f.write("bar\n" * 10							)
			# hidden file
			with open(data_dir / "subdir" / ".test.txt"				,       "w"							) as f:
						f.write("bar\n" * 10							)

			# hidden directory
			(data_dir / ".subdir").mkdir()
			with open(data_dir / ".subdir" / "train.txt"				,       "w"							) as f:
						f.write("foo\n" * 10							)
			with open(data_dir / ".subdir" / "test.txt"				,       "w"							) as f:
						f.write("bar\n" * 10							)

			return data_dir








"""simple docstring"""





import json
import logging
import os
import socket

import git
import numpy as np
import torch


logging.basicConfig(
    format="""%(asctime)s - %(levelname)s - %(name)s - PID: %(process)d -  %(message)s""",
    datefmt="""%m/%d/%Y %H:%M:%S""",
    level=logging.INFO,
)
A   =       logging.getLogger(__name__)

def 					_UpperCamelCase    (			UpperCamelCase							)			->			Any:


			"""simple docstring"""
			__UpperCAmelCase	: Optional[Any]		=					git.Repo(search_parent_directories=UpperCamelCase							)
			__UpperCAmelCase	: Any		=					{
			    "repo_id": str(UpperCamelCase							),
			    "repo_sha": str(repo.head.object.hexsha							),
			    "repo_branch": str(repo.active_branch							),
			}

			with open(os.path.join(UpperCamelCase				,       "git_log.json"							)				,       "w"							) as f:
						json.dump(UpperCamelCase				,       UpperCamelCase				,       indent=4							)

def 					_UpperCamelCase    (			UpperCamelCase							)			->			str:


			"""simple docstring"""
			if params.n_gpu <= 0:
						__UpperCAmelCase	: str		=					0
						__UpperCAmelCase	: Dict		=					-1
						__UpperCAmelCase	: Tuple		=					True
						__UpperCAmelCase	: List[str]		=					False
						return

			assert torch.cuda.is_available()

			logger.info("Initializing GPUs"							)
			if params.n_gpu > 1:
						assert params.local_rank != -1

						__UpperCAmelCase	: Optional[int]		=					int(os.environ["WORLD_SIZE"]							)
						__UpperCAmelCase	: Union[str, Any]		=					int(os.environ["N_GPU_NODE"]							)
						__UpperCAmelCase	: Optional[int]		=					int(os.environ["RANK"]							)

						# number of nodes / node ID
						__UpperCAmelCase	: int		=					params.world_size // params.n_gpu_per_node
						__UpperCAmelCase	: Optional[int]		=					params.global_rank // params.n_gpu_per_node
						__UpperCAmelCase	: Tuple		=					True

						assert params.n_nodes == int(os.environ["N_NODES"]							)
						assert params.node_id == int(os.environ["NODE_RANK"]							)

			# local job (single GPU)
			else:
						assert params.local_rank == -1

						__UpperCAmelCase	: Union[str, Any]		=					1
						__UpperCAmelCase	: Dict		=					0
						__UpperCAmelCase	: List[Any]		=					0
						__UpperCAmelCase	: Tuple		=					0
						__UpperCAmelCase	: Any		=					1
						__UpperCAmelCase	: str		=					1
						__UpperCAmelCase	: Dict		=					False

			# sanity checks
			assert params.n_nodes >= 1
			assert 0 <= params.node_id < params.n_nodes
			assert 0 <= params.local_rank <= params.global_rank < params.world_size
			assert params.world_size == params.n_nodes * params.n_gpu_per_node

			# define whether this is the master process / if we are in multi-node distributed mode
			__UpperCAmelCase	: Union[str, Any]		=					params.node_id == 0 and params.local_rank == 0
			__UpperCAmelCase	: Dict		=					params.n_nodes > 1

			# summary
			__UpperCAmelCase	: Any		=					f"--- Global rank: {params.global_rank} - "
			logger.info(PREFIX + "Number of nodes: %i" % params.n_nodes							)
			logger.info(PREFIX + "Node ID        : %i" % params.node_id							)
			logger.info(PREFIX + "Local rank     : %i" % params.local_rank							)
			logger.info(PREFIX + "World size     : %i" % params.world_size							)
			logger.info(PREFIX + "GPUs per node  : %i" % params.n_gpu_per_node							)
			logger.info(PREFIX + "Master         : %s" % str(params.is_master							)							)
			logger.info(PREFIX + "Multi-node     : %s" % str(params.multi_node							)							)
			logger.info(PREFIX + "Multi-GPU      : %s" % str(params.multi_gpu							)							)
			logger.info(PREFIX + "Hostname       : %s" % socket.gethostname()							)

			# set GPU device
			torch.cuda.set_device(params.local_rank							)

			# initialize multi-GPU
			if params.multi_gpu:
						logger.info("Initializing PyTorch distributed"							)
						torch.distributed.init_process_group(
						    init_method="env://"				,       backend="nccl"				,       )





def 					_UpperCamelCase    (			UpperCamelCase							)			->			Tuple:


			"""simple docstring"""
			np.random.seed(args.seed							)
			torch.manual_seed(args.seed							)
			if args.n_gpu > 0:
						torch.cuda.manual_seed_all(args.seed							)


