


import json
import sys
import tempfile
import unittest
from pathlib import Path

import transformers
from transformers import (
    CONFIG_MAPPING,
    FEATURE_EXTRACTOR_MAPPING,
    AutoConfig,
    AutoFeatureExtractor,
    WavaVecaConfig,
    WavaVecaFeatureExtractor,
)
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, get_tests_dir


sys.path.append(str(Path(__file__).parent.parent.parent.parent / "utils"))

from test_module.custom_configuration import CustomConfig  # noqa E402
from test_module.custom_feature_extraction import CustomFeatureExtractor  # noqa E402


UpperCAmelCase   :    str     =		get_tests_dir("fixtures")
UpperCAmelCase   :    Any     =		get_tests_dir("fixtures/dummy_feature_extractor_config.json")
UpperCAmelCase   :    Dict     =		get_tests_dir("fixtures/dummy-config.json")







class        __lowercase       (							unittest.TestCase  ):



		"""simple docstring"""

		def 					__A   ( self	)  -> Optional[int]:







					'''simple docstring'''







					lowerCamelCase    		=  0







		def 					__A   ( self	)  -> Tuple:







					'''simple docstring'''







					lowerCamelCase    		=  AutoFeatureExtractor.from_pretrained("""facebook/wav2vec2-base-960h"""	)
					self.assertIsInstance(A		,      A	)







		def 					__A   ( self	)  -> Any:







					'''simple docstring'''







					lowerCamelCase    		=  AutoFeatureExtractor.from_pretrained(A	)
					self.assertIsInstance(A		,      A	)







		def 					__A   ( self	)  -> Any:







					'''simple docstring'''







					with tempfile.TemporaryDirectory() as tmpdirname:
								lowerCamelCase    		=  WavaVecaConfig()

								# remove feature_extractor_type to make sure config.json alone is enough to load feature processor locally
								lowerCamelCase    		=  AutoFeatureExtractor.from_pretrained(A	).to_dict()

								config_dict.pop("""feature_extractor_type"""	)
								lowerCamelCase    		=  WavaVecaFeatureExtractor(**A	)

								# save in new folder
								model_config.save_pretrained(A	)
								config.save_pretrained(A	)

								lowerCamelCase    		=  AutoFeatureExtractor.from_pretrained(A	)

								# make sure private variable is not incorrectly saved
								lowerCamelCase    		=  json.loads(config.to_json_string()	)
								self.assertTrue("""_processor_class""" not in dict_as_saved	)

					self.assertIsInstance(A		,      A	)







		def 					__A   ( self	)  -> int:







					'''simple docstring'''







					lowerCamelCase    		=  AutoFeatureExtractor.from_pretrained(A	)
					self.assertIsInstance(A		,      A	)







		def 					__A   ( self	)  -> Any:







					'''simple docstring'''







					with self.assertRaisesRegex(
					    A		,      """bert-base is not a local folder and is not a valid model identifier"""	):
								lowerCamelCase    		=  AutoFeatureExtractor.from_pretrained("""bert-base"""	)







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







					'''simple docstring'''







					with self.assertRaisesRegex(
					    A		,      r"""aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)"""	):
								lowerCamelCase    		=  AutoFeatureExtractor.from_pretrained(A		,      revision="""aaaaaa"""	)







		def 					__A   ( self	)  -> str:







					'''simple docstring'''







					with self.assertRaisesRegex(
					    A		,      """hf-internal-testing/config-no-model does not appear to have a file named preprocessor_config.json."""		,      ):
								lowerCamelCase    		=  AutoFeatureExtractor.from_pretrained("""hf-internal-testing/config-no-model"""	)







		def 					__A   ( self	)  -> str:







					'''simple docstring'''







					with self.assertRaises(A	):
								lowerCamelCase    		=  AutoFeatureExtractor.from_pretrained(
								    """hf-internal-testing/test_dynamic_feature_extractor"""	)
					# If remote code is disabled, we can't load this config.
					with self.assertRaises(A	):
								lowerCamelCase    		=  AutoFeatureExtractor.from_pretrained(
								    """hf-internal-testing/test_dynamic_feature_extractor"""		,      trust_remote_code=A	)

					lowerCamelCase    		=  AutoFeatureExtractor.from_pretrained(
					    """hf-internal-testing/test_dynamic_feature_extractor"""		,      trust_remote_code=A	)
					self.assertEqual(feature_extractor.__class__.__name__		,      """NewFeatureExtractor"""	)

					# Test feature extractor can be reloaded.
					with tempfile.TemporaryDirectory() as tmp_dir:
								feature_extractor.save_pretrained(A	)
								lowerCamelCase    		=  AutoFeatureExtractor.from_pretrained(A		,      trust_remote_code=A	)
					self.assertEqual(reloaded_feature_extractor.__class__.__name__		,      """NewFeatureExtractor"""	)







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







					'''simple docstring'''







					try:
								AutoConfig.register("""custom"""		,      A	)
								AutoFeatureExtractor.register(A		,      A	)
								# Trying to register something existing in the Transformers library will raise an error
								with self.assertRaises(A	):
											AutoFeatureExtractor.register(A		,      A	)

								# Now that the config is registered, it can be used as any other config with the auto-API
								lowerCamelCase    		=  CustomFeatureExtractor.from_pretrained(A	)
								with tempfile.TemporaryDirectory() as tmp_dir:
											feature_extractor.save_pretrained(A	)
											lowerCamelCase    		=  AutoFeatureExtractor.from_pretrained(A	)
											self.assertIsInstance(A		,      A	)

					finally:
								if "custom" in CONFIG_MAPPING._extra_content:
											del CONFIG_MAPPING._extra_content["custom"]
								if CustomConfig in FEATURE_EXTRACTOR_MAPPING._extra_content:
											del FEATURE_EXTRACTOR_MAPPING._extra_content[CustomConfig]







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







					'''simple docstring'''







					class        __lowercase       (							a_  ):



							"""simple docstring"""

							UpperCamelCase     :					Dict			       =		True

					try:
								AutoConfig.register("""custom"""		,      A	)
								AutoFeatureExtractor.register(A		,      A	)
								# If remote code is not set, the default is to use local
								lowerCamelCase    		=  AutoFeatureExtractor.from_pretrained(
								    """hf-internal-testing/test_dynamic_feature_extractor"""	)
								self.assertEqual(feature_extractor.__class__.__name__		,      """NewFeatureExtractor"""	)
								self.assertTrue(feature_extractor.is_local	)

								# If remote code is disabled, we load the local one.
								lowerCamelCase    		=  AutoFeatureExtractor.from_pretrained(
								    """hf-internal-testing/test_dynamic_feature_extractor"""		,      trust_remote_code=A	)
								self.assertEqual(feature_extractor.__class__.__name__		,      """NewFeatureExtractor"""	)
								self.assertTrue(feature_extractor.is_local	)

								# If remote is enabled, we load from the Hub
								lowerCamelCase    		=  AutoFeatureExtractor.from_pretrained(
								    """hf-internal-testing/test_dynamic_feature_extractor"""		,      trust_remote_code=A	)
								self.assertEqual(feature_extractor.__class__.__name__		,      """NewFeatureExtractor"""	)
								self.assertTrue(not hasattr(A		,      """is_local"""	)	)

					finally:
								if "custom" in CONFIG_MAPPING._extra_content:
											del CONFIG_MAPPING._extra_content["custom"]
								if CustomConfig in FEATURE_EXTRACTOR_MAPPING._extra_content:
											del FEATURE_EXTRACTOR_MAPPING._extra_content[CustomConfig]





import os
from datetime import datetime as dt

from github import Github


UpperCAmelCase   :    str     =		[
    "good first issue",
    "good second issue",
    "good difficult issue",
    "enhancement",
    "new pipeline/model",
    "new scheduler",
    "wip",
]






def 	__lowerCamelCase						(							):





			'''simple docstring'''




			lowerCamelCase    		=  Github(os.environ["""GITHUB_TOKEN"""]      )
			lowerCamelCase    		=  g.get_repo("""huggingface/diffusers"""      )
			lowerCamelCase    		=  repo.get_issues(state="""open"""      )

			for issue in open_issues:
						lowerCamelCase    		=  sorted(issue.get_comments()  ,							key=lambda lowerCamelCase__      : i.created_at  ,							reverse=lowerCamelCase__      )
						lowerCamelCase    		=  comments[0] if len(lowerCamelCase__      ) > 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()

