Skip to content

Commit 8f84f3e

Browse files
authored
Merge pull request pypa#619 from techalchemy/windows_concurrency
Windows concurrency
2 parents dc1e55a + 5f21651 commit 8f84f3e

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

pipenv/cli.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from .utils import (
3333
convert_deps_from_pip, convert_deps_to_pip, is_required_version,
3434
proper_case, pep423_name, split_vcs, resolve_deps, shellquote, is_vcs,
35-
python_version, suggest_package, is_file
35+
python_version, suggest_package, find_windows_executable, is_file
3636
)
3737
from .__version__ import __version__
3838
from . import pep508checker, progress
@@ -1136,10 +1136,6 @@ def pip_install(
11361136
no_deps=True, verbose=False, block=True
11371137
):
11381138

1139-
# Block is always true on windows, for there be bugs.
1140-
if os.name == 'nt':
1141-
block=True
1142-
11431139
# Create files for hash mode.
11441140
if (not ignore_hashes) and (r is None):
11451141
r = tempfile.mkstemp(prefix='pipenv-', suffix='-requirement.txt')[1]
@@ -1173,8 +1169,12 @@ def pip_install(
11731169

11741170
no_deps = '--no-deps' if no_deps else ''
11751171

1176-
pip_command = '"{0}" install {3} {1} -i {2} --exists-action w'.format(
1177-
which_pip(allow_global=allow_global),
1172+
quoted_pip = which_pip(allow_global=allow_global)
1173+
if os.name != 'nt':
1174+
quoted_pip = shellquote(quoted_pip)
1175+
1176+
pip_command = '{0} install {3} {1} -i {2} --exists-action w'.format(
1177+
quoted_pip,
11781178
install_reqs,
11791179
source['url'],
11801180
no_deps
@@ -1211,10 +1211,7 @@ def which(command, location=None, allow_global=False):
12111211

12121212
if not allow_global:
12131213
if os.name == 'nt':
1214-
if command.endswith('.py'):
1215-
p = os.sep.join([location] + ['Scripts\{0}'.format(command)])
1216-
else:
1217-
p = os.sep.join([location] + ['Scripts\{0}.exe'.format(command)])
1214+
p = find_windows_executable(os.path.join(location, 'Scripts'), command)
12181215
else:
12191216
p = os.sep.join([location] + ['bin/{0}'.format(command)])
12201217
else:

pipenv/utils.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,28 @@ def recase_file(file_dict):
725725
return file_dict
726726

727727

728+
def get_windows_path(*args):
729+
"""Sanitize a path for windows environments
730+
731+
Accepts an arbitrary list of arguments and makes a clean windows path"""
732+
clean_path = os.path.join(*args)
733+
return os.path.normpath(clean_path)
734+
735+
736+
def find_windows_executable(bin_path, exe_name):
737+
"""Given an executable name, search the given location for an executable"""
738+
requested_path = get_windows_path(bin_path, exe_name)
739+
if os.path.exists(requested_path):
740+
return requested_path
741+
742+
# Ensure we aren't adding two layers of file extensions
743+
exe_name = os.path.splitext(exe_name)[0]
744+
files = ['{0}.{1}'.format(exe_name, ext) for ext in ['', 'py', 'exe', 'bat']]
745+
exec_paths = [get_windows_path(bin_path, f) for f in files]
746+
exec_files = [filename for filename in exec_paths if os.path.isfile(filename)]
747+
return exec_files[0]
748+
749+
728750
def walk_up(bottom):
729751
"""Mimic os.walk, but walk 'up' instead of down the directory tree.
730752
From: https://gist.github.com/zdavkeos/1098474

0 commit comments

Comments
 (0)