<s> from pip . basecommand import Command <EOL> from pip . exceptions import DistributionNotFound , BestVersionAlreadyInstalled <EOL> from pip . index import PackageFinder <EOL> from pip . log import logger <EOL> from pip . req import InstallRequirement <EOL> from pip . util import get_installed_distributions , dist_is_editable <EOL> from pip . cmdoptions import make_option_group , index_group <EOL> class ListCommand ( Command ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT:list>' <EOL> usage = """<STR_LIT>""" <EOL> summary = '<STR_LIT>' <EOL> skip = [ '<STR_LIT>' ] <EOL> def __init__ ( self , * args , ** kw ) : <EOL> super ( ListCommand , self ) . __init__ ( * args , ** kw ) <EOL> cmd_opts = self . cmd_opts <EOL> cmd_opts . add_option ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = False , <EOL> help = '<STR_LIT>' ) <EOL> cmd_opts . add_option ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = False , <EOL> help = '<STR_LIT>' ) <EOL> cmd_opts . add_option ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = False , <EOL> help = '<STR_LIT>' ) <EOL> cmd_opts . add_option ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = False , <EOL> help = '<STR_LIT>' ) <EOL> cmd_opts . add_option ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = False , <EOL> help = "<STR_LIT>" ) <EOL> index_opts = make_option_group ( index_group , self . parser ) <EOL> self . parser . insert_option_group ( <NUM_LIT:0> , index_opts ) <EOL> self . parser . insert_option_group ( <NUM_LIT:0> , cmd_opts ) <EOL> def _build_package_finder ( self , options , index_urls , session ) : <EOL> """<STR_LIT>""" <EOL> return PackageFinder ( find_links = options . find_links , <EOL> index_urls = index_urls , <EOL> allow_external = options . allow_external , <EOL> allow_unverified = options . allow_unverified , <EOL> allow_all_external = options . allow_all_external , <EOL> allow_all_prereleases = options . pre , <EOL> process_dependency_links = <EOL> options . process_dependency_links , <EOL> session = session , <EOL> ) <EOL> def run ( self , options , args ) : <EOL> if options . outdated : <EOL> self . run_outdated ( options ) <EOL> elif options . uptodate : <EOL> self . run_uptodate ( options ) <EOL> elif options . editable : <EOL> self . run_editables ( options ) <EOL> else : <EOL> self . run_listing ( options ) <EOL> def run_outdated ( self , options ) : <EOL> for dist , remote_version_raw , remote_version_parsed in self . find_packages_latests_versions ( options ) : <EOL> if remote_version_parsed > dist . parsed_version : <EOL> logger . notify ( '<STR_LIT>' % ( dist . project_name , <EOL> dist . version , remote_version_raw ) ) <EOL> def find_packages_latests_versions ( self , options ) : <EOL> index_urls = [ options . index_url ] + options . extra_index_urls <EOL> if options . no_index : <EOL> logger . notify ( '<STR_LIT>' % '<STR_LIT:U+002C>' . join ( index_urls ) ) <EOL> index_urls = [ ] <EOL> if options . use_mirrors : <EOL> logger . deprecated ( "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if options . mirrors : <EOL> logger . deprecated ( "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> index_urls += options . mirrors <EOL> dependency_links = [ ] <EOL> for dist in get_installed_distributions ( local_only = options . local , skip = self . skip ) : <EOL> if dist . has_metadata ( '<STR_LIT>' ) : <EOL> dependency_links . extend ( <EOL> dist . get_metadata_lines ( '<STR_LIT>' ) , <EOL> ) <EOL> session = self . _build_session ( options ) <EOL> finder = self . _build_package_finder ( options , index_urls , session ) <EOL> finder . add_dependency_links ( dependency_links ) <EOL> installed_packages = get_installed_distributions ( local_only = options . local , include_editables = False , skip = self . skip ) <EOL> for dist in installed_packages : <EOL> req = InstallRequirement . from_line ( dist . key , None ) <EOL> try : <EOL> link = finder . find_requirement ( req , True ) <EOL> if link is None : <EOL> continue <EOL> except DistributionNotFound : <EOL> continue <EOL> except BestVersionAlreadyInstalled : <EOL> remote_version = req . installed_version <EOL> else : <EOL> remote_version = finder . _link_package_versions ( link , req . name ) [ <NUM_LIT:0> ] <EOL> remote_version_raw = remote_version [ <NUM_LIT:2> ] <EOL> remote_version_parsed = remote_version [ <NUM_LIT:0> ] <EOL> yield dist , remote_version_raw , remote_version_parsed <EOL> def run_listing ( self , options ) : <EOL> installed_packages = get_installed_distributions ( local_only = options . local , skip = self . skip ) <EOL> self . output_package_listing ( installed_packages ) <EOL> def run_editables ( self , options ) : <EOL> installed_packages = get_installed_distributions ( local_only = options . local , editables_only = True ) <EOL> self . output_package_listing ( installed_packages ) <EOL> def output_package_listing ( self , installed_packages ) : <EOL> installed_packages = sorted ( installed_packages , key = lambda dist : dist . project_name . lower ( ) ) <EOL> for dist in installed_packages : <EOL> if dist_is_editable ( dist ) : <EOL> line = '<STR_LIT>' % ( dist . project_name , dist . version , dist . location ) <EOL> else : <EOL> line = '<STR_LIT>' % ( dist . project_name , dist . version ) <EOL> logger . notify ( line ) <EOL> def run_uptodate ( self , options ) : <EOL> uptodate = [ ] <EOL> for dist , remote_version_raw , remote_version_parsed in self . find_packages_latests_versions ( options ) : <EOL> if dist . parsed_version == remote_version_parsed : <EOL> uptodate . append ( dist ) <EOL> self . output_package_listing ( uptodate ) </s>
