diff --git a/news/5558.bugfix b/news/5558.bugfix new file mode 100644 index 000000000..f8965d55a --- /dev/null +++ b/news/5558.bugfix @@ -0,0 +1 @@ +Fix error trying to generate scripts warning when PATH not set diff --git a/src/pip/_internal/wheel.py b/src/pip/_internal/wheel.py index 7ad7a1b8a..fcf9d3d38 100644 --- a/src/pip/_internal/wheel.py +++ b/src/pip/_internal/wheel.py @@ -163,7 +163,7 @@ def message_about_scripts_not_on_PATH(scripts): # We don't want to warn for directories that are on PATH. not_warn_dirs = [ os.path.normcase(i).rstrip(os.sep) for i in - os.environ["PATH"].split(os.pathsep) + os.environ.get("PATH", "").split(os.pathsep) ] # If an executable sits with sys.executable, we don't warn for it. # This covers the case of venv invocations without activating the venv. diff --git a/tests/unit/test_wheel.py b/tests/unit/test_wheel.py index 6d3c1c7a7..005fde42c 100644 --- a/tests/unit/test_wheel.py +++ b/tests/unit/test_wheel.py @@ -470,3 +470,16 @@ class TestMessageAboutScriptsNotOnPATH(object): scripts=[os.path.join('a', 'b', 'c')] ) assert retval is None + + def test_missing_PATH_env_treated_as_empty_PATH_env(self): + scripts = ['a/b/foo'] + + env = os.environ.copy() + del env['PATH'] + with patch.dict('os.environ', env, clear=True): + retval_missing = wheel.message_about_scripts_not_on_PATH(scripts) + + with patch.dict('os.environ', {'PATH': ''}): + retval_empty = wheel.message_about_scripts_not_on_PATH(scripts) + + assert retval_missing == retval_empty