





import argparse
import os
import re

import packaging.version


__A     =    "examples/"
__A     =    {
    "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     =    {
    "init": "src/diffusers/__init__.py",
    "setup": "setup.py",
}
__A     =    "README.md"





def 					lowerCAmelCase_			(	__a     ,   __a     ,   __a		)					->		Optional[int]:







  """simple docstring"""





  with open(__a     ,   "r"     ,   encoding="utf-8"     ,   newline="\n"		) as f:
    lowerCamelCase__:				List[Any]        =f.read()
  lowerCamelCase__  , lowerCamelCase__:				int        =REPLACE_PATTERNS[pattern]
  lowerCamelCase__:				Optional[Any]        =replace.replace("VERSION"     ,   __a		)
  lowerCamelCase__:				Tuple        =re_pattern.sub(__a     ,   __a		)
  with open(__a     ,   "w"     ,   encoding="utf-8"     ,   newline="\n"		) as f:
    f.write(__a		)





def 					lowerCAmelCase_			(	__a		)					->		str:







  """simple docstring"""





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





def 					lowerCAmelCase_			(	__a     ,   __a=False		)					->		Tuple:







  """simple docstring"""





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





def 					lowerCAmelCase_			(	)					->		int:







  """simple docstring"""





  lowerCamelCase__:				Tuple        ="🤗 Transformers currently provides the following architectures"
  lowerCamelCase__:				List[str]        ="1. Want to contribute a new model?"
  with open(__a     ,   "r"     ,   encoding="utf-8"     ,   newline="\n"		) as f:
    lowerCamelCase__:				int        =f.readlines()

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

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

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





def 					lowerCAmelCase_			(	)					->		Optional[Any]:







  """simple docstring"""





  with open(REPLACE_FILES["init"]     ,   "r"		) as f:
    lowerCamelCase__:				List[str]        =f.read()
  lowerCamelCase__:				str        =REPLACE_PATTERNS["init"][0].search(__a		).groups()[0]
  return packaging.version.parse(__a		)





def 					lowerCAmelCase_			(	__a=False		)					->		int:







  """simple docstring"""





  lowerCamelCase__:				Optional[int]        =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__:				List[Any]        =default_version.base_version
  elif patch:
    lowerCamelCase__:				List[Any]        =F"""{default_version.major}.{default_version.minor}.{default_version.micro + 1}"""
  else:
    lowerCamelCase__:				Optional[Any]        =F"""{default_version.major}.{default_version.minor + 1}.0"""

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

  print(F"""Updating version to {version}."""		)
  global_version_update(__a     ,   patch=__a		)





def 					lowerCAmelCase_			(	)					->		List[Any]:







  """simple docstring"""





  lowerCamelCase__:				List[Any]        =get_version()
  lowerCamelCase__:				Dict        =F"""{current_version.major}.{current_version.minor + 1}.0.dev0"""
  lowerCamelCase__:				Tuple        =current_version.base_version

  # Check with the user we got that right.
  lowerCamelCase__:				Union[str, Any]        =input(F"""Which version are we developing now? [{dev_version}]"""		)
  if len(__a		) == 0:
    lowerCamelCase__:				int        =dev_version

  print(F"""Updating version to {version}."""		)
  global_version_update(__a		)


#    print("Cleaning main README, don't forget to run `make fix-copies`.")
#    clean_main_ref_in_model_list()


if __name__ == "__main__":
     __A     =    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     =    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()








import json
import os
import unittest

from transformers.models.ctrl.tokenization_ctrl import VOCAB_FILES_NAMES, CTRLTokenizer

from ...test_tokenization_common import TokenizerTesterMixin



class        _SCREAMING_SNAKE_CASE						(     __SCREAMING_SNAKE_CASE   ,							unittest.TestCase   ):







 '''simple docstring'''
 lowercase_		=      CTRLTokenizer
 lowercase_		=      False
 lowercase_		=      False

 def 							SCREAMING_SNAKE_CASE_ (self    :       str)	->Union[str, Any]:



   '''simple docstring'''



   super().setUp()

   # Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
   lowerCamelCase__:				Optional[Any]        =["adapt", "re@@", "a@@", "apt", "c@@", "t", "<unk>"]
   lowerCamelCase__:				Optional[Any]        =dict(zip(UpperCAmelCase_	,			range(len(UpperCAmelCase_))))
   lowerCamelCase__:				Union[str, Any]        =["#version: 0.2", "a p", "ap t</w>", "r e", "a d", "ad apt</w>", ""]
   lowerCamelCase__:				Union[str, Any]        ={"unk_token": "<unk>"}

   lowerCamelCase__:				Union[str, Any]        =os.path.join(self.tmpdirname	,			VOCAB_FILES_NAMES["vocab_file"])
   lowerCamelCase__:				Optional[Any]        =os.path.join(self.tmpdirname	,			VOCAB_FILES_NAMES["merges_file"])
   with open(self.vocab_file	,			"w"	,			encoding="utf-8") as fp:
     fp.write(json.dumps(UpperCAmelCase_) + "\n")
   with open(self.merges_file	,			"w"	,			encoding="utf-8") as fp:
     fp.write("\n".join(UpperCAmelCase_))

 def 							SCREAMING_SNAKE_CASE_ (self    :       List[str]	,			**UpperCAmelCase_    :       str)	->List[Any]:



   '''simple docstring'''



   kwargs.update(self.special_tokens_map)
   return CTRLTokenizer.from_pretrained(self.tmpdirname	,			**UpperCAmelCase_)

 def 							SCREAMING_SNAKE_CASE_ (self    :       List[Any]	,			UpperCAmelCase_    :       Optional[int])	->Optional[int]:



   '''simple docstring'''



   lowerCamelCase__:				int        ="adapt react readapt apt"
   lowerCamelCase__:				int        ="adapt react readapt apt"
   return input_text, output_text







 def 							SCREAMING_SNAKE_CASE_ (self    :       str)	->Union[str, Any]:



   '''simple docstring'''



   lowerCamelCase__:				List[str]        =CTRLTokenizer(self.vocab_file	,			self.merges_file	,			**self.special_tokens_map)
   lowerCamelCase__:				Union[str, Any]        ="adapt react readapt apt"
   lowerCamelCase__:				Tuple        ="adapt re@@ a@@ c@@ t re@@ adapt apt".split()
   lowerCamelCase__:				Dict        =tokenizer.tokenize(UpperCAmelCase_)
   self.assertListEqual(UpperCAmelCase_	,			UpperCAmelCase_)

   lowerCamelCase__:				Optional[int]        =tokens + [tokenizer.unk_token]

   lowerCamelCase__:				List[str]        =[0, 1, 2, 4, 5, 1, 0, 3, 6]
   self.assertListEqual(tokenizer.convert_tokens_to_ids(UpperCAmelCase_)	,			UpperCAmelCase_)

