





'''simple docstring'''


from collections import deque
from math import floor
from random import random
from time import time






class       UpperCamelCase__  :







 def __init__(				self			:   str		):




    '''simple docstring'''
    a__     = {}







 def 						__a   (				self			:   int , lowerCamelCase			:   List[str] , lowerCamelCase			:   Tuple , lowerCamelCase			:   Optional[int]=1		):




    '''simple docstring'''
    if self.graph.get(lowerCamelCase		):
       if self.graph[u].count([w, v]		) == 0:
          self.graph[u].append([w, v]		)
    else:
       a__     = [[w, v]]
    if not self.graph.get(lowerCamelCase		):
       a__     = []







 def 						__a   (				self			:   int		):




    '''simple docstring'''
    return list(self.graph		)







 def 						__a   (				self			:   Any , lowerCamelCase			:   Tuple , lowerCamelCase			:   List[str]		):




    '''simple docstring'''
    if self.graph.get(lowerCamelCase		):
       for _ in self.graph[u]:
          if _[1] == v:
             self.graph[u].remove(lowerCamelCase		)







 def 						__a   (				self			:   Any , lowerCamelCase			:   Optional[Any]=-2 , lowerCamelCase			:   int=-1		):




    '''simple docstring'''
    if s == d:
       return []
    a__     = []
    a__     = []
    if s == -2:
       a__     = list(self.graph		)[0]
    stack.append(lowerCamelCase		)
    visited.append(lowerCamelCase		)
    a__     = s

    while True:
       # check if there is any non isolated nodes
       if len(self.graph[s]		) != 0:
          a__     = s
          for node in self.graph[s]:
             if visited.count(node[1]		) < 1:
                if node[1] == d:
                   visited.append(lowerCamelCase		)
                   return visited
                else:
                   stack.append(node[1]		)
                   visited.append(node[1]		)
                   a__     = node[1]
                   break

            # check if all the children are visited
       if s == ss:
          stack.pop()
          if len(lowerCamelCase		) != 0:
             a__     = stack[len(lowerCamelCase		) - 1]
       else:
          a__     = ss

       # check if se have reached the starting point
       if len(lowerCamelCase		) == 0:
          return visited







 def 						__a   (				self			:   Union[str, Any] , lowerCamelCase			:   Optional[Any]=-1		):




    '''simple docstring'''
    if c == -1:
       a__     = floor(random() * 1_0_0_0_0		) + 1_0
    for i in range(lowerCamelCase		):
       # every vertex has max 100 edges
       for _ in range(floor(random() * 1_0_2		) + 1		):
          a__     = floor(random() * c		) + 1
          if n != i:
             self.add_pair(lowerCamelCase , lowerCamelCase , 1		)







 def 						__a   (				self			:   Optional[Any] , lowerCamelCase			:   Optional[int]=-2		):




    '''simple docstring'''
    a__     = deque()
    a__     = []
    if s == -2:
       a__     = list(self.graph		)[0]
    d.append(lowerCamelCase		)
    visited.append(lowerCamelCase		)
    while d:
       a__     = d.popleft()
       if len(self.graph[s]		) != 0:
          for node in self.graph[s]:
             if visited.count(node[1]		) < 1:
                d.append(node[1]		)
                visited.append(node[1]		)
    return visited







 def 						__a   (				self			:   Any , lowerCamelCase			:   Tuple		):




    '''simple docstring'''
    a__     = 0
    for x in self.graph:
       for y in self.graph[x]:
          if y[1] == u:
             count += 1
    return count







 def 						__a   (				self			:   Union[str, Any] , lowerCamelCase			:   Union[str, Any]		):




    '''simple docstring'''
    return len(self.graph[u]		)







 def 						__a   (				self			:   str , lowerCamelCase			:   int=-2		):




    '''simple docstring'''
    a__     = []
    a__     = []
    if s == -2:
       a__     = list(self.graph		)[0]
    stack.append(lowerCamelCase		)
    visited.append(lowerCamelCase		)
    a__     = s
    a__     = []

    while True:
       # check if there is any non isolated nodes
       if len(self.graph[s]		) != 0:
          a__     = s
          for node in self.graph[s]:
             if visited.count(node[1]		) < 1:
                stack.append(node[1]		)
                visited.append(node[1]		)
                a__     = node[1]
                break

            # check if all the children are visited
       if s == ss:
          sorted_nodes.append(stack.pop()		)
          if len(lowerCamelCase		) != 0:
             a__     = stack[len(lowerCamelCase		) - 1]
       else:
          a__     = ss

       # check if se have reached the starting point
       if len(lowerCamelCase		) == 0:
          return sorted_nodes







 def 						__a   (				self			:   Dict		):




    '''simple docstring'''
    a__     = []
    a__     = []
    a__     = list(self.graph		)[0]
    stack.append(lowerCamelCase		)
    visited.append(lowerCamelCase		)
    a__     = -2
    a__     = []
    a__     = s
    a__     = False
    a__     = set()

    while True:
       # check if there is any non isolated nodes
       if len(self.graph[s]		) != 0:
          a__     = s
          for node in self.graph[s]:
             if (
                 visited.count(node[1]		) > 0
                 and node[1] != parent
                 and indirect_parents.count(node[1]		) > 0
                 and not on_the_way_back
             ):
                a__     = len(lowerCamelCase		) - 1
                while len_stack >= 0:
                   if stack[len_stack] == node[1]:
                      anticipating_nodes.add(node[1]		)
                      break
                   else:
                      anticipating_nodes.add(stack[len_stack]		)
                      len_stack -= 1
             if visited.count(node[1]		) < 1:
                stack.append(node[1]		)
                visited.append(node[1]		)
                a__     = node[1]
                break

            # check if all the children are visited
       if s == ss:
          stack.pop()
          a__     = True
          if len(lowerCamelCase		) != 0:
             a__     = stack[len(lowerCamelCase		) - 1]
       else:
          a__     = False
          indirect_parents.append(lowerCamelCase		)
          a__     = s
          a__     = ss

       # check if se have reached the starting point
       if len(lowerCamelCase		) == 0:
          return list(lowerCamelCase		)







 def 						__a   (				self			:   Union[str, Any]		):




    '''simple docstring'''
    a__     = []
    a__     = []
    a__     = list(self.graph		)[0]
    stack.append(lowerCamelCase		)
    visited.append(lowerCamelCase		)
    a__     = -2
    a__     = []
    a__     = s
    a__     = False
    a__     = set()

    while True:
       # check if there is any non isolated nodes
       if len(self.graph[s]		) != 0:
          a__     = s
          for node in self.graph[s]:
             if (
                 visited.count(node[1]		) > 0
                 and node[1] != parent
                 and indirect_parents.count(node[1]		) > 0
                 and not on_the_way_back
             ):
                a__     = len(lowerCamelCase		) - 1
                while len_stack_minus_one >= 0:
                   if stack[len_stack_minus_one] == node[1]:
                      anticipating_nodes.add(node[1]		)
                      break
                   else:
                      return True
             if visited.count(node[1]		) < 1:
                stack.append(node[1]		)
                visited.append(node[1]		)
                a__     = node[1]
                break

            # check if all the children are visited
       if s == ss:
          stack.pop()
          a__     = True
          if len(lowerCamelCase		) != 0:
             a__     = stack[len(lowerCamelCase		) - 1]
       else:
          a__     = False
          indirect_parents.append(lowerCamelCase		)
          a__     = s
          a__     = ss

       # check if se have reached the starting point
       if len(lowerCamelCase		) == 0:
          return False







 def 						__a   (				self			:   Union[str, Any] , lowerCamelCase			:   int=-2 , lowerCamelCase			:   Tuple=-1		):




    '''simple docstring'''
    a__     = time()
    self.dfs(lowerCamelCase , lowerCamelCase		)
    a__     = time()
    return end - begin







 def 						__a   (				self			:   str , lowerCamelCase			:   str=-2		):




    '''simple docstring'''
    a__     = time()
    self.bfs(lowerCamelCase		)
    a__     = time()
    return end - begin






