



'''simple docstring'''





import copy
import json
import os
import tempfile

from transformers import is_torch_available

from .test_configuration_utils import config_common_kwargs






class        lowerCAmelCase_(				SCREAMING_SNAKE_CASE_     ):
  '''simple docstring'''




  def __init__(    self  ,__UpperCAmelCase  ,__UpperCAmelCase=None  ,__UpperCAmelCase=True  ,__UpperCAmelCase=None  ,**__UpperCAmelCase      )    ->		Dict:
      lowerCAmelCase__ :  List[str]							      =					parent
      lowerCAmelCase__ :  Optional[Any]							      =					config_class
      lowerCAmelCase__ :  List[str]							      =					has_text_modality
      lowerCAmelCase__ :  Union[str, Any]							      =					kwargs
      lowerCAmelCase__ :  str							      =					common_properties




  def 							UpperCAmelCase_	(    self      )    ->		List[Any]:
      lowerCAmelCase__ :  int							      =					self.config_class(**self.inputs_dict      )
      lowerCAmelCase__ :  Dict							      =					(
          ["""hidden_size""", """num_attention_heads""", """num_hidden_layers"""]
          if self.common_properties is None
          else self.common_properties
      )

      # Add common fields for text models
      if self.has_text_modality:
          common_properties.extend(["""vocab_size"""]      )

      # Test that config has the common properties as getters
      for prop in common_properties:
          self.parent.assertTrue(hasattr(__UpperCAmelCase  ,__UpperCAmelCase      )  ,msg=F"""`{prop}` does not exist"""      )

      # Test that config has the common properties as setter
      for idx, name in enumerate(__UpperCAmelCase      ):
          try:
              setattr(__UpperCAmelCase  ,__UpperCAmelCase  ,__UpperCAmelCase      )
              self.parent.assertEqual(
                  getattr(__UpperCAmelCase  ,__UpperCAmelCase      )  ,__UpperCAmelCase  ,msg=F"""`{name} value {idx} expected, but was {getattr(__UpperCAmelCase  ,__UpperCAmelCase      )}"""      )
          except NotImplementedError:
              # Some models might not be able to implement setters for common_properties
              # In that case, a NotImplementedError is raised
              pass

        # Test if config class can be called with Config(prop_name=..)
      for idx, name in enumerate(__UpperCAmelCase      ):
          try:
              lowerCAmelCase__ :  str							      =					self.config_class(**{name: idx}      )
              self.parent.assertEqual(
                  getattr(__UpperCAmelCase  ,__UpperCAmelCase      )  ,__UpperCAmelCase  ,msg=F"""`{name} value {idx} expected, but was {getattr(__UpperCAmelCase  ,__UpperCAmelCase      )}"""      )
          except NotImplementedError:
              # Some models might not be able to implement setters for common_properties
              # In that case, a NotImplementedError is raised
              pass




  def 							UpperCAmelCase_	(    self      )    ->		List[str]:
      lowerCAmelCase__ :  str							      =					self.config_class(**self.inputs_dict      )
      lowerCAmelCase__ :  Union[str, Any]							      =					json.loads(config.to_json_string()      )
      for key, value in self.inputs_dict.items():
          self.parent.assertEqual(obj[key]  ,__UpperCAmelCase      )




  def 							UpperCAmelCase_	(    self      )    ->		Tuple:
      lowerCAmelCase__ :  int							      =					self.config_class(**self.inputs_dict      )

      with tempfile.TemporaryDirectory() as tmpdirname:
          lowerCAmelCase__ :  Union[str, Any]							      =					os.path.join(__UpperCAmelCase  ,"""config.json"""      )
          config_first.to_json_file(__UpperCAmelCase      )
          lowerCAmelCase__ :  str							      =					self.config_class.from_json_file(__UpperCAmelCase      )

      self.parent.assertEqual(config_second.to_dict()  ,config_first.to_dict()      )




  def 							UpperCAmelCase_	(    self      )    ->		Optional[int]:
      lowerCAmelCase__ :  Optional[Any]							      =					self.config_class(**self.inputs_dict      )

      with tempfile.TemporaryDirectory() as tmpdirname:
          config_first.save_pretrained(__UpperCAmelCase      )
          lowerCAmelCase__ :  Optional[Any]							      =					self.config_class.from_pretrained(__UpperCAmelCase      )

      self.parent.assertEqual(config_second.to_dict()  ,config_first.to_dict()      )




  def 							UpperCAmelCase_	(    self      )    ->		List[Any]:
      lowerCAmelCase__ :  List[str]							      =					self.config_class(**self.inputs_dict      )

      lowerCAmelCase__ :  Union[str, Any]							      =					"""test"""
      with tempfile.TemporaryDirectory() as tmpdirname:
          lowerCAmelCase__ :  List[Any]							      =					os.path.join(__UpperCAmelCase  ,__UpperCAmelCase      )
          config_first.save_pretrained(__UpperCAmelCase      )
          lowerCAmelCase__ :  Optional[int]							      =					self.config_class.from_pretrained(__UpperCAmelCase  ,subfolder=__UpperCAmelCase      )

      self.parent.assertEqual(config_second.to_dict()  ,config_first.to_dict()      )




  def 							UpperCAmelCase_	(    self      )    ->		Dict:
      lowerCAmelCase__ :  Dict							      =					self.config_class(**self.inputs_dict  ,num_labels=5      )
      self.parent.assertEqual(len(config.idalabel      )  ,5      )
      self.parent.assertEqual(len(config.labelaid      )  ,5      )

      lowerCAmelCase__ :  List[str]							      =					3
      self.parent.assertEqual(len(config.idalabel      )  ,3      )
      self.parent.assertEqual(len(config.labelaid      )  ,3      )




  def 							UpperCAmelCase_	(    self      )    ->		str:
      if self.config_class.is_composition:
          return
      lowerCAmelCase__ :  Tuple							      =					self.config_class()
      self.parent.assertIsNotNone(__UpperCAmelCase      )




  def 							UpperCAmelCase_	(    self      )    ->		List[str]:
      lowerCAmelCase__ :  Optional[Any]							      =					copy.deepcopy(__UpperCAmelCase      )
      lowerCAmelCase__ :  int							      =					self.config_class(**__UpperCAmelCase      )
      lowerCAmelCase__ :  Dict							      =					[]
      for key, value in config_common_kwargs.items():
          if key == "torch_dtype":
              if not is_torch_available():
                  continue
              else:
                  import torch

                  if config.torch_dtype != torch.floataa:
                      wrong_values.append(("""torch_dtype""", config.torch_dtype, torch.floataa)      )
          elif getattr(__UpperCAmelCase  ,__UpperCAmelCase      ) != value:
              wrong_values.append((key, getattr(__UpperCAmelCase  ,__UpperCAmelCase      ), value)      )

      if len(__UpperCAmelCase      ) > 0:
          lowerCAmelCase__ :  Any							      =					"""\n""".join([F"""- {v[0]}: got {v[1]} instead of {v[2]}""" for v in wrong_values]      )
          raise ValueError(F"""The following keys were not properly set in the config:\n{errors}"""      )






  def 							UpperCAmelCase_	(    self      )    ->		Tuple:
      self.create_and_test_config_common_properties()
      self.create_and_test_config_to_json_string()
      self.create_and_test_config_to_json_file()
      self.create_and_test_config_from_and_save_pretrained()
      self.create_and_test_config_from_and_save_pretrained_subfolder()
      self.create_and_test_config_with_num_labels()
      self.check_config_can_be_init_without_params()
      self.check_config_arguments_init()







