Skip to content

Commit b227c45

Browse files
committed
Ignore distutils prefix when using --user
Fixes bug #2683 There are two changes here; one to fix the using-wheels codepath and one to fix the no-wheels codepath. Two tests are introduced, one to test each codepath.
1 parent 0b9beab commit b227c45

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

pip/commands/install.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ def run(self, options, args):
212212
"are not visible in this virtualenv."
213213
)
214214
install_options.append('--user')
215+
install_options.append('--prefix=')
215216

216217
temp_target_dir = None
217218
if options.target_dir:

pip/locations.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ def distutils_scheme(dist_name, user=False, home=None, root=None,
185185
# or user base for installations during finalize_options()
186186
# ideally, we'd prefer a scheme class that has no side-effects.
187187
i.user = user or i.user
188+
if user:
189+
i.prefix = ""
188190
i.home = home or i.home
189191
i.root = root or i.root
190192
i.finalize_options()

tests/functional/test_install_reqs.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,34 @@ def test_install_local_editable_with_subdirectory(script):
191191
result.assert_installed('version-subpkg', sub_dir='version_subdir')
192192

193193

194+
def test_user_with_prefix_in_pydistutils_cfg(script, data, virtualenv):
195+
virtualenv.system_site_packages = True
196+
homedir = script.environ["HOME"]
197+
script.scratch_path.join("bin").mkdir()
198+
with open(os.path.join(homedir, ".pydistutils.cfg"), "w") as cfg:
199+
cfg.write(textwrap.dedent("""
200+
[install]
201+
prefix=%s""" % script.scratch_path))
202+
203+
result = script.pip('install', '--user', '--no-index', '-f',
204+
data.find_links, 'requiresupper')
205+
assert 'installed requiresupper' in result.stdout
206+
207+
208+
def test_nowheel_user_with_prefix_in_pydistutils_cfg(script, data, virtualenv):
209+
virtualenv.system_site_packages = True
210+
homedir = script.environ["HOME"]
211+
script.scratch_path.join("bin").mkdir()
212+
with open(os.path.join(homedir, ".pydistutils.cfg"), "w") as cfg:
213+
cfg.write(textwrap.dedent("""
214+
[install]
215+
prefix=%s""" % script.scratch_path))
216+
217+
result = script.pip('install', '--no-use-wheel', '--user', '--no-index',
218+
'-f', data.find_links, 'requiresupper')
219+
assert 'installed requiresupper' in result.stdout
220+
221+
194222
def test_install_option_in_requirements_file(script, data, virtualenv):
195223
"""
196224
Test --install-option in requirements file overrides same option in cli

0 commit comments

Comments
 (0)