mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Warn if a path in PATH starts with tilde during install
This commit is contained in:
parent
9e1b1c7466
commit
f6aaba9fd9
3 changed files with 58 additions and 0 deletions
1
news/6414.feature
Normal file
1
news/6414.feature
Normal file
|
@ -0,0 +1 @@
|
|||
Warn if a path in PATH starts with tilde during ``pip install``.
|
|
@ -210,6 +210,17 @@ def message_about_scripts_not_on_PATH(scripts):
|
|||
else:
|
||||
msg_lines.append(last_line_fmt.format("these directories"))
|
||||
|
||||
# Add a note if any directory starts with ~
|
||||
warn_for_tilde = any(
|
||||
i[0] == "~" for i in os.environ.get("PATH", "").split(os.pathsep) if i
|
||||
)
|
||||
if warn_for_tilde:
|
||||
tilde_warning_msg = (
|
||||
"NOTE: The current PATH contains path(s) starting with `~`, "
|
||||
"which may not be expanded by all applications."
|
||||
)
|
||||
msg_lines.append(tilde_warning_msg)
|
||||
|
||||
# Returns the formatted multiline message
|
||||
return "\n".join(msg_lines)
|
||||
|
||||
|
|
|
@ -524,6 +524,11 @@ class TestInstallUnpackedWheel(object):
|
|||
|
||||
class TestMessageAboutScriptsNotOnPATH(object):
|
||||
|
||||
tilde_warning_msg = (
|
||||
"NOTE: The current PATH contains path(s) starting with `~`, "
|
||||
"which may not be expanded by all applications."
|
||||
)
|
||||
|
||||
def _template(self, paths, scripts):
|
||||
with patch.dict('os.environ', {'PATH': os.pathsep.join(paths)}):
|
||||
return wheel.message_about_scripts_not_on_PATH(scripts)
|
||||
|
@ -543,6 +548,7 @@ class TestMessageAboutScriptsNotOnPATH(object):
|
|||
assert retval is not None
|
||||
assert "--no-warn-script-location" in retval
|
||||
assert "foo is installed in '/c/d'" in retval
|
||||
assert self.tilde_warning_msg not in retval
|
||||
|
||||
def test_two_script__single_dir_not_on_PATH(self):
|
||||
retval = self._template(
|
||||
|
@ -552,6 +558,7 @@ class TestMessageAboutScriptsNotOnPATH(object):
|
|||
assert retval is not None
|
||||
assert "--no-warn-script-location" in retval
|
||||
assert "baz and foo are installed in '/c/d'" in retval
|
||||
assert self.tilde_warning_msg not in retval
|
||||
|
||||
def test_multi_script__multi_dir_not_on_PATH(self):
|
||||
retval = self._template(
|
||||
|
@ -562,6 +569,7 @@ class TestMessageAboutScriptsNotOnPATH(object):
|
|||
assert "--no-warn-script-location" in retval
|
||||
assert "bar, baz and foo are installed in '/c/d'" in retval
|
||||
assert "spam is installed in '/a/b/c'" in retval
|
||||
assert self.tilde_warning_msg not in retval
|
||||
|
||||
def test_multi_script_all__multi_dir_not_on_PATH(self):
|
||||
retval = self._template(
|
||||
|
@ -575,6 +583,7 @@ class TestMessageAboutScriptsNotOnPATH(object):
|
|||
assert "--no-warn-script-location" in retval
|
||||
assert "bar, baz and foo are installed in '/c/d'" in retval
|
||||
assert "eggs and spam are installed in '/a/b/c'" in retval
|
||||
assert self.tilde_warning_msg not in retval
|
||||
|
||||
def test_two_script__single_dir_on_PATH(self):
|
||||
retval = self._template(
|
||||
|
@ -613,6 +622,7 @@ class TestMessageAboutScriptsNotOnPATH(object):
|
|||
assert retval is None
|
||||
else:
|
||||
assert retval is not None
|
||||
assert self.tilde_warning_msg not in retval
|
||||
|
||||
def test_trailing_ossep_removal(self):
|
||||
retval = self._template(
|
||||
|
@ -634,6 +644,42 @@ class TestMessageAboutScriptsNotOnPATH(object):
|
|||
|
||||
assert retval_missing == retval_empty
|
||||
|
||||
def test_no_script_tilde_in_path(self):
|
||||
retval = self._template(
|
||||
paths=['/a/b', '/c/d/bin', '~/e', '/f/g~g'],
|
||||
scripts=[]
|
||||
)
|
||||
assert retval is None
|
||||
|
||||
def test_multi_script_all_tilde__multi_dir_not_on_PATH(self):
|
||||
retval = self._template(
|
||||
paths=['/a/b', '/c/d/bin', '~e/f'],
|
||||
scripts=[
|
||||
'/c/d/foo', '/c/d/bar', '/c/d/baz',
|
||||
'/a/b/c/spam', '/a/b/c/eggs', '/e/f/tilde'
|
||||
]
|
||||
)
|
||||
assert retval is not None
|
||||
assert "--no-warn-script-location" in retval
|
||||
assert "bar, baz and foo are installed in '/c/d'" in retval
|
||||
assert "eggs and spam are installed in '/a/b/c'" in retval
|
||||
assert "tilde is installed in '/e/f'" in retval
|
||||
assert self.tilde_warning_msg in retval
|
||||
|
||||
def test_multi_script_all_tilde_not_at_start__multi_dir_not_on_PATH(self):
|
||||
retval = self._template(
|
||||
paths=['/e/f~f', '/c/d/bin'],
|
||||
scripts=[
|
||||
'/c/d/foo', '/c/d/bar', '/c/d/baz',
|
||||
'/e/f~f/c/spam', '/e/f~f/c/eggs'
|
||||
]
|
||||
)
|
||||
assert retval is not None
|
||||
assert "--no-warn-script-location" in retval
|
||||
assert "bar, baz and foo are installed in '/c/d'" in retval
|
||||
assert "eggs and spam are installed in '/e/f~f/c'" in retval
|
||||
assert self.tilde_warning_msg not in retval
|
||||
|
||||
|
||||
class TestWheelHashCalculators(object):
|
||||
|
||||
|
|
Loading…
Reference in a new issue