






"""simple docstring"""







import argparse
import os
import re

import packaging.version


lowerCAmelCase_	:    Tuple            =      '''examples/'''
lowerCAmelCase_	:    str            =      {
    '''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_	:    Dict            =      {
    '''init''': '''src/transformers/__init__.py''',
    '''setup''': '''setup.py''',
}
lowerCAmelCase_	:    Tuple            =      '''README.md'''






def       _lowerCAmelCase       (      lowerCAmelCase	,      lowerCAmelCase	,      lowerCAmelCase		):







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






def       _lowerCAmelCase       (      lowerCAmelCase		):







       '''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       _lowerCAmelCase       (      lowerCAmelCase	,      lowerCAmelCase=False		):







       '''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       _lowerCAmelCase       (      ):







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






def       _lowerCAmelCase       (      ):







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






def       _lowerCAmelCase       (      lowerCAmelCase=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(lowerCAmelCase		) == 0:
              UpperCAmelCase	    =			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       _lowerCAmelCase       (      ):







       '''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(lowerCAmelCase		) == 0:
              UpperCAmelCase	    =			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_	:    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.''')
 lowerCAmelCase_	:    Optional[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"""







def       _lowerCAmelCase       (      lowerCAmelCase		):







       '''simple docstring'''
       UpperCAmelCase	    =			0
       UpperCAmelCase	    =			len(lowerCAmelCase		)

       for i in range(n - 1		):
              for j in range(i + 1	,      lowerCAmelCase		):
                     if arr[i] > arr[j]:
                            num_inversions += 1

       return num_inversions






def       _lowerCAmelCase       (      lowerCAmelCase		):







       '''simple docstring'''
       if len(lowerCAmelCase		) <= 1:
              return arr, 0
       UpperCAmelCase	    =			len(lowerCAmelCase		) // 2
       UpperCAmelCase	    =			arr[0:mid]
       UpperCAmelCase	    =			arr[mid:]

       UpperCAmelCase    ,       UpperCAmelCase	    =			count_inversions_recursive(lowerCAmelCase		)
       UpperCAmelCase    ,       UpperCAmelCase	    =			count_inversions_recursive(lowerCAmelCase		)
       UpperCAmelCase    ,       UpperCAmelCase	    =			_count_cross_inversions(lowerCAmelCase	,      lowerCAmelCase		)

       UpperCAmelCase	    =			inversion_p + inversions_q + cross_inversions
       return c, num_inversions






def       _lowerCAmelCase       (      lowerCAmelCase	,      lowerCAmelCase		):







       '''simple docstring'''
       UpperCAmelCase	    =			[]
       UpperCAmelCase	    =			UpperCAmelCase	    =			UpperCAmelCase	    =			0
       while i < len(lowerCAmelCase		) and j < len(lowerCAmelCase		):
              if p[i] > q[j]:
                     # if P[1] > Q[j], then P[k] > Q[k] for all  i < k <= len(P)
                     # These are all inversions. The claim emerges from the
                     # property that P is sorted.
                     num_inversion += len(lowerCAmelCase		) - i
                     r.append(q[j]		)
                     j += 1
              else:
                     r.append(p[i]		)
                     i += 1

       if i < len(lowerCAmelCase		):
              r.extend(p[i:]		)
       else:
              r.extend(q[j:]		)

       return r, num_inversion






def       _lowerCAmelCase       (      ):







       '''simple docstring'''
       UpperCAmelCase	    =			[10, 2, 1, 5, 5, 2, 11]

       # this arr has 8 inversions:
       # (10, 2), (10, 1), (10, 5), (10, 5), (10, 2), (2, 1), (5, 2), (5, 2)

       UpperCAmelCase	    =			count_inversions_bf(lowerCAmelCase		)
       UpperCAmelCase    ,       UpperCAmelCase	    =			count_inversions_recursive(lowerCAmelCase		)

       assert num_inversions_bf == num_inversions_recursive == 8

       print("""number of inversions = """	,      lowerCAmelCase		)

       # testing an array with zero inversion (a sorted arr_1)

       arr_a.sort()
       UpperCAmelCase	    =			count_inversions_bf(lowerCAmelCase		)
       UpperCAmelCase    ,       UpperCAmelCase	    =			count_inversions_recursive(lowerCAmelCase		)

       assert num_inversions_bf == num_inversions_recursive == 0
       print("""number of inversions = """	,      lowerCAmelCase		)

       # an empty list should also have zero inversions
       UpperCAmelCase	    =			[]
       UpperCAmelCase	    =			count_inversions_bf(lowerCAmelCase		)
       UpperCAmelCase    ,       UpperCAmelCase	    =			count_inversions_recursive(lowerCAmelCase		)

       assert num_inversions_bf == num_inversions_recursive == 0
       print("""number of inversions = """	,      lowerCAmelCase		)


if __name__ == "__main__":
 main()
