mirror of https://github.com/pypa/pip
Made version control and commands loading use pkgutil.
This commit is contained in:
parent
78394430b1
commit
0cb87df5cd
|
@ -1,14 +1,15 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
import os
|
||||
import optparse
|
||||
import pkgutil
|
||||
import subprocess
|
||||
import sys
|
||||
import re
|
||||
from pip.log import logger
|
||||
|
||||
from pip.basecommand import command_dict, load_command, load_all_commands
|
||||
from pip.baseparser import parser
|
||||
from pip.exceptions import InstallationError
|
||||
from pip.basecommand import command_dict, load_command, load_all_commands
|
||||
from pip.vcs import vcs, get_src_requirement, import_vcs_support
|
||||
from pip.log import logger
|
||||
from pip.util import get_installed_distributions
|
||||
|
||||
|
||||
|
@ -76,11 +77,18 @@ def autocomplete():
|
|||
print ' '.join(filter(lambda x: x.startswith(current), subcommands))
|
||||
sys.exit(1)
|
||||
|
||||
def version_control():
|
||||
# Import all the version control support modules:
|
||||
from pip import vcs
|
||||
for importer, modname, ispkg in \
|
||||
pkgutil.walk_packages(path=vcs.__path__, prefix=vcs.__name__+'.'):
|
||||
__import__(modname)
|
||||
|
||||
def main(initial_args=None):
|
||||
if initial_args is None:
|
||||
initial_args = sys.argv[1:]
|
||||
autocomplete()
|
||||
version_control()
|
||||
options, args = parser.parse_args(initial_args)
|
||||
if options.help and not args:
|
||||
args = ['help']
|
||||
|
@ -115,6 +123,7 @@ class FrozenRequirement(object):
|
|||
def from_dist(cls, dist, dependency_links, find_tags=False):
|
||||
location = os.path.normcase(os.path.abspath(dist.location))
|
||||
comments = []
|
||||
from pip.vcs import vcs, get_src_requirement
|
||||
if vcs.get_backend_name(location):
|
||||
editable = True
|
||||
req = get_src_requirement(dist, location, find_tags)
|
||||
|
@ -233,7 +242,6 @@ def call_subprocess(cmd, show_stdout=True,
|
|||
if stdout is not None:
|
||||
return ''.join(all_output)
|
||||
|
||||
import_vcs_support()
|
||||
|
||||
if __name__ == '__main__':
|
||||
exit = main()
|
||||
|
|
|
@ -6,8 +6,11 @@ import socket
|
|||
import urllib2
|
||||
import urllib
|
||||
from cStringIO import StringIO
|
||||
from pkgutil import walk_packages
|
||||
import traceback
|
||||
import time
|
||||
|
||||
from pip import commands
|
||||
from pip.log import logger
|
||||
from pip.baseparser import parser, ConfigOptionParser, UpdatingDefaultsHelpFormatter
|
||||
from pip.exceptions import BadCommand, InstallationError, UninstallationError
|
||||
|
@ -222,9 +225,5 @@ def load_all_commands():
|
|||
|
||||
|
||||
def command_names():
|
||||
dir = os.path.join(os.path.dirname(__file__), 'commands')
|
||||
names = []
|
||||
for name in os.listdir(dir):
|
||||
if name.endswith('.py') and os.path.isfile(os.path.join(dir, name)):
|
||||
names.append(os.path.splitext(name)[0])
|
||||
return names
|
||||
names = set((pkg[1] for pkg in walk_packages(path=commands.__path__)))
|
||||
return list(names)
|
||||
|
|
|
@ -4,9 +4,10 @@ import os
|
|||
import shutil
|
||||
import urlparse
|
||||
import urllib
|
||||
from pip.util import display_path, backup_dir, find_command, ask
|
||||
|
||||
from pip.exceptions import BadCommand
|
||||
from pip.log import logger
|
||||
from pip.util import display_path, backup_dir, find_command, ask
|
||||
|
||||
|
||||
__all__ = ['vcs', 'get_src_requirement', 'import_vcs_support']
|
||||
|
@ -235,12 +236,3 @@ def get_src_requirement(dist, location, find_tags):
|
|||
return version_control().get_src_requirement(dist, location, find_tags)
|
||||
logger.warn('cannot determine version of editable source in %s (is not SVN checkout, Git clone, Mercurial clone or Bazaar branch)' % location)
|
||||
return dist.as_requirement()
|
||||
|
||||
|
||||
def import_vcs_support():
|
||||
# Import all the version control support modules:
|
||||
here = os.path.dirname(__file__)
|
||||
for name in os.listdir(here):
|
||||
if name != '__init__.py' and name.endswith('.py'):
|
||||
name = os.path.splitext(name)[0]
|
||||
__import__('pip.vcs.%s' % name)
|
||||
|
|
Loading…
Reference in New Issue