


"""simple docstring"""







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 					a__			(				SCREAMING_SNAKE_CASE    :    List[str]				,      SCREAMING_SNAKE_CASE    :    Any				,      SCREAMING_SNAKE_CASE    :    int				):


  '''simple docstring'''







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


  '''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 					a__			(				SCREAMING_SNAKE_CASE    :    Any				,      SCREAMING_SNAKE_CASE    :    Dict=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 					a__			(				):


  '''simple docstring'''







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

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

  lowerCAmelCase     :     int								=							start_index
  # Update the lines in the model list.
  while not lines[index].startswith(_end_prompt				):
    if lines[index].startswith("1."				):
      lowerCAmelCase     :     Tuple								=							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 					a__			(				):


  '''simple docstring'''







  with open(REPLACE_FILES["init"]				,      "r"				) as f:
    lowerCAmelCase     :     List[Any]								=							f.read()
  lowerCAmelCase     :     Optional[int]								=							REPLACE_PATTERNS['''init'''][0].search(lowerCAmelCase_				).groups()[0]
  return packaging.version.parse(lowerCAmelCase_				)
def 					a__			(				SCREAMING_SNAKE_CASE    :    Tuple=False				):


  '''simple docstring'''







  lowerCAmelCase     :     List[Any]								=							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:
    lowerCAmelCase     :     int								=							default_version.base_version
  elif patch:
    lowerCAmelCase     :     List[str]								=							f"""{default_version.major}.{default_version.minor}.{default_version.micro + 1}"""
  else:
    lowerCAmelCase     :     Dict								=							f"""{default_version.major}.{default_version.minor + 1}.0"""

  # Now let's ask nicely if that's the right one.
  lowerCAmelCase     :     Any								=							input(f"""Which version are you releasing? [{default_version}]"""				)
  if len(lowerCAmelCase_				) == 0:
    lowerCAmelCase     :     Optional[Any]								=							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 					a__			(				):


  '''simple docstring'''







  lowerCAmelCase     :     List[Any]								=							get_version()
  lowerCAmelCase     :     Optional[int]								=							f"""{current_version.major}.{current_version.minor + 1}.0.dev0"""
  lowerCAmelCase     :     int								=							current_version.base_version

  # Check with the user we got that right.
  lowerCAmelCase     :     Tuple								=							input(f"""Which version are we developing now? [{dev_version}]"""				)
  if len(lowerCAmelCase_				) == 0:
    lowerCAmelCase     :     int								=							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()









def 	lowerCAmelCase       (						lowerCAmelCase_       )->       set:
				lowerCAmelCase_       :					Optional[int]			 = set()
				# edges = list of graph's edges
				lowerCAmelCase_       :					List[str]			 = get_edges(lowerCAmelCase_       )

				# While there are still elements in edges list, take an arbitrary edge
				# (from_node, to_node) and add his extremity to chosen_vertices and then
				# remove all arcs adjacent to the from_node and to_node
				while edges:
								lowerCAmelCase_ ,     lowerCAmelCase_       :					Optional[int]			 = edges.pop()
								chosen_vertices.add(lowerCAmelCase_       )
								chosen_vertices.add(lowerCAmelCase_       )
								for edge in edges.copy():
												if from_node in edge or to_node in edge:
																edges.discard(lowerCAmelCase_       )
				return chosen_vertices



def 	lowerCAmelCase       (						lowerCAmelCase_       )->       set:
				lowerCAmelCase_       :					List[Any]			 = set()
				for from_node, to_nodes in graph.items():
								for to_node in to_nodes:
												edges.add((from_node, to_node)       )
				return edges


if __name__ == "__main__":
						import doctest

						doctest.testmod()

						# graph = {0: [1, 3], 1: [0, 3], 2: [0, 3, 4], 3: [0, 1, 2], 4: [2, 3]}
						# print(f"Matching vertex cover:\n{matching_min_vertex_cover(graph)}")