




import argparse
import os
import re

import packaging.version


lowerCAmelCase_						=			"examples/"
lowerCAmelCase_						=			{
    "examples": (re.compile(R'^check_min_version\(\"[^\"]+\"\)\s*$', re.MULTILINE), "check_min_version(\"VERSION\")\n"),
    "init": (re.compile(R'^__version__\s+=\s+\"([^\"]+)\"\s*$', re.MULTILINE), "__version__ = \"VERSION\"\n"),
    "setup": (re.compile(R'^(\s*)version\s*=\s*\"[^\"]+\",', re.MULTILINE), R"\1version=\"VERSION\","),
    "doc": (re.compile(R'^(\s*)release\s*=\s*\"[^\"]+\"$', re.MULTILINE), "release = \"VERSION\"\n"),
}
lowerCAmelCase_						=			{
    "init": "src/transformers/__init__.py",
    "setup": "setup.py",
}
lowerCAmelCase_						=			"README.md"






def  snake_case(    __magic_name__			,		__magic_name__			,		__magic_name__   )			->							Optional[Any]:





     '''simple docstring'''


     with open(lowerCAmelCase__			,		'''r'''			,		encoding='''utf-8'''			,		newline='''\n'''   ) as f:
          lowercase :       List[Any]       =			f.read()
     lowercase      ,	lowercase :       List[Any]       =			REPLACE_PATTERNS[pattern]
     lowercase :       str       =			replace.replace('''VERSION'''			,		lowerCAmelCase__   )
     lowercase :       List[str]       =			re_pattern.sub(lowerCAmelCase__			,		lowerCAmelCase__   )
     with open(lowerCAmelCase__			,		'''w'''			,		encoding='''utf-8'''			,		newline='''\n'''   ) as f:
          f.write(lowerCAmelCase__   )






def  snake_case(    __magic_name__   )			->							Optional[Any]:





     '''simple docstring'''


     for folder, directories, fnames in os.walk(lowerCAmelCase__   ):
          # Removing some of the folders with non-actively maintained examples from the walk
          if "research_projects" in directories:
               directories.remove('''research_projects'''   )
          if "legacy" in directories:
               directories.remove('''legacy'''   )
          for fname in fnames:
               if fname.endswith('''.py'''   ):
                    update_version_in_file(os.path.join(lowerCAmelCase__			,		lowerCAmelCase__   )			,		lowerCAmelCase__			,		pattern='''examples'''   )






def  snake_case(    __magic_name__			,		__magic_name__=False   )			->							List[Any]:





     '''simple docstring'''


     for pattern, fname in REPLACE_FILES.items():
          update_version_in_file(lowerCAmelCase__			,		lowerCAmelCase__			,		lowerCAmelCase__   )
     if not patch:
          update_version_in_examples(lowerCAmelCase__   )






def  snake_case(    )			->							str:





     '''simple docstring'''


     lowercase :       Any       =			'''🤗 Transformers currently provides the following architectures'''
     lowercase :       Tuple       =			'''1. Want to contribute a new model?'''
     with open(lowerCAmelCase__			,		'''r'''			,		encoding='''utf-8'''			,		newline='''\n'''   ) as f:
          lowercase :       Optional[int]       =			f.readlines()

     # Find the start of the list.
     lowercase :       Tuple       =			0
     while not lines[start_index].startswith(_start_prompt   ):
          start_index += 1
     start_index += 1

     lowercase :       List[Any]       =			start_index
     # Update the lines in the model list.
     while not lines[index].startswith(_end_prompt   ):
          if lines[index].startswith('''1.'''   ):
               lowercase :       str       =			lines[index].replace(
                   '''https://huggingface.co/docs/transformers/main/model_doc'''			,		'''https://huggingface.co/docs/transformers/model_doc'''			,		)
          index += 1

     with open(lowerCAmelCase__			,		'''w'''			,		encoding='''utf-8'''			,		newline='''\n'''   ) as f:
          f.writelines(lowerCAmelCase__   )






