Skip to content

Commit e0e19cc

Browse files
committed
Merge pull request #1003 from qwcode/test_new_setuptools
support the new setuptools
2 parents d5e2c64 + 31bc083 commit e0e19cc

14 files changed

+58
-160
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ before_install:
1010
- echo -e "[web]\ncacerts = /etc/ssl/certs/ca-certificates.crt" >> ~/.hgrc
1111
- git config --global user.email "[email protected]"
1212
- git config --global user.name "Pip"
13-
install: pip install nose virtualenv>=1.9.1 scripttest mock
13+
install: pip install nose git+https://github.com/pypa/virtualenv@develop#egg=virtualenv scripttest mock
1414
script: nosetests
1515
notifications:
1616
irc: "irc.freenode.org#pip"

pip/commands/install.py

-7
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,6 @@ def run(self, options, args):
232232
logger.warn(msg)
233233
return
234234

235-
import setuptools
236-
if (options.use_user_site and
237-
requirement_set.has_editables and
238-
not getattr(setuptools, '_distribute', False)):
239-
240-
raise InstallationError('--user --editable not supported with setuptools, use distribute')
241-
242235
try:
243236
if not options.no_download:
244237
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)

pip/commands/wheel.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from pip.exceptions import CommandError
1111
from pip.req import InstallRequirement, RequirementSet, parse_requirements
1212
from pip.util import normalize_path
13-
from pip.wheel import WheelBuilder, wheel_distribute_support, distribute_requirement
13+
from pip.wheel import WheelBuilder, wheel_setuptools_support, distribute_requirement, setuptools_requirement
1414
from pip import cmdoptions
1515

1616
DEFAULT_WHEEL_DIR = os.path.join(normalize_path(os.curdir), 'wheelhouse')
@@ -22,7 +22,7 @@ class WheelCommand(Command):
2222
Wheel is a built-package format, and offers the advantage of not recompiling your software during every install.
2323
For more details, see the wheel docs: http://wheel.readthedocs.org/en/latest.
2424
25-
Requirements: distribute>=0.6.34 (not setuptools), and wheel.
25+
Requirements: distribute>=0.6.34 or setuptools>=0.7.2, and wheel.
2626
2727
'pip wheel' uses the bdist_wheel setuptools extension from the wheel package to build individual wheels.
2828
@@ -78,13 +78,13 @@ def __init__(self, *args, **kw):
7878

7979
def run(self, options, args):
8080

81-
# requirements: wheel, and distribute
81+
# confirm requirements
8282
try:
8383
import wheel.bdist_wheel
8484
except ImportError:
8585
raise CommandError("'pip wheel' requires bdist_wheel from the 'wheel' distribution.")
86-
if not wheel_distribute_support():
87-
raise CommandError("'pip wheel' requires %s." % distribute_requirement)
86+
if not wheel_setuptools_support():
87+
raise CommandError("'pip wheel' requires %s or %s." % (distribute_requirement, setuptools_requirement))
8888

8989
index_urls = [options.index_url] + options.extra_index_urls
9090
if options.no_index:

pip/index.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
Empty as QueueEmpty)
3030
from pip.backwardcompat import CertificateError
3131
from pip.download import urlopen, path_to_url2, url_to_path, geturl, Urllib2HeadRequest
32-
from pip.wheel import Wheel, wheel_ext, wheel_distribute_support, distribute_requirement
32+
from pip.wheel import Wheel, wheel_ext, wheel_setuptools_support, distribute_requirement
3333
from pip.pep425tags import supported_tags
3434
from pip.vendor import html5lib
3535

@@ -90,7 +90,7 @@ def use_wheel(self):
9090
@use_wheel.setter
9191
def use_wheel(self, value):
9292
self._use_wheel = value
93-
if self._use_wheel and not wheel_distribute_support():
93+
if self._use_wheel and not wheel_setuptools_support():
9494
raise InstallationError("pip's wheel support requires %s." % distribute_requirement)
9595

9696
def add_dependency_links(self, links):

pip/wheel.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,27 @@
2020

2121
wheel_ext = '.whl'
2222
distribute_requirement = pkg_resources.Requirement.parse("distribute>=0.6.34")
23+
setuptools_requirement = pkg_resources.Requirement.parse("setuptools>=0.7.2")
2324

