#NEWLINE# def install( self , paths , maker , **kwargs ) : #NEWLINE# #INDENT# '\n        Install a wheel to the specified paths. If kwarg ``warner`` is\n        specified, it should be a callable, which will be called with two\n        tuples indicating the wheel version of this software and the wheel\n        version in the file, if there is a discrepancy in the versions.\n        This can be used to issue any warnings to raise any exceptions.\n        If kwarg ``lib_only`` is True, only the purelib/platlib files are\n        installed, and the headers, scripts, data and dist-info metadata are\n        not written.\n\n        The return value is a :class:`InstalledDistribution` instance unless\n        ``options.lib_only`` is True, in which case the return value is ``None``.\n        ' #NEWLINE# dry_run = maker . dry_run #NEWLINE# warner = kwargs . get ( 'warner' ) #NEWLINE# lib_only = kwargs . get ( 'lib_only' , False ) #NEWLINE# pathname = os . path . join ( self . dirname , self . filename ) #NEWLINE# name_ver = ( '%s-%s' % ( self . name , self . version ) ) #NEWLINE# data_dir = ( '%s.data' % name_ver ) #NEWLINE# info_dir = ( '%s.dist-info' % name_ver ) #NEWLINE# metadata_name = posixpath . join ( info_dir , METADATA_FILENAME ) #NEWLINE# wheel_metadata_name = posixpath . join ( info_dir , 'WHEEL' ) #NEWLINE# record_name = posixpath . join ( info_dir , 'RECORD' ) #NEWLINE# wrapper = codecs . getreader ( 'utf-8' ) #NEWLINE# with ZipFile ( pathname , 'r' ) as zf : #NEWLINE# #INDENT# with zf . open ( wheel_metadata_name ) as bwf : #NEWLINE# #INDENT# wf = wrapper ( bwf ) #NEWLINE# message = message_from_file ( wf ) #NEWLINE# #UNINDENT# wv = message [ 'Wheel-Version' ] . split ( '.' , 1 ) #NEWLINE# file_version = tuple ( [ int ( i ) for i in wv ] ) #NEWLINE# if ( ( file_version != self . wheel_version ) and warner ) : #NEWLINE# #INDENT# warner ( self . wheel_version , file_version ) #NEWLINE# #UNINDENT# if ( message [ 'Root-Is-Purelib' ] == 'true' ) : #NEWLINE# #INDENT# libdir = paths [ 'purelib' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# libdir = paths [ 'platlib' ] #NEWLINE# #UNINDENT# records = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# with zf . open ( record_name ) as bf : #NEWLINE# #INDENT# with CSVReader ( stream = bf ) as reader : #NEWLINE# #INDENT# for row in reader : #NEWLINE# #INDENT# p = row [ 0 ] #NEWLINE# records [ p ] = row #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# data_pfx = posixpath . join ( data_dir , '' ) #NEWLINE# info_pfx = posixpath . join ( info_dir , '' ) #NEWLINE# script_pfx = posixpath . join ( data_dir , 'scripts' , '' ) #NEWLINE# fileop = FileOperator ( dry_run = dry_run ) #NEWLINE# fileop . record = True #NEWLINE# bc = ( not sys . dont_write_bytecode ) #NEWLINE# outfiles = [ ] #NEWLINE# workdir = tempfile . mkdtemp ( ) #NEWLINE# maker . source_dir = workdir #NEWLINE# maker . target_dir = None #NEWLINE# try : #NEWLINE# #INDENT# for zinfo in zf . infolist ( ) : #NEWLINE# #INDENT# arcname = zinfo . filename #NEWLINE# if isinstance ( arcname , text_type ) : #NEWLINE# #INDENT# u_arcname = arcname #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# u_arcname = arcname . decode ( 'utf-8' ) #NEWLINE# #UNINDENT# if u_arcname . endswith ( '/RECORD.jws' ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# row = records [ u_arcname ] #NEWLINE# if ( row [ 2 ] and ( str ( zinfo . file_size ) != row [ 2 ] ) ) : #NEWLINE# #INDENT# raise DistlibException ( ( 'size mismatch for %s' % u_arcname ) ) #NEWLINE# #UNINDENT# if row [ 1 ] : #NEWLINE# #INDENT# ( kind , value ) = row [ 1 ] . split ( '=' , 1 ) #NEWLINE# with zf . open ( arcname ) as bf : #NEWLINE# #INDENT# data = bf . read ( ) #NEWLINE# #UNINDENT# ( _ , digest ) = self . get_hash ( data , kind ) #NEWLINE# if ( digest != value ) : #NEWLINE# #INDENT# raise DistlibException ( ( 'digest mismatch for %s' % arcname ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( lib_only and u_arcname . startswith ( ( info_pfx , data_pfx ) ) ) : #NEWLINE# #INDENT# logger . debug ( 'lib_only: skipping %s' , u_arcname ) #NEWLINE# continue #NEWLINE# #UNINDENT# is_script = ( u_arcname . startswith ( script_pfx ) and ( not u_arcname . endswith ( '.exe' ) ) ) #NEWLINE# if u_arcname . startswith ( data_pfx ) : #NEWLINE# #INDENT# ( _ , where , rp ) = u_arcname . split ( '/' , 2 ) #NEWLINE# outfile = os . path . join ( paths [ where ] , convert_path ( rp ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( u_arcname in ( wheel_metadata_name , record_name ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# outfile = os . path . join ( libdir , convert_path ( u_arcname ) ) #NEWLINE# #UNINDENT# if ( not is_script ) : #NEWLINE# #INDENT# with zf . open ( arcname ) as bf : #NEWLINE# #INDENT# fileop . copy_stream ( bf , outfile ) #NEWLINE# #UNINDENT# outfiles . append ( outfile ) #NEWLINE# if ( ( not dry_run ) and row [ 1 ] ) : #NEWLINE# #INDENT# with open ( outfile , 'rb' ) as bf : #NEWLINE# #INDENT# data = bf . read ( ) #NEWLINE# ( _ , newdigest ) = self . get_hash ( data , kind ) #NEWLINE# if ( newdigest != digest ) : #NEWLINE# #INDENT# raise DistlibException ( ( 'digest mismatch on write for %s' % outfile ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( bc and outfile . endswith ( '.py' ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# pyc = fileop . byte_compile ( outfile ) #NEWLINE# outfiles . append ( pyc ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# logger . warning ( 'Byte-compilation failed' , exc_info = True ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# fn = os . path . basename ( convert_path ( arcname ) ) #NEWLINE# workname = os . path . join ( workdir , fn ) #NEWLINE# with zf . open ( arcname ) as bf : #NEWLINE# #INDENT# fileop . copy_stream ( bf , workname ) #NEWLINE# #UNINDENT# ( dn , fn ) = os . path . split ( outfile ) #NEWLINE# maker . target_dir = dn #NEWLINE# filenames = maker . make ( fn ) #NEWLINE# fileop . set_executable_mode ( filenames ) #NEWLINE# outfiles . extend ( filenames ) #NEWLINE# #UNINDENT# #UNINDENT# if lib_only : #NEWLINE# #INDENT# logger . debug ( 'lib_only: returning None' ) #NEWLINE# dist = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# commands = None #NEWLINE# file_version = self . info [ 'Wheel-Version' ] #NEWLINE# if ( file_version == '1.0' ) : #NEWLINE# #INDENT# ep = posixpath . join ( info_dir , 'entry_points.txt' ) #NEWLINE# try : #NEWLINE# #INDENT# with zf . open ( ep ) as bwf : #NEWLINE# #INDENT# epdata = read_exports ( bwf ) #NEWLINE# #UNINDENT# commands = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for key in ( 'console' , 'gui' ) : #NEWLINE# #INDENT# k = ( '%s_scripts' % key ) #NEWLINE# if ( k in epdata ) : #NEWLINE# #INDENT# commands [ ( 'wrap_%s' % key ) ] = d = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for v in epdata [ k ] . values ( ) : #NEWLINE# #INDENT# s = ( '%s:%s' % ( v . prefix , v . suffix ) ) #NEWLINE# if v . flags : #NEWLINE# #INDENT# s += ( ' %s' % v . flags ) #NEWLINE# #UNINDENT# d [ v . name ] = s #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# except Exception : #NEWLINE# #INDENT# logger . warning ( 'Unable to read legacy script metadata, so cannot generate scripts' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# with zf . open ( metadata_name ) as bwf : #NEWLINE# #INDENT# wf = wrapper ( bwf ) #NEWLINE# commands = json . load ( wf ) . get ( 'extensions' ) #NEWLINE# if commands : #NEWLINE# #INDENT# commands = commands . get ( 'python.commands' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except Exception : #NEWLINE# #INDENT# logger . warning ( 'Unable to read JSON metadata, so cannot generate scripts' ) #NEWLINE# #UNINDENT# #UNINDENT# if commands : #NEWLINE# #INDENT# console_scripts = commands . get ( 'wrap_console' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# gui_scripts = commands . get ( 'wrap_gui' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# if ( console_scripts or gui_scripts ) : #NEWLINE# #INDENT# script_dir = paths . get ( 'scripts' , '' ) #NEWLINE# if ( not os . path . isdir ( script_dir ) ) : #NEWLINE# #INDENT# raise ValueError ( 'Valid script path not specified' ) #NEWLINE# #UNINDENT# maker . target_dir = script_dir #NEWLINE# for ( k , v ) in console_scripts . items ( ) : #NEWLINE# #INDENT# script = ( '%s = %s' % ( k , v ) ) #NEWLINE# filenames = maker . make ( script ) #NEWLINE# fileop . set_executable_mode ( filenames ) #NEWLINE# #UNINDENT# if gui_scripts : #NEWLINE# #INDENT# options = { #NEWLINE# #INDENT# 'gui' : True , #NEWLINE# #UNINDENT# } #NEWLINE# for ( k , v ) in gui_scripts . items ( ) : #NEWLINE# #INDENT# script = ( '%s = %s' % ( k , v ) ) #NEWLINE# filenames = maker . make ( script , options ) #NEWLINE# fileop . set_executable_mode ( filenames ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# p = os . path . join ( libdir , info_dir ) #NEWLINE# dist = InstalledDistribution ( rp ) #NEWLINE# paths = dict ( paths ) #NEWLINE# del paths [ 'purelib' ] #NEWLINE# del paths [ 'platlib' ] #NEWLINE# paths [ 'lib' ] = libdir #NEWLINE# p = dist . write_shared_locations ( paths , dry_run ) #NEWLINE# if p : #NEWLINE# #INDENT# outfiles . append ( p ) #NEWLINE# #UNINDENT# dist . write_installed_files ( outfiles , paths [ 'prefix' ] , dry_run ) #NEWLINE# #UNINDENT# return dist #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# logger . exception ( 'installation failed.' ) #NEWLINE# fileop . rollback ( ) #NEWLINE# raise #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# shutil . rmtree ( workdir )