






import importlib.metadata
import operator
import re
import sys
from typing import Optional

from packaging import version


__UpperCAmelCase								=						{
    '''<''': operator.lt,
    '''<=''': operator.le,
    '''==''': operator.eq,
    '''!=''': operator.ne,
    '''>=''': operator.ge,
    '''>''': operator.gt,
}




def      lowercase__      (     __snake_case    :							Union[str, Any]     ,       __snake_case    :							Optional[Any]     ,       __snake_case    :							Dict     ,       __snake_case    :							str     ,       __snake_case    :							List[Any]     ,       __snake_case    :							Dict  ):


					'''simple docstring'''


					if got_ver is None or want_ver is None:
										raise ValueError(
										    F"Unable to compare versions for {requirement}: need={want_ver} found={got_ver}. This is unusual. Consider"
										    F" reinstalling {pkg}."  )
					if not ops[op](version.parse(__a  )     ,       version.parse(__a  )  ):
										raise ImportError(
										    F"{requirement} is required for a normal functioning of this module, but found {pkg}=={got_ver}.{hint}"  )




def      lowercase__      (     __snake_case    :							str     ,       __snake_case    :							Optional[str] = None  ):


					'''simple docstring'''


					UpperCAmelCase_    :      Dict            =						F"\n{hint}" if hint is not None else ''

					# non-versioned check
					if re.match(R'^[\w_\-\d]+$'     ,       __a  ):
										UpperCAmelCase_       ,  UpperCAmelCase_       ,  UpperCAmelCase_    :      str            =						requirement, None, None
					else:
										UpperCAmelCase_    :      Union[str, Any]            =						re.findall(R'^([^!=<>\s]+)([\s!=<>]{1,2}.+)'     ,       __a  )
										if not match:
															raise ValueError(
															    'requirement needs to be in the pip package format, .e.g., package_a==1.23, or package_b>=1.23, but'
															    F" got {requirement}"  )
										UpperCAmelCase_       ,  UpperCAmelCase_    :      Optional[int]            =						match[0]
										UpperCAmelCase_    :      str            =						want_full.split(','  )  # there could be multiple requirements
										UpperCAmelCase_    :      int            =						{}
										for w in want_range:
															UpperCAmelCase_    :      Optional[Any]            =						re.findall(R'^([\s!=<>]{1,2})(.+)'     ,       __a  )
															if not match:
																				raise ValueError(
																				    'requirement needs to be in the pip package format, .e.g., package_a==1.23, or package_b>=1.23,'
																				    F" but got {requirement}"  )
															UpperCAmelCase_       ,  UpperCAmelCase_    :      Dict            =						match[0]
															UpperCAmelCase_    :      str            =						want_ver
															if op not in ops:
																				raise ValueError(F"{requirement}: need one of {list(ops.keys()  )}, but got {op}"  )

    # special case
					if pkg == "python":
										UpperCAmelCase_    :      List[Any]            =						'.'.join([str(__a  ) for x in sys.version_info[:3]]  )
										for op, want_ver in wanted.items():
															_compare_versions(__a     ,       __a     ,       __a     ,       __a     ,       __a     ,       __a  )
										return

					# check if any version is installed
					try:
										UpperCAmelCase_    :      Any            =						importlib.metadata.version(__a  )
					except importlib.metadata.PackageNotFoundError:
										raise importlib.metadata.PackageNotFoundError(
										    F"The \'{requirement}\' distribution was not found and is required by this application. {hint}"  )

					# check that the right version is installed if version number or a range was provided
					if want_ver is not None:
										for op, want_ver in wanted.items():
															_compare_versions(__a     ,       __a     ,       __a     ,       __a     ,       __a     ,       __a  )






def      lowercase__      (     __snake_case    :							Optional[Any]  ):


					'''simple docstring'''


					UpperCAmelCase_    :      Union[str, Any]            =						'Try: pip install transformers -U or pip install -e \'.[dev]\' if you\'re working with git main'
					return require_version(__a     ,       __a  )













# This code is adapted from OpenAI's release
# https://github.com/openai/human-eval/blob/master/human_eval/execution.py

import contextlib
import faulthandler
import io
import multiprocessing
import os
import platform
import signal
import tempfile







