<s> from __future__ import absolute_import <EOL> import logging <EOL> import os <EOL> import re <EOL> import shutil <EOL> import sys <EOL> import tempfile <EOL> import warnings <EOL> import zipfile <EOL> from distutils . util import change_root <EOL> from distutils import sysconfig <EOL> from email . parser import FeedParser <EOL> from pip . _vendor import pkg_resources , six <EOL> from pip . _vendor . distlib . markers import interpret as markers_interpret <EOL> from pip . _vendor . six . moves import configparser <EOL> import pip . wheel <EOL> from pip . compat import native_str , WINDOWS <EOL> from pip . download import is_url , url_to_path , path_to_url , is_archive_file <EOL> from pip . exceptions import ( <EOL> InstallationError , UninstallationError , UnsupportedWheel , <EOL> ) <EOL> from pip . locations import ( <EOL> bin_py , running_under_virtualenv , PIP_DELETE_MARKER_FILENAME , bin_user , <EOL> ) <EOL> from pip . utils import ( <EOL> display_path , rmtree , ask_path_exists , backup_dir , is_installable_dir , <EOL> dist_in_usersite , dist_in_site_packages , egg_link_path , make_path_relative , <EOL> call_subprocess , read_text_file , FakeFile , _make_build_dir , ensure_dir , <EOL> ) <EOL> from pip . utils . deprecation import RemovedInPip8Warning <EOL> from pip . utils . logging import indent_log <EOL> from pip . req . req_uninstall import UninstallPathSet <EOL> from pip . vcs import vcs <EOL> from pip . wheel import move_wheel_files , Wheel <EOL> from pip . _vendor . packaging . version import Version <EOL> logger = logging . getLogger ( __name__ ) <EOL> def _strip_extras ( path ) : <EOL> m = re . match ( r'<STR_LIT>' , path ) <EOL> extras = None <EOL> if m : <EOL> path_no_extras = m . group ( <NUM_LIT:1> ) <EOL> extras = m . group ( <NUM_LIT:2> ) <EOL> else : <EOL> path_no_extras = path <EOL> return path_no_extras , extras <EOL> class InstallRequirement ( object ) : <EOL> def __init__ ( self , req , comes_from , source_dir = None , editable = False , <EOL> link = None , as_egg = False , update = True , editable_options = None , <EOL> pycompile = True , markers = None , isolated = False , options = None , <EOL> wheel_cache = None ) : <EOL> self . extras = ( ) <EOL> if isinstance ( req , six . string_types ) : <EOL> req = pkg_resources . Requirement . parse ( req ) <EOL> self . extras = req . extras <EOL> self . req = req <EOL> self . comes_from = comes_from <EOL> self . source_dir = source_dir <EOL> self . editable = editable <EOL> if editable_options is None : <EOL> editable_options = { } <EOL> self . editable_options = editable_options <EOL> self . _wheel_cache = wheel_cache <EOL> self . link = link <EOL> self . as_egg = as_egg <EOL> self . markers = markers <EOL> self . _egg_info_path = None <EOL> self . satisfied_by = None <EOL> self . conflicts_with = None <EOL> self . _temp_build_dir = None <EOL> self . _ideal_global_dir = None <EOL> self . update = update <EOL> self . install_succeeded = None <EOL> self . uninstalled = None <EOL> self . use_user_site = False <EOL> self . target_dir = None <EOL> self . options = options if options else { } <EOL> self . pycompile = pycompile <EOL> self . isolated = isolated <EOL> @ classmethod <EOL> def from_editable ( cls , editable_req , comes_from = None , default_vcs = None , <EOL> isolated = False , options = None , wheel_cache = None ) : <EOL> from pip . index import Link <EOL> name , url , extras_override , editable_options = parse_editable ( <EOL> editable_req , default_vcs ) <EOL> if url . startswith ( '<STR_LIT>' ) : <EOL> source_dir = url_to_path ( url ) <EOL> else : <EOL> source_dir = None <EOL> res = cls ( name , comes_from , source_dir = source_dir , <EOL> editable = True , <EOL> link = Link ( url ) , <EOL> editable_options = editable_options , <EOL> isolated = isolated , <EOL> options = options if options else { } , <EOL> wheel_cache = wheel_cache ) <EOL> if extras_override is not None : <EOL> res . extras = extras_override <EOL> return res <EOL> @ classmethod <EOL> def from_line ( <EOL> cls , name , comes_from = None , isolated = False , options = None , <EOL> wheel_cache = None ) : <EOL> """<STR_LIT>""" <EOL> from pip . index import Link <EOL> if is_url ( name ) : <EOL> marker_sep = '<STR_LIT>' <EOL> else : <EOL> marker_sep = '<STR_LIT:;>' <EOL> if marker_sep in name : <EOL> name , markers = name . split ( marker_sep , <NUM_LIT:1> ) <EOL> markers = markers . strip ( ) <EOL> if not markers : <EOL> markers = None <EOL> else : <EOL> markers = None <EOL> name = name . strip ( ) <EOL> req = None <EOL> path = os . path . normpath ( os . path . abspath ( name ) ) <EOL> link = None <EOL> extras = None <EOL> if is_url ( name ) : <EOL> link = Link ( name ) <EOL> else : <EOL> p , extras = _strip_extras ( path ) <EOL> if ( os . path . isdir ( p ) and <EOL> ( os . path . sep in name or name . startswith ( '<STR_LIT:.>' ) ) ) : <EOL> if not is_installable_dir ( p ) : <EOL> raise InstallationError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % name <EOL> ) <EOL> link = Link ( path_to_url ( p ) ) <EOL> elif is_archive_file ( p ) : <EOL> if not os . path . isfile ( p ) : <EOL> logger . warning ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> name <EOL> ) <EOL> link = Link ( path_to_url ( p ) ) <EOL> if link : <EOL> if link . scheme == '<STR_LIT:file>' and re . search ( r'<STR_LIT>' , link . url ) : <EOL> link = Link ( <EOL> path_to_url ( os . path . normpath ( os . path . abspath ( link . path ) ) ) ) <EOL> if link . is_wheel : <EOL> wheel = Wheel ( link . filename ) <EOL> if not wheel . supported ( ) : <EOL> raise UnsupportedWheel ( <EOL> "<STR_LIT>" % <EOL> wheel . filename <EOL> ) <EOL> req = "<STR_LIT>" % ( wheel . name , wheel . version ) <EOL> else : <EOL> req = link . egg_fragment <EOL> else : <EOL> req = name <EOL> options = options if options else { } <EOL> res = cls ( req , comes_from , link = link , markers = markers , <EOL> isolated = isolated , options = options , <EOL> wheel_cache = wheel_cache ) <EOL> if extras : <EOL> res . extras = pkg_resources . Requirement . parse ( '<STR_LIT>' + <EOL> extras ) . extras <EOL> return res <EOL> def __str__ ( self ) : <EOL> if self . req : <EOL> s = str ( self . req ) <EOL> if self . link : <EOL> s += '<STR_LIT>' % self . link . url <EOL> else : <EOL> s = self . link . url if self . link else None <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 , six . 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 __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( <EOL> self . __class__ . __name__ , str ( self ) , self . editable ) <EOL> def populate_link ( self , finder , upgrade ) : <EOL> """<STR_LIT>""" <EOL> if self . link is None : <EOL> self . link = finder . find_requirement ( self , upgrade ) <EOL> @ property <EOL> def link ( self ) : <EOL> return self . _link <EOL> @ link . setter <EOL> def link ( self , link ) : <EOL> if self . _wheel_cache is None : <EOL> self . _link = link <EOL> else : <EOL> self . _link = self . _wheel_cache . cached_wheel ( link , self . name ) <EOL> @ property <EOL> def specifier ( self ) : <EOL> return self . req . specifier <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 , six . 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 ) : <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> logger . debug ( '<STR_LIT>' , 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> assert self . _ideal_build_dir <EOL> old_location = self . _temp_build_dir <EOL> self . _temp_build_dir = None <EOL> new_location = self . build_location ( self . _ideal_build_dir ) <EOL> if os . path . exists ( new_location ) : <EOL> raise InstallationError ( <EOL> '<STR_LIT>' <EOL> % display_path ( new_location ) ) <EOL> logger . debug ( <EOL> '<STR_LIT>' , <EOL> self , display_path ( old_location ) , display_path ( new_location ) , <EOL> ) <EOL> shutil . move ( old_location , new_location ) <EOL> self . _temp_build_dir = new_location <EOL> self . _ideal_build_dir = None <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 native_str ( self . req . project_name ) <EOL> @ property <EOL> def setup_py ( self ) : <EOL> assert self . source_dir , "<STR_LIT>" % self <EOL> try : <EOL> import setuptools <EOL> except ImportError : <EOL> raise InstallationError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> setup_file = '<STR_LIT>' <EOL> if self . editable_options and '<STR_LIT>' in self . editable_options : <EOL> setup_py = os . path . join ( self . source_dir , <EOL> self . editable_options [ '<STR_LIT>' ] , <EOL> setup_file ) <EOL> else : <EOL> setup_py = os . path . join ( self . source_dir , setup_file ) <EOL> if six . PY2 and isinstance ( setup_py , six . text_type ) : <EOL> setup_py = setup_py . encode ( sys . getfilesystemencoding ( ) ) <EOL> return setup_py <EOL> def run_egg_info ( self ) : <EOL> assert self . source_dir <EOL> if self . name : <EOL> logger . debug ( <EOL> '<STR_LIT>' , <EOL> self . setup_py , self . name , <EOL> ) <EOL> else : <EOL> logger . debug ( <EOL> '<STR_LIT>' , <EOL> self . setup_py , self . link , <EOL> ) <EOL> with indent_log ( ) : <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> base_cmd = [ sys . executable , '<STR_LIT:-c>' , script ] <EOL> if self . isolated : <EOL> base_cmd += [ "<STR_LIT>" ] <EOL> egg_info_cmd = base_cmd + [ '<STR_LIT>' ] <EOL> if self . editable : <EOL> egg_base_option = [ ] <EOL> else : <EOL> egg_info_dir = os . path . join ( self . source_dir , '<STR_LIT>' ) <EOL> ensure_dir ( egg_info_dir ) <EOL> egg_base_option = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> cwd = self . source_dir <EOL> if self . editable_options and '<STR_LIT>' in self . editable_options : <EOL> cwd = os . path . join ( cwd , self . editable_options [ '<STR_LIT>' ] ) <EOL> call_subprocess ( <EOL> egg_info_cmd + egg_base_option , <EOL> cwd = cwd , <EOL> show_stdout = False , <EOL> command_level = logging . DEBUG , <EOL> command_desc = '<STR_LIT>' ) <EOL> if not self . req : <EOL> if isinstance ( <EOL> pkg_resources . parse_version ( self . pkg_info ( ) [ "<STR_LIT>" ] ) , <EOL> Version ) : <EOL> op = "<STR_LIT>" <EOL> else : <EOL> op = "<STR_LIT>" <EOL> self . req = pkg_resources . Requirement . parse ( <EOL> "<STR_LIT>" . join ( [ <EOL> self . pkg_info ( ) [ "<STR_LIT:Name>" ] , <EOL> op , <EOL> self . pkg_info ( ) [ "<STR_LIT>" ] , <EOL> ] ) ) <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> data = read_text_file ( filename ) <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 list ( dirs ) : <EOL> if ( <EOL> os . path . exists ( <EOL> os . path . join ( root , dir , '<STR_LIT>' , '<STR_LIT>' ) <EOL> ) or <EOL> os . path . exists ( <EOL> os . path . join ( <EOL> root , dir , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> ) ) : <EOL> dirs . remove ( dir ) <EOL> elif 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 ( <EOL> '<STR_LIT>' % ( base , filename ) <EOL> ) <EOL> assert filenames , "<STR_LIT>" % ( base , filename ) <EOL> if len ( filenames ) > <NUM_LIT:1> : <EOL> filenames . sort ( <EOL> key = lambda x : x . count ( os . path . sep ) + <EOL> ( os . path . altsep and x . count ( os . path . altsep ) or <NUM_LIT:0> ) <EOL> ) <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 pkg_info ( self ) : <EOL> p = FeedParser ( ) <EOL> data = self . egg_info_data ( '<STR_LIT>' ) <EOL> if not data : <EOL> logger . warning ( <EOL> '<STR_LIT>' , <EOL> display_path ( self . egg_info_path ( '<STR_LIT>' ) ) , <EOL> ) <EOL> p . feed ( data or '<STR_LIT>' ) <EOL> return p . close ( ) <EOL> _requirements_section_re = re . compile ( r'<STR_LIT>' ) <EOL> @ property <EOL> def installed_version ( self ) : <EOL> req = pkg_resources . Requirement . parse ( self . name ) <EOL> working_set = pkg_resources . WorkingSet ( ) <EOL> dist = working_set . find ( req ) <EOL> if dist : <EOL> return dist . version <EOL> def assert_source_matches_version ( self ) : <EOL> assert self . source_dir <EOL> version = self . pkg_info ( ) [ '<STR_LIT:version>' ] <EOL> if version not in self . req : <EOL> logger . warning ( <EOL> '<STR_LIT>' , <EOL> self , <EOL> self . installed_version , <EOL> ) <EOL> else : <EOL> logger . debug ( <EOL> '<STR_LIT>' , <EOL> display_path ( self . source_dir ) , <EOL> version , <EOL> self , <EOL> ) <EOL> def update_editable ( self , obtain = True ) : <EOL> if not self . link : <EOL> logger . debug ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> self . source_dir , <EOL> ) <EOL> return <EOL> assert self . editable <EOL> assert self . source_dir <EOL> if self . link . scheme == '<STR_LIT:file>' : <EOL> return <EOL> assert '<STR_LIT:+>' in self . link . url , "<STR_LIT>" % self . link . url <EOL> if not self . update : <EOL> return <EOL> vc_type , url = self . link . url . split ( '<STR_LIT:+>' , <NUM_LIT:1> ) <EOL> backend = vcs . get_backend ( vc_type ) <EOL> if backend : <EOL> vcs_backend = backend ( self . link . 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 . link , vc_type ) ) <EOL> def uninstall ( self , auto_confirm = False ) : <EOL> """<STR_LIT>""" <EOL> if not self . check_if_exists ( ) : <EOL> raise UninstallationError ( <EOL> "<STR_LIT>" % ( self . name , ) <EOL> ) <EOL> dist = self . satisfied_by or self . conflicts_with <EOL> paths_to_remove = UninstallPathSet ( dist ) <EOL> develop_egg_link = egg_link_path ( dist ) <EOL> develop_egg_link_egg_info = '<STR_LIT>' . format ( <EOL> pkg_resources . to_filename ( dist . project_name ) ) <EOL> egg_info_exists = dist . egg_info and os . path . exists ( dist . egg_info ) <EOL> distutils_egg_info = getattr ( dist . _provider , '<STR_LIT:path>' , None ) <EOL> if ( egg_info_exists and dist . egg_info . endswith ( '<STR_LIT>' ) and <EOL> not dist . egg_info . endswith ( develop_egg_link_egg_info ) ) : <EOL> paths_to_remove . add ( dist . egg_info ) <EOL> if dist . has_metadata ( '<STR_LIT>' ) : <EOL> for installed_file in dist . get_metadata ( <EOL> '<STR_LIT>' ) . splitlines ( ) : <EOL> path = os . path . normpath ( <EOL> os . path . join ( dist . egg_info , installed_file ) <EOL> ) <EOL> paths_to_remove . add ( path ) <EOL> elif 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 [ <EOL> 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 distutils_egg_info : <EOL> warnings . warn ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" . format ( self . name ) , <EOL> RemovedInPip8Warning , <EOL> ) <EOL> paths_to_remove . add ( distutils_egg_info ) <EOL> elif dist . location . endswith ( '<STR_LIT>' ) : <EOL> paths_to_remove . add ( dist . location ) <EOL> easy_install_egg = os . path . split ( dist . location ) [ <NUM_LIT:1> ] <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 develop_egg_link : <EOL> with open ( develop_egg_link , '<STR_LIT:r>' ) as fh : <EOL> link_pointer = os . path . normcase ( fh . readline ( ) . strip ( ) ) <EOL> assert ( link_pointer == dist . location ) , ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( link_pointer , self . name , dist . location ) <EOL> ) <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> elif egg_info_exists and dist . egg_info . endswith ( '<STR_LIT>' ) : <EOL> for path in pip . wheel . uninstallation_paths ( dist ) : <EOL> paths_to_remove . add ( path ) <EOL> else : <EOL> logger . debug ( <EOL> '<STR_LIT>' , <EOL> dist , 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> if dist_in_usersite ( dist ) : <EOL> bin_dir = bin_user <EOL> else : <EOL> bin_dir = bin_py <EOL> paths_to_remove . add ( os . path . join ( bin_dir , script ) ) <EOL> if WINDOWS : <EOL> paths_to_remove . add ( os . path . join ( bin_dir , script ) + '<STR_LIT>' ) <EOL> if dist . has_metadata ( '<STR_LIT>' ) : <EOL> config = configparser . SafeConfigParser ( ) <EOL> config . readfp ( <EOL> FakeFile ( dist . get_metadata_lines ( '<STR_LIT>' ) ) <EOL> ) <EOL> if config . has_section ( '<STR_LIT>' ) : <EOL> for name , value in config . items ( '<STR_LIT>' ) : <EOL> if dist_in_usersite ( dist ) : <EOL> bin_dir = bin_user <EOL> else : <EOL> bin_dir = bin_py <EOL> paths_to_remove . add ( os . path . join ( bin_dir , name ) ) <EOL> if WINDOWS : <EOL> paths_to_remove . add ( <EOL> os . path . join ( bin_dir , name ) + '<STR_LIT>' <EOL> ) <EOL> paths_to_remove . add ( <EOL> os . path . join ( bin_dir , name ) + '<STR_LIT>' <EOL> ) <EOL> paths_to_remove . add ( <EOL> os . path . join ( bin_dir , name ) + '<STR_LIT>' <EOL> ) <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 ( <EOL> "<STR_LIT>" , self . project_name , <EOL> ) <EOL> def commit_uninstall ( self ) : <EOL> if self . uninstalled : <EOL> self . uninstalled . commit ( ) <EOL> else : <EOL> logger . error ( <EOL> "<STR_LIT>" , self . project_name , <EOL> ) <EOL> def archive ( self , build_dir ) : <EOL> assert self . source_dir <EOL> create_archive = True <EOL> archive_name = '<STR_LIT>' % ( self . name , self . pkg_info ( ) [ "<STR_LIT:version>" ] ) <EOL> archive_path = os . path . join ( build_dir , archive_name ) <EOL> if os . path . exists ( archive_path ) : <EOL> response = ask_path_exists ( <EOL> '<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 . warning ( '<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 . warning ( <EOL> '<STR_LIT>' , <EOL> display_path ( archive_path ) , <EOL> display_path ( dest_file ) , <EOL> ) <EOL> shutil . move ( archive_path , dest_file ) <EOL> if create_archive : <EOL> zip = zipfile . ZipFile ( <EOL> archive_path , '<STR_LIT:w>' , zipfile . ZIP_DEFLATED , <EOL> allowZip64 = True <EOL> ) <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 . info ( '<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> ) <EOL> name = name [ len ( prefix ) + <NUM_LIT:1> : ] <EOL> name = name . replace ( os . path . sep , '<STR_LIT:/>' ) <EOL> return name <EOL> def match_markers ( self ) : <EOL> if self . markers is not None : <EOL> return markers_interpret ( self . markers ) <EOL> else : <EOL> return True <EOL> def install ( self , install_options , global_options = [ ] , root = None ) : <EOL> if self . editable : <EOL> self . install_editable ( install_options , global_options ) <EOL> return <EOL> if self . is_wheel : <EOL> version = pip . wheel . wheel_version ( self . source_dir ) <EOL> pip . wheel . check_compatibility ( version , self . name ) <EOL> self . move_wheel_files ( self . source_dir , root = root ) <EOL> self . install_succeeded = True <EOL> return <EOL> global_options += self . options . get ( '<STR_LIT>' , [ ] ) <EOL> install_options += self . options . get ( '<STR_LIT>' , [ ] ) <EOL> if self . isolated : <EOL> global_options = list ( global_options ) + [ "<STR_LIT>" ] <EOL> temp_location = tempfile . mkdtemp ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> record_filename = os . path . join ( temp_location , '<STR_LIT>' ) <EOL> try : <EOL> install_args = [ sys . executable ] <EOL> install_args . append ( '<STR_LIT:-c>' ) <EOL> install_args . append ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % self . setup_py <EOL> ) <EOL> install_args += list ( global_options ) + [ '<STR_LIT>' , '<STR_LIT>' , record_filename ] <EOL> if not self . as_egg : <EOL> install_args += [ '<STR_LIT>' ] <EOL> if root is not None : <EOL> install_args += [ '<STR_LIT>' , root ] <EOL> if self . pycompile : <EOL> install_args += [ "<STR_LIT>" ] <EOL> else : <EOL> install_args += [ "<STR_LIT>" ] <EOL> if running_under_virtualenv ( ) : <EOL> py_ver_str = '<STR_LIT>' + sysconfig . get_python_version ( ) <EOL> install_args += [ '<STR_LIT>' , <EOL> os . path . join ( sys . prefix , '<STR_LIT>' , '<STR_LIT>' , <EOL> py_ver_str , self . name ) ] <EOL> logger . info ( '<STR_LIT>' , self . name ) <EOL> with indent_log ( ) : <EOL> call_subprocess ( <EOL> install_args + install_options , <EOL> cwd = self . source_dir , <EOL> show_stdout = False , <EOL> ) <EOL> if not os . path . exists ( record_filename ) : <EOL> logger . debug ( '<STR_LIT>' , record_filename ) <EOL> return <EOL> self . install_succeeded = True <EOL> if self . as_egg : <EOL> return <EOL> def prepend_root ( path ) : <EOL> if root is None or not os . path . isabs ( path ) : <EOL> return path <EOL> else : <EOL> return change_root ( root , path ) <EOL> with open ( record_filename ) as f : <EOL> for line in f : <EOL> directory = os . path . dirname ( line ) <EOL> if directory . endswith ( '<STR_LIT>' ) : <EOL> egg_info_dir = prepend_root ( directory ) <EOL> break <EOL> else : <EOL> logger . warning ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> self , <EOL> ) <EOL> return <EOL> new_lines = [ ] <EOL> with open ( record_filename ) as f : <EOL> for line in f : <EOL> filename = line . strip ( ) <EOL> if os . path . isdir ( filename ) : <EOL> filename += os . path . sep <EOL> new_lines . append ( <EOL> make_path_relative ( <EOL> prepend_root ( filename ) , egg_info_dir ) <EOL> ) <EOL> inst_files_path = os . path . join ( egg_info_dir , '<STR_LIT>' ) <EOL> with open ( inst_files_path , '<STR_LIT:w>' ) as f : <EOL> f . write ( '<STR_LIT:\n>' . join ( new_lines ) + '<STR_LIT:\n>' ) <EOL> finally : <EOL> if os . path . exists ( record_filename ) : <EOL> os . remove ( record_filename ) <EOL> rmtree ( temp_location ) <EOL> def ensure_has_source_dir ( self , parent_dir ) : <EOL> """<STR_LIT>""" <EOL> if self . source_dir is None : <EOL> self . source_dir = self . build_location ( parent_dir ) <EOL> return self . source_dir <EOL> def remove_temporary_source ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . source_dir and os . path . exists ( <EOL> os . path . join ( self . source_dir , PIP_DELETE_MARKER_FILENAME ) ) : <EOL> logger . debug ( '<STR_LIT>' , 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 . info ( '<STR_LIT>' , self . name ) <EOL> if self . isolated : <EOL> global_options = list ( global_options ) + [ "<STR_LIT>" ] <EOL> with indent_log ( ) : <EOL> cwd = self . source_dir <EOL> if self . editable_options and '<STR_LIT>' in self . editable_options : <EOL> cwd = os . path . join ( cwd , self . editable_options [ '<STR_LIT>' ] ) <EOL> call_subprocess ( <EOL> [ <EOL> sys . executable , <EOL> '<STR_LIT:-c>' , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % self . setup_py <EOL> ] + <EOL> list ( global_options ) + <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] + <EOL> list ( install_options ) , <EOL> cwd = cwd , <EOL> show_stdout = False ) <EOL> self . install_succeeded = True <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> existing_dist = pkg_resources . get_distribution ( <EOL> self . req . project_name <EOL> ) <EOL> if self . use_user_site : <EOL> if dist_in_usersite ( existing_dist ) : <EOL> self . conflicts_with = existing_dist <EOL> elif ( running_under_virtualenv ( ) and <EOL> dist_in_site_packages ( existing_dist ) ) : <EOL> raise InstallationError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( existing_dist . project_name , existing_dist . location ) <EOL> ) <EOL> else : <EOL> self . conflicts_with = existing_dist <EOL> return True <EOL> @ property <EOL> def is_wheel ( self ) : <EOL> return self . link and self . link . is_wheel <EOL> def move_wheel_files ( self , wheeldir , root = None ) : <EOL> move_wheel_files ( <EOL> self . name , self . req , wheeldir , <EOL> user = self . use_user_site , <EOL> home = self . target_dir , <EOL> root = root , <EOL> pycompile = self . pycompile , <EOL> isolated = self . isolated , <EOL> ) <EOL> def get_dist ( self ) : <EOL> """<STR_LIT>""" <EOL> egg_info = self . egg_info_path ( '<STR_LIT>' ) . rstrip ( '<STR_LIT:/>' ) <EOL> base_dir = os . path . dirname ( egg_info ) <EOL> metadata = pkg_resources . PathMetadata ( base_dir , egg_info ) <EOL> dist_name = os . path . splitext ( os . path . basename ( egg_info ) ) [ <NUM_LIT:0> ] <EOL> return pkg_resources . Distribution ( <EOL> os . path . dirname ( egg_info ) , <EOL> project_name = dist_name , <EOL> metadata = metadata ) <EOL> def _strip_postfix ( req ) : <EOL> """<STR_LIT>""" <EOL> match = re . search ( r'<STR_LIT>' , req ) <EOL> if match : <EOL> req = match . group ( <NUM_LIT:1> ) <EOL> return req <EOL> def _build_req_from_url ( url ) : <EOL> parts = [ p for p in url . split ( '<STR_LIT:#>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] . split ( '<STR_LIT:/>' ) if p ] <EOL> req = None <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> return req <EOL> def _build_editable_options ( req ) : <EOL> """<STR_LIT>""" <EOL> regexp = re . compile ( r"<STR_LIT>" ) <EOL> matched = regexp . findall ( req ) <EOL> if matched : <EOL> ret = dict ( ) <EOL> for option in matched : <EOL> ( name , value ) = option <EOL> if name in ret : <EOL> raise Exception ( "<STR_LIT>" % name ) <EOL> ret [ name ] = value <EOL> return ret <EOL> return None <EOL> def parse_editable ( editable_req , default_vcs = None ) : <EOL> """<STR_LIT>""" <EOL> url = editable_req <EOL> extras = None <EOL> m = re . match ( r'<STR_LIT>' , url ) <EOL> if m : <EOL> url_no_extras = m . group ( <NUM_LIT:1> ) <EOL> extras = m . group ( <NUM_LIT:2> ) <EOL> else : <EOL> url_no_extras = url <EOL> if os . path . isdir ( url_no_extras ) : <EOL> if not os . path . exists ( os . path . join ( url_no_extras , '<STR_LIT>' ) ) : <EOL> raise InstallationError ( <EOL> "<STR_LIT>" % <EOL> url_no_extras <EOL> ) <EOL> url_no_extras = path_to_url ( url_no_extras ) <EOL> if url_no_extras . lower ( ) . startswith ( '<STR_LIT>' ) : <EOL> if extras : <EOL> return ( <EOL> None , <EOL> url_no_extras , <EOL> pkg_resources . Requirement . parse ( <EOL> '<STR_LIT>' + extras <EOL> ) . extras , <EOL> { } , <EOL> ) <EOL> else : <EOL> return None , url_no_extras , None , { } <EOL> for version_control in vcs : <EOL> if url . lower ( ) . startswith ( '<STR_LIT>' % version_control ) : <EOL> url = '<STR_LIT>' % ( version_control , url ) <EOL> break <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>' <EOL> '<STR_LIT>' % <EOL> editable_req <EOL> ) <EOL> vc_type = url . split ( '<STR_LIT:+>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] . lower ( ) <EOL> if not vcs . get_backend ( vc_type ) : <EOL> error_message = '<STR_LIT>' % editable_req + '<STR_LIT:U+002CU+0020>' . join ( [ backend . name + '<STR_LIT>' for backend in vcs . backends ] ) + '<STR_LIT>' <EOL> raise InstallationError ( error_message ) <EOL> try : <EOL> options = _build_editable_options ( editable_req ) <EOL> except Exception as exc : <EOL> raise InstallationError ( <EOL> '<STR_LIT>' % ( editable_req , exc ) <EOL> ) <EOL> if not options or '<STR_LIT>' not in options : <EOL> req = _build_req_from_url ( editable_req ) <EOL> if not req : <EOL> raise InstallationError ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % editable_req <EOL> ) <EOL> else : <EOL> req = options [ '<STR_LIT>' ] <EOL> package = _strip_postfix ( req ) <EOL> return package , url , None , options </s>