24-
def wheel_distribute_support(distribute_req=distribute_requirement):
25+
def wheel_setuptools_support():
2526
"""
2627
Return True if we have a distribute that supports wheel.
2728
2829
distribute_req: a pkg_resources.Requirement for distribute
2930
"""
31+
32+
installed_distribute = installed_setuptools = ''
33+
try:
34+
installed_distribute = pkg_resources.get_distribution('distribute')
35+
except pkg_resources.DistributionNotFound:
36+
pass
3037
try:
31-
installed_dist = pkg_resources.get_distribution('distribute')
32-
supported = installed_dist in distribute_req
38+
installed_setuptools = pkg_resources.get_distribution('setuptools')
3339
except pkg_resources.DistributionNotFound:
34-
supported = False
40+
pass
41+
supported = (installed_distribute in distribute_requirement) or (installed_setuptools in setuptools_requirement)
3542
if not supported:
36-
logger.warn("%s is required for wheel installs.", distribute_req)
43+
logger.warn("%s or %s is required for wheel installs." % (setuptools_requirement, distribute_requirement))
3744
return supported
3845

3946

tests/functional/test_freeze.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import re
33
import textwrap
44
from doctest import OutputChecker, ELLIPSIS
5-
from tests.lib import reset_env, run_pip, write_file, get_env, pyversion
5+
from tests.lib import reset_env, run_pip, write_file, get_env, pyversion, pip_install_local
66
from tests.lib.local_repos import local_checkout, local_repo
77

88