"""simple docstring"""

import os
from datetime import datetime as dt

from github import Github


lowercase__    :  int							    =	[
    '''good first issue''',
    '''good second issue''',
    '''good difficult issue''',
    '''enhancement''',
    '''new pipeline/model''',
    '''new scheduler''',
    '''wip''',
]




def __lowercase			(							):
    snake_case_ :     Optional[Any]				=	Github(os.environ['''GITHUB_TOKEN''']    )
    snake_case_ :     Any				=	g.get_repo('''huggingface/diffusers'''    )
    snake_case_ :     Any				=	repo.get_issues(state='''open'''    )

    for issue in open_issues:
        snake_case_ :     str				=	sorted(issue.get_comments()		,			key=lambda _a    : i.created_at		,			reverse=_a    )
        snake_case_ :     Dict				=	comments[0] if len(_a    ) > 0 else None
        if (
            last_comment is not None
            and last_comment.user.login == "github-actions[bot]"
            and (dt.utcnow() - issue.updated_at).days > 7
            and (dt.utcnow() - issue.created_at).days >= 30
            and not any(label.name.lower() in LABELS_TO_EXEMPT for label in issue.get_labels()    )
        ):
            # Closes the issue after 7 days of inactivity since the Stalebot notification.
            issue.edit(state='''closed'''    )
        elif (
            "stale" in issue.get_labels()
            and last_comment is not None
            and last_comment.user.login != "github-actions[bot]"
        ):
            # Opens the issue if someone other than Stalebot commented.
            issue.edit(state='''open'''    )
            issue.remove_from_labels('''stale'''    )
        elif (
            (dt.utcnow() - issue.updated_at).days > 23
            and (dt.utcnow() - issue.created_at).days >= 30
            and not any(label.name.lower() in LABELS_TO_EXEMPT for label in issue.get_labels()    )
        ):
            # Post a Stalebot notification after 23 days of inactivity.
            issue.create_comment(
                '''This issue has been automatically marked as stale because it has not had '''
                '''recent activity. If you think this still needs to be addressed '''
                '''please comment on this thread.\n\nPlease note that issues that do not follow the '''
                '''[contributing guidelines](https://github.com/huggingface/diffusers/blob/main/CONTRIBUTING.md) '''
                '''are likely to be ignored.'''    )
            issue.add_to_labels('''stale'''    )


if __name__ == "__main__":
     main()





