Skip to content

Commit 4abb40e

Browse files
authored
Merge pull request #8462 from pfmoore/nr_nonlocal_compatible_wheel_path
Test is checking the old resolver's broken behaviour
2 parents 0b5ad47 + f162236 commit 4abb40e

File tree

2 files changed

+61
-54
lines changed

2 files changed

+61
-54
lines changed

src/pip/_internal/commands/install.py

+48-48
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ def run(self, options, args):
269269
# Create a target directory for using with the target option
270270
target_temp_dir = TempDirectory(kind="target")
271271
target_temp_dir_path = target_temp_dir.path
272+
self.enter_context(target_temp_dir)
272273

273274
global_options = options.global_options or []
274275

@@ -452,54 +453,53 @@ def _handle_target_dir(self, target_dir, target_temp_dir, upgrade):
452453
# packages to be moved to target directory
453454
lib_dir_list = []
454455

455-
with target_temp_dir:
456-
# Checking both purelib and platlib directories for installed
457-
# packages to be moved to target directory
458-
scheme = distutils_scheme('', home=target_temp_dir.path)
459-
purelib_dir = scheme['purelib']
460-
platlib_dir = scheme['platlib']
461-
data_dir = scheme['data']
462-
463-
if os.path.exists(purelib_dir):
464-
lib_dir_list.append(purelib_dir)
465-
if os.path.exists(platlib_dir) and platlib_dir != purelib_dir:
466-
lib_dir_list.append(platlib_dir)
467-
if os.path.exists(data_dir):
468-
lib_dir_list.append(data_dir)
469-
470-
for lib_dir in lib_dir_list:
471-
for item in os.listdir(lib_dir):
472-
if lib_dir == data_dir:
473-
ddir = os.path.join(data_dir, item)
474-
if any(s.startswith(ddir) for s in lib_dir_list[:-1]):
475-
continue
476-
target_item_dir = os.path.join(target_dir, item)
477-
if os.path.exists(target_item_dir):
478-
if not upgrade:
479-
logger.warning(
480-
'Target directory %s already exists. Specify '
481-
'--upgrade to force replacement.',
482-
target_item_dir
483-
)
484-
continue
485-
if os.path.islink(target_item_dir):
486-
logger.warning(
487-
'Target directory %s already exists and is '
488-
'a link. pip will not automatically replace '
489-
'links, please remove if replacement is '
490-
'desired.',
491-
target_item_dir
492-
)
493-
continue
494-
if os.path.isdir(target_item_dir):
495-
shutil.rmtree(target_item_dir)
496-
else:
497-
os.remove(target_item_dir)
498-
499-
shutil.move(
500-
os.path.join(lib_dir, item),
501-
target_item_dir
502-
)
456+
# Checking both purelib and platlib directories for installed
457+
# packages to be moved to target directory
458+
scheme = distutils_scheme('', home=target_temp_dir.path)
459+
purelib_dir = scheme['purelib']
460+
platlib_dir = scheme['platlib']
461+
data_dir = scheme['data']
462+
463+
if os.path.exists(purelib_dir):
464+
lib_dir_list.append(purelib_dir)
465+
if os.path.exists(platlib_dir) and platlib_dir != purelib_dir:
466+
lib_dir_list.append(platlib_dir)
467+
if os.path.exists(data_dir):
468+
lib_dir_list.append(data_dir)
469+
470+
for lib_dir in lib_dir_list:
471+
for item in os.listdir(lib_dir):
472+
if lib_dir == data_dir:
473+
ddir = os.path.join(data_dir, item)
474+
if any(s.startswith(ddir) for s in lib_dir_list[:-1]):
475+
continue
476+
target_item_dir = os.path.join(target_dir, item)
477+
if os.path.exists(target_item_dir):
478+
if not upgrade:
479+
logger.warning(
480+
'Target directory %s already exists. Specify '
481+
'--upgrade to force replacement.',
482+
target_item_dir
483+
)
484+
continue
485+
if os.path.islink(target_item_dir):
486+
logger.warning(
487+
'Target directory %s already exists and is '
488+
'a link. pip will not automatically replace '
489+
'links, please remove if replacement is '
490+
'desired.',
491+
target_item_dir
492+
)
493+
continue
494+
if os.path.isdir(target_item_dir):
495+
shutil.rmtree(target_item_dir)
496+
else:
497+
os.remove(target_item_dir)
498+
499+
shutil.move(
500+
os.path.join(lib_dir, item),
501+
target_item_dir
502+
)
503503

504504
def _warn_about_conflicts(self, to_install):
505505
try:

tests/functional/test_install.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -927,8 +927,11 @@ def test_install_nonlocal_compatible_wheel(script, data):
927927
assert result.returncode == ERROR
928928

929929

930-
@pytest.mark.fails_on_new_resolver
931-
def test_install_nonlocal_compatible_wheel_path(script, data):
930+
def test_install_nonlocal_compatible_wheel_path(
931+
script,
932+
data,
933+
use_new_resolver
934+
):
932935
target_dir = script.scratch_path / 'target'
933936

934937
# Test a full path requirement
@@ -937,12 +940,16 @@ def test_install_nonlocal_compatible_wheel_path(script, data):
937940
'-t', target_dir,
938941
'--no-index',
939942
'--only-binary=:all:',
940-
Path(data.packages) / 'simplewheel-2.0-py3-fakeabi-fakeplat.whl'
943+
Path(data.packages) / 'simplewheel-2.0-py3-fakeabi-fakeplat.whl',
944+
expect_error=use_new_resolver
941945
)
942-
assert result.returncode == SUCCESS
946+
if use_new_resolver:
947+
assert result.returncode == ERROR
948+
else:
949+
assert result.returncode == SUCCESS
943950

944-
distinfo = Path('scratch') / 'target' / 'simplewheel-2.0.dist-info'
945-
result.did_create(distinfo)
951+
distinfo = Path('scratch') / 'target' / 'simplewheel-2.0.dist-info'
952+
result.did_create(distinfo)
946953

947954
# Test a full path requirement (without --target)
948955
result = script.pip(

0 commit comments

Comments
 (0)