@@ -44,17 +44,17 @@ def test_freeze_basic():
4444
"""
4545
env = reset_env()
4646
write_file('initools-req.txt', textwrap.dedent("""\
47-
INITools==0.2
47+
simple==2.0
4848
# and something else to test out:
49-
MarkupSafe<=0.12
49+
simple2<=3.0
5050
"""))
51-
result = run_pip('install', '-r', env.scratch_path/'initools-req.txt')
51+
result = pip_install_local('-r', env.scratch_path/'initools-req.txt')
5252
result = run_pip('freeze', expect_stderr=True)
5353
expected = textwrap.dedent("""\
5454
Script result: pip freeze
5555
-- stdout: --------------------
56-
INITools==0.2
57-
MarkupSafe==0.12...
56+
...simple==2.0
57+
simple2==3.0...
5858
<BLANKLINE>""")
5959
_check_output(result, expected)
6060

@@ -236,7 +236,7 @@ def test_freeze_with_requirement_option():
236236
NoExist==4.2
237237
""") + ignores)
238238
result = run_pip('install', 'initools==0.2')
239-
result = run_pip('install', 'MarkupSafe')
239+
result = pip_install_local('simple')
240240
result = run_pip('freeze', '--requirement', 'hint.txt', expect_stderr=True)
241241
expected = textwrap.dedent("""\
242242
Script result: pip freeze --requirement hint.txt

tests/functional/test_install_index.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_find_links_requirements_file_relative_path():
2727
e = reset_env()
2828
write_file('test-req.txt', textwrap.dedent("""
2929
--no-index
30-
--find-links=../../../../data/packages/
30+
--find-links=../../../data/packages/
3131
parent==0.1
3232
"""))
3333
result = run_pip(

tests/functional/test_install_user.py

+4-19
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,11 @@ def test_reset_env_system_site_packages_usersite(self):
3838
assert 'INITools'== project_name, "'%s' should be 'INITools'" %project_name
3939

4040

41-
def test_install_subversion_usersite_editable_with_setuptools_fails(self):
42-
"""
43-
Test installing current directory ('.') into usersite using setuptools fails
44-
"""
45-
# We don't try to use setuptools for 3.X.
46-
if sys.version_info >= (3,):
47-
raise SkipTest()
48-
env = reset_env(use_distribute=False, system_site_packages=True)
49-
result = run_pip('install', '--user', '-e',
50-
'%s#egg=initools-dev' %
51-
local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'),
52-
expect_error=True)
53-
assert '--user --editable not supported with setuptools, use distribute' in result.stdout
54-
55-
5641
def test_install_subversion_usersite_editable_with_distribute(self):
5742
"""
5843
Test installing current directory ('.') into usersite after installing distribute
5944
"""
60-
env = reset_env(use_distribute=True, system_site_packages=True)
45+
env = reset_env(system_site_packages=True)
6146
result = run_pip('install', '--user', '-e',
6247
'%s#egg=initools-dev' %
6348
local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'))
@@ -68,7 +53,7 @@ def test_install_curdir_usersite(self):
6853
"""
6954
Test installing current directory ('.') into usersite
7055
"""
71-
env = reset_env(use_distribute=True, system_site_packages=True)
56+
env = reset_env(system_site_packages=True)
7257
run_from = abspath(join(tests_data, 'packages', 'FSPkg'))
7358
result = run_pip('install', '--user', curdir, cwd=run_from, expect_error=False)
7459
fspkg_folder = env.user_site/'fspkg'
@@ -225,7 +210,7 @@ def test_uninstall_editable_from_usersite(self):
225210
"""
226211
Test uninstall editable local user install
227212
"""
228-
env = reset_env(use_distribute=True, system_site_packages=True)
213+
env = reset_env(system_site_packages=True)
229214

230215
#install
231216
to_install = abspath(join(tests_data, 'packages', 'FSPkg'))
@@ -245,7 +230,7 @@ def test_install_user_wheel(self):
245230
"""
246231
Test user install from wheel
247232
"""
248-
env = reset_env(system_site_packages=True, use_distribute=True)
233+
env = reset_env(system_site_packages=True)
249234
pip_install_local('wheel')
250235
result = run_pip('install', 'simple.dist==0.1', '--user', '--use-wheel',
251236
'--no-index', '--find-links='+find_links)

tests/functional/test_install_wheel.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def test_install_from_wheel():
99
"""
1010
Test installing from a wheel.
1111
"""
12-
env = reset_env(use_distribute=True)
12+
env = reset_env()
1313
result = run_pip('install', 'simple.dist', '--use-wheel',
1414
'--no-index', '--find-links='+find_links,
1515
expect_error=False)
@@ -27,7 +27,7 @@ def test_install_from_wheel_with_extras():
2727
import ast
2828
except ImportError:
2929
raise SkipTest("Need ast module to interpret wheel extras")
30-
env = reset_env(use_distribute=True)
30+
env = reset_env()
3131
result = run_pip('install', 'complex-dist[simple]', '--use-wheel',
3232
'--no-index', '--find-links='+find_links,
3333
expect_error=False)
@@ -45,7 +45,7 @@ def test_install_from_wheel_file():
4545
"""
4646
Test installing directly from a wheel file.
4747
"""
48-
env = reset_env(use_distribute=True)
48+
env = reset_env()
4949
package = abspath(join(tests_data,
5050
'packages',
5151
'headers.dist-0.1-py2.py3-none-any.whl'))
@@ -60,7 +60,7 @@ def test_install_wheel_with_target():
6060
"""
6161
Test installing a wheel using pip install --target
6262
"""
63-
env = reset_env(use_distribute=True)
63+
env = reset_env()
6464
pip_install_local('wheel')
6565
target_dir = env.scratch_path/'target'
6666
result = run_pip('install', 'simple.dist==0.1', '-t', target_dir, '--use-wheel',
@@ -73,7 +73,7 @@ def test_install_from_wheel_installs_deps():
7373
Test can install dependencies of wheels
7474
"""
7575
# 'requires_source' depends on the 'source' project
76-
env = reset_env(use_distribute=True)
76+
env = reset_env()
7777
package = abspath(join(tests_data,
7878
'packages',
7979
'requires_source-1.0-py2.py3-none-any.whl'))
@@ -86,7 +86,7 @@ def test_install_from_wheel_no_deps():
8686
Test --no-deps works with wheel installs
8787
"""
8888
# 'requires_source' depends on the 'source' project
89-
env = reset_env(use_distribute=True)
89+
env = reset_env()
9090
package = abspath(join(tests_data,
9191
'packages',
9292
'requires_source-1.0-py2.py3-none-any.whl'))

tests/functional/test_search.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_search_missing_argument():
8080
"""
8181
Test missing required argument for search
8282
"""
83-
env = reset_env(use_distribute=True)
83+
env = reset_env()
8484
result = run_pip('search', expect_error=True)
8585
assert 'ERROR: Missing required argument (search query).' in result.stdout
8686

@@ -111,7 +111,7 @@ def test_search_should_exit_status_code_zero_when_find_packages():
111111
"""
112112
Test search exit status code for package found
113113
"""
114-
env = reset_env(use_distribute=True)
114+
env = reset_env()
115115
result = run_pip('search', 'pip')
116116
assert result.returncode == SUCCESS
117117

@@ -120,6 +120,6 @@ def test_search_exit_status_code_when_finds_no_package():
120120
"""
121121
Test search exit status code for no matches
122122
"""
123-
env = reset_env(use_distribute=True)
123+
env = reset_env()
124124
result = run_pip('search', 'non-existant-package', expect_error=True)
125125
assert result.returncode == NO_MATCHES_FOUND, result.returncode

tests/functional/test_wheel.py

+6-18
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,15 @@ def test_pip_wheel_fails_without_wheel():
1414
"""
1515
Test 'pip wheel' fails without wheel
1616
"""
17-
env = reset_env(use_distribute=True)
17+
env = reset_env()
1818
result = run_pip('wheel', '--no-index', '-f', find_links, 'simple==3.0', expect_error=True)
1919
assert "'pip wheel' requires bdist_wheel" in result.stdout
2020

21-
def test_pip_wheel_setuptools_fails():
22-
"""
23-
Test 'pip wheel' fails with setuptools
24-
"""
25-
if sys.version_info >= (3, 0):
26-
# virtualenv installs distribute in py3
27-
raise SkipTest()
28-
env = reset_env(use_distribute=False)
29-
pip_install_local('wheel')
30-
result = run_pip('wheel', '--no-index', '-f', find_links, 'simple==3.0', expect_error=True)
31-
assert "'pip wheel' requires %s" % wheel.distribute_requirement in result.stdout, result.stdout
32-
3321
def test_pip_wheel_success():
3422
"""
3523
Test 'pip wheel' success.
3624
"""
37-
env = reset_env(use_distribute=True)
25+
env = reset_env()
3826
pip_install_local('wheel')
3927
result = run_pip('wheel', '--no-index', '-f', find_links, 'simple==3.0')
4028
wheel_file_name = 'simple-3.0-py%s-none-any.whl' % pyversion_nodot
@@ -47,7 +35,7 @@ def test_pip_wheel_fail():
4735
"""
4836
Test 'pip wheel' failure.
4937
"""
50-
env = reset_env(use_distribute=True)
38+
env = reset_env()
5139
pip_install_local('wheel')
5240
result = run_pip('wheel', '--no-index', '-f', find_links, 'wheelbroken==0.1')
5341
wheel_file_name = 'wheelbroken-0.1-py%s-none-any.whl' % pyversion_nodot
@@ -61,7 +49,7 @@ def test_pip_wheel_ignore_wheels_editables():
6149
"""
6250
Test 'pip wheel' ignores editables and *.whl files in requirements
6351
"""
64-
env = reset_env(use_distribute=True)
52+
env = reset_env()
6553
pip_install_local('wheel')
6654

6755
local_wheel = '%s/simple.dist-0.1-py2.py3-none-any.whl' % find_links
@@ -89,7 +77,7 @@ def test_no_clean_option_blocks_cleaning_after_wheel():
8977
"""
9078
Test --no-clean option blocks cleaning after wheel build
9179
"""
92-
env = reset_env(use_distribute=True)
80+
env = reset_env()
9381
pip_install_local('wheel')
9482
result = run_pip('wheel', '--no-clean', '--no-index', '--find-links=%s' % find_links, 'simple')
9583
build = env.venv_path/'build'/'simple'
@@ -101,7 +89,7 @@ def test_pip_wheel_source_deps():
10189
Test 'pip wheel --use-wheel' finds and builds source archive dependencies of wheels
10290
"""
10391
# 'requires_source' is a wheel that depends on the 'source' project
104-
env = reset_env(use_distribute=True)
92+
env = reset_env()
10593
pip_install_local('wheel')
10694
result = run_pip('wheel', '--use-wheel', '--no-index', '-f', find_links, 'requires_source')
10795
wheel_file_name = 'source-1.0-py%s-none-any.whl' % pyversion_nodot

0 commit comments

Comments
 (0)