o nh@sUdZddlmZddlZddlZddlZddlZddlmZm Z m Z ddl Z edZ edeejZgZded< d d Ze d!d dZe d"ddZd#ddZd$ddZddZddZddZdd ZdS)%z Monkey patching of distutils. ) annotationsN)TypeVarcastoverload_T _UnpatchTz list[str]__all__cCs"tdkr |f|jSt|S)am Returns the bases classes for cls sorted by the MRO. Works around an issue on Jython where inspect.getmro will not return all base classes if multiple classes share the same name. Instead, this function will return a tuple containing the class itself, and the contents of cls.__bases__. See https://github.com/pypa/setuptools/issues/1024. Jython)platformpython_implementation __bases__inspectgetmro)clsrT/opt/prometheus-monitoring-scripts/lib/python3.10/site-packages/setuptools/monkey.py_get_mros  ritemreturncCdSNrrrrr get_unpatched(robjectNonecCrrrrrrrr*r"type | types.FunctionType | object type | types.FunctionType | NonecCs*t|tr t|St|tjrt|SdSr) isinstancetypeget_unpatched_classtypes FunctionTypeget_unpatched_functionrrrrr,s  rtype[_T]cCs<ddt|D}t|}|jdsd|}t||S)zProtect against re-patching the distutils if reloaded Also ensures that no other distutils extension monkeypatched the distutils first. css*|]}|jdsttt|VqdS) setuptoolsN) __module__ startswithrrr).0rrrr <s   z&get_unpatched_class.. distutilsz&distutils has already been patched by )rnextr&r'AssertionError)rexternal_basesbasemsgrrrr 6s  r cCsrddl}|jtj_ttjtjtjfD]}|jj|_q|jj tj_ |jj tj_ dt j vr7|jj t j d_ dSdS)Nrzdistutils.command.build_ext) r%Commandr*core_patch_distribution_metadatadistcmd Distribution extension Extensionsysmodules)r%modulerrr patch_allHs     r;cCs6ddlm} dD]}t||}ttjj||q dS)N)_core_metadata)write_pkg_infowrite_pkg_file read_pkg_fileget_metadata_version get_fullname)r=getattrsetattrr*r3DistributionMetadata)r=attrnew_valrrrr2]s  r2cCs*t||}t|d|t|||dS)z Patch func_name in target_mod with replacement Important - original must be resolved by name to avoid patching an already patched function. unpatchedN)rDvars setdefaultrE) replacement target_mod func_nameoriginalrrr patch_funcls rPcCs|jSr)rI) candidaterrrr#}sr#)rrrr)rrrr)rrrr)rr$rr$)__doc__ __future__rr r r8r!typingrrrdistutils.filelistr*rrr"rr__annotations__rrr r;r2rPr#rrrrs.