def  snake_case(    )			->							Optional[int]:





     '''simple docstring'''


     with open(REPLACE_FILES['''init''']			,		'''r'''   ) as f:
          lowercase :       str       =			f.read()
     lowercase :       Union[str, Any]       =			REPLACE_PATTERNS['''init'''][0].search(lowerCAmelCase__   ).groups()[0]
     return packaging.version.parse(lowerCAmelCase__   )






def  snake_case(    __magic_name__=False   )			->							Any:





     '''simple docstring'''


     lowercase :       int       =			get_version()
     if patch and default_version.is_devrelease:
          raise ValueError('''Can\'t create a patch version from the dev branch, checkout a released version!'''   )
     if default_version.is_devrelease:
          lowercase :       List[Any]       =			default_version.base_version
     elif patch:
          lowercase :       Tuple       =			F"""{default_version.major}.{default_version.minor}.{default_version.micro + 1}"""
     else:
          lowercase :       Tuple       =			F"""{default_version.major}.{default_version.minor + 1}.0"""

     # Now let's ask nicely if that's the right one.
     lowercase :       Union[str, Any]       =			input(F"""Which version are you releasing? [{default_version}]"""   )
     if len(lowerCAmelCase__   ) == 0:
          lowercase :       Tuple       =			default_version

     print(F"""Updating version to {version}."""   )
     global_version_update(lowerCAmelCase__			,		patch=lowerCAmelCase__   )
     if not patch:
          print('''Cleaning main README, don\'t forget to run `make fix-copies`.'''   )
          clean_main_ref_in_model_list()






def  snake_case(    )			->							Optional[Any]:





     '''simple docstring'''


     lowercase :       Optional[int]       =			get_version()
     lowercase :       Dict       =			F"""{current_version.major}.{current_version.minor + 1}.0.dev0"""
     lowercase :       Optional[Any]       =			current_version.base_version

     # Check with the user we got that right.
     lowercase :       int       =			input(F"""Which version are we developing now? [{dev_version}]"""   )
     if len(lowerCAmelCase__   ) == 0:
          lowercase :       Any       =			dev_version

     print(F"""Updating version to {version}."""   )
     global_version_update(lowerCAmelCase__   )
     print('''Cleaning main README, don\'t forget to run `make fix-copies`.'''   )
     clean_main_ref_in_model_list()


if __name__ == "__main__":
 lowerCAmelCase_						=			argparse.ArgumentParser()
 parser.add_argument('--post_release', action='store_true', help='Whether this is pre or post release.')
 parser.add_argument('--patch', action='store_true', help='Whether or not this is a patch release.')
 lowerCAmelCase_						=			parser.parse_args()
 if not args.post_release:
  pre_release_work(patch=args.patch)
 elif args.patch:
  print('Nothing to do after a patch :-)')
 else:
  post_release_work()





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,
)


lowerCAmelCase_						=			'\\n    Text data.\n    Second line of data.'

lowerCAmelCase_						=			'file'






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





     '''simple docstring'''


     lowercase :       Any       =			tmp_path_factory.mktemp('''data'''   ) / (FILE_PATH + '''.zstd''')
     lowercase :       List[Any]       =			bytes(__magic_name__			,		'''utf-8'''   )
     with zstd.open(__magic_name__			,		'''wb'''   ) as f:
          f.write(__magic_name__   )
     return path






@pytest.fixture
def  snake_case(    __magic_name__   )			->							List[Any]:





     '''simple docstring'''


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






