


import inspect
import tempfile
from collections import OrderedDict, UserDict
from collections.abc import MutableMapping
from contextlib import ExitStack, contextmanager
from dataclasses import fields
from enum import Enum
from typing import Any, ContextManager, List, Tuple

import numpy as np

from .import_utils import is_flax_available, is_tf_available, is_torch_available, is_torch_fx_proxy


if is_flax_available():
 import jax.numpy as jnp






class 	__lowercase					(	__snake_case	):





      def __get__(		self    :       Dict       ,							__lowerCamelCase    :       Optional[int]       ,							__lowerCamelCase    :       List[Any]=None							)     -> List[Any]:






         """simple docstring"""







         if obj is None:
            return self
         if self.fget is None:
            raise AttributeError("""unreadable attribute"""							)
         UpperCAmelCase      					=  """__cached_""" + self.fget.__name__
         UpperCAmelCase      					=  getattr(__lowerCamelCase       ,							__lowerCamelCase       ,							__lowerCamelCase							)
         if cached is None:
            UpperCAmelCase      					=  self.fget(__lowerCamelCase							)
            setattr(__lowerCamelCase       ,							__lowerCamelCase       ,							__lowerCamelCase							)
         return cached

def 	_UpperCamelCase					(    lowerCAmelCase_ )    ->List[Any]:
   UpperCAmelCase      					=  val.lower()
   if val in {"y", "yes", "t", "true", "on", "1"}:
      return 1
   if val in {"n", "no", "f", "false", "off", "0"}:
      return 0
   raise ValueError(F"""invalid truth value {val!r}""" )
def 	_UpperCamelCase					(    lowerCAmelCase_ )    ->Union[str, Any]:
   if is_torch_fx_proxy(lowerCAmelCase_ ):
      return True
   if is_torch_available():
      import torch

      if isinstance(lowerCAmelCase_	,    torch.Tensor ):
         return True
   if is_tf_available():
      import tensorflow as tf

      if isinstance(lowerCAmelCase_	,    tf.Tensor ):
         return True

   if is_flax_available():
      import jax.numpy as jnp
      from jax.core import Tracer

      if isinstance(lowerCAmelCase_	,    (jnp.ndarray, Tracer) ):
         return True

   return isinstance(lowerCAmelCase_	,    np.ndarray )
def 	_UpperCamelCase					(    lowerCAmelCase_ )    ->List[str]:
   return isinstance(lowerCAmelCase_	,    np.ndarray )
def 	_UpperCamelCase					(    lowerCAmelCase_ )    ->List[Any]:
   return _is_numpy(lowerCAmelCase_ )
def 	_UpperCamelCase					(    lowerCAmelCase_ )    ->List[Any]:
   import torch

   return isinstance(lowerCAmelCase_	,    torch.Tensor )
def 	_UpperCamelCase					(    lowerCAmelCase_ )    ->Tuple:
   return False if not is_torch_available() else _is_torch(lowerCAmelCase_ )
def 	_UpperCamelCase					(    lowerCAmelCase_ )    ->Optional[Any]:
   import torch

   return isinstance(lowerCAmelCase_	,    torch.device )
def 	_UpperCamelCase					(    lowerCAmelCase_ )    ->Optional[Any]:
   return False if not is_torch_available() else _is_torch_device(lowerCAmelCase_ )
def 	_UpperCamelCase					(    lowerCAmelCase_ )    ->Optional[int]:
   import torch

   if isinstance(lowerCAmelCase_	,    lowerCAmelCase_ ):
      if hasattr(lowerCAmelCase_	,    lowerCAmelCase_ ):
         UpperCAmelCase      					=  getattr(lowerCAmelCase_	,    lowerCAmelCase_ )
      else:
         return False
   return isinstance(lowerCAmelCase_	,    torch.dtype )
def 	_UpperCamelCase					(    lowerCAmelCase_ )    ->Union[str, Any]:
   return False if not is_torch_available() else _is_torch_dtype(lowerCAmelCase_ )
def 	_UpperCamelCase					(    lowerCAmelCase_ )    ->Union[str, Any]:
   import tensorflow as tf

   return isinstance(lowerCAmelCase_	,    tf.Tensor )
def 	_UpperCamelCase					(    lowerCAmelCase_ )    ->List[Any]:
   return False if not is_tf_available() else _is_tensorflow(lowerCAmelCase_ )
