



'''simple docstring'''



import argparse
import os
import re

import packaging.version


a__  :	Any								=	"""examples/"""
a__  :	Optional[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"""),
}
a__  :	int								=	{
    """init""": """src/transformers/__init__.py""",
    """setup""": """setup.py""",
}
a__  :	Tuple								=	"""README.md"""







def _lowercase      (     __A							,__A							,__A				):



 '''simple docstring'''



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







def _lowercase      (     __A				):



 '''simple docstring'''



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







def _lowercase      (     __A							,__A=False				):



 '''simple docstring'''



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







def _lowercase      (     ):



 '''simple docstring'''



 __UpperCamelCase 					=     '🤗 Transformers currently provides the following architectures'
 __UpperCamelCase 					=     '1. Want to contribute a new model?'
 with open(UpperCAmelCase_							,"""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(UpperCAmelCase_							,"""w"""							,encoding="""utf-8"""							,newline="""\n"""				) as f:
  f.writelines(UpperCAmelCase_				)







def _lowercase      (     ):



 '''simple docstring'''



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







def _lowercase      (     __A=False				):



 '''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(UpperCAmelCase_				) == 0:
  __UpperCamelCase 					=     default_version

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







def _lowercase      (     ):



 '''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(UpperCAmelCase_				) == 0:
  __UpperCamelCase 					=     dev_version

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


if __name__ == "__main__":
 a__  :	Optional[Any]								=	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.')
 a__  :	Any								=	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'''



A__		:					Optional[int]												=  """ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"""



def 			UpperCAmelCase__					(	UpperCAmelCase_    :				bytes							)     ->		bytes:
     # Make sure the supplied data is a bytes-like object
     if not isinstance(UpperCAmelCase_      ,    UpperCAmelCase_							):
          __lowerCamelCase   :	Dict								=		F'a bytes-like object is required, not \'{data.__class__.__name__}\''
          raise TypeError(UpperCAmelCase_							)

     __lowerCamelCase   :	Optional[int]								=		''.join(bin(UpperCAmelCase_							)[2:].zfill(8							) for byte in data							)

     __lowerCamelCase   :	Any								=		len(UpperCAmelCase_							) % 6 != 0

     if padding_needed:
          # The padding that will be added later
          __lowerCamelCase   :	int								=		B'=' * ((6 - len(UpperCAmelCase_							) % 6) // 2)

          # Append binary_stream with arbitrary binary digits (0's by default) to make its
          # length a multiple of 6.
          binary_stream += "0" * (6 - len(UpperCAmelCase_							) % 6)
     else:
          __lowerCamelCase   :	str								=		B''

     # Encode every 6 binary digits to their corresponding Base64 character
     return (
         "".join(
             B64_CHARSET[int(binary_stream[index : index + 6]      ,    2							)]
             for index in range(0      ,    len(UpperCAmelCase_							)      ,    6							)							).encode()
         + padding
     )



def 			UpperCAmelCase__					(	UpperCAmelCase_    :				str							)     ->		bytes:
     # Make sure encoded_data is either a string or a bytes-like object
     if not isinstance(UpperCAmelCase_      ,    UpperCAmelCase_							) and not isinstance(UpperCAmelCase_      ,    UpperCAmelCase_							):
          __lowerCamelCase   :	Dict								=		(
              'argument should be a bytes-like object or ASCII string, '
              F'not \'{encoded_data.__class__.__name__}\''
          )
          raise TypeError(UpperCAmelCase_							)

     # In case encoded_data is a bytes-like object, make sure it contains only
     # ASCII characters so we convert it to a string object
     if isinstance(UpperCAmelCase_      ,    UpperCAmelCase_							):
          try:
               __lowerCamelCase   :	int								=		encoded_data.decode('utf-8'							)
          except UnicodeDecodeError:
               raise ValueError('base64 encoded data should only contain ASCII characters'							)

     __lowerCamelCase   :	Union[str, Any]								=		encoded_data.count('='							)

     # Check if the encoded string contains non base64 characters
     if padding:
          assert all(
              char in B64_CHARSET for char in encoded_data[:-padding]							), "Invalid base64 character(s) found."
     else:
          assert all(
              char in B64_CHARSET for char in encoded_data							), "Invalid base64 character(s) found."

     # Check the padding
     assert len(UpperCAmelCase_							) % 4 == 0 and padding < 3, "Incorrect padding"

     if padding:
          # Remove padding if there is one
          __lowerCamelCase   :	Any								=		encoded_data[:-padding]

          __lowerCamelCase   :	Optional[Any]								=		''.join(
              bin(B64_CHARSET.index(UpperCAmelCase_							)							)[2:].zfill(6							) for char in encoded_data							)[: -padding * 2]
     else:
          __lowerCamelCase   :	Any								=		''.join(
              bin(B64_CHARSET.index(UpperCAmelCase_							)							)[2:].zfill(6							) for char in encoded_data							)

     __lowerCamelCase   :	str								=		[
         int(binary_stream[index : index + 8]      ,    2							)
         for index in range(0      ,    len(UpperCAmelCase_							)      ,    8							)
     ]

     return bytes(UpperCAmelCase_							)


if __name__ == "__main__":
      import doctest

      doctest.testmod()






