




'''simple docstring'''







import re
import tempfile
import unittest
from pathlib import Path

from datasets.utils.metadata import DatasetMetadata







def 	_A			(   UpperCAmelCase	):






   '''simple docstring'''







   A__         =    min(re.search('^ +'			,UpperCAmelCase	).end() if t.startswith(' '	) else 0 for t in string.splitlines()	)
   return "\n".join([line[indent_level:] for line in string.splitlines() if indent_level < len(UpperCAmelCase	)]	)


lowerCAmelCase_    	=							'''\
---
language:
- zh
- en
task_ids:
- sentiment-classification
---
# Begin of markdown

Some cool dataset card
'''

lowerCAmelCase_    	=							'''\
---
---
# Begin of markdown

Some cool dataset card
'''


lowerCAmelCase_    	=							'''\
# Begin of markdown

Some cool dataset card
'''







class   _snake_case( unittest.TestCase			):






 def 	_UpperCamelCase   (self					:     Any						)					->      Optional[Any]:






    """simple docstring"""


    with tempfile.TemporaryDirectory() as tmp_dir:
       A__         =    Path(a						) / 'README.md'
       with open(a						,		'w+'						) as readme_file:
          readme_file.write(a						)
       A__         =    DatasetMetadata.from_readme(a						)
       self.assertDictEqual(a						,		{'language': ['zh', 'en'], 'task_ids': ['sentiment-classification']}						)

       with open(a						,		'w+'						) as readme_file:
          readme_file.write(a						)
       A__         =    DatasetMetadata.from_readme(a						)
       self.assertDictEqual(a						,		{}						)

       with open(a						,		'w+'						) as readme_file:
          readme_file.write(a						)
       A__         =    DatasetMetadata.from_readme(a						)
       self.assertEqual(a						,		{}						)






 def 	_UpperCamelCase   (self					:     Optional[Any]						)					->      int:






    """simple docstring"""


    A__         =    _dedent(
        '\\n            annotations_creators:\n            - found\n            language_creators:\n            - found\n            language:\n            - en\n            license:\n            - unknown\n            multilinguality:\n            - monolingual\n            pretty_name: Test Dataset\n            size_categories:\n            - 10K<n<100K\n            source_datasets:\n            - extended|other-yahoo-webscope-l6\n            task_categories:\n            - question-answering\n            task_ids:\n            - open-domain-qa\n            '						)
    assert DatasetMetadata.from_yaml_string(a						)

    A__         =    _dedent(
        '\\n            annotations_creators:\n            - found\n            language:\n            - en\n            license:\n            - unknown\n            multilinguality:\n            - monolingual\n            pretty_name: Test Dataset\n            size_categories:\n            - 10K<n<100K\n            source_datasets:\n            - extended|other-yahoo-webscope-l6\n            task_categories:\n            - question-answering\n            task_ids:\n            - open-domain-qa\n            task_ids:\n            - open-domain-qa\n            '						)
    with self.assertRaises(a						):
       DatasetMetadata.from_yaml_string(a						)

    A__         =    _dedent(
        '\\n            annotations_creators:\n            - found\n            language_creators:\n            - found\n            language:\n            - en\n            license:\n            - unknown\n            multilinguality:\n            - monolingual\n            pretty_name: Test Dataset\n            size_categories:\n            - 10K<n<100K\n            source_datasets:\n            - extended|other-yahoo-webscope-l6\n            task_categories:\n            - text-classification\n            task_ids:\n            - multi-class-classification\n            paperswithcode_id:\n            - squad\n            configs:\n            - en\n            train-eval-index:\n            - config: en\n              task: text-classification\n              task_id: multi_class_classification\n              splits:\n                train_split: train\n                eval_split: test\n              col_mapping:\n                text: text\n                label: target\n              metrics:\n                - type: accuracy\n                  name: Accuracy\n            extra_gated_prompt: |\n              By clicking on “Access repository” below, you also agree to ImageNet Terms of Access:\n              [RESEARCHER_FULLNAME] (the "Researcher") has requested permission to use the ImageNet database (the "Database") at Princeton University and Stanford University. In exchange for such permission, Researcher hereby agrees to the following terms and conditions:\n              1. Researcher shall use the Database only for non-commercial research and educational purposes.\n            extra_gated_fields:\n              Company: text\n              Country: text\n              I agree to use this model for non-commerical use ONLY: checkbox\n            '						)
    assert DatasetMetadata.from_yaml_string(a						)








'''simple docstring'''







import os

from apache_beam.io.filesystems import FileSystems
from apache_beam.pipeline import Pipeline

from .logging import get_logger


lowerCAmelCase_    	=							2 << 2_0  # 2mb
lowerCAmelCase_    	=							get_logger(__name__)

class   _snake_case( UpperCAmelCase			):






 def 	_UpperCamelCase   (self					:     Optional[int]						)					->      Optional[Any]:






    """simple docstring"""


    A__         =    self._options.get_all_options().get('runner'						)
    return runner in [None, "DirectRunner", "PortableRunner"]







def 	_A			(   UpperCAmelCase			,UpperCAmelCase			,UpperCAmelCase=False	):






   '''simple docstring'''







   A__         =    FileSystems
   if fs.exists(UpperCAmelCase	):
      if force_upload:
         logger.info(F"""Remote path already exist: {remote_file_path}. Overwriting it as force_upload=True."""	)
      else:
         logger.info(F"""Remote path already exist: {remote_file_path}. Skipping it as force_upload=False."""	)
         return
   with fs.create(UpperCAmelCase	) as remote_file:
      with open(UpperCAmelCase			,'rb'	) as local_file:
         A__         =    local_file.read(UpperCAmelCase	)
         while chunk:
            remote_file.write(UpperCAmelCase	)
            A__         =    local_file.read(UpperCAmelCase	)







def 	_A			(   UpperCAmelCase			,UpperCAmelCase			,UpperCAmelCase=False	):






   '''simple docstring'''







   A__         =    FileSystems
   if os.path.exists(UpperCAmelCase	):
      if force_download:
         logger.info(F"""Local path already exist: {remote_file_path}. Overwriting it as force_upload=True."""	)
      else:
         logger.info(F"""Local path already exist: {remote_file_path}. Skipping it as force_upload=False."""	)
         return
   with fs.open(UpperCAmelCase	) as remote_file:
      with open(UpperCAmelCase			,'wb'	) as local_file:
         A__         =    remote_file.read(UpperCAmelCase	)
         while chunk:
            local_file.write(UpperCAmelCase	)
            A__         =    remote_file.read(UpperCAmelCase	)