def 	_UpperCamelCase					(    lowerCAmelCase_ )    ->Union[str, Any]:
   import tensorflow as tf

   # the `is_symbolic_tensor` predicate is only available starting with TF 2.14
   if hasattr(lowerCAmelCase_	,    """is_symbolic_tensor""" ):
      return tf.is_symbolic_tensor(lowerCAmelCase_ )
   return type(lowerCAmelCase_ ) == tf.Tensor
def 	_UpperCamelCase					(    lowerCAmelCase_ )    ->Optional[Any]:
   return False if not is_tf_available() else _is_tf_symbolic_tensor(lowerCAmelCase_ )
def 	_UpperCamelCase					(    lowerCAmelCase_ )    ->List[Any]:
   import jax.numpy as jnp  # noqa: F811

   return isinstance(lowerCAmelCase_	,    jnp.ndarray )
def 	_UpperCamelCase					(    lowerCAmelCase_ )    ->Optional[Any]:
   return False if not is_flax_available() else _is_jax(lowerCAmelCase_ )
def 	_UpperCamelCase					(    lowerCAmelCase_ )    ->Any:
   if isinstance(lowerCAmelCase_	,    (dict, UserDict) ):
      return {k: to_py_obj(lowerCAmelCase_ ) for k, v in obj.items()}
   elif isinstance(lowerCAmelCase_	,    (list, tuple) ):
      return [to_py_obj(lowerCAmelCase_ ) for o in obj]
   elif is_tf_tensor(lowerCAmelCase_ ):
      return obj.numpy().tolist()
   elif is_torch_tensor(lowerCAmelCase_ ):
      return obj.detach().cpu().tolist()
   elif is_jax_tensor(lowerCAmelCase_ ):
      return np.asarray(lowerCAmelCase_ ).tolist()
   elif isinstance(lowerCAmelCase_	,    (np.ndarray, np.number) ):  # tolist also works on 0d np arrays
      return obj.tolist()
   else:
      return obj
def 	_UpperCamelCase					(    lowerCAmelCase_ )    ->Optional[int]:
   if isinstance(lowerCAmelCase_	,    (dict, UserDict) ):
      return {k: to_numpy(lowerCAmelCase_ ) for k, v in obj.items()}
   elif isinstance(lowerCAmelCase_	,    (list, tuple) ):
      return np.array(lowerCAmelCase_ )
   elif is_tf_tensor(lowerCAmelCase_ ):
      return obj.numpy()
   elif is_torch_tensor(lowerCAmelCase_ ):
      return obj.detach().cpu().numpy()
   elif is_jax_tensor(lowerCAmelCase_ ):
      return np.asarray(lowerCAmelCase_ )
   else:
      return obj