class       UpperCamelCase__  :







 def __init__(				self			:   Optional[int]		):




    '''simple docstring'''
    a__     = {}







 def 						__a   (				self			:   Optional[int] , lowerCamelCase			:   str , lowerCamelCase			:   Any , lowerCamelCase			:   List[str]=1		):




    '''simple docstring'''
    # check if the u exists
    if self.graph.get(lowerCamelCase		):
       # if there already is a edge
       if self.graph[u].count([w, v]		) == 0:
          self.graph[u].append([w, v]		)
    else:
       # if u does not exist
       a__     = [[w, v]]
    # add the other way
    if self.graph.get(lowerCamelCase		):
       # if there already is a edge
       if self.graph[v].count([w, u]		) == 0:
          self.graph[v].append([w, u]		)
    else:
       # if u does not exist
       a__     = [[w, u]]







 def 						__a   (				self			:   Optional[Any] , lowerCamelCase			:   Any , lowerCamelCase			:   List[Any]		):




    '''simple docstring'''
    if self.graph.get(lowerCamelCase		):
       for _ in self.graph[u]:
          if _[1] == v:
             self.graph[u].remove(lowerCamelCase		)
        # the other way round
    if self.graph.get(lowerCamelCase		):
       for _ in self.graph[v]:
          if _[1] == u:
             self.graph[v].remove(lowerCamelCase		)







 def 						__a   (				self			:   str , lowerCamelCase			:   str=-2 , lowerCamelCase			:   Union[str, Any]=-1		):




    '''simple docstring'''
    if s == d:
       return []
    a__     = []
    a__     = []
    if s == -2:
       a__     = list(self.graph		)[0]
    stack.append(lowerCamelCase		)
    visited.append(lowerCamelCase		)
    a__     = s

    while True:
       # check if there is any non isolated nodes
       if len(self.graph[s]		) != 0:
          a__     = s
          for node in self.graph[s]:
             if visited.count(node[1]		) < 1:
                if node[1] == d:
                   visited.append(lowerCamelCase		)
                   return visited
                else:
                   stack.append(node[1]		)
                   visited.append(node[1]		)
                   a__     = node[1]
                   break

            # check if all the children are visited
       if s == ss:
          stack.pop()
          if len(lowerCamelCase		) != 0:
             a__     = stack[len(lowerCamelCase		) - 1]
       else:
          a__     = ss

       # check if se have reached the starting point
       if len(lowerCamelCase		) == 0:
          return visited







 def 						__a   (				self			:   List[Any] , lowerCamelCase			:   Optional[int]=-1		):




    '''simple docstring'''
    if c == -1:
       a__     = floor(random() * 1_0_0_0_0		) + 1_0
    for i in range(lowerCamelCase		):
       # every vertex has max 100 edges
       for _ in range(floor(random() * 1_0_2		) + 1		):
          a__     = floor(random() * c		) + 1
          if n != i:
             self.add_pair(lowerCamelCase , lowerCamelCase , 1		)







 def 						__a   (				self			:   Tuple , lowerCamelCase			:   List[str]=-2		):




    '''simple docstring'''
    a__     = deque()
    a__     = []
    if s == -2:
       a__     = list(self.graph		)[0]
    d.append(lowerCamelCase		)
    visited.append(lowerCamelCase		)
    while d:
       a__     = d.popleft()
       if len(self.graph[s]		) != 0:
          for node in self.graph[s]:
             if visited.count(node[1]		) < 1:
                d.append(node[1]		)
                visited.append(node[1]		)
    return visited







 def 						__a   (				self			:   str , lowerCamelCase			:   Dict		):




    '''simple docstring'''
    return len(self.graph[u]		)







 def 						__a   (				self			:   str		):




    '''simple docstring'''
    a__     = []
    a__     = []
    a__     = list(self.graph		)[0]
    stack.append(lowerCamelCase		)
    visited.append(lowerCamelCase		)
    a__     = -2
    a__     = []
    a__     = s
    a__     = False
    a__     = set()

    while True:
       # check if there is any non isolated nodes
       if len(self.graph[s]		) != 0:
          a__     = s
          for node in self.graph[s]:
             if (
                 visited.count(node[1]		) > 0
                 and node[1] != parent
                 and indirect_parents.count(node[1]		) > 0
                 and not on_the_way_back
             ):
                a__     = len(lowerCamelCase		) - 1
                while len_stack >= 0:
                   if stack[len_stack] == node[1]:
                      anticipating_nodes.add(node[1]		)
                      break
                   else:
                      anticipating_nodes.add(stack[len_stack]		)
                      len_stack -= 1
             if visited.count(node[1]		) < 1:
                stack.append(node[1]		)
                visited.append(node[1]		)
                a__     = node[1]
                break

            # check if all the children are visited
       if s == ss:
          stack.pop()
          a__     = True
          if len(lowerCamelCase		) != 0:
             a__     = stack[len(lowerCamelCase		) - 1]
       else:
          a__     = False
          indirect_parents.append(lowerCamelCase		)
          a__     = s
          a__     = ss

       # check if se have reached the starting point
       if len(lowerCamelCase		) == 0:
          return list(lowerCamelCase		)







 def 						__a   (				self			:   Optional[int]		):




    '''simple docstring'''
    a__     = []
    a__     = []
    a__     = list(self.graph		)[0]
    stack.append(lowerCamelCase		)
    visited.append(lowerCamelCase		)
    a__     = -2
    a__     = []
    a__     = s
    a__     = False
    a__     = set()

    while True:
       # check if there is any non isolated nodes
       if len(self.graph[s]		) != 0:
          a__     = s
          for node in self.graph[s]:
             if (
                 visited.count(node[1]		) > 0
                 and node[1] != parent
                 and indirect_parents.count(node[1]		) > 0
                 and not on_the_way_back
             ):
                a__     = len(lowerCamelCase		) - 1
                while len_stack_minus_one >= 0:
                   if stack[len_stack_minus_one] == node[1]:
                      anticipating_nodes.add(node[1]		)
                      break
                   else:
                      return True
             if visited.count(node[1]		) < 1:
                stack.append(node[1]		)
                visited.append(node[1]		)
                a__     = node[1]
                break

            # check if all the children are visited
       if s == ss:
          stack.pop()
          a__     = True
          if len(lowerCamelCase		) != 0:
             a__     = stack[len(lowerCamelCase		) - 1]
       else:
          a__     = False
          indirect_parents.append(lowerCamelCase		)
          a__     = s
          a__     = ss

       # check if se have reached the starting point
       if len(lowerCamelCase		) == 0:
          return False







 def 						__a   (				self			:   Optional[int]		):




    '''simple docstring'''
    return list(self.graph		)







 def 						__a   (				self			:   Optional[int] , lowerCamelCase			:   Union[str, Any]=-2 , lowerCamelCase			:   Tuple=-1		):




    '''simple docstring'''
    a__     = time()
    self.dfs(lowerCamelCase , lowerCamelCase		)
    a__     = time()
    return end - begin







 def 						__a   (				self			:   Dict , lowerCamelCase			:   Any=-2		):




    '''simple docstring'''
    a__     = time()
    self.bfs(lowerCamelCase		)
    a__     = time()
    return end - begin










