From f934b77d61a5ee22e66ef7acbc10c57aabc07abf Mon Sep 17 00:00:00 2001 From: Donald Stufft Date: Tue, 7 Jan 2014 08:36:04 -0500 Subject: [PATCH] Have a nice error when setuptools is not available --- pip/req.py | 9 +++++++++ tests/functional/test_install.py | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/pip/req.py b/pip/req.py index a808c6215..602502337 100644 --- a/pip/req.py +++ b/pip/req.py @@ -261,6 +261,15 @@ class InstallRequirement(object): @property def setup_py(self): + try: + import pkg_resources + except ImportError: + # Setuptools is not available + raise InstallationError( + "setuptools must be installed to install from a source " + "distribution" + ) + setup_file = 'setup.py' if self.editable_options and 'subdirectory' in self.editable_options: diff --git a/tests/functional/test_install.py b/tests/functional/test_install.py index 22343a5ba..f58dce1ba 100644 --- a/tests/functional/test_install.py +++ b/tests/functional/test_install.py @@ -13,6 +13,18 @@ from tests.lib.local_repos import local_checkout from tests.lib.path import Path +def test_without_setuptools(script): + script.run("pip", "uninstall", "setuptools", "-y") + result = script.run( + "python", "-m", "pip", "install", "INITools==0.2", "--no-use-wheel", + expect_error=True, + ) + assert ( + "setuptools must be installed to install from a source distribution" + in result.stdout + ) + + def test_pip_second_command_line_interface_works(script): """ Check if ``pip`` commands behaves equally