aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2023-12-12 21:14:39 +0300
committershadchin <shadchin@yandex-team.com>2023-12-12 21:39:21 +0300
commit2ce9cccb9b0bdd4cd7a3491dc5cbf8687cda51de (patch)
treea412d03dc02b70689ae5cb6dd6178c79f0c573f5
parent4c3a87e9ad4684ade203e501dd9ce64cd95d5a0e (diff)
downloadydb-2ce9cccb9b0bdd4cd7a3491dc5cbf8687cda51de.tar.gz
Support override `distutils` from `setuptools`
-rw-r--r--contrib/python/numpy/py3/ya.make4
-rw-r--r--contrib/python/setuptools/py3/_distutils_hack/__init__.py2
-rw-r--r--library/python/runtime_py3/importer.pxi26
3 files changed, 29 insertions, 3 deletions
diff --git a/contrib/python/numpy/py3/ya.make b/contrib/python/numpy/py3/ya.make
index 52ce727235..cc5ca1691b 100644
--- a/contrib/python/numpy/py3/ya.make
+++ b/contrib/python/numpy/py3/ya.make
@@ -35,8 +35,8 @@ NO_LINT()
NO_CHECK_IMPORTS(
numpy._pyinstaller.*
numpy.core.umath_tests
- numpy.distutils.command.*
- numpy.distutils.msvc9compiler
+ numpy.distutils.*
+ numpy.f2py.*
)
CFLAGS(
diff --git a/contrib/python/setuptools/py3/_distutils_hack/__init__.py b/contrib/python/setuptools/py3/_distutils_hack/__init__.py
index 51da093e5d..b951c2defd 100644
--- a/contrib/python/setuptools/py3/_distutils_hack/__init__.py
+++ b/contrib/python/setuptools/py3/_distutils_hack/__init__.py
@@ -44,7 +44,7 @@ def enabled():
"""
Allow selection of distutils by environment variable.
"""
- which = os.environ.get('SETUPTOOLS_USE_DISTUTILS', 'stdlib')
+ which = os.environ.get('SETUPTOOLS_USE_DISTUTILS', 'local')
return which == 'local'
diff --git a/library/python/runtime_py3/importer.pxi b/library/python/runtime_py3/importer.pxi
index 3853678939..901c9faa3a 100644
--- a/library/python/runtime_py3/importer.pxi
+++ b/library/python/runtime_py3/importer.pxi
@@ -219,6 +219,32 @@ class ResourceImporter(object):
return self.arcadia_source_finder.get_module_path(fullname)
def find_spec(self, fullname, path=None, target=None):
+ # Поддежка переопределения стандартного distutils из пакетом из setuptools
+ if fullname.startswith("distutils."):
+ if path and len(path) > 0 and "/setuptools/_distutils" in path[0]:
+ import importlib
+ import importlib.abc
+
+ setuptools_name = "setuptools._distutils.{}".format(fullname.removeprefix("distutils."))
+ is_package = self.is_package(setuptools_name)
+ if is_package:
+ source = self.get_source(f"{setuptools_name}.__init__")
+ relpath = self._find_mod_path(f"{setuptools_name}.__init__")
+ else:
+ source = self.get_source(setuptools_name)
+ relpath = self._find_mod_path(setuptools_name)
+
+ class DistutilsLoader(importlib.abc.Loader):
+ def exec_module(self, module):
+ code = compile(source, _s(relpath), 'exec', dont_inherit=True)
+ module.__file__ = code.co_filename
+ if is_package:
+ module.__path__= [executable + path_sep + setuptools_name.replace('.', path_sep)]
+
+ _call_with_frames_removed(exec, code, module.__dict__)
+
+ return spec_from_loader(fullname, DistutilsLoader(), is_package=is_package)
+
try:
is_package = self.is_package(fullname)
except ImportError: