<s> import sys <EOL> import os <EOL> import shutil <EOL> import re <EOL> import zipfile <EOL> import pkg_resources <EOL> import tempfile <EOL> from pip . locations import bin_py , running_under_virtualenv <EOL> from pip . exceptions import InstallationError , UninstallationError <EOL> from pip . vcs import vcs <EOL> from pip . log import logger <EOL> from pip . util import display_path , rmtree <EOL> from pip . util import ask , backup_dir <EOL> from pip . util import is_installable_dir , is_local , dist_is_local <EOL> from pip . util import renames , normalize_path , egg_link_path <EOL> from pip . util import make_path_relative <EOL> from pip import call_subprocess <EOL> from pip . backwardcompat import ( any , copytree , urlparse , urllib , <EOL> ConfigParser , string_types , HTTPError , <EOL> FeedParser , get_python_version , <EOL> b ) <EOL> from pip . index import Link <EOL> from pip . locations import build_prefix <EOL> from pip . download import ( get_file_content , is_url , url_to_path , <EOL> path_to_url , is_archive_file , <EOL> unpack_vcs_link , is_vcs_url , is_file_url , <EOL> unpack_file_url , unpack_http_url ) <EOL> PIP_DELETE_MARKER_FILENAME = '<STR_LIT>' <EOL> class InstallRequirement ( object ) : <EOL> def __init__ ( self , req , comes_from , source_dir = None , editable = False , <EOL> url = None , update = True ) : <EOL> if isinstance ( req , string_types ) : <EOL> req = pkg_resources . Requirement . parse ( req ) <EOL> self . req = req <EOL> self . comes_from = comes_from <EOL> self . source_dir = source_dir <EOL> self . editable = editable <EOL> self . url = url <EOL> self . _egg_info_path = None <EOL> self . satisfied_by = None <EOL> self . conflicts_with = None <EOL> self . _temp_build_dir = None <EOL> self . _is_bundle = None <EOL> self . update = update <EOL> self . install_succeeded = None <EOL> self . uninstalled = None <EOL> @ classmethod <EOL> def from_editable ( cls , editable_req , comes_from = None , default_vcs = None ) : <EOL> name , url = parse_editable ( editable_req , default_vcs ) <EOL> if url . startswith ( '<STR_LIT>' ) : <EOL> source_dir = url_to_path ( url ) <EOL> else : <EOL> source_dir = None <EOL> return cls ( name , comes_from , source_dir = source_dir , editable = True , url = url ) <EOL> @ classmethod <EOL> def from_line ( cls , name , comes_from = None ) : <EOL> """<STR_LIT>""" <EOL> url = None <EOL> name = name . strip ( ) <EOL> req = name <EOL> path = os . path . normpath ( os . path . abspath ( name ) ) <EOL> if is_url ( name ) : <EOL> url = name <EOL> req = None <EOL> elif os . path . isdir ( path ) and ( os . path . sep in name or name . startswith ( '<STR_LIT:.>' ) ) : <EOL> if not is_installable_dir ( path ) : <EOL> raise InstallationError ( "<STR_LIT>" <EOL> % name ) <EOL> url = path_to_url ( name ) <EOL> req = None <EOL> elif is_archive_file ( path ) : <EOL> if not os . path . isfile ( path ) : <EOL> logger . warn ( '<STR_LIT>' <EOL> % name ) <EOL> url = path_to_url ( name ) <EOL> req = None <EOL> return cls ( req , comes_from , url = url ) <EOL> def __str__ ( self ) : <EOL> if self . req : <EOL> s = str ( self . req ) <EOL> if self . url : <EOL> s += '<STR_LIT>' % self . url <EOL> else : <EOL> s = self . url <EOL> if self . satisfied_by is not None : <EOL> s += '<STR_LIT>' % display_path ( self . satisfied_by . location ) <EOL> if self . comes_from : <EOL> if isinstance ( self . comes_from , string_types ) : <EOL> comes_from = self . comes_from <EOL> else : <EOL> comes_from = self . comes_from . from_path ( ) <EOL> if comes_from : <EOL> s += '<STR_LIT>' % comes_from <EOL> return s <EOL> def from_path ( self ) : <EOL> if self . req is None : <EOL> return None <EOL> s = str ( self . req ) <EOL> if self . comes_from : <EOL> if isinstance ( self . comes_from , string_types ) : <EOL> comes_from = self . comes_from <EOL> else : <EOL> comes_from = self . comes_from . from_path ( ) <EOL> if comes_from : <EOL> s += '<STR_LIT>' + comes_from <EOL> return s <EOL> def build_location ( self , build_dir , unpack = True ) : <EOL> if self . _temp_build_dir is not None : <EOL> return self . _temp_build_dir <EOL> if self . req is None : <EOL> self . _temp_build_dir = tempfile . mkdtemp ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . _ideal_build_dir = build_dir <EOL> return self . _temp_build_dir <EOL> if self . editable : <EOL> name = self . name . lower ( ) <EOL> else : <EOL> name = self . name <EOL> if not os . path . exists ( build_dir ) : <EOL> _make_build_dir ( build_dir ) <EOL> return os . path . join ( build_dir , name ) <EOL> def correct_build_location ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . source_dir is not None : <EOL> return <EOL> assert self . req is not None <EOL> assert self . _temp_build_dir <EOL> old_location = self . _temp_build_dir <EOL> new_build_dir = self . _ideal_build_dir <EOL> del self . _ideal_build_dir <EOL> if self . editable : <EOL> name = self . name . lower ( ) <EOL> else : <EOL> name = self . name <EOL> new_location = os . path . join ( new_build_dir , name ) <EOL> if not os . path . exists ( new_build_dir ) : <EOL> logger . debug ( '<STR_LIT>' % new_build_dir ) <EOL> _make_build_dir ( new_build_dir ) <EOL> if os . path . exists ( new_location ) : <EOL> raise InstallationError ( <EOL> '<STR_LIT>' <EOL> % display_path ( new_location ) ) <EOL> logger . debug ( '<STR_LIT>' <EOL> % ( self , display_path ( old_location ) , display_path ( new_location ) ) ) <EOL> shutil . move ( old_location , new_location ) <EOL> self . _temp_build_dir = new_location <EOL> self . source_dir = new_location <EOL> self . _egg_info_path = None <EOL> @ property <EOL> def name ( self ) : <EOL> if self . req is None : <EOL> return None <EOL> return self . req . project_name <EOL> @ property <EOL> def url_name ( self ) : <EOL> if self . req is None : <EOL> return None <EOL> return urllib . quote ( self . req . unsafe_name ) <EOL> @ property <EOL> def setup_py ( self ) : <EOL> return os . path . join ( self . source_dir , '<STR_LIT>' ) <EOL> def run_egg_info ( self , force_root_egg_info = False ) : <EOL> assert self . source_dir <EOL> if self . name : <EOL> logger . notify ( '<STR_LIT>' % self . name ) <EOL> else : <EOL> logger . notify ( '<STR_LIT>' % self . url ) <EOL> logger . indent += <NUM_LIT:2> <EOL> try : <EOL> script = self . _run_setup_py <EOL> script = script . replace ( '<STR_LIT>' , repr ( self . setup_py ) ) <EOL> script = script . replace ( '<STR_LIT>' , repr ( self . name ) ) <EOL> if self . editable or force_root_egg_info : <EOL> egg_base_option = [ ] <EOL> else : <EOL> egg_info_dir = os . path . join ( self . source_dir , '<STR_LIT>' ) <EOL> if not os . path . exists ( egg_info_dir ) : <EOL> os . makedirs ( egg_info_dir ) <EOL> egg_base_option = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> call_subprocess ( <EOL> [ sys . executable , '<STR_LIT:-c>' , script , '<STR_LIT>' ] + egg_base_option , <EOL> cwd = self . source_dir , filter_stdout = self . _filter_install , show_stdout = False , <EOL> command_level = logger . VERBOSE_DEBUG , <EOL> command_desc = '<STR_LIT>' ) <EOL> finally : <EOL> logger . indent -= <NUM_LIT:2> <EOL> if not self . req : <EOL> self . req = pkg_resources . Requirement . parse ( <EOL> "<STR_LIT>" % self . pkg_info ( ) ) <EOL> self . correct_build_location ( ) <EOL> _run_setup_py = """<STR_LIT>""" <EOL> def egg_info_data ( self , filename ) : <EOL> if self . satisfied_by is not None : <EOL> if not self . satisfied_by . has_metadata ( filename ) : <EOL> return None <EOL> return self . satisfied_by . get_metadata ( filename ) <EOL> assert self . source_dir <EOL> filename = self . egg_info_path ( filename ) <EOL> if not os . path . exists ( filename ) : <EOL> return None <EOL> fp = open ( filename , '<STR_LIT:r>' ) <EOL> data = fp . read ( ) <EOL> fp . close ( ) <EOL> return data <EOL> def egg_info_path ( self , filename ) : <EOL> if self . _egg_info_path is None : <EOL> if self . editable : <EOL> base = self . source_dir <EOL> else : <EOL> base = os . path . join ( self . source_dir , '<STR_LIT>' ) <EOL> filenames = os . listdir ( base ) <EOL> if self . editable : <EOL> filenames = [ ] <EOL> for root , dirs , files in os . walk ( base ) : <EOL> for dir in vcs . dirnames : <EOL> if dir in dirs : <EOL> dirs . remove ( dir ) <EOL> for dir in dirs : <EOL> if ( os . path . exists ( os . path . join ( root , dir , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> or os . path . exists ( os . path . join ( root , dir , '<STR_LIT>' , '<STR_LIT>' ) ) ) : <EOL> dirs . remove ( dir ) <EOL> if dir == '<STR_LIT:test>' or dir == '<STR_LIT>' : <EOL> dirs . remove ( dir ) <EOL> filenames . extend ( [ os . path . join ( root , dir ) <EOL> for dir in dirs ] ) <EOL> filenames = [ f for f in filenames if f . endswith ( '<STR_LIT>' ) ] <EOL> if not filenames : <EOL> raise InstallationError ( '<STR_LIT>' % ( base , filename ) ) <EOL> assert filenames , "<STR_LIT>" % ( base , filename ) <EOL> if len ( filenames ) > <NUM_LIT:1> : <EOL> filenames . sort ( key = lambda x : x . count ( os . path . sep ) + <EOL> ( os . path . altsep and <EOL> x . count ( os . path . altsep ) or <NUM_LIT:0> ) ) <EOL> self . _egg_info_path = os . path . join ( base , filenames [ <NUM_LIT:0> ] ) <EOL> return os . path . join ( self . _egg_info_path , filename ) <EOL> def egg_info_lines ( self , filename ) : <EOL> data = self . egg_info_data ( filename ) <EOL> if not data : <EOL> return [ ] <EOL> result = [ ] <EOL> for line in data . splitlines ( ) : <EOL> line = line . strip ( ) <EOL> if not line or line . startswith ( '<STR_LIT:#>' ) : <EOL> continue <EOL> result . append ( line ) <EOL> return result <EOL> def pkg_info ( self ) : <EOL> p = FeedParser ( ) <EOL> data = self . egg_info_data ( '<STR_LIT>' ) <EOL> if not data : <EOL> logger . warn ( '<STR_LIT>' % display_path ( self . egg_info_path ( '<STR_LIT>' ) ) ) <EOL> p . feed ( data or '<STR_LIT>' ) <EOL> return p . close ( ) <EOL> @ property <EOL> def dependency_links ( self ) : <EOL> return self . egg_info_lines ( '<STR_LIT>' ) <EOL> _requirements_section_re = re . compile ( r'<STR_LIT>' ) <EOL> def requirements ( self , extras = ( ) ) : <EOL> in_extra = None <EOL> for line in self . egg_info_lines ( '<STR_LIT>' ) : <EOL> match = self . _requirements_section_re . match ( line ) <EOL> if match : <EOL> in_extra = match . group ( <NUM_LIT:1> ) <EOL> continue <EOL> if in_extra and in_extra not in extras : <EOL> continue <EOL> yield line <EOL> @ property <EOL> def absolute_versions ( self ) : <EOL> for qualifier , version in self . req . specs : <EOL> if qualifier == '<STR_LIT>' : <EOL> yield version <EOL> @ property <EOL> def installed_version ( self ) : <EOL> return self . pkg_info ( ) [ '<STR_LIT:version>' ] <EOL> def assert_source_matches_version ( self ) : <EOL> assert self . source_dir <EOL> if self . comes_from is None : <EOL> return <EOL> version = self . installed_version <EOL> if version not in self . req : <EOL> logger . fatal ( <EOL> '<STR_LIT>' <EOL> % ( display_path ( self . source_dir ) , version , self ) ) <EOL> raise InstallationError ( <EOL> '<STR_LIT>' <EOL> % ( display_path ( self . source_dir ) , version , self ) ) <EOL> else : <EOL> logger . debug ( '<STR_LIT>' <EOL> % ( display_path ( self . source_dir ) , version , self ) ) <EOL> def update_editable ( self , obtain = True ) : <EOL> if not self . url : <EOL> logger . info ( "<STR_LIT>" % self . source_dir ) <EOL> return <EOL> assert self . editable <EOL> assert self . source_dir <EOL> if self . url . startswith ( '<STR_LIT>' ) : <EOL> return <EOL> assert '<STR_LIT:+>' in self . url , "<STR_LIT>" % self . url <EOL> if not self . update : <EOL> return <EOL> vc_type , url = self . url . split ( '<STR_LIT:+>' , <NUM_LIT:1> ) <EOL> backend = vcs . get_backend ( vc_type ) <EOL> if backend : <EOL> vcs_backend = backend ( self . url ) <EOL> if obtain : <EOL> vcs_backend . obtain ( self . source_dir ) <EOL> else : <EOL> vcs_backend . export ( self . source_dir ) <EOL> else : <EOL> assert <NUM_LIT:0> , ( <EOL> '<STR_LIT>' <EOL> % ( self . url , vc_type ) ) <EOL> def uninstall ( self , auto_confirm = False ) : <EOL> """<STR_LIT>""" <EOL> if not self . check_if_exists ( ) : <EOL> raise UninstallationError ( "<STR_LIT>" % ( self . name , ) ) <EOL> dist = self . satisfied_by or self . conflicts_with <EOL> paths_to_remove = UninstallPathSet ( dist ) <EOL> pip_egg_info_path = os . path . join ( dist . location , <EOL> dist . egg_name ( ) ) + '<STR_LIT>' <EOL> debian_egg_info_path = pip_egg_info_path . replace ( <EOL> '<STR_LIT>' % pkg_resources . PY_MAJOR , '<STR_LIT>' ) <EOL> easy_install_egg = dist . egg_name ( ) + '<STR_LIT>' <EOL> develop_egg_link = egg_link_path ( dist ) <EOL> pip_egg_info_exists = os . path . exists ( pip_egg_info_path ) <EOL> debian_egg_info_exists = os . path . exists ( debian_egg_info_path ) <EOL> if pip_egg_info_exists or debian_egg_info_exists : <EOL> if pip_egg_info_exists : <EOL> egg_info_path = pip_egg_info_path <EOL> else : <EOL> egg_info_path = debian_egg_info_path <EOL> paths_to_remove . add ( egg_info_path ) <EOL> if dist . has_metadata ( '<STR_LIT>' ) : <EOL> for installed_file in dist . get_metadata ( '<STR_LIT>' ) . splitlines ( ) : <EOL> path = os . path . normpath ( os . path . join ( egg_info_path , installed_file ) ) <EOL> paths_to_remove . add ( path ) <EOL> if dist . has_metadata ( '<STR_LIT>' ) : <EOL> if dist . has_metadata ( '<STR_LIT>' ) : <EOL> namespaces = dist . get_metadata ( '<STR_LIT>' ) <EOL> else : <EOL> namespaces = [ ] <EOL> for top_level_pkg in [ p for p <EOL> in dist . get_metadata ( '<STR_LIT>' ) . splitlines ( ) <EOL> if p and p not in namespaces ] : <EOL> path = os . path . join ( dist . location , top_level_pkg ) <EOL> paths_to_remove . add ( path ) <EOL> paths_to_remove . add ( path + '<STR_LIT>' ) <EOL> paths_to_remove . add ( path + '<STR_LIT>' ) <EOL> elif dist . location . endswith ( easy_install_egg ) : <EOL> paths_to_remove . add ( dist . location ) <EOL> easy_install_pth = os . path . join ( os . path . dirname ( dist . location ) , <EOL> '<STR_LIT>' ) <EOL> paths_to_remove . add_pth ( easy_install_pth , '<STR_LIT>' + easy_install_egg ) <EOL> elif os . path . isfile ( develop_egg_link ) : <EOL> fh = open ( develop_egg_link , '<STR_LIT:r>' ) <EOL> link_pointer = os . path . normcase ( fh . readline ( ) . strip ( ) ) <EOL> fh . close ( ) <EOL> assert ( link_pointer == dist . location ) , '<STR_LIT>' % ( link_pointer , self . name , dist . location ) <EOL> paths_to_remove . add ( develop_egg_link ) <EOL> easy_install_pth = os . path . join ( os . path . dirname ( develop_egg_link ) , <EOL> '<STR_LIT>' ) <EOL> paths_to_remove . add_pth ( easy_install_pth , dist . location ) <EOL> if dist . has_metadata ( '<STR_LIT>' ) and dist . metadata_isdir ( '<STR_LIT>' ) : <EOL> for script in dist . metadata_listdir ( '<STR_LIT>' ) : <EOL> paths_to_remove . add ( os . path . join ( bin_py , script ) ) <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> paths_to_remove . add ( os . path . join ( bin_py , script ) + '<STR_LIT>' ) <EOL> if dist . has_metadata ( '<STR_LIT>' ) : <EOL> config = ConfigParser . SafeConfigParser ( ) <EOL> config . readfp ( FakeFile ( dist . get_metadata_lines ( '<STR_LIT>' ) ) ) <EOL> if config . has_section ( '<STR_LIT>' ) : <EOL> for name , value in config . items ( '<STR_LIT>' ) : <EOL> paths_to_remove . add ( os . path . join ( bin_py , name ) ) <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> paths_to_remove . add ( os . path . join ( bin_py , name ) + '<STR_LIT>' ) <EOL> paths_to_remove . add ( os . path . join ( bin_py , name ) + '<STR_LIT>' ) <EOL> paths_to_remove . add ( os . path . join ( bin_py , name ) + '<STR_LIT>' ) <EOL> paths_to_remove . remove ( auto_confirm ) <EOL> self . uninstalled = paths_to_remove <EOL> def rollback_uninstall ( self ) : <EOL> if self . uninstalled : <EOL> self . uninstalled . rollback ( ) <EOL> else : <EOL> logger . error ( "<STR_LIT>" <EOL> % ( self . project_name , ) ) <EOL> def commit_uninstall ( self ) : <EOL> if self . uninstalled : <EOL> self . uninstalled . commit ( ) <EOL> else : <EOL> logger . error ( "<STR_LIT>" <EOL> % ( self . project_name , ) ) <EOL> def archive ( self , build_dir ) : <EOL> assert self . source_dir <EOL> create_archive = True <EOL> archive_name = '<STR_LIT>' % ( self . name , self . installed_version ) <EOL> archive_path = os . path . join ( build_dir , archive_name ) <EOL> if os . path . exists ( archive_path ) : <EOL> response = ask ( '<STR_LIT>' <EOL> % display_path ( archive_path ) , ( '<STR_LIT:i>' , '<STR_LIT:w>' , '<STR_LIT:b>' ) ) <EOL> if response == '<STR_LIT:i>' : <EOL> create_archive = False <EOL> elif response == '<STR_LIT:w>' : <EOL> logger . warn ( '<STR_LIT>' % display_path ( archive_path ) ) <EOL> os . remove ( archive_path ) <EOL> elif response == '<STR_LIT:b>' : <EOL> dest_file = backup_dir ( archive_path ) <EOL> logger . warn ( '<STR_LIT>' <EOL> % ( display_path ( archive_path ) , display_path ( dest_file ) ) ) <EOL> shutil . move ( archive_path , dest_file ) <EOL> if create_archive : <EOL> zip = zipfile . ZipFile ( archive_path , '<STR_LIT:w>' , zipfile . ZIP_DEFLATED ) <EOL> dir = os . path . normcase ( os . path . abspath ( self . source_dir ) ) <EOL> for dirpath , dirnames , filenames in os . walk ( dir ) : <EOL> if '<STR_LIT>' in dirnames : <EOL> dirnames . remove ( '<STR_LIT>' ) <EOL> for dirname in dirnames : <EOL> dirname = os . path . join ( dirpath , dirname ) <EOL> name = self . _clean_zip_name ( dirname , dir ) <EOL> zipdir = zipfile . ZipInfo ( self . name + '<STR_LIT:/>' + name + '<STR_LIT:/>' ) <EOL> zipdir . external_attr = <NUM_LIT> << <NUM_LIT:16> <EOL> zip . writestr ( zipdir , '<STR_LIT>' ) <EOL> for filename in filenames : <EOL> if filename == PIP_DELETE_MARKER_FILENAME : <EOL> continue <EOL> filename = os . path . join ( dirpath , filename ) <EOL> name = self . _clean_zip_name ( filename , dir ) <EOL> zip . write ( filename , self . name + '<STR_LIT:/>' + name ) <EOL> zip . close ( ) <EOL> logger . indent -= <NUM_LIT:2> <EOL> logger . notify ( '<STR_LIT>' % display_path ( archive_path ) ) <EOL> def _clean_zip_name ( self , name , prefix ) : <EOL> assert name . startswith ( prefix + os . path . sep ) , ( <EOL> "<STR_LIT>" % ( name , prefix ) ) <EOL> name = name [ len ( prefix ) + <NUM_LIT:1> : ] <EOL> name = name . replace ( os . path . sep , '<STR_LIT:/>' ) <EOL> return name <EOL> def install ( self , install_options , global_options = ( ) ) : <EOL> if self . editable : <EOL> self . install_editable ( install_options , global_options ) <EOL> return <EOL> temp_location = tempfile . mkdtemp ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> record_filename = os . path . join ( temp_location , '<STR_LIT>' ) <EOL> try : <EOL> install_args = [ <EOL> sys . executable , '<STR_LIT:-c>' , <EOL> "<STR_LIT>" "<STR_LIT>" % self . setup_py ] + list ( global_options ) + [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , record_filename ] <EOL> if running_under_virtualenv ( ) : <EOL> install_args += [ '<STR_LIT>' , <EOL> os . path . join ( sys . prefix , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' + get_python_version ( ) ) ] <EOL> logger . notify ( '<STR_LIT>' % self . name ) <EOL> logger . indent += <NUM_LIT:2> <EOL> try : <EOL> call_subprocess ( install_args + install_options , <EOL> cwd = self . source_dir , filter_stdout = self . _filter_install , show_stdout = False ) <EOL> finally : <EOL> logger . indent -= <NUM_LIT:2> <EOL> if not os . path . exists ( record_filename ) : <EOL> logger . notify ( '<STR_LIT>' % record_filename ) <EOL> return <EOL> self . install_succeeded = True <EOL> f = open ( record_filename ) <EOL> for line in f : <EOL> line = line . strip ( ) <EOL> if line . endswith ( '<STR_LIT>' ) : <EOL> egg_info_dir = line <EOL> break <EOL> else : <EOL> logger . warn ( '<STR_LIT>' % self ) <EOL> return <EOL> f . close ( ) <EOL> new_lines = [ ] <EOL> f = open ( record_filename ) <EOL> for line in f : <EOL> filename = line . strip ( ) <EOL> if os . path . isdir ( filename ) : <EOL> filename += os . path . sep <EOL> new_lines . append ( make_path_relative ( filename , egg_info_dir ) ) <EOL> f . close ( ) <EOL> f = open ( os . path . join ( egg_info_dir , '<STR_LIT>' ) , '<STR_LIT:w>' ) <EOL> f . write ( '<STR_LIT:\n>' . join ( new_lines ) + '<STR_LIT:\n>' ) <EOL> f . close ( ) <EOL> finally : <EOL> if os . path . exists ( record_filename ) : <EOL> os . remove ( record_filename ) <EOL> os . rmdir ( temp_location ) <EOL> def remove_temporary_source ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . is_bundle or os . path . exists ( self . delete_marker_filename ) : <EOL> logger . info ( '<STR_LIT>' % self . source_dir ) <EOL> if self . source_dir : <EOL> rmtree ( self . source_dir ) <EOL> self . source_dir = None <EOL> if self . _temp_build_dir and os . path . exists ( self . _temp_build_dir ) : <EOL> rmtree ( self . _temp_build_dir ) <EOL> self . _temp_build_dir = None <EOL> def install_editable ( self , install_options , global_options = ( ) ) : <EOL> logger . notify ( '<STR_LIT>' % self . name ) <EOL> logger . indent += <NUM_LIT:2> <EOL> try : <EOL> call_subprocess ( <EOL> [ sys . executable , '<STR_LIT:-c>' , <EOL> "<STR_LIT>" % self . setup_py ] <EOL> + list ( global_options ) + [ '<STR_LIT>' , '<STR_LIT>' ] + list ( install_options ) , <EOL> cwd = self . source_dir , filter_stdout = self . _filter_install , <EOL> show_stdout = False ) <EOL> finally : <EOL> logger . indent -= <NUM_LIT:2> <EOL> self . install_succeeded = True <EOL> def _filter_install ( self , line ) : <EOL> level = logger . NOTIFY <EOL> for regex in [ r'<STR_LIT>' , r'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> r'<STR_LIT>' , r"<STR_LIT>" , <EOL> r'<STR_LIT>' , <EOL> r"<STR_LIT>" ] : <EOL> if re . search ( regex , line . strip ( ) ) : <EOL> level = logger . INFO <EOL> break <EOL> return ( level , line ) <EOL> def check_if_exists ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . req is None : <EOL> return False <EOL> try : <EOL> self . satisfied_by = pkg_resources . get_distribution ( self . req ) <EOL> except pkg_resources . DistributionNotFound : <EOL> return False <EOL> except pkg_resources . VersionConflict : <EOL> self . conflicts_with = pkg_resources . get_distribution ( self . req . project_name ) <EOL> return True <EOL> @ property <EOL> def is_bundle ( self ) : <EOL> if self . _is_bundle is not None : <EOL> return self . _is_bundle <EOL> base = self . _temp_build_dir <EOL> if not base : <EOL> return False <EOL> self . _is_bundle = ( os . path . exists ( os . path . join ( base , '<STR_LIT>' ) ) <EOL> or os . path . exists ( os . path . join ( base , '<STR_LIT>' ) ) ) <EOL> return self . _is_bundle <EOL> def bundle_requirements ( self ) : <EOL> for dest_dir in self . _bundle_editable_dirs : <EOL> package = os . path . basename ( dest_dir ) <EOL> for vcs_backend in vcs . backends : <EOL> url = rev = None <EOL> vcs_bundle_file = os . path . join ( <EOL> dest_dir , vcs_backend . bundle_file ) <EOL> if os . path . exists ( vcs_bundle_file ) : <EOL> vc_type = vcs_backend . name <EOL> fp = open ( vcs_bundle_file ) <EOL> content = fp . read ( ) <EOL> fp . close ( ) <EOL> url , rev = vcs_backend ( ) . parse_vcs_bundle_file ( content ) <EOL> break <EOL> if url : <EOL> url = '<STR_LIT>' % ( vc_type , url , rev ) <EOL> else : <EOL> url = None <EOL> yield InstallRequirement ( <EOL> package , self , editable = True , url = url , <EOL> update = False , source_dir = dest_dir ) <EOL> for dest_dir in self . _bundle_build_dirs : <EOL> package = os . path . basename ( dest_dir ) <EOL> yield InstallRequirement ( <EOL> package , self , <EOL> source_dir = dest_dir ) <EOL> def move_bundle_files ( self , dest_build_dir , dest_src_dir ) : <EOL> base = self . _temp_build_dir <EOL> assert base <EOL> src_dir = os . path . join ( base , '<STR_LIT:src>' ) <EOL> build_dir = os . path . join ( base , '<STR_LIT>' ) <EOL> bundle_build_dirs = [ ] <EOL> bundle_editable_dirs = [ ] <EOL> for source_dir , dest_dir , dir_collection in [ <EOL> ( src_dir , dest_src_dir , bundle_editable_dirs ) , <EOL> ( build_dir , dest_build_dir , bundle_build_dirs ) ] : <EOL> if os . path . exists ( source_dir ) : <EOL> for dirname in os . listdir ( source_dir ) : <EOL> dest = os . path . join ( dest_dir , dirname ) <EOL> dir_collection . append ( dest ) <EOL> if os . path . exists ( dest ) : <EOL> logger . warn ( '<STR_LIT>' <EOL> % ( dest , dirname , self ) ) <EOL> continue <EOL> if not os . path . exists ( dest_dir ) : <EOL> logger . info ( '<STR_LIT>' % dest_dir ) <EOL> os . makedirs ( dest_dir ) <EOL> shutil . move ( os . path . join ( source_dir , dirname ) , dest ) <EOL> if not os . listdir ( source_dir ) : <EOL> os . rmdir ( source_dir ) <EOL> self . _temp_build_dir = None <EOL> self . _bundle_build_dirs = bundle_build_dirs <EOL> self . _bundle_editable_dirs = bundle_editable_dirs <EOL> @ property <EOL> def delete_marker_filename ( self ) : <EOL> assert self . source_dir <EOL> return os . path . join ( self . source_dir , PIP_DELETE_MARKER_FILENAME ) <EOL> DELETE_MARKER_MESSAGE = '''<STR_LIT>''' <EOL> class Requirements ( object ) : <EOL> def __init__ ( self ) : <EOL> self . _keys = [ ] <EOL> self . _dict = { } <EOL> def keys ( self ) : <EOL> return self . _keys <EOL> def values ( self ) : <EOL> values_list = [ ] <EOL> for key in self . _keys : <EOL> values_list . append ( self . _dict [ key ] ) <EOL> return values_list <EOL> def __contains__ ( self , item ) : <EOL> return item in self . _keys <EOL> def __setitem__ ( self , key , value ) : <EOL> if key not in self . _keys : <EOL> self . _keys . append ( key ) <EOL> self . _dict [ key ] = value <EOL> def __getitem__ ( self , key ) : <EOL> return self . _dict [ key ] <EOL> def __repr__ ( self ) : <EOL> values = [ '<STR_LIT>' % ( repr ( k ) , repr ( self [ k ] ) ) for k in self . keys ( ) ] <EOL> return '<STR_LIT>' % '<STR_LIT:U+002CU+0020>' . join ( values ) <EOL> class RequirementSet ( object ) : <EOL> def __init__ ( self , build_dir , src_dir , download_dir , download_cache = None , <EOL> upgrade = False , ignore_installed = False , <EOL> ignore_dependencies = False ) : <EOL> self . build_dir = build_dir <EOL> self . src_dir = src_dir <EOL> self . download_dir = download_dir <EOL> self . download_cache = download_cache <EOL> self . upgrade = upgrade <EOL> self . ignore_installed = ignore_installed <EOL> self . requirements = Requirements ( ) <EOL> self . requirement_aliases = { } <EOL> self . unnamed_requirements = [ ] <EOL> self . ignore_dependencies = ignore_dependencies <EOL> self . successfully_downloaded = [ ] <EOL> self . successfully_installed = [ ] <EOL> self . reqs_to_cleanup = [ ] <EOL> def __str__ ( self ) : <EOL> reqs = [ req for req in self . requirements . values ( ) <EOL> if not req . comes_from ] <EOL> reqs . sort ( key = lambda req : req . name . lower ( ) ) <EOL> return '<STR_LIT:U+0020>' . join ( [ str ( req . req ) for req in reqs ] ) <EOL> def add_requirement ( self , install_req ) : <EOL> name = install_req . name <EOL> if not name : <EOL> self . unnamed_requirements . append ( install_req ) <EOL> else : <EOL> if self . has_requirement ( name ) : <EOL> raise InstallationError ( <EOL> '<STR_LIT>' <EOL> % ( install_req , self . get_requirement ( name ) , name ) ) <EOL> self . requirements [ name ] = install_req <EOL> if name . lower ( ) != name : <EOL> self . requirement_aliases [ name . lower ( ) ] = name <EOL> def has_requirement ( self , project_name ) : <EOL> for name in project_name , project_name . lower ( ) : <EOL> if name in self . requirements or name in self . requirement_aliases : <EOL> return True <EOL> return False <EOL> @ property <EOL> def has_requirements ( self ) : <EOL> return list ( self . requirements . values ( ) ) or self . unnamed_requirements <EOL> @ property <EOL> def has_editables ( self ) : <EOL> if any ( req . editable for req in self . requirements . values ( ) ) : <EOL> return True <EOL> if any ( req . editable for req in self . unnamed_requirements ) : <EOL> return True <EOL> return False <EOL> @ property <EOL> def is_download ( self ) : <EOL> if self . download_dir : <EOL> self . download_dir = os . path . expanduser ( self . download_dir ) <EOL> if os . path . exists ( self . download_dir ) : <EOL> return True <EOL> else : <EOL> logger . fatal ( '<STR_LIT>' ) <EOL> raise InstallationError ( <EOL> "<STR_LIT>" <EOL> % display_path ( self . download_dir ) ) <EOL> return False <EOL> def get_requirement ( self , project_name ) : <EOL> for name in project_name , project_name . lower ( ) : <EOL> if name in self . requirements : <EOL> return self . requirements [ name ] <EOL> if name in self . requirement_aliases : <EOL> return self . requirements [ self . requirement_aliases [ name ] ] <EOL> raise KeyError ( "<STR_LIT>" % project_name ) <EOL> def uninstall ( self , auto_confirm = False ) : <EOL> for req in self . requirements . values ( ) : <EOL> req . uninstall ( auto_confirm = auto_confirm ) <EOL> req . commit_uninstall ( ) <EOL> def locate_files ( self ) : <EOL> unnamed = list ( self . unnamed_requirements ) <EOL> reqs = list ( self . requirements . values ( ) ) <EOL> while reqs or unnamed : <EOL> if unnamed : <EOL> req_to_install = unnamed . pop ( <NUM_LIT:0> ) <EOL> else : <EOL> req_to_install = reqs . pop ( <NUM_LIT:0> ) <EOL> install_needed = True <EOL> if not self . ignore_installed and not req_to_install . editable : <EOL> req_to_install . check_if_exists ( ) <EOL> if req_to_install . satisfied_by : <EOL> if self . upgrade : <EOL> req_to_install . conflicts_with = req_to_install . satisfied_by <EOL> req_to_install . satisfied_by = None <EOL> else : <EOL> install_needed = False <EOL> if req_to_install . satisfied_by : <EOL> logger . notify ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> % req_to_install ) <EOL> if req_to_install . editable : <EOL> if req_to_install . source_dir is None : <EOL> req_to_install . source_dir = req_to_install . build_location ( self . src_dir ) <EOL> elif install_needed : <EOL> req_to_install . source_dir = req_to_install . build_location ( self . build_dir , not self . is_download ) <EOL> if req_to_install . source_dir is not None and not os . path . isdir ( req_to_install . source_dir ) : <EOL> raise InstallationError ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> % ( req_to_install , req_to_install . source_dir ) ) <EOL> def prepare_files ( self , finder , force_root_egg_info = False , bundle = False ) : <EOL> """<STR_LIT>""" <EOL> unnamed = list ( self . unnamed_requirements ) <EOL> reqs = list ( self . requirements . values ( ) ) <EOL> while reqs or unnamed : <EOL> if unnamed : <EOL> req_to_install = unnamed . pop ( <NUM_LIT:0> ) <EOL> else : <EOL> req_to_install = reqs . pop ( <NUM_LIT:0> ) <EOL> install = True <EOL> if not self . ignore_installed and not req_to_install . editable : <EOL> req_to_install . check_if_exists ( ) <EOL> if req_to_install . satisfied_by : <EOL> if self . upgrade : <EOL> req_to_install . conflicts_with = req_to_install . satisfied_by <EOL> req_to_install . satisfied_by = None <EOL> else : <EOL> install = False <EOL> if req_to_install . satisfied_by : <EOL> logger . notify ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> % req_to_install ) <EOL> if req_to_install . editable : <EOL> logger . notify ( '<STR_LIT>' % req_to_install ) <EOL> elif install : <EOL> if req_to_install . url and req_to_install . url . lower ( ) . startswith ( '<STR_LIT>' ) : <EOL> logger . notify ( '<STR_LIT>' % display_path ( url_to_path ( req_to_install . url ) ) ) <EOL> else : <EOL> logger . notify ( '<STR_LIT>' % req_to_install ) <EOL> logger . indent += <NUM_LIT:2> <EOL> try : <EOL> is_bundle = False <EOL> if req_to_install . editable : <EOL> if req_to_install . source_dir is None : <EOL> location = req_to_install . build_location ( self . src_dir ) <EOL> req_to_install . source_dir = location <EOL> else : <EOL> location = req_to_install . source_dir <EOL> if not os . path . exists ( self . build_dir ) : <EOL> _make_build_dir ( self . build_dir ) <EOL> req_to_install . update_editable ( not self . is_download ) <EOL> if self . is_download : <EOL> req_to_install . run_egg_info ( ) <EOL> req_to_install . archive ( self . download_dir ) <EOL> else : <EOL> req_to_install . run_egg_info ( ) <EOL> elif install : <EOL> location = req_to_install . build_location ( self . build_dir , not self . is_download ) <EOL> unpack = True <EOL> if not os . path . exists ( os . path . join ( location , '<STR_LIT>' ) ) : <EOL> if req_to_install . url is None : <EOL> url = finder . find_requirement ( req_to_install , upgrade = self . upgrade ) <EOL> else : <EOL> url = Link ( req_to_install . url ) <EOL> assert url <EOL> if url : <EOL> try : <EOL> self . unpack_url ( url , location , self . is_download ) <EOL> except HTTPError : <EOL> e = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> logger . fatal ( '<STR_LIT>' <EOL> % ( req_to_install , e ) ) <EOL> raise InstallationError ( <EOL> '<STR_LIT>' <EOL> % ( req_to_install , e , url ) ) <EOL> else : <EOL> unpack = False <EOL> if unpack : <EOL> is_bundle = req_to_install . is_bundle <EOL> url = None <EOL> if is_bundle : <EOL> req_to_install . move_bundle_files ( self . build_dir , self . src_dir ) <EOL> for subreq in req_to_install . bundle_requirements ( ) : <EOL> reqs . append ( subreq ) <EOL> self . add_requirement ( subreq ) <EOL> elif self . is_download : <EOL> req_to_install . source_dir = location <EOL> if url and url . scheme in vcs . all_schemes : <EOL> req_to_install . run_egg_info ( ) <EOL> req_to_install . archive ( self . download_dir ) <EOL> else : <EOL> req_to_install . source_dir = location <EOL> req_to_install . run_egg_info ( ) <EOL> if force_root_egg_info : <EOL> req_to_install . run_egg_info ( force_root_egg_info = True ) <EOL> req_to_install . assert_source_matches_version ( ) <EOL> if bundle and req_to_install . url : <EOL> self . copy_to_build_dir ( req_to_install ) <EOL> install = False <EOL> req_to_install . check_if_exists ( ) <EOL> if req_to_install . satisfied_by : <EOL> if self . upgrade : <EOL> req_to_install . conflicts_with = req_to_install . satisfied_by <EOL> req_to_install . satisfied_by = None <EOL> else : <EOL> install = False <EOL> if not is_bundle and not self . is_download : <EOL> finder . add_dependency_links ( req_to_install . dependency_links ) <EOL> if not self . ignore_dependencies : <EOL> for req in req_to_install . requirements ( ) : <EOL> try : <EOL> name = pkg_resources . Requirement . parse ( req ) . project_name <EOL> except ValueError : <EOL> e = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> logger . error ( '<STR_LIT>' % ( req , e , req_to_install ) ) <EOL> continue <EOL> if self . has_requirement ( name ) : <EOL> continue <EOL> subreq = InstallRequirement ( req , req_to_install ) <EOL> reqs . append ( subreq ) <EOL> self . add_requirement ( subreq ) <EOL> if req_to_install . name not in self . requirements : <EOL> self . requirements [ req_to_install . name ] = req_to_install <EOL> else : <EOL> self . reqs_to_cleanup . append ( req_to_install ) <EOL> if install : <EOL> self . successfully_downloaded . append ( req_to_install ) <EOL> if bundle and ( req_to_install . url and req_to_install . url . startswith ( '<STR_LIT>' ) ) : <EOL> self . copy_to_build_dir ( req_to_install ) <EOL> finally : <EOL> logger . indent -= <NUM_LIT:2> <EOL> def cleanup_files ( self , bundle = False ) : <EOL> """<STR_LIT>""" <EOL> logger . notify ( '<STR_LIT>' ) <EOL> logger . indent += <NUM_LIT:2> <EOL> for req in self . reqs_to_cleanup : <EOL> req . remove_temporary_source ( ) <EOL> remove_dir = [ ] <EOL> if self . _pip_has_created_build_dir ( ) : <EOL> remove_dir . append ( self . build_dir ) <EOL> if bundle : <EOL> remove_dir . append ( self . src_dir ) <EOL> for dir in remove_dir : <EOL> if os . path . exists ( dir ) : <EOL> logger . info ( '<STR_LIT>' % dir ) <EOL> rmtree ( dir ) <EOL> logger . indent -= <NUM_LIT:2> <EOL> def _pip_has_created_build_dir ( self ) : <EOL> return ( self . build_dir == build_prefix and <EOL> os . path . exists ( os . path . join ( self . build_dir , PIP_DELETE_MARKER_FILENAME ) ) ) <EOL> def copy_to_build_dir ( self , req_to_install ) : <EOL> target_dir = req_to_install . editable and self . src_dir or self . build_dir <EOL> logger . info ( "<STR_LIT>" % ( req_to_install . name , target_dir ) ) <EOL> dest = os . path . join ( target_dir , req_to_install . name ) <EOL> copytree ( req_to_install . source_dir , dest ) <EOL> call_subprocess ( [ "<STR_LIT>" , "<STR_LIT>" % dest , "<STR_LIT>" ] ) <EOL> def unpack_url ( self , link , location , only_download = False ) : <EOL> if only_download : <EOL> location = self . download_dir <EOL> if is_vcs_url ( link ) : <EOL> return unpack_vcs_link ( link , location , only_download ) <EOL> elif is_file_url ( link ) : <EOL> return unpack_file_url ( link , location ) <EOL> else : <EOL> if self . download_cache : <EOL> self . download_cache = os . path . expanduser ( self . download_cache ) <EOL> return unpack_http_url ( link , location , self . download_cache , only_download ) <EOL> def install ( self , install_options , global_options = ( ) ) : <EOL> """<STR_LIT>""" <EOL> to_install = [ r for r in self . requirements . values ( ) <EOL> if self . upgrade or not r . satisfied_by ] <EOL> if to_install : <EOL> logger . notify ( '<STR_LIT>' % ( '<STR_LIT:U+002CU+0020>' . join ( [ req . name for req in to_install ] ) ) ) <EOL> logger . indent += <NUM_LIT:2> <EOL> try : <EOL> for requirement in to_install : <EOL> if requirement . conflicts_with : <EOL> logger . notify ( '<STR_LIT>' <EOL> % requirement . conflicts_with ) <EOL> logger . indent += <NUM_LIT:2> <EOL> try : <EOL> requirement . uninstall ( auto_confirm = True ) <EOL> finally : <EOL> logger . indent -= <NUM_LIT:2> <EOL> try : <EOL> requirement . install ( install_options , global_options ) <EOL> except : <EOL> if requirement . conflicts_with and not requirement . install_succeeded : <EOL> requirement . rollback_uninstall ( ) <EOL> raise <EOL> else : <EOL> if requirement . conflicts_with and requirement . install_succeeded : <EOL> requirement . commit_uninstall ( ) <EOL> requirement . remove_temporary_source ( ) <EOL> finally : <EOL> logger . indent -= <NUM_LIT:2> <EOL> self . successfully_installed = to_install <EOL> def create_bundle ( self , bundle_filename ) : <EOL> zip = zipfile . ZipFile ( bundle_filename , '<STR_LIT:w>' , zipfile . ZIP_DEFLATED ) <EOL> vcs_dirs = [ ] <EOL> for dir , basename in ( self . build_dir , '<STR_LIT>' ) , ( self . src_dir , '<STR_LIT:src>' ) : <EOL> dir = os . path . normcase ( os . path . abspath ( dir ) ) <EOL> for dirpath , dirnames , filenames in os . walk ( dir ) : <EOL> for backend in vcs . backends : <EOL> vcs_backend = backend ( ) <EOL> vcs_url = vcs_rev = None <EOL> if vcs_backend . dirname in dirnames : <EOL> for vcs_dir in vcs_dirs : <EOL> if dirpath . startswith ( vcs_dir ) : <EOL> break <EOL> else : <EOL> vcs_url , vcs_rev = vcs_backend . get_info ( <EOL> os . path . join ( dir , dirpath ) ) <EOL> vcs_dirs . append ( dirpath ) <EOL> vcs_bundle_file = vcs_backend . bundle_file <EOL> vcs_guide = vcs_backend . guide % { '<STR_LIT:url>' : vcs_url , <EOL> '<STR_LIT>' : vcs_rev } <EOL> dirnames . remove ( vcs_backend . dirname ) <EOL> break <EOL> if '<STR_LIT>' in dirnames : <EOL> dirnames . remove ( '<STR_LIT>' ) <EOL> for dirname in dirnames : <EOL> dirname = os . path . join ( dirpath , dirname ) <EOL> name = self . _clean_zip_name ( dirname , dir ) <EOL> zip . writestr ( basename + '<STR_LIT:/>' + name + '<STR_LIT:/>' , '<STR_LIT>' ) <EOL> for filename in filenames : <EOL> if filename == PIP_DELETE_MARKER_FILENAME : <EOL> continue <EOL> filename = os . path . join ( dirpath , filename ) <EOL> name = self . _clean_zip_name ( filename , dir ) <EOL> zip . write ( filename , basename + '<STR_LIT:/>' + name ) <EOL> if vcs_url : <EOL> name = os . path . join ( dirpath , vcs_bundle_file ) <EOL> name = self . _clean_zip_name ( name , dir ) <EOL> zip . writestr ( basename + '<STR_LIT:/>' + name , vcs_guide ) <EOL> zip . writestr ( '<STR_LIT>' , self . bundle_requirements ( ) ) <EOL> zip . close ( ) <EOL> BUNDLE_HEADER = '''<STR_LIT>''' <EOL> def bundle_requirements ( self ) : <EOL> parts = [ self . BUNDLE_HEADER ] <EOL> for req in [ req for req in self . requirements . values ( ) <EOL> if not req . comes_from ] : <EOL> parts . append ( '<STR_LIT>' % ( req . name , req . installed_version ) ) <EOL> parts . append ( '<STR_LIT>' ) <EOL> for req in [ req for req in self . requirements . values ( ) <EOL> if req . comes_from ] : <EOL> parts . append ( '<STR_LIT>' % ( req . name , req . installed_version ) ) <EOL> return '<STR_LIT>' . join ( parts ) <EOL> def _clean_zip_name ( self , name , prefix ) : <EOL> assert name . startswith ( prefix + os . path . sep ) , ( <EOL> "<STR_LIT>" % ( name , prefix ) ) <EOL> name = name [ len ( prefix ) + <NUM_LIT:1> : ] <EOL> name = name . replace ( os . path . sep , '<STR_LIT:/>' ) <EOL> return name <EOL> def _make_build_dir ( build_dir ) : <EOL> os . makedirs ( build_dir ) <EOL> _write_delete_marker_message ( os . path . join ( build_dir , PIP_DELETE_MARKER_FILENAME ) ) <EOL> def _write_delete_marker_message ( filepath ) : <EOL> marker_fp = open ( filepath , '<STR_LIT:w>' ) <EOL> marker_fp . write ( DELETE_MARKER_MESSAGE ) <EOL> marker_fp . close ( ) <EOL> _scheme_re = re . compile ( r'<STR_LIT>' , re . I ) <EOL> def parse_requirements ( filename , finder = None , comes_from = None , options = None ) : <EOL> skip_match = None <EOL> skip_regex = options . skip_requirements_regex <EOL> if skip_regex : <EOL> skip_match = re . compile ( skip_regex ) <EOL> filename , content = get_file_content ( filename , comes_from = comes_from ) <EOL> for line_number , line in enumerate ( content . splitlines ( ) ) : <EOL> line_number += <NUM_LIT:1> <EOL> line = line . strip ( ) <EOL> if not line or line . startswith ( '<STR_LIT:#>' ) : <EOL> continue <EOL> if skip_match and skip_match . search ( line ) : <EOL> continue <EOL> if line . startswith ( '<STR_LIT>' ) or line . startswith ( '<STR_LIT>' ) : <EOL> if line . startswith ( '<STR_LIT>' ) : <EOL> req_url = line [ <NUM_LIT:2> : ] . strip ( ) <EOL> else : <EOL> req_url = line [ len ( '<STR_LIT>' ) : ] . strip ( ) . strip ( '<STR_LIT:=>' ) <EOL> if _scheme_re . search ( filename ) : <EOL> req_url = urlparse . urljoin ( req_url , filename ) <EOL> elif not _scheme_re . search ( req_url ) : <EOL> req_url = os . path . join ( os . path . dirname ( filename ) , req_url ) <EOL> for item in parse_requirements ( req_url , finder , comes_from = filename , options = options ) : <EOL> yield item <EOL> elif line . startswith ( '<STR_LIT>' ) or line . startswith ( '<STR_LIT>' ) : <EOL> pass <EOL> elif line . startswith ( '<STR_LIT>' ) or line . startswith ( '<STR_LIT>' ) : <EOL> if line . startswith ( '<STR_LIT>' ) : <EOL> line = line [ <NUM_LIT:2> : ] . strip ( ) <EOL> else : <EOL> line = line [ len ( '<STR_LIT>' ) : ] . strip ( ) . lstrip ( '<STR_LIT:=>' ) <EOL> if finder : <EOL> finder . find_links . append ( line ) <EOL> elif line . startswith ( '<STR_LIT>' ) or line . startswith ( '<STR_LIT>' ) : <EOL> if line . startswith ( '<STR_LIT>' ) : <EOL> line = line [ <NUM_LIT:2> : ] . strip ( ) <EOL> else : <EOL> line = line [ len ( '<STR_LIT>' ) : ] . strip ( ) . lstrip ( '<STR_LIT:=>' ) <EOL> if finder : <EOL> finder . index_urls = [ line ] <EOL> elif line . startswith ( '<STR_LIT>' ) : <EOL> line = line [ len ( '<STR_LIT>' ) : ] . strip ( ) . lstrip ( '<STR_LIT:=>' ) <EOL> if finder : <EOL> finder . index_urls . append ( line ) <EOL> else : <EOL> comes_from = '<STR_LIT>' % ( filename , line_number ) <EOL> if line . startswith ( '<STR_LIT>' ) or line . startswith ( '<STR_LIT>' ) : <EOL> if line . startswith ( '<STR_LIT>' ) : <EOL> line = line [ <NUM_LIT:2> : ] . strip ( ) <EOL> else : <EOL> line = line [ len ( '<STR_LIT>' ) : ] . strip ( ) <EOL> req = InstallRequirement . from_editable ( <EOL> line , comes_from = comes_from , default_vcs = options . default_vcs ) <EOL> else : <EOL> req = InstallRequirement . from_line ( line , comes_from ) <EOL> yield req <EOL> def parse_editable ( editable_req , default_vcs = None ) : <EOL> """<STR_LIT>""" <EOL> url = editable_req <EOL> if os . path . isdir ( url ) and os . path . exists ( os . path . join ( url , '<STR_LIT>' ) ) : <EOL> url = path_to_url ( url ) <EOL> if url . lower ( ) . startswith ( '<STR_LIT>' ) : <EOL> return None , url <EOL> for version_control in vcs : <EOL> if url . lower ( ) . startswith ( '<STR_LIT>' % version_control ) : <EOL> url = '<STR_LIT>' % ( version_control , url ) <EOL> if '<STR_LIT:+>' not in url : <EOL> if default_vcs : <EOL> url = default_vcs + '<STR_LIT:+>' + url <EOL> else : <EOL> raise InstallationError ( <EOL> '<STR_LIT>' % editable_req ) <EOL> vc_type = url . split ( '<STR_LIT:+>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] . lower ( ) <EOL> if not vcs . get_backend ( vc_type ) : <EOL> raise InstallationError ( <EOL> '<STR_LIT>' % editable_req ) <EOL> match = re . search ( r'<STR_LIT>' , editable_req ) <EOL> if ( not match or not match . group ( <NUM_LIT:1> ) ) and vcs . get_backend ( vc_type ) : <EOL> parts = [ p for p in editable_req . split ( '<STR_LIT:#>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] . split ( '<STR_LIT:/>' ) if p ] <EOL> if parts [ - <NUM_LIT:2> ] in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> req = parts [ - <NUM_LIT:3> ] <EOL> elif parts [ - <NUM_LIT:1> ] == '<STR_LIT>' : <EOL> req = parts [ - <NUM_LIT:2> ] <EOL> else : <EOL> raise InstallationError ( <EOL> '<STR_LIT>' <EOL> % editable_req ) <EOL> else : <EOL> req = match . group ( <NUM_LIT:1> ) <EOL> match = re . search ( r'<STR_LIT>' , req ) <EOL> if match : <EOL> req = match . group ( <NUM_LIT:1> ) <EOL> return req , url <EOL> class UninstallPathSet ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , dist ) : <EOL> self . paths = set ( ) <EOL> self . _refuse = set ( ) <EOL> self . pth = { } <EOL> self . dist = dist <EOL> self . save_dir = None <EOL> self . _moved_paths = [ ] <EOL> def _permitted ( self , path ) : <EOL> """<STR_LIT>""" <EOL> return is_local ( path ) <EOL> def _can_uninstall ( self ) : <EOL> if not dist_is_local ( self . dist ) : <EOL> logger . notify ( "<STR_LIT>" <EOL> % ( self . dist . project_name , normalize_path ( self . dist . location ) , sys . prefix ) ) <EOL> return False <EOL> return True <EOL> def add ( self , path ) : <EOL> path = normalize_path ( path ) <EOL> if not os . path . exists ( path ) : <EOL> return <EOL> if self . _permitted ( path ) : <EOL> self . paths . add ( path ) <EOL> else : <EOL> self . _refuse . add ( path ) <EOL> def add_pth ( self , pth_file , entry ) : <EOL> pth_file = normalize_path ( pth_file ) <EOL> if self . _permitted ( pth_file ) : <EOL> if pth_file not in self . pth : <EOL> self . pth [ pth_file ] = UninstallPthEntries ( pth_file ) <EOL> self . pth [ pth_file ] . add ( entry ) <EOL> else : <EOL> self . _refuse . add ( pth_file ) <EOL> def compact ( self , paths ) : <EOL> """<STR_LIT>""" <EOL> short_paths = set ( ) <EOL> for path in sorted ( paths , key = len ) : <EOL> if not any ( [ ( path . startswith ( shortpath ) and <EOL> path [ len ( shortpath . rstrip ( os . path . sep ) ) ] == os . path . sep ) <EOL> for shortpath in short_paths ] ) : <EOL> short_paths . add ( path ) <EOL> return short_paths <EOL> def _stash ( self , path ) : <EOL> return os . path . join ( <EOL> self . save_dir , os . path . splitdrive ( path ) [ <NUM_LIT:1> ] . lstrip ( os . path . sep ) ) <EOL> def remove ( self , auto_confirm = False ) : <EOL> """<STR_LIT>""" <EOL> if not self . _can_uninstall ( ) : <EOL> return <EOL> logger . notify ( '<STR_LIT>' % self . dist . project_name ) <EOL> logger . indent += <NUM_LIT:2> <EOL> paths = sorted ( self . compact ( self . paths ) ) <EOL> try : <EOL> if auto_confirm : <EOL> response = '<STR_LIT:y>' <EOL> else : <EOL> for path in paths : <EOL> logger . notify ( path ) <EOL> response = ask ( '<STR_LIT>' , ( '<STR_LIT:y>' , '<STR_LIT:n>' ) ) <EOL> if self . _refuse : <EOL> logger . notify ( '<STR_LIT>' ) <EOL> for path in self . compact ( self . _refuse ) : <EOL> logger . notify ( path ) <EOL> if response == '<STR_LIT:y>' : <EOL> self . save_dir = tempfile . mkdtemp ( suffix = '<STR_LIT>' , <EOL> prefix = '<STR_LIT>' ) <EOL> for path in paths : <EOL> new_path = self . _stash ( path ) <EOL> logger . info ( '<STR_LIT>' % path ) <EOL> self . _moved_paths . append ( path ) <EOL> renames ( path , new_path ) <EOL> for pth in self . pth . values ( ) : <EOL> pth . remove ( ) <EOL> logger . notify ( '<STR_LIT>' % self . dist . project_name ) <EOL> finally : <EOL> logger . indent -= <NUM_LIT:2> <EOL> def rollback ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . save_dir is None : <EOL> logger . error ( "<STR_LIT>" % self . dist . project_name ) <EOL> return False <EOL> logger . notify ( '<STR_LIT>' % self . dist . project_name ) <EOL> for path in self . _moved_paths : <EOL> tmp_path = self . _stash ( path ) <EOL> logger . info ( '<STR_LIT>' % path ) <EOL> renames ( tmp_path , path ) <EOL> for pth in self . pth : <EOL> pth . rollback ( ) <EOL> def commit ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . save_dir is not None : <EOL> rmtree ( self . save_dir ) <EOL> self . save_dir = None <EOL> self . _moved_paths = [ ] <EOL> class UninstallPthEntries ( object ) : <EOL> def __init__ ( self , pth_file ) : <EOL> if not os . path . isfile ( pth_file ) : <EOL> raise UninstallationError ( "<STR_LIT>" % pth_file ) <EOL> self . file = pth_file <EOL> self . entries = set ( ) <EOL> self . _saved_lines = None <EOL> def add ( self , entry ) : <EOL> entry = os . path . normcase ( entry ) <EOL> if sys . platform == '<STR_LIT:win32>' and not os . path . splitdrive ( entry ) [ <NUM_LIT:0> ] : <EOL> entry = entry . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) <EOL> self . entries . add ( entry ) <EOL> def remove ( self ) : <EOL> logger . info ( '<STR_LIT>' % self . file ) <EOL> fh = open ( self . file , '<STR_LIT:rb>' ) <EOL> lines = fh . readlines ( ) <EOL> self . _saved_lines = lines <EOL> fh . close ( ) <EOL> if any ( b ( '<STR_LIT:\r\n>' ) in line for line in lines ) : <EOL> endline = '<STR_LIT:\r\n>' <EOL> else : <EOL> endline = '<STR_LIT:\n>' <EOL> for entry in self . entries : <EOL> try : <EOL> logger . info ( '<STR_LIT>' % entry ) <EOL> lines . remove ( b ( entry + endline ) ) <EOL> except ValueError : <EOL> pass <EOL> fh = open ( self . file , '<STR_LIT:wb>' ) <EOL> fh . writelines ( lines ) <EOL> fh . close ( ) <EOL> def rollback ( self ) : <EOL> if self . _saved_lines is None : <EOL> logger . error ( '<STR_LIT>' % self . file ) <EOL> return False <EOL> logger . info ( '<STR_LIT>' % self . file ) <EOL> fh = open ( self . file , '<STR_LIT:wb>' ) <EOL> fh . writelines ( self . _saved_lines ) <EOL> fh . close ( ) <EOL> return True <EOL> class FakeFile ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , lines ) : <EOL> self . _gen = ( l for l in lines ) <EOL> def readline ( self ) : <EOL> try : <EOL> try : <EOL> return next ( self . _gen ) <EOL> except NameError : <EOL> return self . _gen . next ( ) <EOL> except StopIteration : <EOL> return '<STR_LIT>' <EOL> def __iter__ ( self ) : <EOL> return self . _gen </s>
