





'''simple docstring'''






import contextlib
from multiprocessing import Pool, RLock

from tqdm.auto import tqdm

from ..utils import experimental, logging


snake_case_     =	logging.get_logger(__name__)


class   _lowercase						:
   _UpperCamelCase       		=   None







@experimental
def 							_lowerCamelCase(  UpperCamelCase__    : Optional[Any]    ,       UpperCamelCase__    : Tuple    ,       UpperCamelCase__    : List[Any]    ,       UpperCamelCase__    : Tuple    ,       UpperCamelCase__    : int    ,       UpperCamelCase__    : Union[str, Any]    ,       UpperCamelCase__    : List[str]		)		->  List[str]:

    '''simple docstring'''





    if ParallelBackendConfig.backend_name is None:
        return _map_with_multiprocessing_pool(
            UpperCamelCase__    ,       UpperCamelCase__    ,       UpperCamelCase__    ,       UpperCamelCase__    ,       UpperCamelCase__    ,       UpperCamelCase__    ,       UpperCamelCase__		)

    return _map_with_joblib(UpperCamelCase__    ,       UpperCamelCase__    ,       UpperCamelCase__    ,       UpperCamelCase__    ,       UpperCamelCase__    ,       UpperCamelCase__    ,       UpperCamelCase__		)
def 							_lowerCamelCase(  UpperCamelCase__    : List[str]    ,       UpperCamelCase__    : List[Any]    ,       UpperCamelCase__    : Optional[Any]    ,       UpperCamelCase__    : Dict    ,       UpperCamelCase__    : Union[str, Any]    ,       UpperCamelCase__    : Tuple    ,       UpperCamelCase__    : Optional[Any]		)		->  Optional[Any]:

    '''simple docstring'''





    A       :       Dict							=						num_proc if num_proc <= len(UpperCamelCase__		) else len(UpperCamelCase__		)
    A       :       Any							=						[]  # We organize the splits ourselve (contiguous splits)
    for index in range(UpperCamelCase__		):
        A       :       Union[str, Any]							=						len(UpperCamelCase__		) // num_proc
        A       :       List[Any]							=						len(UpperCamelCase__		) % num_proc
        A       :       Optional[Any]							=						div * index + min(UpperCamelCase__    ,       UpperCamelCase__		)
        A       :       List[str]							=						start + div + (1 if index < mod else 0)
        split_kwds.append((function, iterable[start:end], types, index, disable_tqdm, desc)		)

    if len(UpperCamelCase__		) != sum(len(i[1]		) for i in split_kwds		):
        raise ValueError(
            F'''Error dividing inputs iterable among processes. '''
            F'''Total number of objects {len(UpperCamelCase__		)}, '''
            F'''length: {sum(len(i[1]		) for i in split_kwds		)}'''		)

    logger.info(
        F'''Spawning {num_proc} processes for {len(UpperCamelCase__		)} objects in slices of {[len(i[1]		) for i in split_kwds]}'''		)
    A       :       Dict							=						None, None
    if not disable_tqdm:
        A       :       List[str]							=						(RLock(),), tqdm.set_lock
    with Pool(UpperCamelCase__    ,       initargs=UpperCamelCase__    ,       initializer=UpperCamelCase__		) as pool:
        A       :       str							=						pool.map(UpperCamelCase__    ,       UpperCamelCase__		)
    logger.info(F'''Finished {num_proc} processes'''		)
    A       :       List[Any]							=						[obj for proc_res in mapped for obj in proc_res]
    logger.info(F'''Unpacked {len(UpperCamelCase__		)} objects'''		)

    return mapped
def 							_lowerCamelCase(  UpperCamelCase__    : str    ,       UpperCamelCase__    : Dict    ,       UpperCamelCase__    : List[Any]    ,       UpperCamelCase__    : Tuple    ,       UpperCamelCase__    : int    ,       UpperCamelCase__    : Dict    ,       UpperCamelCase__    : List[str]		)		->  Any:

    '''simple docstring'''





    import joblib

    with joblib.parallel_backend(ParallelBackendConfig.backend_name    ,       n_jobs=UpperCamelCase__		):
        return joblib.Parallel()(
            joblib.delayed(UpperCamelCase__		)((function, obj, types, None, True, None)		) for obj in iterable		)





@experimental
@contextlib.contextmanager
def 							_lowerCamelCase(  UpperCamelCase__    : str		)		->  List[str]:

    '''simple docstring'''





    A       :       Any							=						backend_name

    if backend_name == "spark":
        from joblibspark import register_spark

        register_spark()

        # TODO: call create_cache_and_write_probe if "download" in steps
        # TODO: raise NotImplementedError when Dataset.map etc is called

    try:
        yield
    finally:
        A       :       Dict							=						None







'''simple docstring'''






import requests

snake_case_     =	"""YOUR API KEY"""
def 							_lowerCamelCase(  UpperCamelCase__    : str    ,       UpperCamelCase__    : str = giphy_api_key		)		->  list:
    A       :       Optional[Any]							=						'''+'''.join(query.split()		)
    A       :       List[Any]							=						F'''https://api.giphy.com/v1/gifs/search?q={formatted_query}&api_key={api_key}'''
    A       :       int							=						requests.get(UpperCamelCase__		).json()['''data''']
    return [gif["url"] for gif in gifs]


if __name__ == "__main__":
     print("""\n""".join(get_gifs("""space ship""")))