class 	__lowercase					(	__snake_case	):





      def 							_lowercase					(		self    :       Tuple							)     -> List[Any]:






         """simple docstring"""







         UpperCAmelCase      					=  fields(self							)

         # Safety and consistency checks
         if not len(__lowerCamelCase							):
            raise ValueError(F"""{self.__class__.__name__} has no fields."""							)
         if not all(field.default is None for field in class_fields[1:]							):
            raise ValueError(F"""{self.__class__.__name__} should not have more than one required field."""							)

         UpperCAmelCase      					=  getattr(self       ,							class_fields[0].name							)
         UpperCAmelCase      					=  all(getattr(self       ,							field.name							) is None for field in class_fields[1:]							)

         if other_fields_are_none and not is_tensor(__lowerCamelCase							):
            if isinstance(__lowerCamelCase       ,							__lowerCamelCase							):
               UpperCAmelCase      					=  first_field.items()
               UpperCAmelCase      					=  True
            else:
               try:
                  UpperCAmelCase      					=  iter(__lowerCamelCase							)
                  UpperCAmelCase      					=  True
               except TypeError:
                  UpperCAmelCase      					=  False

            # if we provided an iterator as first field and the iterator is a (key, value) iterator
            # set the associated fields
            if first_field_iterator:
               for idx, element in enumerate(__lowerCamelCase							):
                  if (
                      not isinstance(__lowerCamelCase       ,							(list, tuple)							)
                      or not len(__lowerCamelCase							) == 2
                      or not isinstance(element[0]       ,							__lowerCamelCase							)
                  ):
                     if idx == 0:
                        # If we do not have an iterator of key/values, set it as attribute
                        UpperCAmelCase      					=  first_field
                     else:
                        # If we have a mixed iterator, raise an error
                        raise ValueError(
                            F"""Cannot set key/value for {element}. It needs to be a tuple (key, value)."""							)
                     break
                  setattr(self       ,							element[0]       ,							element[1]							)
                  if element[1] is not None:
                     UpperCAmelCase      					=  element[1]
            elif first_field is not None:
               UpperCAmelCase      					=  first_field
         else:
            for field in class_fields:
               UpperCAmelCase      					=  getattr(self       ,							field.name							)
               if v is not None:
                  UpperCAmelCase      					=  v





      def __delitem__(		self    :       Union[str, Any]       ,							*__lowerCamelCase    :       Tuple       ,							**__lowerCamelCase    :       Tuple							)     -> Union[str, Any]:






         """simple docstring"""







         raise Exception(F"""You cannot use ``__delitem__`` on a {self.__class__.__name__} instance."""							)





      def 							_lowercase					(		self    :       List[Any]       ,							*__lowerCamelCase    :       Optional[int]       ,							**__lowerCamelCase    :       Dict							)     -> List[str]:






         """simple docstring"""







         raise Exception(F"""You cannot use ``setdefault`` on a {self.__class__.__name__} instance."""							)





      def 							_lowercase					(		self    :       Dict       ,							*__lowerCamelCase    :       List[Any]       ,							**__lowerCamelCase    :       List[Any]							)     -> str:






         """simple docstring"""







         raise Exception(F"""You cannot use ``pop`` on a {self.__class__.__name__} instance."""							)





      def 							_lowercase					(		self    :       str       ,							*__lowerCamelCase    :       List[Any]       ,							**__lowerCamelCase    :       Optional[int]							)     -> Union[str, Any]:






         """simple docstring"""







         raise Exception(F"""You cannot use ``update`` on a {self.__class__.__name__} instance."""							)





      def __getitem__(		self    :       Union[str, Any]       ,							__lowerCamelCase    :       List[str]							)     -> List[Any]:






         """simple docstring"""







         if isinstance(__lowerCamelCase       ,							__lowerCamelCase							):
            UpperCAmelCase      					=  dict(self.items()							)
            return inner_dict[k]
         else:
            return self.to_tuple()[k]





      def __setattr__(		self    :       List[Any]       ,							__lowerCamelCase    :       str       ,							__lowerCamelCase    :       Union[str, Any]							)     -> Optional[Any]:






         """simple docstring"""







         if name in self.keys() and value is not None:
            # Don't call self.__setitem__ to avoid recursion errors
            super().__setitem__(__lowerCamelCase       ,							__lowerCamelCase							)
         super().__setattr__(__lowerCamelCase       ,							__lowerCamelCase							)





      def __setitem__(		self    :       Optional[Any]       ,							__lowerCamelCase    :       Union[str, Any]       ,							__lowerCamelCase    :       Tuple							)     -> Optional[Any]:






         """simple docstring"""







         super().__setitem__(__lowerCamelCase       ,							__lowerCamelCase							)
         # Don't call self.__setattr__ to avoid recursion errors
         super().__setattr__(__lowerCamelCase       ,							__lowerCamelCase							)





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






         """simple docstring"""







         return tuple(self[k] for k in self.keys()							)






class 	__lowercase					(	__snake_case			,       __snake_case	):





      @classmethod
      def 							_lowercase					(		cls    :       Union[str, Any]       ,							__lowerCamelCase    :       Any							)     -> Any:






         """simple docstring"""







         raise ValueError(
             F"""{value} is not a valid {cls.__name__}, please select one of {list(cls._valueamember_map_.keys()							)}"""							)






class 	__lowercase					(	__snake_case	):
      UpperCamelCase										=							'''longest'''
      UpperCamelCase										=							'''max_length'''
      UpperCamelCase										=							'''do_not_pad'''






class 	__lowercase					(	__snake_case	):
      UpperCamelCase										=							'''pt'''
      UpperCamelCase										=							'''tf'''
      UpperCamelCase										=							'''np'''
      UpperCamelCase										=							'''jax'''






class 	__lowercase					:





      def __init__(		self    :       List[Any]       ,							__lowerCamelCase    :       List[ContextManager]							)     -> List[Any]:






         """simple docstring"""







         UpperCAmelCase      					=  context_managers
         UpperCAmelCase      					=  ExitStack()





      def __enter__(		self    :       Any							)     -> Optional[Any]:






         """simple docstring"""







         for context_manager in self.context_managers:
            self.stack.enter_context(__lowerCamelCase							)





      def __exit__(		self    :       Dict       ,							*__lowerCamelCase    :       List[str]       ,							**__lowerCamelCase    :       List[Any]							)     -> str:






         """simple docstring"""







         self.stack.__exit__(*__lowerCamelCase       ,							**__lowerCamelCase							)

