<s> """<STR_LIT>""" <EOL> import sys , os , marshal <EOL> from setuptools import Command <EOL> from distutils . dir_util import remove_tree , mkpath <EOL> try : <EOL> from sysconfig import get_path , get_python_version <EOL> def _get_purelib ( ) : <EOL> return get_path ( "<STR_LIT>" ) <EOL> except ImportError : <EOL> from distutils . sysconfig import get_python_lib , get_python_version <EOL> def _get_purelib ( ) : <EOL> return get_python_lib ( False ) <EOL> from distutils import log <EOL> from distutils . errors import DistutilsSetupError <EOL> from pkg_resources import get_build_platform , Distribution , ensure_directory <EOL> from pkg_resources import EntryPoint <EOL> from types import CodeType <EOL> from setuptools . compat import basestring , next <EOL> from setuptools . extension import Library <EOL> def strip_module ( filename ) : <EOL> if '<STR_LIT:.>' in filename : <EOL> filename = os . path . splitext ( filename ) [ <NUM_LIT:0> ] <EOL> if filename . endswith ( '<STR_LIT>' ) : <EOL> filename = filename [ : - <NUM_LIT:6> ] <EOL> return filename <EOL> def write_stub ( resource , pyfile ) : <EOL> f = open ( pyfile , '<STR_LIT:w>' ) <EOL> f . write ( '<STR_LIT:\n>' . join ( [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> % resource , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] ) ) <EOL> f . close ( ) <EOL> NS_PKG_STUB = '<STR_LIT>' <EOL> class bdist_egg ( Command ) : <EOL> description = "<STR_LIT>" <EOL> user_options = [ <EOL> ( '<STR_LIT>' , '<STR_LIT:b>' , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:p>' , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % get_build_platform ( ) ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:k>' , <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:d>' , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , None , <EOL> "<STR_LIT>" ) , <EOL> ] <EOL> boolean_options = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ] <EOL> def initialize_options ( self ) : <EOL> self . bdist_dir = None <EOL> self . plat_name = None <EOL> self . keep_temp = <NUM_LIT:0> <EOL> self . dist_dir = None <EOL> self . skip_build = <NUM_LIT:0> <EOL> self . egg_output = None <EOL> self . exclude_source_files = None <EOL> def finalize_options ( self ) : <EOL> ei_cmd = self . ei_cmd = self . get_finalized_command ( "<STR_LIT>" ) <EOL> self . egg_info = ei_cmd . egg_info <EOL> if self . bdist_dir is None : <EOL> bdist_base = self . get_finalized_command ( '<STR_LIT>' ) . bdist_base <EOL> self . bdist_dir = os . path . join ( bdist_base , '<STR_LIT>' ) <EOL> if self . plat_name is None : <EOL> self . plat_name = get_build_platform ( ) <EOL> self . set_undefined_options ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if self . egg_output is None : <EOL> basename = Distribution ( <EOL> None , None , ei_cmd . egg_name , ei_cmd . egg_version , <EOL> get_python_version ( ) , <EOL> self . distribution . has_ext_modules ( ) and self . plat_name <EOL> ) . egg_name ( ) <EOL> self . egg_output = os . path . join ( self . dist_dir , basename + '<STR_LIT>' ) <EOL> def do_install_data ( self ) : <EOL> self . get_finalized_command ( '<STR_LIT>' ) . install_lib = self . bdist_dir <EOL> site_packages = os . path . normcase ( os . path . realpath ( _get_purelib ( ) ) ) <EOL> old , self . distribution . data_files = self . distribution . data_files , [ ] <EOL> for item in old : <EOL> if isinstance ( item , tuple ) and len ( item ) == <NUM_LIT:2> : <EOL> if os . path . isabs ( item [ <NUM_LIT:0> ] ) : <EOL> realpath = os . path . realpath ( item [ <NUM_LIT:0> ] ) <EOL> normalized = os . path . normcase ( realpath ) <EOL> if normalized == site_packages or normalized . startswith ( <EOL> site_packages + os . sep <EOL> ) : <EOL> item = realpath [ len ( site_packages ) + <NUM_LIT:1> : ] , item [ <NUM_LIT:1> ] <EOL> self . distribution . data_files . append ( item ) <EOL> try : <EOL> log . info ( "<STR_LIT>" % self . bdist_dir ) <EOL> self . call_command ( '<STR_LIT>' , force = <NUM_LIT:0> , root = None ) <EOL> finally : <EOL> self . distribution . data_files = old <EOL> def get_outputs ( self ) : <EOL> return [ self . egg_output ] <EOL> def call_command ( self , cmdname , ** kw ) : <EOL> """<STR_LIT>""" <EOL> for dirname in INSTALL_DIRECTORY_ATTRS : <EOL> kw . setdefault ( dirname , self . bdist_dir ) <EOL> kw . setdefault ( '<STR_LIT>' , self . skip_build ) <EOL> kw . setdefault ( '<STR_LIT>' , self . dry_run ) <EOL> cmd = self . reinitialize_command ( cmdname , ** kw ) <EOL> self . run_command ( cmdname ) <EOL> return cmd <EOL> def run ( self ) : <EOL> self . run_command ( "<STR_LIT>" ) <EOL> log . info ( "<STR_LIT>" % self . bdist_dir ) <EOL> instcmd = self . get_finalized_command ( '<STR_LIT>' ) <EOL> old_root = instcmd . root ; instcmd . root = None <EOL> if self . distribution . has_c_libraries ( ) and not self . skip_build : <EOL> self . run_command ( '<STR_LIT>' ) <EOL> cmd = self . call_command ( '<STR_LIT>' , warn_dir = <NUM_LIT:0> ) <EOL> instcmd . root = old_root <EOL> all_outputs , ext_outputs = self . get_ext_outputs ( ) <EOL> self . stubs = [ ] <EOL> to_compile = [ ] <EOL> for ( p , ext_name ) in enumerate ( ext_outputs ) : <EOL> filename , ext = os . path . splitext ( ext_name ) <EOL> pyfile = os . path . join ( self . bdist_dir , strip_module ( filename ) + '<STR_LIT>' ) <EOL> self . stubs . append ( pyfile ) <EOL> log . info ( "<STR_LIT>" % ext_name ) <EOL> if not self . dry_run : <EOL> write_stub ( os . path . basename ( ext_name ) , pyfile ) <EOL> to_compile . append ( pyfile ) <EOL> ext_outputs [ p ] = ext_name . replace ( os . sep , '<STR_LIT:/>' ) <EOL> to_compile . extend ( self . make_init_files ( ) ) <EOL> if to_compile : <EOL> cmd . byte_compile ( to_compile ) <EOL> if self . distribution . data_files : <EOL> self . do_install_data ( ) <EOL> archive_root = self . bdist_dir <EOL> egg_info = os . path . join ( archive_root , '<STR_LIT>' ) <EOL> self . mkpath ( egg_info ) <EOL> if self . distribution . scripts : <EOL> script_dir = os . path . join ( egg_info , '<STR_LIT>' ) <EOL> log . info ( "<STR_LIT>" % script_dir ) <EOL> self . call_command ( '<STR_LIT>' , install_dir = script_dir , no_ep = <NUM_LIT:1> ) <EOL> self . copy_metadata_to ( egg_info ) <EOL> native_libs = os . path . join ( egg_info , "<STR_LIT>" ) <EOL> if all_outputs : <EOL> log . info ( "<STR_LIT>" % native_libs ) <EOL> if not self . dry_run : <EOL> ensure_directory ( native_libs ) <EOL> libs_file = open ( native_libs , '<STR_LIT>' ) <EOL> libs_file . write ( '<STR_LIT:\n>' . join ( all_outputs ) ) <EOL> libs_file . write ( '<STR_LIT:\n>' ) <EOL> libs_file . close ( ) <EOL> elif os . path . isfile ( native_libs ) : <EOL> log . info ( "<STR_LIT>" % native_libs ) <EOL> if not self . dry_run : <EOL> os . unlink ( native_libs ) <EOL> write_safety_flag ( <EOL> os . path . join ( archive_root , '<STR_LIT>' ) , self . zip_safe ( ) <EOL> ) <EOL> if os . path . exists ( os . path . join ( self . egg_info , '<STR_LIT>' ) ) : <EOL> log . warn ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> if self . exclude_source_files : <EOL> self . zap_pyfiles ( ) <EOL> make_zipfile ( self . egg_output , archive_root , verbose = self . verbose , <EOL> dry_run = self . dry_run , mode = self . gen_header ( ) ) <EOL> if not self . keep_temp : <EOL> remove_tree ( self . bdist_dir , dry_run = self . dry_run ) <EOL> getattr ( self . distribution , '<STR_LIT>' , [ ] ) . append ( <EOL> ( '<STR_LIT>' , get_python_version ( ) , self . egg_output ) ) <EOL> def zap_pyfiles ( self ) : <EOL> log . info ( "<STR_LIT>" ) <EOL> for base , dirs , files in walk_egg ( self . bdist_dir ) : <EOL> for name in files : <EOL> if name . endswith ( '<STR_LIT>' ) : <EOL> path = os . path . join ( base , name ) <EOL> log . debug ( "<STR_LIT>" , path ) <EOL> os . unlink ( path ) <EOL> def zip_safe ( self ) : <EOL> safe = getattr ( self . distribution , '<STR_LIT>' , None ) <EOL> if safe is not None : <EOL> return safe <EOL> log . warn ( "<STR_LIT>" ) <EOL> return analyze_egg ( self . bdist_dir , self . stubs ) <EOL> def make_init_files ( self ) : <EOL> """<STR_LIT>""" <EOL> init_files = [ ] <EOL> for base , dirs , files in walk_egg ( self . bdist_dir ) : <EOL> if base == self . bdist_dir : <EOL> continue <EOL> for name in files : <EOL> if name . endswith ( '<STR_LIT>' ) : <EOL> if '<STR_LIT>' not in files : <EOL> pkg = base [ len ( self . bdist_dir ) + <NUM_LIT:1> : ] . replace ( os . sep , '<STR_LIT:.>' ) <EOL> if self . distribution . has_contents_for ( pkg ) : <EOL> log . warn ( "<STR_LIT>" , pkg ) <EOL> filename = os . path . join ( base , '<STR_LIT>' ) <EOL> if not self . dry_run : <EOL> f = open ( filename , '<STR_LIT:w>' ) ; f . write ( NS_PKG_STUB ) <EOL> f . close ( ) <EOL> init_files . append ( filename ) <EOL> break <EOL> else : <EOL> dirs [ : ] = [ ] <EOL> return init_files <EOL> def gen_header ( self ) : <EOL> epm = EntryPoint . parse_map ( self . distribution . entry_points or '<STR_LIT>' ) <EOL> ep = epm . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' ) <EOL> if ep is None : <EOL> return '<STR_LIT:w>' <EOL> if not ep . attrs or ep . extras : <EOL> raise DistutilsSetupError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( ep , ) <EOL> ) <EOL> pyver = sys . version [ : <NUM_LIT:3> ] <EOL> pkg = ep . module_name <EOL> full = '<STR_LIT:.>' . join ( ep . attrs ) <EOL> base = ep . attrs [ <NUM_LIT:0> ] <EOL> basename = os . path . basename ( self . egg_output ) <EOL> header = ( <EOL> "<STR_LIT>" <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) % locals ( ) <EOL> if not self . dry_run : <EOL> mkpath ( os . path . dirname ( self . egg_output ) , dry_run = self . dry_run ) <EOL> f = open ( self . egg_output , '<STR_LIT:w>' ) <EOL> f . write ( header ) <EOL> f . close ( ) <EOL> return '<STR_LIT:a>' <EOL> def copy_metadata_to ( self , target_dir ) : <EOL> "<STR_LIT>" <EOL> norm_egg_info = os . path . normpath ( self . egg_info ) <EOL> prefix = os . path . join ( norm_egg_info , '<STR_LIT>' ) <EOL> for path in self . ei_cmd . filelist . files : <EOL> if path . startswith ( prefix ) : <EOL> target = os . path . join ( target_dir , path [ len ( prefix ) : ] ) <EOL> ensure_directory ( target ) <EOL> self . copy_file ( path , target ) <EOL> def get_ext_outputs ( self ) : <EOL> """<STR_LIT>""" <EOL> all_outputs = [ ] <EOL> ext_outputs = [ ] <EOL> paths = { self . bdist_dir : '<STR_LIT>' } <EOL> for base , dirs , files in os . walk ( self . bdist_dir ) : <EOL> for filename in files : <EOL> if os . path . splitext ( filename ) [ <NUM_LIT:1> ] . lower ( ) in NATIVE_EXTENSIONS : <EOL> all_outputs . append ( paths [ base ] + filename ) <EOL> for filename in dirs : <EOL> paths [ os . path . join ( base , filename ) ] = paths [ base ] + filename + '<STR_LIT:/>' <EOL> if self . distribution . has_ext_modules ( ) : <EOL> build_cmd = self . get_finalized_command ( '<STR_LIT>' ) <EOL> for ext in build_cmd . extensions : <EOL> if isinstance ( ext , Library ) : <EOL> continue <EOL> fullname = build_cmd . get_ext_fullname ( ext . name ) <EOL> filename = build_cmd . get_ext_filename ( fullname ) <EOL> if not os . path . basename ( filename ) . startswith ( '<STR_LIT>' ) : <EOL> if os . path . exists ( os . path . join ( self . bdist_dir , filename ) ) : <EOL> ext_outputs . append ( filename ) <EOL> return all_outputs , ext_outputs <EOL> NATIVE_EXTENSIONS = dict . fromkeys ( '<STR_LIT>' . split ( ) ) <EOL> def walk_egg ( egg_dir ) : <EOL> """<STR_LIT>""" <EOL> walker = os . walk ( egg_dir ) <EOL> base , dirs , files = next ( walker ) <EOL> if '<STR_LIT>' in dirs : <EOL> dirs . remove ( '<STR_LIT>' ) <EOL> yield base , dirs , files <EOL> for bdf in walker : <EOL> yield bdf <EOL> def analyze_egg ( egg_dir , stubs ) : <EOL> for flag , fn in safety_flags . items ( ) : <EOL> if os . path . exists ( os . path . join ( egg_dir , '<STR_LIT>' , fn ) ) : <EOL> return flag <EOL> if not can_scan ( ) : return False <EOL> safe = True <EOL> for base , dirs , files in walk_egg ( egg_dir ) : <EOL> for name in files : <EOL> if name . endswith ( '<STR_LIT>' ) or name . endswith ( '<STR_LIT>' ) : <EOL> continue <EOL> elif name . endswith ( '<STR_LIT>' ) or name . endswith ( '<STR_LIT>' ) : <EOL> safe = scan_module ( egg_dir , base , name , stubs ) and safe <EOL> return safe <EOL> def write_safety_flag ( egg_dir , safe ) : <EOL> for flag , fn in safety_flags . items ( ) : <EOL> fn = os . path . join ( egg_dir , fn ) <EOL> if os . path . exists ( fn ) : <EOL> if safe is None or bool ( safe ) != flag : <EOL> os . unlink ( fn ) <EOL> elif safe is not None and bool ( safe ) == flag : <EOL> f = open ( fn , '<STR_LIT>' ) ; f . write ( '<STR_LIT:\n>' ) ; f . close ( ) <EOL> safety_flags = { <EOL> True : '<STR_LIT>' , <EOL> False : '<STR_LIT>' , <EOL> } <EOL> def scan_module ( egg_dir , base , name , stubs ) : <EOL> """<STR_LIT>""" <EOL> filename = os . path . join ( base , name ) <EOL> if filename [ : - <NUM_LIT:1> ] in stubs : <EOL> return True <EOL> pkg = base [ len ( egg_dir ) + <NUM_LIT:1> : ] . replace ( os . sep , '<STR_LIT:.>' ) <EOL> module = pkg + ( pkg and '<STR_LIT:.>' or '<STR_LIT>' ) + os . path . splitext ( name ) [ <NUM_LIT:0> ] <EOL> if sys . version_info < ( <NUM_LIT:3> , <NUM_LIT:3> ) : <EOL> skip = <NUM_LIT:8> <EOL> else : <EOL> skip = <NUM_LIT:12> <EOL> f = open ( filename , '<STR_LIT:rb>' ) ; f . read ( skip ) <EOL> code = marshal . load ( f ) ; f . close ( ) <EOL> safe = True <EOL> symbols = dict . fromkeys ( iter_symbols ( code ) ) <EOL> for bad in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if bad in symbols : <EOL> log . warn ( "<STR_LIT>" , module , bad ) <EOL> safe = False <EOL> if '<STR_LIT>' in symbols : <EOL> for bad in [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ] : <EOL> if bad in symbols : <EOL> log . warn ( "<STR_LIT>" , module , bad ) <EOL> safe = False <EOL> if '<STR_LIT>' in symbols and '<STR_LIT:__main__>' in symbols and '<STR_LIT:.>' not in module : <EOL> if sys . version [ : <NUM_LIT:3> ] == "<STR_LIT>" : <EOL> log . warn ( "<STR_LIT>" , module ) <EOL> safe = False <EOL> return safe <EOL> def iter_symbols ( code ) : <EOL> """<STR_LIT>""" <EOL> for name in code . co_names : yield name <EOL> for const in code . co_consts : <EOL> if isinstance ( const , basestring ) : <EOL> yield const <EOL> elif isinstance ( const , CodeType ) : <EOL> for name in iter_symbols ( const ) : <EOL> yield name <EOL> def can_scan ( ) : <EOL> if not sys . platform . startswith ( '<STR_LIT>' ) and sys . platform != '<STR_LIT>' : <EOL> return True <EOL> log . warn ( "<STR_LIT>" ) <EOL> log . warn ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> INSTALL_DIRECTORY_ATTRS = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ] <EOL> def make_zipfile ( zip_filename , base_dir , verbose = <NUM_LIT:0> , dry_run = <NUM_LIT:0> , compress = None , <EOL> mode = '<STR_LIT:w>' <EOL> ) : <EOL> """<STR_LIT>""" <EOL> import zipfile <EOL> mkpath ( os . path . dirname ( zip_filename ) , dry_run = dry_run ) <EOL> log . info ( "<STR_LIT>" , zip_filename , base_dir ) <EOL> def visit ( z , dirname , names ) : <EOL> for name in names : <EOL> path = os . path . normpath ( os . path . join ( dirname , name ) ) <EOL> if os . path . isfile ( path ) : <EOL> p = path [ len ( base_dir ) + <NUM_LIT:1> : ] <EOL> if not dry_run : <EOL> z . write ( path , p ) <EOL> log . debug ( "<STR_LIT>" % p ) <EOL> if compress is None : <EOL> compress = ( sys . version >= "<STR_LIT>" ) <EOL> compression = [ zipfile . ZIP_STORED , zipfile . ZIP_DEFLATED ] [ bool ( compress ) ] <EOL> if not dry_run : <EOL> z = zipfile . ZipFile ( zip_filename , mode , compression = compression ) <EOL> for dirname , dirs , files in os . walk ( base_dir ) : <EOL> visit ( z , dirname , files ) <EOL> z . close ( ) <EOL> else : <EOL> for dirname , dirs , files in os . walk ( base_dir ) : <EOL> visit ( None , dirname , files ) <EOL> return zip_filename </s>