def    __lowerCamelCase					(							__a   :List[str]    ,     __a   :List[Any]    ,     __a   :Union[str, Any]    ,     __a   :List[Any]    )		->				Dict:






		"""simple docstring"""

		A__        =   multiprocessing.Manager()
		A__        =   manager.list()

		A__        =   multiprocessing.Process(target=__a    ,     args=(check_program, result, timeout)    )
		p.start()
		p.join(timeout=timeout + 1    )
		if p.is_alive():
				p.kill()

		if not result:
				result.append("""timed out"""    )

		return {
		    "task_id": task_id,
		    "passed": result[0] == "passed",
		    "result": result[0],
		    "completion_id": completion_id,
		}







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






		"""simple docstring"""

		with create_tempdir():
				# These system calls are needed when cleaning up tempdir.
				import os
				import shutil

				A__        =   shutil.rmtree
				A__        =   os.rmdir
				A__        =   os.chdir

				# Disable functionalities that can make destructive changes to the test.
				reliability_guard()

				# Run program.
				try:
						A__        =   {}
						with swallow_io():
								with time_limit(__a    ):
										exec(__a    ,     __a    )
						result.append("""passed"""    )
				except TimeoutException:
						result.append("""timed out"""    )
				except BaseException as e:
						result.append(F'failed: {e}'    )

				# Needed for cleaning up.
				A__        =   rmtree
				A__        =   rmdir
				A__        =   chdir







@contextlib.contextmanager
def    __lowerCamelCase					(							__a   :List[str]    )		->				Dict:






		"""simple docstring"""

		def signal_handler(__a   :List[Any]    ,     __a   :Optional[Any]    ):
				raise TimeoutException("""Timed out!"""    )

		signal.setitimer(signal.ITIMER_REAL    ,     __a    )
		signal.signal(signal.SIGALRM    ,     __a    )
		try:
				yield
		finally:
				signal.setitimer(signal.ITIMER_REAL    ,     0    )







@contextlib.contextmanager
def    __lowerCamelCase					(							)		->				Union[str, Any]:






		"""simple docstring"""

		A__        =   WriteOnlyStringIO()
		with contextlib.redirect_stdout(__a    ):
				with contextlib.redirect_stderr(__a    ):
						with redirect_stdin(__a    ):
								yield







@contextlib.contextmanager
def    __lowerCamelCase					(							)		->				Dict:






		"""simple docstring"""

		with tempfile.TemporaryDirectory() as dirname:
				with chdir(__a    ):
						yield dirname


class   A			(SCREAMING_SNAKE_CASE    ):
			'''simple docstring'''




			pass


class   A			(io.StringIO    ):
			'''simple docstring'''




			def    a_       (			self   :    Any							,	*__lowerCAmelCase   :    List[str]							,	**__lowerCAmelCase   :    str   )	->	Dict:







					"""simple docstring"""






					raise OSError






			def    a_       (			self   :    Optional[Any]							,	*__lowerCAmelCase   :    Any							,	**__lowerCAmelCase   :    Optional[int]   )	->	str:







					"""simple docstring"""






					raise OSError






			def    a_       (			self   :    Optional[Any]							,	*__lowerCAmelCase   :    Any							,	**__lowerCAmelCase   :    Any   )	->	int:







					"""simple docstring"""






					raise OSError







			def    a_       (			self   :    str							,	*__lowerCAmelCase   :    Any							,	**__lowerCAmelCase   :    Union[str, Any]   )	->	int:







					"""simple docstring"""






					return False


class   A			(contextlib._RedirectStream    ):  # type: ignore
			'''simple docstring'''




			__lowerCamelCase	:       Union[str, Any]							=    '''stdin'''







@contextlib.contextmanager
def    __lowerCamelCase					(							__a   :Union[str, Any]    )		->				List[str]:






		"""simple docstring"""

		if root == ".":
				yield
				return
		A__        =   os.getcwd()
		os.chdir(__a    )
		try:
				yield
		except BaseException as exc:
				raise exc
		finally:
				os.chdir(__a    )







def    __lowerCamelCase					(							__a   :Union[str, Any]=None    )		->				Dict:






		"""simple docstring"""

		if maximum_memory_bytes is not None:
				import resource

				resource.setrlimit(resource.RLIMIT_AS    ,     (maximum_memory_bytes, maximum_memory_bytes)    )
				resource.setrlimit(resource.RLIMIT_DATA    ,     (maximum_memory_bytes, maximum_memory_bytes)    )
				if not platform.uname().system == "Darwin":
						resource.setrlimit(resource.RLIMIT_STACK    ,     (maximum_memory_bytes, maximum_memory_bytes)    )

		faulthandler.disable()

		import builtins

		A__        =   None
		A__        =   None

		import os

		A__        =   """1"""

		A__        =   None
		A__        =   None
		A__        =   None
		A__        =   None
		A__        =   None
		A__        =   None
		A__        =   None
		A__        =   None
		A__        =   None
		A__        =   None
		A__        =   None
		A__        =   None
		A__        =   None
		A__        =   None
		A__        =   None
		A__        =   None
		A__        =   None
		A__        =   None
		A__        =   None
		A__        =   None
		A__        =   None
		A__        =   None
		A__        =   None
		A__        =   None
		A__        =   None
		A__        =   None
		A__        =   None

		import shutil

		A__        =   None
		A__        =   None
		A__        =   None

		import subprocess

		A__        =   None  # type: ignore

		A__        =   None

		import sys

		A__        =   None
		A__        =   None
		A__        =   None
		A__        =   None
		A__        =   None