def 	_UpperCamelCase					(    lowerCAmelCase_ )    ->Any:
   UpperCAmelCase      					=  infer_framework(lowerCAmelCase_ )
   if framework == "tf":
      UpperCAmelCase      					=  inspect.signature(model_class.call )  # TensorFlow models
   elif framework == "pt":
      UpperCAmelCase      					=  inspect.signature(model_class.forward )  # PyTorch models
   else:
      UpperCAmelCase      					=  inspect.signature(model_class.__call__ )  # Flax models

   for p in signature.parameters:
      if p == "return_loss" and signature.parameters[p].default is True:
         return True

   return False
def 	_UpperCamelCase					(    lowerCAmelCase_ )    ->Tuple:
   UpperCAmelCase      					=  model_class.__name__
   UpperCAmelCase      					=  infer_framework(lowerCAmelCase_ )
   if framework == "tf":
      UpperCAmelCase      					=  inspect.signature(model_class.call )  # TensorFlow models
   elif framework == "pt":
      UpperCAmelCase      					=  inspect.signature(model_class.forward )  # PyTorch models
   else:
      UpperCAmelCase      					=  inspect.signature(model_class.__call__ )  # Flax models

   if "QuestionAnswering" in model_name:
      return [p for p in signature.parameters if "label" in p or p in ("start_positions", "end_positions")]
   else:
      return [p for p in signature.parameters if "label" in p]
def 	_UpperCamelCase					(    lowerCAmelCase_	,    lowerCAmelCase_ = ""	,    lowerCAmelCase_ = "." )    ->List[Any]:

   def _flatten_dict(lowerCAmelCase_	,    lowerCAmelCase_=""	,    lowerCAmelCase_="." ):
      for k, v in d.items():
         UpperCAmelCase      					=  str(lowerCAmelCase_ ) + delimiter + str(lowerCAmelCase_ ) if parent_key else k
         if v and isinstance(lowerCAmelCase_	,    lowerCAmelCase_ ):
            yield from flatten_dict(lowerCAmelCase_	,    lowerCAmelCase_	,    delimiter=lowerCAmelCase_ ).items()
         else:
            yield key, v

   return dict(_flatten_dict(lowerCAmelCase_	,    lowerCAmelCase_	,    lowerCAmelCase_ ) )
@contextmanager
def 	_UpperCamelCase					(    lowerCAmelCase_	,    lowerCAmelCase_ = False )    ->List[Any]:
   if use_temp_dir:
      with tempfile.TemporaryDirectory() as tmp_dir:
         yield tmp_dir
   else:
      yield working_dir
def 	_UpperCamelCase					(    lowerCAmelCase_	,    lowerCAmelCase_=None )    ->Optional[int]:
   if is_numpy_array(lowerCAmelCase_ ):
      return np.transpose(lowerCAmelCase_	,    axes=lowerCAmelCase_ )
   elif is_torch_tensor(lowerCAmelCase_ ):
      return array.T if axes is None else array.permute(*lowerCAmelCase_ )
   elif is_tf_tensor(lowerCAmelCase_ ):
      import tensorflow as tf

      return tf.transpose(lowerCAmelCase_	,    perm=lowerCAmelCase_ )
   elif is_jax_tensor(lowerCAmelCase_ ):
      return jnp.transpose(lowerCAmelCase_	,    axes=lowerCAmelCase_ )
   else:
      raise ValueError(F"""Type not supported for transpose: {type(lowerCAmelCase_ )}.""" )
def 	_UpperCamelCase					(    lowerCAmelCase_	,    lowerCAmelCase_ )    ->Optional[Any]:
   if is_numpy_array(lowerCAmelCase_ ):
      return np.reshape(lowerCAmelCase_	,    lowerCAmelCase_ )
   elif is_torch_tensor(lowerCAmelCase_ ):
      return array.reshape(*lowerCAmelCase_ )
   elif is_tf_tensor(lowerCAmelCase_ ):
      import tensorflow as tf

      return tf.reshape(lowerCAmelCase_	,    lowerCAmelCase_ )
   elif is_jax_tensor(lowerCAmelCase_ ):
      return jnp.reshape(lowerCAmelCase_	,    lowerCAmelCase_ )
   else:
      raise ValueError(F"""Type not supported for reshape: {type(lowerCAmelCase_ )}.""" )
