|
| 1 | +import imp |
1 | 2 | import os
|
2 | 3 | import sys
|
3 |
| -import warnings |
4 |
| -import imp |
5 |
| -import opcode # opcode is not a virtualenv module, so we can use it to find the stdlib |
6 |
| - # Important! To work on pypy, this must be a module that resides in the |
7 |
| - # lib-python/modified-x.y.z directory |
| 4 | +import warnings |
| 5 | + |
| 6 | +# opcode is not a virtualenv module, so we can use it to find the stdlib |
| 7 | +# Important! To work on pypy, this must be a module that resides in the |
| 8 | +# lib-python/modified-x.y.z directory |
| 9 | +import opcode |
8 | 10 |
|
9 | 11 | dirname = os.path.dirname
|
10 | 12 |
|
11 |
| -distutils_path = os.path.join(os.path.dirname(opcode.__file__), 'distutils') |
| 13 | +distutils_path = os.path.join(os.path.dirname(opcode.__file__), "distutils") |
12 | 14 | if os.path.normpath(distutils_path) == os.path.dirname(os.path.normpath(__file__)):
|
13 |
| - warnings.warn( |
14 |
| - "The virtualenv distutils package at %s appears to be in the same location as the system distutils?") |
| 15 | + warnings.warn("The virtualenv distutils package at %s appears to be in the same location as the system distutils?") |
15 | 16 | else:
|
16 | 17 | __path__.insert(0, distutils_path)
|
17 |
| - real_distutils = imp.load_module("_virtualenv_distutils", None, distutils_path, ('', '', imp.PKG_DIRECTORY)) |
| 18 | + real_distutils = imp.load_module("_virtualenv_distutils", None, distutils_path, ("", "", imp.PKG_DIRECTORY)) |
18 | 19 | # Copy the relevant attributes
|
19 | 20 | try:
|
20 | 21 | __revision__ = real_distutils.__revision__
|
21 | 22 | except AttributeError:
|
22 | 23 | pass
|
23 | 24 | __version__ = real_distutils.__version__
|
24 | 25 |
|
25 |
| -from distutils import dist, sysconfig |
| 26 | +from distutils import dist, sysconfig # isort:skip |
26 | 27 |
|
27 | 28 | try:
|
28 | 29 | basestring
|
|
32 | 33 | ## patch build_ext (distutils doesn't know how to get the libs directory
|
33 | 34 | ## path on windows - it hardcodes the paths around the patched sys.prefix)
|
34 | 35 |
|
35 |
| -if sys.platform == 'win32': |
| 36 | +if sys.platform == "win32": |
36 | 37 | from distutils.command.build_ext import build_ext as old_build_ext
|
| 38 | + |
37 | 39 | class build_ext(old_build_ext):
|
38 |
| - def finalize_options (self): |
| 40 | + def finalize_options(self): |
39 | 41 | if self.library_dirs is None:
|
40 | 42 | self.library_dirs = []
|
41 | 43 | elif isinstance(self.library_dirs, basestring):
|
42 | 44 | self.library_dirs = self.library_dirs.split(os.pathsep)
|
43 |
| - |
| 45 | + |
44 | 46 | self.library_dirs.insert(0, os.path.join(sys.real_prefix, "Libs"))
|
45 | 47 | old_build_ext.finalize_options(self)
|
46 |
| - |
47 |
| - from distutils.command import build_ext as build_ext_module |
| 48 | + |
| 49 | + from distutils.command import build_ext as build_ext_module |
| 50 | + |
48 | 51 | build_ext_module.build_ext = build_ext
|
49 | 52 |
|
50 | 53 | ## distutils.dist patches:
|
51 | 54 |
|
52 | 55 | old_find_config_files = dist.Distribution.find_config_files
|
| 56 | + |
| 57 | + |
53 | 58 | def find_config_files(self):
|
54 | 59 | found = old_find_config_files(self)
|
55 |
| - system_distutils = os.path.join(distutils_path, 'distutils.cfg') |
56 |
| - #if os.path.exists(system_distutils): |
| 60 | + system_distutils = os.path.join(distutils_path, "distutils.cfg") |
| 61 | + # if os.path.exists(system_distutils): |
57 | 62 | # found.insert(0, system_distutils)
|
58 |
| - # What to call the per-user config file |
59 |
| - if os.name == 'posix': |
| 63 | + # What to call the per-user config file |
| 64 | + if os.name == "posix": |
60 | 65 | user_filename = ".pydistutils.cfg"
|
61 | 66 | else:
|
62 | 67 | user_filename = "pydistutils.cfg"
|
63 | 68 | user_filename = os.path.join(sys.prefix, user_filename)
|
64 | 69 | if os.path.isfile(user_filename):
|
65 | 70 | for item in list(found):
|
66 |
| - if item.endswith('pydistutils.cfg'): |
| 71 | + if item.endswith("pydistutils.cfg"): |
67 | 72 | found.remove(item)
|
68 | 73 | found.append(user_filename)
|
69 | 74 | return found
|
| 75 | + |
| 76 | + |
70 | 77 | dist.Distribution.find_config_files = find_config_files
|
71 | 78 |
|
72 | 79 | ## distutils.sysconfig patches:
|
73 | 80 |
|
74 | 81 | old_get_python_inc = sysconfig.get_python_inc
|
| 82 | + |
| 83 | + |
75 | 84 | def sysconfig_get_python_inc(plat_specific=0, prefix=None):
|
76 | 85 | if prefix is None:
|
77 | 86 | prefix = sys.real_prefix
|
78 | 87 | return old_get_python_inc(plat_specific, prefix)
|
| 88 | + |
| 89 | + |
79 | 90 | sysconfig_get_python_inc.__doc__ = old_get_python_inc.__doc__
|
80 | 91 | sysconfig.get_python_inc = sysconfig_get_python_inc
|
81 | 92 |
|
82 | 93 | old_get_python_lib = sysconfig.get_python_lib
|
| 94 | + |
| 95 | + |
83 | 96 | def sysconfig_get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
|
84 | 97 | if standard_lib and prefix is None:
|
85 | 98 | prefix = sys.real_prefix
|
86 | 99 | return old_get_python_lib(plat_specific, standard_lib, prefix)
|
| 100 | + |
| 101 | + |
87 | 102 | sysconfig_get_python_lib.__doc__ = old_get_python_lib.__doc__
|
88 | 103 | sysconfig.get_python_lib = sysconfig_get_python_lib
|
89 | 104 |
|
90 | 105 | old_get_config_vars = sysconfig.get_config_vars
|
| 106 | + |
| 107 | + |
91 | 108 | def sysconfig_get_config_vars(*args):
|
92 | 109 | real_vars = old_get_config_vars(*args)
|
93 |
| - if sys.platform == 'win32': |
| 110 | + if sys.platform == "win32": |
94 | 111 | lib_dir = os.path.join(sys.real_prefix, "libs")
|
95 |
| - if isinstance(real_vars, dict) and 'LIBDIR' not in real_vars: |
96 |
| - real_vars['LIBDIR'] = lib_dir # asked for all |
97 |
| - elif isinstance(real_vars, list) and 'LIBDIR' in args: |
98 |
| - real_vars = real_vars + [lib_dir] # asked for list |
| 112 | + if isinstance(real_vars, dict) and "LIBDIR" not in real_vars: |
| 113 | + real_vars["LIBDIR"] = lib_dir # asked for all |
| 114 | + elif isinstance(real_vars, list) and "LIBDIR" in args: |
| 115 | + real_vars = real_vars + [lib_dir] # asked for list |
99 | 116 | return real_vars
|
| 117 | + |
| 118 | + |
100 | 119 | sysconfig_get_config_vars.__doc__ = old_get_config_vars.__doc__
|
101 | 120 | sysconfig.get_config_vars = sysconfig_get_config_vars
|
0 commit comments