'''simple docstring'''


import argparse
import os
import re

import packaging.version


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







def    _lowerCamelCase  (__lowerCamelCase  :     Dict					,  __lowerCamelCase  :     List[Any]					,  __lowerCamelCase  :     Optional[Any]     )   ->    str:
			with open(__lowerCamelCase					,  "r"					,  encoding="utf-8"					,  newline="\n"     ) as f:
						a__     = f.read()
			a__   ,				a__     = REPLACE_PATTERNS[pattern]
			a__     = replace.replace("VERSION"					,  __lowerCamelCase     )
			a__     = re_pattern.sub(__lowerCamelCase					,  __lowerCamelCase     )
			with open(__lowerCamelCase					,  "w"					,  encoding="utf-8"					,  newline="\n"     ) as f:
						f.write(__lowerCamelCase     )







def    _lowerCamelCase  (__lowerCamelCase  :     Union[str, Any]     )   ->    Dict:
			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  :     int					,  __lowerCamelCase  :     Any=False     )   ->    Optional[Any]:
			for pattern, fname in REPLACE_FILES.items():
						update_version_in_file(__lowerCamelCase					,  __lowerCamelCase					,  __lowerCamelCase     )
			if not patch:
						update_version_in_examples(__lowerCamelCase     )







def    _lowerCamelCase  ()   ->    Tuple:
			a__     = "🤗 Transformers currently provides the following architectures"
			a__     = "1. Want to contribute a new model?"
			with open(__lowerCamelCase					,  "r"					,  encoding="utf-8"					,  newline="\n"     ) as f:
						a__     = f.readlines()

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

			a__     = start_index
			# Update the lines in the model list.
			while not lines[index].startswith(_end_prompt     ):
						if lines[index].startswith("1."     ):
									a__     = 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  ()   ->    Tuple:
			with open(REPLACE_FILES["init"]					,  "r"     ) as f:
						a__     = f.read()
			a__     = REPLACE_PATTERNS["init"][0].search(__lowerCamelCase     ).groups()[0]
			return packaging.version.parse(__lowerCamelCase     )







def    _lowerCamelCase  (__lowerCamelCase  :     Any=False     )   ->    int:
			a__     = 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:
						a__     = default_version.base_version
			elif patch:
						a__     = f'''{default_version.major}.{default_version.minor}.{default_version.micro + 1}'''
			else:
						a__     = f'''{default_version.major}.{default_version.minor + 1}.0'''

			# Now let's ask nicely if that's the right one.
			a__     = input(f'''Which version are you releasing? [{default_version}]'''     )
			if len(__lowerCamelCase     ) == 0:
						a__     = 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  ()   ->    Tuple:
			a__     = get_version()
			a__     = f'''{current_version.major}.{current_version.minor + 1}.0.dev0'''
			a__     = current_version.base_version

			# Check with the user we got that right.
			a__     = input(f'''Which version are we developing now? [{dev_version}]'''     )
			if len(__lowerCamelCase     ) == 0:
						a__     = 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_   :   List[str]       =					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_   :   int       =					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()



