14
14
import sysconfig
15
15
from distutils import sysconfig as distutils_sysconfig
16
16
from distutils .command .install import SCHEME_KEYS # type: ignore
17
+ from distutils .command .install import install as distutils_install_command
17
18
18
19
from pip ._internal .utils import appdirs
19
20
from pip ._internal .utils .compat import WINDOWS
20
- from pip ._internal .utils .typing import MYPY_CHECK_RUNNING
21
+ from pip ._internal .utils .typing import MYPY_CHECK_RUNNING , cast
21
22
from pip ._internal .utils .virtualenv import running_under_virtualenv
22
23
23
24
if MYPY_CHECK_RUNNING :
24
- from typing import Any , Union , Dict , List , Optional
25
+ from typing import Dict , List , Optional , Union
26
+
27
+ from distutils .cmd import Command as DistutilsCommand
25
28
26
29
27
30
# Application Directories
@@ -88,29 +91,25 @@ def get_src_prefix():
88
91
bin_py = '/usr/local/bin'
89
92
90
93
91
- def distutils_scheme (dist_name , user = False , home = None , root = None ,
92
- isolated = False , prefix = None ):
94
+ def distutils_scheme (
95
+ dist_name , user = False , home = None , root = None , isolated = False , prefix = None
96
+ ):
93
97
# type:(str, bool, str, str, bool, str) -> dict
94
98
"""
95
99
Return a distutils install scheme
96
100
"""
97
101
from distutils .dist import Distribution
98
102
99
- scheme = {}
100
-
101
- if isolated :
102
- extra_dist_args = {"script_args" : ["--no-user-cfg" ]}
103
- else :
104
- extra_dist_args = {}
105
103
dist_args = {'name' : dist_name } # type: Dict[str, Union[str, List[str]]]
106
- dist_args .update (extra_dist_args )
104
+ if isolated :
105
+ dist_args ["script_args" ] = ["--no-user-cfg" ]
107
106
108
107
d = Distribution (dist_args )
109
- # Ignoring, typeshed issue reported python/typeshed/issues/2567
110
108
d .parse_config_files ()
111
- # NOTE: Ignoring type since mypy can't find attributes on 'Command'
112
- i = d .get_command_obj ('install' , create = True ) # type: Any
113
- assert i is not None
109
+ obj = None # type: Optional[DistutilsCommand]
110
+ obj = d .get_command_obj ('install' , create = True )
111
+ assert obj is not None
112
+ i = cast (distutils_install_command , obj )
114
113
# NOTE: setting user or home has the side-effect of creating the home dir
115
114
# or user base for installations during finalize_options()
116
115
# ideally, we'd prefer a scheme class that has no side-effects.
@@ -123,6 +122,8 @@ def distutils_scheme(dist_name, user=False, home=None, root=None,
123
122
i .home = home or i .home
124
123
i .root = root or i .root
125
124
i .finalize_options ()
125
+
126
+ scheme = {}
126
127
for key in SCHEME_KEYS :
127
128
scheme [key ] = getattr (i , 'install_' + key )
128
129
@@ -131,9 +132,7 @@ def distutils_scheme(dist_name, user=False, home=None, root=None,
131
132
# platlib). Note, i.install_lib is *always* set after
132
133
# finalize_options(); we only want to override here if the user
133
134
# has explicitly requested it hence going back to the config
134
-
135
- # Ignoring, typeshed issue reported python/typeshed/issues/2567
136
- if 'install_lib' in d .get_option_dict ('install' ): # type: ignore
135
+ if 'install_lib' in d .get_option_dict ('install' ):
137
136
scheme .update (dict (purelib = i .install_lib , platlib = i .install_lib ))
138
137
139
138
if running_under_virtualenv ():
0 commit comments