mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Merge pull request #2420 from msabramo/wheel_check_required_packages
Refactor wheel command check of required packages
This commit is contained in:
commit
b26195443d
2 changed files with 29 additions and 27 deletions
|
@ -9,7 +9,7 @@ from pip.basecommand import Command
|
||||||
from pip.index import PackageFinder
|
from pip.index import PackageFinder
|
||||||
from pip.exceptions import CommandError, PreviousBuildDirError
|
from pip.exceptions import CommandError, PreviousBuildDirError
|
||||||
from pip.req import InstallRequirement, RequirementSet, parse_requirements
|
from pip.req import InstallRequirement, RequirementSet, parse_requirements
|
||||||
from pip.utils import normalize_path
|
from pip.utils import import_or_raise, normalize_path
|
||||||
from pip.utils.build import BuildDirectory
|
from pip.utils.build import BuildDirectory
|
||||||
from pip.utils.deprecation import RemovedInPip7Warning, RemovedInPip8Warning
|
from pip.utils.deprecation import RemovedInPip7Warning, RemovedInPip8Warning
|
||||||
from pip.wheel import WheelBuilder
|
from pip.wheel import WheelBuilder
|
||||||
|
@ -100,33 +100,28 @@ class WheelCommand(Command):
|
||||||
self.parser.insert_option_group(0, index_opts)
|
self.parser.insert_option_group(0, index_opts)
|
||||||
self.parser.insert_option_group(0, cmd_opts)
|
self.parser.insert_option_group(0, cmd_opts)
|
||||||
|
|
||||||
|
def check_required_packages(self):
|
||||||
|
import_or_raise(
|
||||||
|
'wheel.bdist_wheel',
|
||||||
|
CommandError,
|
||||||
|
"'pip wheel' requires the 'wheel' package. To fix this, run: "
|
||||||
|
"pip install wheel"
|
||||||
|
)
|
||||||
|
pkg_resources = import_or_raise(
|
||||||
|
'pkg_resources',
|
||||||
|
CommandError,
|
||||||
|
"'pip wheel' requires setuptools >= 0.8 for dist-info support."
|
||||||
|
" To fix this, run: pip install --upgrade setuptools"
|
||||||
|
)
|
||||||
|
if not hasattr(pkg_resources, 'DistInfoDistribution'):
|
||||||
|
raise CommandError(
|
||||||
|
"'pip wheel' requires setuptools >= 0.8 for dist-info "
|
||||||
|
"support. To fix this, run: pip install --upgrade "
|
||||||
|
"setuptools"
|
||||||
|
)
|
||||||
|
|
||||||
def run(self, options, args):
|
def run(self, options, args):
|
||||||
|
self.check_required_packages()
|
||||||
# confirm requirements
|
|
||||||
try:
|
|
||||||
import wheel.bdist_wheel
|
|
||||||
# Hack to make flake8 not complain about an unused import
|
|
||||||
wheel.bdist_wheel
|
|
||||||
except ImportError:
|
|
||||||
raise CommandError(
|
|
||||||
"'pip wheel' requires the 'wheel' package. To fix this, run: "
|
|
||||||
"pip install wheel"
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
|
||||||
import pkg_resources
|
|
||||||
except ImportError:
|
|
||||||
raise CommandError(
|
|
||||||
"'pip wheel' requires setuptools >= 0.8 for dist-info support."
|
|
||||||
" To fix this, run: pip install --upgrade setuptools"
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
if not hasattr(pkg_resources, 'DistInfoDistribution'):
|
|
||||||
raise CommandError(
|
|
||||||
"'pip wheel' requires setuptools >= 0.8 for dist-info "
|
|
||||||
"support. To fix this, run: pip install --upgrade "
|
|
||||||
"setuptools"
|
|
||||||
)
|
|
||||||
|
|
||||||
index_urls = [options.index_url] + options.extra_index_urls
|
index_urls = [options.index_url] + options.extra_index_urls
|
||||||
if options.no_index:
|
if options.no_index:
|
||||||
|
|
|
@ -45,6 +45,13 @@ __all__ = ['rmtree', 'display_path', 'backup_dir',
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def import_or_raise(pkg_or_module_string, ExceptionType, *args, **kwargs):
|
||||||
|
try:
|
||||||
|
return __import__(pkg_or_module_string)
|
||||||
|
except ImportError:
|
||||||
|
raise ExceptionType(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def get_prog():
|
def get_prog():
|
||||||
try:
|
try:
|
||||||
if os.path.basename(sys.argv[0]) in ('__main__.py', '-c'):
|
if os.path.basename(sys.argv[0]) in ('__main__.py', '-c'):
|
||||||
|
|
Loading…
Reference in a new issue