




import argparse
import os
import re

import packaging.version


snake_case_ : List[str]    		=       'examples/'
snake_case_ : int    		=       {
    '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'),
}
snake_case_ : List[Any]    		=       {
    'init': 'src/transformers/__init__.py',
    'setup': 'setup.py',
}
snake_case_ : Any    		=       'README.md'


def    A						(__A   :    Optional[Any]   ,				__A   :    List[str]   ,				__A   :    str       )   ->      Optional[int]:







     """simple docstring"""


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


def    A						(__A   :    Optional[int]       )   ->      Optional[int]:







     """simple docstring"""


     for folder, directories, fnames in os.walk(__snake_case       ):
          # 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(__snake_case   ,				__snake_case       )   ,				__snake_case   ,				pattern='''examples'''       )


def    A						(__A   :    Optional[Any]   ,				__A   :    Union[str, Any]=False       )   ->      List[Any]:







     """simple docstring"""


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


def    A						()   ->      str:







     """simple docstring"""


     UpperCAmelCase_          =							"🤗 Transformers currently provides the following architectures"
     UpperCAmelCase_          =							"1. Want to contribute a new model?"
     with open(__snake_case   ,				'''r'''   ,				encoding='''utf-8'''   ,				newline='''\n'''       ) as f:
          UpperCAmelCase_          =							f.readlines()

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

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

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


def    A						()   ->      List[Any]:







     """simple docstring"""


     with open(REPLACE_FILES['''init''']   ,				'''r'''       ) as f:
          UpperCAmelCase_          =							f.read()
     UpperCAmelCase_          =							REPLACE_PATTERNS["init"][0].search(__snake_case       ).groups()[0]
     return packaging.version.parse(__snake_case       )


def    A						(__A   :    Optional[Any]=False       )   ->      int:







     """simple docstring"""


     UpperCAmelCase_          =							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:
          UpperCAmelCase_          =							default_version.base_version
     elif patch:
          UpperCAmelCase_          =							F"""{default_version.major}.{default_version.minor}.{default_version.micro + 1}"""
     else:
          UpperCAmelCase_          =							F"""{default_version.major}.{default_version.minor + 1}.0"""

     # Now let's ask nicely if that's the right one.
     UpperCAmelCase_          =							input(F"""Which version are you releasing? [{default_version}]"""       )
     if len(__snake_case       ) == 0:
          UpperCAmelCase_          =							default_version

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


def    A						()   ->      List[str]:







     """simple docstring"""


     UpperCAmelCase_          =							get_version()
     UpperCAmelCase_          =							F"""{current_version.major}.{current_version.minor + 1}.0.dev0"""
     UpperCAmelCase_          =							current_version.base_version

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

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


if __name__ == "__main__":
    snake_case_ : Tuple    		=       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.")
    snake_case_ : List[str]    		=       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()











"""simple docstring"""






import re
from pathlib import Path
from unittest import TestCase

import pytest



@pytest.mark.integration
class 			A__   (  __SCREAMING_SNAKE_CASE							):




	'''simple docstring'''





	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[int]       ,			_SCREAMING_SNAKE_CASE:		str)				->       Dict:

				"""simple docstring"""

				with open(_SCREAMING_SNAKE_CASE       ,			encoding="utf-8") as input_file:
							__lowerCAmelCase      :  List[str]												=       re.compile(r"(?!.*\b(?:encoding|rb|w|wb|w+|wb+|ab|ab+)\b)(?<=\s)(open)\((.*)\)")
							__lowerCAmelCase      :  List[Any]												=       input_file.read()
							__lowerCAmelCase      :  Any												=       regexp.search(_SCREAMING_SNAKE_CASE)

				return match

	def 							_SCREAMING_SNAKE_CASE   (     self:		List[Any]       ,			_SCREAMING_SNAKE_CASE:		str)				->       Optional[Any]:

				"""simple docstring"""

				with open(_SCREAMING_SNAKE_CASE       ,			encoding="utf-8") as input_file:
							__lowerCAmelCase      :  Any												=       re.compile(r"#[^\r\n]*print\(|\"[^\r\n]*print\(|\"\"\".*?print\(.*?\"\"\"|(print\()"       ,			re.DOTALL)
							__lowerCAmelCase      :  Optional[int]												=       input_file.read()
							# use `re.finditer` to handle the case where the ignored groups would be matched first by `re.search`
							__lowerCAmelCase      :  int												=       regexp.finditer(_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase      :  Union[str, Any]												=       [match for match in matches if match is not None and match.group(1) is not None]
				return matches[0] if matches else None

	def 							_SCREAMING_SNAKE_CASE   (     self:		str)				->       List[Any]:

				"""simple docstring"""

				__lowerCAmelCase      :  Optional[Any]												=       Path("./datasets")
				__lowerCAmelCase      :  Optional[int]												=       list(dataset_paths.absolute().glob("**/*.py"))

				for dataset in dataset_files:
							if self._no_encoding_on_file_open(str(_SCREAMING_SNAKE_CASE)):
										raise AssertionError(F"""open(...) must use utf-8 encoding in {dataset}""")







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

				"""simple docstring"""

				__lowerCAmelCase      :  Dict												=       Path("./datasets")
				__lowerCAmelCase      :  Union[str, Any]												=       list(dataset_paths.absolute().glob("**/*.py"))

				for dataset in dataset_files:
							if self._no_print_statements(str(_SCREAMING_SNAKE_CASE)):
										raise AssertionError(F"""print statement found in {dataset}. Use datasets.logger/logging instead.""")