def 	_UpperCamelCase					(    lowerCAmelCase_	,    lowerCAmelCase_=None )    ->Dict:
   if is_numpy_array(lowerCAmelCase_ ):
      return np.squeeze(lowerCAmelCase_	,    axis=lowerCAmelCase_ )
   elif is_torch_tensor(lowerCAmelCase_ ):
      return array.squeeze() if axis is None else array.squeeze(dim=lowerCAmelCase_ )
   elif is_tf_tensor(lowerCAmelCase_ ):
      import tensorflow as tf

      return tf.squeeze(lowerCAmelCase_	,    axis=lowerCAmelCase_ )
   elif is_jax_tensor(lowerCAmelCase_ ):
      return jnp.squeeze(lowerCAmelCase_	,    axis=lowerCAmelCase_ )
   else:
      raise ValueError(F"""Type not supported for squeeze: {type(lowerCAmelCase_ )}.""" )
def 	_UpperCamelCase					(    lowerCAmelCase_	,    lowerCAmelCase_ )    ->int:
   if is_numpy_array(lowerCAmelCase_ ):
      return np.expand_dims(lowerCAmelCase_	,    lowerCAmelCase_ )
   elif is_torch_tensor(lowerCAmelCase_ ):
      return array.unsqueeze(dim=lowerCAmelCase_ )
   elif is_tf_tensor(lowerCAmelCase_ ):
      import tensorflow as tf

      return tf.expand_dims(lowerCAmelCase_	,    axis=lowerCAmelCase_ )
   elif is_jax_tensor(lowerCAmelCase_ ):
      return jnp.expand_dims(lowerCAmelCase_	,    axis=lowerCAmelCase_ )
   else:
      raise ValueError(F"""Type not supported for expand_dims: {type(lowerCAmelCase_ )}.""" )
def 	_UpperCamelCase					(    lowerCAmelCase_ )    ->Tuple:
   if is_numpy_array(lowerCAmelCase_ ):
      return np.size(lowerCAmelCase_ )
   elif is_torch_tensor(lowerCAmelCase_ ):
      return array.numel()
   elif is_tf_tensor(lowerCAmelCase_ ):
      import tensorflow as tf

      return tf.size(lowerCAmelCase_ )
   elif is_jax_tensor(lowerCAmelCase_ ):
      return array.size
   else:
      raise ValueError(F"""Type not supported for expand_dims: {type(lowerCAmelCase_ )}.""" )
def 	_UpperCamelCase					(    lowerCAmelCase_	,    lowerCAmelCase_ )    ->Union[str, Any]:
   for key, value in auto_map.items():
      if isinstance(lowerCAmelCase_	,    (tuple, list) ):
         UpperCAmelCase      					=  [F"""{repo_id}--{v}""" if (v is not None and """--""" not in v) else v for v in value]
      elif value is not None and "--" not in value:
         UpperCAmelCase      					=  F"""{repo_id}--{value}"""

   return auto_map







def 	_UpperCamelCase					(    lowerCAmelCase_ )    ->Optional[int]:
   for base_class in inspect.getmro(lowerCAmelCase_ ):
      UpperCAmelCase      					=  base_class.__module__
      UpperCAmelCase      					=  base_class.__name__
      if module.startswith("""tensorflow""" ) or module.startswith("""keras""" ) or name == "TFPreTrainedModel":
         return "tf"
      elif module.startswith("""torch""" ) or name == "PreTrainedModel":
         return "pt"
      elif module.startswith("""flax""" ) or module.startswith("""jax""" ) or name == "FlaxPreTrainedModel":
         return "flax"
   else:
      raise TypeError(F"""Could not infer framework from class {model_class}.""" )







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 	_UpperCamelCase					(    lowerCAmelCase_	,    lowerCAmelCase_	,    lowerCAmelCase_ )    ->Optional[Any]:
   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 	_UpperCamelCase					(    lowerCAmelCase_ )    ->int:
   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 	_UpperCamelCase					(    lowerCAmelCase_	,    lowerCAmelCase_=False )    ->Optional[int]:
   for pattern, fname in REPLACE_FILES.items():
      update_version_in_file(lowerCAmelCase_	,    lowerCAmelCase_	,    lowerCAmelCase_ )
   if not patch:
      update_version_in_examples(lowerCAmelCase_ )
def 	_UpperCamelCase					(    )    ->List[str]:
   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/diffusers/main/model_doc"""	,    """https://huggingface.co/docs/diffusers/model_doc"""	,    )
      index += 1

   with open(lowerCAmelCase_	,    """w"""	,    encoding="""utf-8"""	,    newline="""\n""" ) as f:
      f.writelines(lowerCAmelCase_ )
def 	_UpperCamelCase					(    )    ->List[str]:
   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 	_UpperCamelCase					(    lowerCAmelCase_=False )    ->int:
   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_ )
def 	_UpperCamelCase					(    )    ->int:
   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__":
 __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()