@pytest.mark.parametrize('''compression_format'''			,		['''gzip''', '''xz''', '''zstd''']   )
def  snake_case(    __magic_name__			,		__magic_name__			,		__magic_name__			,		__magic_name__			,		__magic_name__			,		__magic_name__   )			->							List[str]:





     '''simple docstring'''


     lowercase :       Optional[int]       =			{'''gzip''': gz_file, '''xz''': xz_file, '''zstd''': zstd_path}
     lowercase :       int       =			input_paths[compression_format]
     lowercase :       Any       =			tmp_path / '''cache'''
     lowercase :       int       =			DownloadConfig(cache_dir=__magic_name__			,		extract_compressed_file=__magic_name__   )
     lowercase :       Optional[Any]       =			cached_path(__magic_name__			,		download_config=__magic_name__   )
     with open(__magic_name__   ) as f:
          lowercase :       Optional[int]       =			f.read()
     with open(__magic_name__   ) as f:
          lowercase :       str       =			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  snake_case(    __magic_name__			,		__magic_name__			,		__magic_name__			,		__magic_name__			,		__magic_name__   )			->							List[str]:





     '''simple docstring'''


     lowercase :       Dict       =			'''custom_cache'''
     lowercase :       Union[str, Any]       =			'''custom_extracted_dir'''
     lowercase :       str       =			tmp_path / '''custom_extracted_path'''
     if default_extracted:
          lowercase :       Tuple       =			('''downloads''' if default_cache_dir else custom_cache_dir, '''extracted''')
     else:
          monkeypatch.setattr('''datasets.config.EXTRACTED_DATASETS_DIR'''			,		__magic_name__   )
          monkeypatch.setattr('''datasets.config.EXTRACTED_DATASETS_PATH'''			,		str(__magic_name__   )   )
          lowercase :       int       =			custom_extracted_path.parts[-2:] if default_cache_dir else (custom_cache_dir, custom_extracted_dir)

     lowercase :       List[str]       =			xz_file
     lowercase :       Any       =			(
         DownloadConfig(extract_compressed_file=__magic_name__   )
         if default_cache_dir
         else DownloadConfig(cache_dir=tmp_path / custom_cache_dir			,		extract_compressed_file=__magic_name__   )
     )
     lowercase :       Optional[int]       =			cached_path(__magic_name__			,		download_config=__magic_name__   )
     assert Path(__magic_name__   ).parent.parts[-2:] == expected






def  snake_case(    __magic_name__   )			->							List[Any]:





     '''simple docstring'''


     lowercase :       Any       =			str(Path(__magic_name__   ).resolve()   )
     assert cached_path(__magic_name__   ) == text_file
     # relative path
     lowercase :       Union[str, Any]       =			str(Path(__magic_name__   ).resolve().relative_to(Path(os.getcwd()   )   )   )
     assert cached_path(__magic_name__   ) == text_file






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





     '''simple docstring'''


     lowercase :       List[Any]       =			str(tmp_path.resolve() / '''__missing_file__.txt'''   )
     with pytest.raises(__magic_name__   ):
          cached_path(__magic_name__   )
     # relative path
     lowercase :       Optional[int]       =			'''./__missing_file__.txt'''
     with pytest.raises(__magic_name__   ):
          cached_path(__magic_name__   )






def  snake_case(    __magic_name__   )			->							List[str]:





     '''simple docstring'''


     lowercase :       List[str]       =			get_from_cache(F"""tmp://{tmpfs_file}"""   )
     with open(__magic_name__   ) as f:
          lowercase :       List[Any]       =			f.read()
     assert output_file_content == FILE_CONTENT






@patch('''datasets.config.HF_DATASETS_OFFLINE'''			,		__magic_name__   )
def  snake_case(    )			->							List[Any]:





     '''simple docstring'''


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






@patch('''datasets.config.HF_DATASETS_OFFLINE'''			,		__magic_name__   )
def  snake_case(    __magic_name__   )			->							Tuple:





     '''simple docstring'''


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






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





     '''simple docstring'''


     lowercase :       Optional[Any]       =			tmp_path_factory.mktemp('''data'''   ) / '''file.html'''
     with pytest.raises(__magic_name__   ):
          ftp_get('''ftp://huggingface.co'''			,		temp_file=__magic_name__   )
     with pytest.raises(__magic_name__   ):
          ftp_head('''ftp://huggingface.co'''   )






@patch('''datasets.config.HF_DATASETS_OFFLINE'''			,		__magic_name__   )
def  snake_case(    __magic_name__   )			->							List[str]:





     '''simple docstring'''


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