Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wiseplat
GitHub Repository: wiseplat/python-code
Path: blob/master/ invest-robot-contest_TinkoffBotTwitch-main/venv/lib/python3.8/site-packages/setuptools/distutils_patch.py
7738 views
1
"""
2
Ensure that the local copy of distutils is preferred over stdlib.
3
4
See https://github.com/pypa/setuptools/issues/417#issuecomment-392298401
5
for more motivation.
6
"""
7
8
import sys
9
import re
10
import os
11
import importlib
12
import warnings
13
14
15
is_pypy = '__pypy__' in sys.builtin_module_names
16
17
18
def warn_distutils_present():
19
if 'distutils' not in sys.modules:
20
return
21
if is_pypy and sys.version_info < (3, 7):
22
# PyPy for 3.6 unconditionally imports distutils, so bypass the warning
23
# https://foss.heptapod.net/pypy/pypy/-/blob/be829135bc0d758997b3566062999ee8b23872b4/lib-python/3/site.py#L250
24
return
25
warnings.warn(
26
"Distutils was imported before Setuptools. This usage is discouraged "
27
"and may exhibit undesirable behaviors or errors. Please use "
28
"Setuptools' objects directly or at least import Setuptools first.")
29
30
31
def clear_distutils():
32
if 'distutils' not in sys.modules:
33
return
34
warnings.warn("Setuptools is replacing distutils.")
35
mods = [name for name in sys.modules if re.match(r'distutils\b', name)]
36
for name in mods:
37
del sys.modules[name]
38
39
40
def enabled():
41
"""
42
Allow selection of distutils by environment variable.
43
"""
44
which = os.environ.get('SETUPTOOLS_USE_DISTUTILS', 'stdlib')
45
return which == 'local'
46
47
48
def ensure_local_distutils():
49
clear_distutils()
50
distutils = importlib.import_module('setuptools._distutils')
51
distutils.__name__ = 'distutils'
52
sys.modules['distutils'] = distutils
53
54
# sanity check that submodules load as expected
55
core = importlib.import_module('distutils.core')
56
assert '_distutils' in core.__file__, core.__file__
57
58
59
warn_distutils_present()
60
if enabled():
61
ensure_local_distutils()
62
63