<s> """<STR_LIT>""" <EOL> import os , re <EOL> from setuptools import Command <EOL> from distutils . errors import * <EOL> from distutils import log <EOL> from setuptools . command . sdist import sdist <EOL> from distutils . util import convert_path <EOL> from distutils . filelist import FileList <EOL> from pkg_resources import parse_requirements , safe_name , parse_version , safe_version , yield_lines , EntryPoint , iter_entry_points , to_filename <EOL> from sdist import walk_revctrl <EOL> class egg_info ( Command ) : <EOL> description = "<STR_LIT>" <EOL> user_options = [ <EOL> ( '<STR_LIT>' , '<STR_LIT:e>' , "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:r>' , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:d>' , "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:b>' , "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:R>' , <EOL> "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:D>' , "<STR_LIT>" ) , <EOL> ] <EOL> boolean_options = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> negative_opt = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> def initialize_options ( self ) : <EOL> self . egg_name = None <EOL> self . egg_version = None <EOL> self . egg_base = None <EOL> self . egg_info = None <EOL> self . tag_build = None <EOL> self . tag_svn_revision = <NUM_LIT:0> <EOL> self . tag_date = <NUM_LIT:0> <EOL> self . broken_egg_info = False <EOL> self . vtags = None <EOL> def save_version_info ( self , filename ) : <EOL> from setopt import edit_config <EOL> edit_config ( <EOL> filename , <EOL> { '<STR_LIT>' : <EOL> { '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : <NUM_LIT:0> , '<STR_LIT>' : self . tags ( ) } <EOL> } <EOL> ) <EOL> def finalize_options ( self ) : <EOL> self . egg_name = safe_name ( self . distribution . get_name ( ) ) <EOL> self . vtags = self . tags ( ) <EOL> self . egg_version = self . tagged_version ( ) <EOL> try : <EOL> list ( <EOL> parse_requirements ( '<STR_LIT>' % ( self . egg_name , self . egg_version ) ) <EOL> ) <EOL> except ValueError : <EOL> raise DistutilsOptionError ( <EOL> "<STR_LIT>" % <EOL> ( self . egg_name , self . egg_version ) <EOL> ) <EOL> if self . egg_base is None : <EOL> dirs = self . distribution . package_dir <EOL> self . egg_base = ( dirs or { } ) . get ( '<STR_LIT>' , os . curdir ) <EOL> self . ensure_dirname ( '<STR_LIT>' ) <EOL> self . egg_info = to_filename ( self . egg_name ) + '<STR_LIT>' <EOL> if self . egg_base != os . curdir : <EOL> self . egg_info = os . path . join ( self . egg_base , self . egg_info ) <EOL> if '<STR_LIT:->' in self . egg_name : self . check_broken_egg_info ( ) <EOL> self . distribution . metadata . version = self . egg_version <EOL> pd = self . distribution . _patched_dist <EOL> if pd is not None and pd . key == self . egg_name . lower ( ) : <EOL> pd . _version = self . egg_version <EOL> pd . _parsed_version = parse_version ( self . egg_version ) <EOL> self . distribution . _patched_dist = None <EOL> def write_or_delete_file ( self , what , filename , data , force = False ) : <EOL> """<STR_LIT>""" <EOL> if data : <EOL> self . write_file ( what , filename , data ) <EOL> elif os . path . exists ( filename ) : <EOL> if data is None and not force : <EOL> log . warn ( <EOL> "<STR_LIT>" , what , filename <EOL> ) <EOL> return <EOL> else : <EOL> self . delete_file ( filename ) <EOL> def write_file ( self , what , filename , data ) : <EOL> """<STR_LIT>""" <EOL> log . info ( "<STR_LIT>" , what , filename ) <EOL> if not self . dry_run : <EOL> f = open ( filename , '<STR_LIT:wb>' ) <EOL> f . write ( data ) <EOL> f . close ( ) <EOL> def delete_file ( self , filename ) : <EOL> """<STR_LIT>""" <EOL> log . info ( "<STR_LIT>" , filename ) <EOL> if not self . dry_run : <EOL> os . unlink ( filename ) <EOL> def tagged_version ( self ) : <EOL> return safe_version ( self . distribution . get_version ( ) + self . vtags ) <EOL> def run ( self ) : <EOL> self . mkpath ( self . egg_info ) <EOL> installer = self . distribution . fetch_build_egg <EOL> for ep in iter_entry_points ( '<STR_LIT>' ) : <EOL> writer = ep . load ( installer = installer ) <EOL> writer ( self , ep . name , os . path . join ( self . egg_info , ep . name ) ) <EOL> nl = os . path . join ( self . egg_info , "<STR_LIT>" ) <EOL> if os . path . exists ( nl ) : <EOL> self . delete_file ( nl ) <EOL> self . find_sources ( ) <EOL> def tags ( self ) : <EOL> version = '<STR_LIT>' <EOL> if self . tag_build : <EOL> version += self . tag_build <EOL> if self . tag_svn_revision and ( <EOL> os . path . exists ( '<STR_LIT>' ) or os . path . exists ( '<STR_LIT>' ) <EOL> ) : version += '<STR_LIT>' % self . get_svn_revision ( ) <EOL> if self . tag_date : <EOL> import time ; version += time . strftime ( "<STR_LIT>" ) <EOL> return version <EOL> def get_svn_revision ( self ) : <EOL> revision = <NUM_LIT:0> <EOL> urlre = re . compile ( '<STR_LIT>' ) <EOL> revre = re . compile ( '<STR_LIT>' ) <EOL> for base , dirs , files in os . walk ( os . curdir ) : <EOL> if '<STR_LIT>' not in dirs : <EOL> dirs [ : ] = [ ] <EOL> continue <EOL> dirs . remove ( '<STR_LIT>' ) <EOL> f = open ( os . path . join ( base , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> data = f . read ( ) <EOL> f . close ( ) <EOL> if data . startswith ( '<STR_LIT>' ) : <EOL> dirurl = urlre . search ( data ) . group ( <NUM_LIT:1> ) <EOL> localrev = max ( [ int ( m . group ( <NUM_LIT:1> ) ) for m in revre . finditer ( data ) ] + [ <NUM_LIT:0> ] ) <EOL> else : <EOL> try : svnver = int ( data . splitlines ( ) [ <NUM_LIT:0> ] ) <EOL> except : svnver = - <NUM_LIT:1> <EOL> if data < <NUM_LIT:8> : <EOL> log . warn ( "<STR_LIT>" , base ) <EOL> dirs [ : ] = [ ] <EOL> continue <EOL> data = map ( str . splitlines , data . split ( '<STR_LIT>' ) ) <EOL> del data [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> dirurl = data [ <NUM_LIT:0> ] [ <NUM_LIT:3> ] <EOL> localrev = max ( [ int ( d [ <NUM_LIT:9> ] ) for d in data if len ( d ) > <NUM_LIT:9> and d [ <NUM_LIT:9> ] ] + [ <NUM_LIT:0> ] ) <EOL> if base == os . curdir : <EOL> base_url = dirurl + '<STR_LIT:/>' <EOL> elif not dirurl . startswith ( base_url ) : <EOL> dirs [ : ] = [ ] <EOL> continue <EOL> revision = max ( revision , localrev ) <EOL> return str ( revision or get_pkg_info_revision ( ) ) <EOL> def find_sources ( self ) : <EOL> """<STR_LIT>""" <EOL> manifest_filename = os . path . join ( self . egg_info , "<STR_LIT>" ) <EOL> mm = manifest_maker ( self . distribution ) <EOL> mm . manifest = manifest_filename <EOL> mm . run ( ) <EOL> self . filelist = mm . filelist <EOL> def check_broken_egg_info ( self ) : <EOL> bei = self . egg_name + '<STR_LIT>' <EOL> if self . egg_base != os . curdir : <EOL> bei = os . path . join ( self . egg_base , bei ) <EOL> if os . path . exists ( bei ) : <EOL> log . warn ( <EOL> "<STR_LIT:->" * <NUM_LIT> + '<STR_LIT:\n>' <EOL> "<STR_LIT>" <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' + '<STR_LIT:->' * <NUM_LIT> , <EOL> bei , self . egg_info <EOL> ) <EOL> self . broken_egg_info = self . egg_info <EOL> self . egg_info = bei <EOL> class FileList ( FileList ) : <EOL> """<STR_LIT>""" <EOL> def append ( self , item ) : <EOL> if item . endswith ( '<STR_LIT:\r>' ) : <EOL> item = item [ : - <NUM_LIT:1> ] <EOL> path = convert_path ( item ) <EOL> if os . path . exists ( path ) : <EOL> self . files . append ( path ) <EOL> class manifest_maker ( sdist ) : <EOL> template = "<STR_LIT>" <EOL> def initialize_options ( self ) : <EOL> self . use_defaults = <NUM_LIT:1> <EOL> self . prune = <NUM_LIT:1> <EOL> self . manifest_only = <NUM_LIT:1> <EOL> self . force_manifest = <NUM_LIT:1> <EOL> def finalize_options ( self ) : <EOL> pass <EOL> def run ( self ) : <EOL> self . filelist = FileList ( ) <EOL> if not os . path . exists ( self . manifest ) : <EOL> self . write_manifest ( ) <EOL> self . filelist . findall ( ) <EOL> self . add_defaults ( ) <EOL> if os . path . exists ( self . template ) : <EOL> self . read_template ( ) <EOL> self . prune_file_list ( ) <EOL> self . filelist . sort ( ) <EOL> self . filelist . remove_duplicates ( ) <EOL> self . write_manifest ( ) <EOL> def write_manifest ( self ) : <EOL> """<STR_LIT>""" <EOL> files = self . filelist . files <EOL> if os . sep != '<STR_LIT:/>' : <EOL> files = [ f . replace ( os . sep , '<STR_LIT:/>' ) for f in files ] <EOL> self . execute ( write_file , ( self . manifest , files ) , <EOL> "<STR_LIT>" % self . manifest ) <EOL> def warn ( self , msg ) : <EOL> if not msg . startswith ( "<STR_LIT>" ) : <EOL> sdist . warn ( self , msg ) <EOL> def add_defaults ( self ) : <EOL> sdist . add_defaults ( self ) <EOL> self . filelist . append ( self . template ) <EOL> self . filelist . append ( self . manifest ) <EOL> rcfiles = list ( walk_revctrl ( ) ) <EOL> if rcfiles : <EOL> self . filelist . extend ( rcfiles ) <EOL> elif os . path . exists ( self . manifest ) : <EOL> self . read_manifest ( ) <EOL> ei_cmd = self . get_finalized_command ( '<STR_LIT>' ) <EOL> self . filelist . include_pattern ( "<STR_LIT:*>" , prefix = ei_cmd . egg_info ) <EOL> def prune_file_list ( self ) : <EOL> build = self . get_finalized_command ( '<STR_LIT>' ) <EOL> base_dir = self . distribution . get_fullname ( ) <EOL> self . filelist . exclude_pattern ( None , prefix = build . build_base ) <EOL> self . filelist . exclude_pattern ( None , prefix = base_dir ) <EOL> sep = re . escape ( os . sep ) <EOL> self . filelist . exclude_pattern ( sep + r'<STR_LIT>' + sep , is_regex = <NUM_LIT:1> ) <EOL> def write_file ( filename , contents ) : <EOL> """<STR_LIT>""" <EOL> f = open ( filename , "<STR_LIT:wb>" ) <EOL> f . write ( "<STR_LIT:\n>" . join ( contents ) ) <EOL> f . close ( ) <EOL> def write_pkg_info ( cmd , basename , filename ) : <EOL> log . info ( "<STR_LIT>" , filename ) <EOL> if not cmd . dry_run : <EOL> metadata = cmd . distribution . metadata <EOL> metadata . version , oldver = cmd . egg_version , metadata . version <EOL> metadata . name , oldname = cmd . egg_name , metadata . name <EOL> try : <EOL> metadata . write_pkg_info ( cmd . egg_info ) <EOL> finally : <EOL> metadata . name , metadata . version = oldname , oldver <EOL> safe = getattr ( cmd . distribution , '<STR_LIT>' , None ) <EOL> import bdist_egg ; bdist_egg . write_safety_flag ( cmd . egg_info , safe ) <EOL> def warn_depends_obsolete ( cmd , basename , filename ) : <EOL> if os . path . exists ( filename ) : <EOL> log . warn ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def write_requirements ( cmd , basename , filename ) : <EOL> dist = cmd . distribution <EOL> data = [ '<STR_LIT:\n>' . join ( yield_lines ( dist . install_requires or ( ) ) ) ] <EOL> for extra , reqs in ( dist . extras_require or { } ) . items ( ) : <EOL> data . append ( '<STR_LIT>' % ( extra , '<STR_LIT:\n>' . join ( yield_lines ( reqs ) ) ) ) <EOL> cmd . write_or_delete_file ( "<STR_LIT>" , filename , '<STR_LIT>' . join ( data ) ) <EOL> def write_toplevel_names ( cmd , basename , filename ) : <EOL> pkgs = dict . fromkeys ( <EOL> [ k . split ( '<STR_LIT:.>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> for k in cmd . distribution . iter_distribution_names ( ) <EOL> ] <EOL> ) <EOL> cmd . write_file ( "<STR_LIT>" , filename , '<STR_LIT:\n>' . join ( pkgs ) + '<STR_LIT:\n>' ) <EOL> def overwrite_arg ( cmd , basename , filename ) : <EOL> write_arg ( cmd , basename , filename , True ) <EOL> def write_arg ( cmd , basename , filename , force = False ) : <EOL> argname = os . path . splitext ( basename ) [ <NUM_LIT:0> ] <EOL> value = getattr ( cmd . distribution , argname , None ) <EOL> if value is not None : <EOL> value = '<STR_LIT:\n>' . join ( value ) + '<STR_LIT:\n>' <EOL> cmd . write_or_delete_file ( argname , filename , value , force ) <EOL> def write_entries ( cmd , basename , filename ) : <EOL> ep = cmd . distribution . entry_points <EOL> if isinstance ( ep , basestring ) or ep is None : <EOL> data = ep <EOL> elif ep is not None : <EOL> data = [ ] <EOL> for section , contents in ep . items ( ) : <EOL> if not isinstance ( contents , basestring ) : <EOL> contents = EntryPoint . parse_group ( section , contents ) <EOL> contents = '<STR_LIT:\n>' . join ( map ( str , contents . values ( ) ) ) <EOL> data . append ( '<STR_LIT>' % ( section , contents ) ) <EOL> data = '<STR_LIT>' . join ( data ) <EOL> cmd . write_or_delete_file ( '<STR_LIT>' , filename , data , True ) <EOL> def get_pkg_info_revision ( ) : <EOL> if os . path . exists ( '<STR_LIT>' ) : <EOL> f = open ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> for line in f : <EOL> match = re . match ( r"<STR_LIT>" , line ) <EOL> if match : <EOL> return int ( match . group ( <NUM_LIT:1> ) ) <EOL> return <NUM_LIT:0> </s>
