






"""simple docstring"""






from importlib import import_module

from .logging import get_logger


SCREAMING_SNAKE_CASE						:						Optional[Any]					   =       get_logger(__name__)





class       snake_case_       :



	"""simple docstring"""

	def __init__(      self  ,					__a  ,					__a=None						):


					"""simple docstring"""

					A__							 =       attrs or []
					if module is not None:
									for key in module.__dict__:
													if key in attrs or not key.startswith('__'						):
																	setattr(self  ,					__a  ,					getattr(__a  ,					__a						)						)
					A__							 =       module._original_module if isinstance(__a  ,					_PatchedModuleObj						) else module





class       snake_case_       :



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							Tuple   			=					[]


	def __init__(      self  ,					__a  ,					__a  ,					__a  ,					__a=None						):


					"""simple docstring"""

					A__							 =       obj
					A__							 =       target
					A__							 =       new
					A__							 =       target.split('.'						)[0]
					A__							 =       {}
					A__							 =       attrs or []


	def __enter__(      self						):


					"""simple docstring"""

					*A__ ,			A__							 =       self.target.split('.'						)

					# Patch modules:
					# it's used to patch attributes of submodules like "os.path.join";
					# in this case we need to patch "os" and "os.path"

					for i in range(len(__a						)						):
									try:
													A__							 =       import_module('.'.join(submodules[: i + 1]						)						)
									except ModuleNotFoundError:
													continue
									# We iterate over all the globals in self.obj in case we find "os" or "os.path"
									for attr in self.obj.__dir__():
													A__							 =       getattr(self.obj  ,					__a						)
													# We don't check for the name of the global, but rather if its value *is* "os" or "os.path".
													# This allows to patch renamed modules like "from os import path as ospath".
													if obj_attr is submodule or (
													    (isinstance(__a  ,					_PatchedModuleObj						) and obj_attr._original_module is submodule)
													):
																	A__							 =       obj_attr
																	# patch at top level
																	setattr(self.obj  ,					__a  ,					_PatchedModuleObj(__a  ,					attrs=self.attrs						)						)
																	A__							 =       getattr(self.obj  ,					__a						)
																	# construct lower levels patches
																	for key in submodules[i + 1 :]:
																					setattr(__a  ,					__a  ,					_PatchedModuleObj(getattr(__a  ,					__a  ,					__a						)  ,					attrs=self.attrs						)						)
																					A__							 =       getattr(__a  ,					__a						)
																	# finally set the target attribute
																	setattr(__a  ,					__a  ,					self.new						)

        # Patch attribute itself:
        # it's used for builtins like "open",
        # and also to patch "os.path.join" we may also need to patch "join"
        # itself if it was imported as "from os.path import join".

					if submodules:  # if it's an attribute of a submodule like "os.path.join"
									try:
													A__							 =       getattr(import_module('.'.join(__a						)						)  ,					__a						)
									except (AttributeError, ModuleNotFoundError):
													return
									# We iterate over all the globals in self.obj in case we find "os.path.join"
									for attr in self.obj.__dir__():
													# We don't check for the name of the global, but rather if its value *is* "os.path.join".
													# This allows to patch renamed attributes like "from os.path import join as pjoin".
													if getattr(self.obj  ,					__a						) is attr_value:
																	A__							 =       getattr(self.obj  ,					__a						)
																	setattr(self.obj  ,					__a  ,					self.new						)
					elif target_attr in globals()["__builtins__"]:  # if it'a s builtin like "open"
									A__							 =       globals()['__builtins__'][target_attr]
									setattr(self.obj  ,					__a  ,					self.new						)
					else:
									raise RuntimeError(f'''Tried to patch attribute {target_attr} instead of a submodule.'''						)


	def __exit__(      self  ,					*__a						):


					"""simple docstring"""

					for attr in list(self.original						):
									setattr(self.obj  ,					__a  ,					self.original.pop(__a						)						)


	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					self.__enter__()
					self._active_patches.append(self						)






	def       _UpperCAmelCase						(      self						):


					"""simple docstring"""

					try:
									self._active_patches.remove(self						)
					except ValueError:
									# If the patch hasn't been started this will fail
									return None

					return self.__exit__()










"""simple docstring"""






from ...configuration_utils import PretrainedConfig
from ...utils import logging


SCREAMING_SNAKE_CASE						:						Any					   =       logging.get_logger(__name__)





class       snake_case_       (    _lowerCamelCase       ):



	"""simple docstring"""

	SCREAMING_SNAKE_CASE_:							Union[str, Any]   			=					"""timm_backbone"""


	def __init__(      self  ,					__a=None  ,					__a=3  ,					__a=True  ,					__a=True  ,					__a=None  ,					**__a  ,					):


					"""simple docstring"""

					super().__init__(**__a						)
					A__							 =       backbone
					A__							 =       num_channels
					A__							 =       features_only
					A__							 =       use_pretrained_backbone
					A__							 =       True
					A__							 =       out_indices if out_indices is not None else (-1,)


