|
9 | 9 | from pip.index import PackageFinder
|
10 | 10 | from pip.exceptions import CommandError, PreviousBuildDirError
|
11 | 11 | from pip.req import InstallRequirement, RequirementSet, parse_requirements
|
12 |
| -from pip.utils import normalize_path |
| 12 | +from pip.utils import import_or_raise, normalize_path |
13 | 13 | from pip.utils.build import BuildDirectory
|
14 | 14 | from pip.utils.deprecation import RemovedInPip7Warning, RemovedInPip8Warning
|
15 | 15 | from pip.wheel import WheelBuilder
|
@@ -100,33 +100,28 @@ def __init__(self, *args, **kw):
|
100 | 100 | self.parser.insert_option_group(0, index_opts)
|
101 | 101 | self.parser.insert_option_group(0, cmd_opts)
|
102 | 102 |
|
103 |
| - def run(self, options, args): |
104 |
| - |
105 |
| - # confirm requirements |
106 |
| - try: |
107 |
| - import wheel.bdist_wheel |
108 |
| - # Hack to make flake8 not complain about an unused import |
109 |
| - wheel.bdist_wheel |
110 |
| - except ImportError: |
| 103 | + def check_required_packages(self): |
| 104 | + import_or_raise( |
| 105 | + 'wheel.bdist_wheel', |
| 106 | + CommandError, |
| 107 | + "'pip wheel' requires the 'wheel' package. To fix this, run: " |
| 108 | + "pip install wheel" |
| 109 | + ) |
| 110 | + pkg_resources = import_or_raise( |
| 111 | + 'pkg_resources', |
| 112 | + CommandError, |
| 113 | + "'pip wheel' requires setuptools >= 0.8 for dist-info support." |
| 114 | + " To fix this, run: pip install --upgrade setuptools" |
| 115 | + ) |
| 116 | + if not hasattr(pkg_resources, 'DistInfoDistribution'): |
111 | 117 | raise CommandError(
|
112 |
| - "'pip wheel' requires the 'wheel' package. To fix this, run: " |
113 |
| - "pip install wheel" |
| 118 | + "'pip wheel' requires setuptools >= 0.8 for dist-info " |
| 119 | + "support. To fix this, run: pip install --upgrade " |
| 120 | + "setuptools" |
114 | 121 | )
|
115 | 122 |
|
116 |
| - try: |
117 |
| - import pkg_resources |
118 |
| - except ImportError: |
119 |
| - raise CommandError( |
120 |
| - "'pip wheel' requires setuptools >= 0.8 for dist-info support." |
121 |
| - " To fix this, run: pip install --upgrade setuptools" |
122 |
| - ) |
123 |
| - else: |
124 |
| - if not hasattr(pkg_resources, 'DistInfoDistribution'): |
125 |
| - raise CommandError( |
126 |
| - "'pip wheel' requires setuptools >= 0.8 for dist-info " |
127 |
| - "support. To fix this, run: pip install --upgrade " |
128 |
| - "setuptools" |
129 |
| - ) |
| 123 | + def run(self, options, args): |
| 124 | + self.check_required_packages() |
130 | 125 |
|
131 | 126 | index_urls = [options.index_url] + options.extra_index_urls
|
132 | 127 | if options.no_index:
|
|
0 commit comments