Skip to content

Commit 4ae443b

Browse files
committed
Try to make pip 10.x work on Windows
there is a number of bugs Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent 31d7846 commit 4ae443b

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

etc/configure.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
1313
# specific language governing permissions and limitations under the License.
1414

15-
1615
"""
1716
This script a configuration helper to select pip requirement files to install
1817
and python and shell configuration scripts to execute based on provided config
@@ -74,7 +73,6 @@
7473
import shutil
7574
import subprocess
7675

77-
7876
# platform-specific file base names
7977
sys_platform = str(sys.platform).lower()
8078
on_win = False
@@ -89,7 +87,6 @@
8987
raise Exception('Unsupported OS/platform')
9088
platform_names = tuple()
9189

92-
9390
# common file basenames for requirements and scripts
9491
base = ('base',)
9592

@@ -108,9 +105,12 @@
108105
shell_scripts = ('win.bat',)
109106

110107

111-
def call(cmd, root_dir):
108+
def call(cmd, root_dir, quiet=True):
112109
""" Run a `cmd` command (as a list of args) with all env vars."""
113110
cmd = ' '.join(cmd)
111+
if not quiet:
112+
print(' Running command:', repr(cmd))
113+
114114
if subprocess.Popen(cmd, shell=True, env=dict(os.environ), cwd=root_dir).wait() != 0:
115115
print()
116116
print('Failed to execute command:\n%(cmd)s. Aborting...' % locals())
@@ -188,18 +188,18 @@ def create_virtualenv(std_python, root_dir, tpp_dirs, quiet=False):
188188
components.
189189
"""
190190
if not quiet:
191-
print("* Configuring Python ...")
191+
print('* Configuring Python ...')
192192
# search virtualenv.py in the tpp_dirs. keep the first found
193193
venv_py = None
194194
for tpd in tpp_dirs:
195195
venv = os.path.join(root_dir, tpd, 'virtualenv.py')
196196
if os.path.exists(venv):
197-
venv_py = '"' + venv + '"'
197+
venv_py = ''' + venv + '''
198198
break
199199

200200
# error out if venv_py not found
201201
if not venv_py:
202-
print("Configuration Error ... aborting.")
202+
print('Configuration Error ... aborting.')
203203
exit(1)
204204

205205
vcmd = [std_python, venv_py, '--never-download']
@@ -209,12 +209,12 @@ def create_virtualenv(std_python, root_dir, tpp_dirs, quiet=False):
209209
vcmd.extend(build_pip_dirs_args(tpp_dirs, root_dir))
210210
# we create the virtualenv in the root_dir
211211
vcmd.append('"' + root_dir + '"')
212-
call(vcmd, root_dir)
212+
call(vcmd, root_dir, quiet)
213213

214214

215215
def activate(root_dir):
216216
""" Activate a virtualenv in the current process."""
217-
print("* Activating ...")
217+
print('* Activating ...')
218218
bin_dir = os.path.join(root_dir, 'bin')
219219
activate_this = os.path.join(bin_dir, 'activate_this.py')
220220
with open(activate_this) as f:
@@ -228,29 +228,36 @@ def install_3pp(configs, root_dir, tpp_dirs, quiet=False):
228228
using the vendored components in `tpp_dirs`.
229229
"""
230230
if not quiet:
231-
print("* Installing components ...")
231+
print('* Installing components ...')
232232
requirement_files = get_conf_files(configs, root_dir, requirements)
233233
for req_file in requirement_files:
234-
pcmd = ['pip', 'install', '--no-index', '--no-cache-dir']
234+
if on_win:
235+
pcmd = ['python', '-m']
236+
else:
237+
pcmd = []
238+
pcmd += ['pip', 'install', '--no-index', '--no-cache-dir']
235239
if quiet:
236240
pcmd += ['--quiet']
241+
if on_win:
242+
pcmd += ['--verbose', '--verbose', '--verbose']
243+
237244
pip_dir_args = list(build_pip_dirs_args(tpp_dirs, root_dir, '--find-links='))
238245
pcmd.extend(pip_dir_args)
239246
req_loc = os.path.join(root_dir, req_file)
240247
pcmd.extend(['-r' , '"' + req_loc + '"'])
241-
call(pcmd, root_dir)
248+
call(pcmd, root_dir, quiet)
242249

243250

244251
def run_scripts(configs, root_dir, configured_python, quiet=False):
245252
"""
246253
Run Python scripts and shell scripts found in `configs`.
247254
"""
248255
if not quiet:
249-
print("* Configuring ...")
256+
print('* Configuring ...')
250257
# Run Python scripts for each configurations
251258
for py_script in get_conf_files(configs, root_dir, python_scripts):
252259
cmd = [configured_python, '"' + os.path.join(root_dir, py_script) + '"']
253-
call(cmd, root_dir)
260+
call(cmd, root_dir, quiet)
254261

255262
# Run sh_script scripts for each configurations
256263
for sh_script in get_conf_files(configs, root_dir, shell_scripts):
@@ -259,7 +266,7 @@ def run_scripts(configs, root_dir, configured_python, quiet=False):
259266
if on_win:
260267
cmd = []
261268
cmd = cmd + [os.path.join(root_dir, sh_script)]
262-
call(cmd, root_dir)
269+
call(cmd, root_dir, quiet)
263270

264271

265272
def chmod_bin(directory):
@@ -352,8 +359,11 @@ def get_conf_files(config_dir_paths, root_dir, file_names=requirements):
352359
if not os.path.exists(scripts_dir):
353360
os.makedirs(scripts_dir)
354361
if not os.path.exists(bin_dir):
355-
cmd = ('mklink /J "%(bin_dir)s" "%(scripts_dir)s"' % locals()).split()
356-
call(cmd, root_dir)
362+
cmd = [
363+
'mklink', '/J',
364+
'"%(bin_dir)s"' % locals(),
365+
'"%(scripts_dir)s"' % locals()]
366+
call(cmd, root_dir, run_quiet)
357367
else:
358368
configured_python = os.path.join(bin_dir, 'python')
359369
scripts_dir = bin_dir
@@ -398,5 +408,5 @@ def get_conf_files(config_dir_paths, root_dir, file_names=requirements):
398408
run_scripts(configs, root_dir, configured_python, quiet=run_quiet)
399409
chmod_bin(bin_dir)
400410
if not run_quiet:
401-
print("* Configuration completed.")
411+
print('* Configuration completed.')
402412
print()

0 commit comments

Comments
 (0)