58
58
59
59
CACHE_DIR = os .environ .get ("PIPENV_CACHE_DIR" , user_cache_dir ("pipenv" ))
60
60
61
- # The following are necessary for people who like to use "if __name__" conditionals
62
- # in their setup.py scripts
63
- _setup_stop_after = None
64
- _setup_distribution = None
65
-
66
61
67
62
def pep517_subprocess_runner (cmd , cwd = None , extra_environ = None ) -> None :
68
63
"""The default method of calling the wrapper subprocess."""
@@ -75,8 +70,9 @@ def pep517_subprocess_runner(cmd, cwd=None, extra_environ=None) -> None:
75
70
76
71
class BuildEnv (envbuild .BuildEnvironment ):
77
72
def pip_install (self , reqs ):
73
+ python = os .environ .get ("PIP_PYTHON_PATH" , sys .executable )
78
74
cmd = [
79
- sys . executable ,
75
+ python ,
80
76
"-m" ,
81
77
"pip" ,
82
78
"install" ,
@@ -1123,46 +1119,24 @@ def run_setup(script_path, egg_base=None):
1123
1119
:return: The metadata dictionary
1124
1120
:rtype: Dict[Any, Any]
1125
1121
"""
1122
+ from pathlib import Path
1126
1123
1127
1124
if not os .path .exists (script_path ):
1128
1125
raise FileNotFoundError (script_path )
1129
1126
target_cwd = os .path .dirname (os .path .abspath (script_path ))
1130
1127
if egg_base is None :
1131
1128
egg_base = os .path .join (target_cwd , "reqlib-metadata" )
1132
1129
with temp_path (), cd (target_cwd ):
1133
- # This is for you, Hynek
1134
- # see https://github.com/hynek/environ_config/blob/69b1c8a/setup.py
1135
1130
args = ["egg_info" ]
1136
1131
if egg_base :
1137
1132
args += ["--egg-base" , egg_base ]
1138
- script_name = os .path .basename (script_path )
1139
- g = {"__file__" : script_name , "__name__" : "__main__" }
1140
- sys .path .insert (0 , target_cwd )
1141
-
1142
- save_argv = sys .argv .copy ()
1143
- try :
1144
- global _setup_distribution , _setup_stop_after
1145
- _setup_stop_after = "run"
1146
- sys .argv [0 ] = script_name
1147
- sys .argv [1 :] = args
1148
- with open (script_name , "rb" ) as f :
1149
- contents = f .read ().replace (rb"\r\n" , rb"\n" )
1150
- exec (contents , g )
1151
- # We couldn't import everything needed to run setup
1152
- except Exception :
1153
- python = os .environ .get ("PIP_PYTHON_PATH" , sys .executable )
1154
1133
1155
- sp .run (
1156
- [python , "setup.py" ] + args ,
1157
- cwd = target_cwd ,
1158
- stdout = sp .PIPE ,
1159
- stderr = sp .PIPE ,
1160
- )
1161
- finally :
1162
- _setup_stop_after = None
1163
- sys .argv = save_argv
1164
- _setup_distribution = get_metadata (egg_base , metadata_type = "egg" )
1165
- dist = _setup_distribution
1134
+ python = os .environ .get ("PIP_PYTHON_PATH" , sys .executable )
1135
+ sp .run (
1136
+ [python , "setup.py" ] + args ,
1137
+ capture_output = True ,
1138
+ )
1139
+ dist = get_metadata (egg_base , metadata_type = "egg" )
1166
1140
return dist
1167
1141
1168
1142
0 commit comments