<s> """<STR_LIT>""" <EOL> import os , sys , re <EOL> from distutils . core import Command <EOL> from distutils . command . sdist import sdist as _sdist <EOL> from distutils . command . build import build as _build <EOL> versionfile_source = None <EOL> versionfile_build = None <EOL> tag_prefix = None <EOL> parentdir_prefix = None <EOL> VCS = "<STR_LIT>" <EOL> IN_LONG_VERSION_PY = False <EOL> LONG_VERSION_PY = '''<STR_LIT>''' <EOL> import subprocess <EOL> import sys <EOL> def run_command ( args , cwd = None , verbose = False ) : <EOL> try : <EOL> p = subprocess . Popen ( args , stdout = subprocess . PIPE , cwd = cwd ) <EOL> except EnvironmentError : <EOL> e = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> if verbose : <EOL> print ( "<STR_LIT>" % args [ <NUM_LIT:0> ] ) <EOL> print ( e ) <EOL> return None <EOL> stdout = p . communicate ( ) [ <NUM_LIT:0> ] . strip ( ) <EOL> if sys . version >= '<STR_LIT:3>' : <EOL> stdout = stdout . decode ( ) <EOL> if p . returncode != <NUM_LIT:0> : <EOL> if verbose : <EOL> print ( "<STR_LIT>" % args [ <NUM_LIT:0> ] ) <EOL> return None <EOL> return stdout <EOL> import sys <EOL> import re <EOL> import os . path <EOL> def get_expanded_variables ( versionfile_source ) : <EOL> variables = { } <EOL> try : <EOL> for line in open ( versionfile_source , "<STR_LIT:r>" ) . readlines ( ) : <EOL> if line . strip ( ) . startswith ( "<STR_LIT>" ) : <EOL> mo = re . search ( r'<STR_LIT>' , line ) <EOL> if mo : <EOL> variables [ "<STR_LIT>" ] = mo . group ( <NUM_LIT:1> ) <EOL> if line . strip ( ) . startswith ( "<STR_LIT>" ) : <EOL> mo = re . search ( r'<STR_LIT>' , line ) <EOL> if mo : <EOL> variables [ "<STR_LIT>" ] = mo . group ( <NUM_LIT:1> ) <EOL> except EnvironmentError : <EOL> pass <EOL> return variables <EOL> def versions_from_expanded_variables ( variables , tag_prefix , verbose = False ) : <EOL> refnames = variables [ "<STR_LIT>" ] . strip ( ) <EOL> if refnames . startswith ( "<STR_LIT>" ) : <EOL> if verbose : <EOL> print ( "<STR_LIT>" ) <EOL> return { } <EOL> refs = set ( [ r . strip ( ) for r in refnames . strip ( "<STR_LIT>" ) . split ( "<STR_LIT:U+002C>" ) ] ) <EOL> for ref in list ( refs ) : <EOL> if not re . search ( r'<STR_LIT>' , ref ) : <EOL> if verbose : <EOL> print ( "<STR_LIT>" % ref ) <EOL> refs . discard ( ref ) <EOL> if verbose : <EOL> print ( "<STR_LIT>" % "<STR_LIT:U+002C>" . join ( sorted ( refs ) ) ) <EOL> for ref in sorted ( refs ) : <EOL> if ref . startswith ( tag_prefix ) : <EOL> r = ref [ len ( tag_prefix ) : ] <EOL> if verbose : <EOL> print ( "<STR_LIT>" % r ) <EOL> return { "<STR_LIT:version>" : r , <EOL> "<STR_LIT>" : variables [ "<STR_LIT>" ] . strip ( ) } <EOL> if verbose : <EOL> print ( "<STR_LIT>" ) <EOL> return { "<STR_LIT:version>" : variables [ "<STR_LIT>" ] . strip ( ) , <EOL> "<STR_LIT>" : variables [ "<STR_LIT>" ] . strip ( ) } <EOL> def versions_from_vcs ( tag_prefix , versionfile_source , verbose = False ) : <EOL> try : <EOL> here = os . path . abspath ( __file__ ) <EOL> except NameError : <EOL> return { } <EOL> root = here <EOL> if IN_LONG_VERSION_PY : <EOL> for i in range ( len ( versionfile_source . split ( "<STR_LIT:/>" ) ) ) : <EOL> root = os . path . dirname ( root ) <EOL> else : <EOL> root = os . path . dirname ( here ) <EOL> if not os . path . exists ( os . path . join ( root , "<STR_LIT>" ) ) : <EOL> if verbose : <EOL> print ( "<STR_LIT>" % root ) <EOL> return { } <EOL> GIT = "<STR_LIT>" <EOL> if sys . platform == "<STR_LIT:win32>" : <EOL> GIT = "<STR_LIT>" <EOL> stdout = run_command ( [ GIT , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> cwd = root ) <EOL> if stdout is None : <EOL> return { } <EOL> if not stdout . startswith ( tag_prefix ) : <EOL> if verbose : <EOL> print ( "<STR_LIT>" % ( stdout , tag_prefix ) ) <EOL> return { } <EOL> tag = stdout [ len ( tag_prefix ) : ] <EOL> stdout = run_command ( [ GIT , "<STR_LIT>" , "<STR_LIT>" ] , cwd = root ) <EOL> if stdout is None : <EOL> return { } <EOL> full = stdout . strip ( ) <EOL> if tag . endswith ( "<STR_LIT>" ) : <EOL> full += "<STR_LIT>" <EOL> return { "<STR_LIT:version>" : tag , "<STR_LIT>" : full } <EOL> def versions_from_parentdir ( parentdir_prefix , versionfile_source , verbose = False ) : <EOL> if IN_LONG_VERSION_PY : <EOL> try : <EOL> here = os . path . abspath ( __file__ ) <EOL> except NameError : <EOL> return { } <EOL> root = here <EOL> for i in range ( len ( versionfile_source . split ( "<STR_LIT:/>" ) ) ) : <EOL> root = os . path . dirname ( root ) <EOL> else : <EOL> here = os . path . abspath ( sys . argv [ <NUM_LIT:0> ] ) <EOL> root = os . path . dirname ( here ) <EOL> dirname = os . path . basename ( root ) <EOL> if not dirname . startswith ( parentdir_prefix ) : <EOL> if verbose : <EOL> print ( "<STR_LIT>" % <EOL> ( root , dirname , parentdir_prefix ) ) <EOL> return None <EOL> return { "<STR_LIT:version>" : dirname [ len ( parentdir_prefix ) : ] , "<STR_LIT>" : "<STR_LIT>" } <EOL> import sys <EOL> def do_vcs_install ( versionfile_source , ipy ) : <EOL> GIT = "<STR_LIT>" <EOL> if sys . platform == "<STR_LIT:win32>" : <EOL> GIT = "<STR_LIT>" <EOL> run_command ( [ GIT , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> run_command ( [ GIT , "<STR_LIT>" , versionfile_source ] ) <EOL> run_command ( [ GIT , "<STR_LIT>" , ipy ] ) <EOL> present = False <EOL> try : <EOL> f = open ( "<STR_LIT>" , "<STR_LIT:r>" ) <EOL> for line in f . readlines ( ) : <EOL> if line . strip ( ) . startswith ( versionfile_source ) : <EOL> if "<STR_LIT>" in line . strip ( ) . split ( ) [ <NUM_LIT:1> : ] : <EOL> present = True <EOL> f . close ( ) <EOL> except EnvironmentError : <EOL> pass <EOL> if not present : <EOL> f = open ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> f . write ( "<STR_LIT>" % versionfile_source ) <EOL> f . close ( ) <EOL> run_command ( [ GIT , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> SHORT_VERSION_PY = """<STR_LIT>""" <EOL> DEFAULT = { "<STR_LIT:version>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } <EOL> def versions_from_file ( filename ) : <EOL> versions = { } <EOL> try : <EOL> f = open ( filename ) <EOL> except EnvironmentError : <EOL> return versions <EOL> for line in f . readlines ( ) : <EOL> mo = re . match ( "<STR_LIT>" , line ) <EOL> if mo : <EOL> versions [ "<STR_LIT:version>" ] = mo . group ( <NUM_LIT:1> ) <EOL> mo = re . match ( "<STR_LIT>" , line ) <EOL> if mo : <EOL> versions [ "<STR_LIT>" ] = mo . group ( <NUM_LIT:1> ) <EOL> return versions <EOL> def write_to_version_file ( filename , versions ) : <EOL> f = open ( filename , "<STR_LIT:w>" ) <EOL> f . write ( SHORT_VERSION_PY % versions ) <EOL> f . close ( ) <EOL> print ( "<STR_LIT>" % ( filename , versions [ "<STR_LIT:version>" ] ) ) <EOL> def get_best_versions ( versionfile , tag_prefix , parentdir_prefix , <EOL> default = DEFAULT , verbose = False ) : <EOL> variables = get_expanded_variables ( versionfile_source ) <EOL> if variables : <EOL> ver = versions_from_expanded_variables ( variables , tag_prefix ) <EOL> if ver : <EOL> if verbose : print ( "<STR_LIT>" % ver ) <EOL> return ver <EOL> ver = versions_from_file ( versionfile ) <EOL> if ver : <EOL> if verbose : print ( "<STR_LIT>" % ( versionfile , ver ) ) <EOL> return ver <EOL> ver = versions_from_vcs ( tag_prefix , versionfile_source , verbose ) <EOL> if ver : <EOL> if verbose : print ( "<STR_LIT>" % ver ) <EOL> return ver <EOL> ver = versions_from_parentdir ( parentdir_prefix , versionfile_source , verbose ) <EOL> if ver : <EOL> if verbose : print ( "<STR_LIT>" % ver ) <EOL> return ver <EOL> if verbose : print ( "<STR_LIT>" % ver ) <EOL> return default <EOL> def get_versions ( default = DEFAULT , verbose = False ) : <EOL> assert versionfile_source is not None , "<STR_LIT>" <EOL> assert tag_prefix is not None , "<STR_LIT>" <EOL> assert parentdir_prefix is not None , "<STR_LIT>" <EOL> return get_best_versions ( versionfile_source , tag_prefix , parentdir_prefix , <EOL> default = default , verbose = verbose ) <EOL> def get_version ( verbose = False ) : <EOL> return get_versions ( verbose = verbose ) [ "<STR_LIT:version>" ] <EOL> class cmd_version ( Command ) : <EOL> description = "<STR_LIT>" <EOL> user_options = [ ] <EOL> boolean_options = [ ] <EOL> def initialize_options ( self ) : <EOL> pass <EOL> def finalize_options ( self ) : <EOL> pass <EOL> def run ( self ) : <EOL> ver = get_version ( verbose = True ) <EOL> print ( "<STR_LIT>" % ver ) <EOL> class cmd_build ( _build ) : <EOL> def run2 ( self ) : <EOL> versions = get_versions ( verbose = True ) <EOL> _build . run ( self ) <EOL> target_versionfile = os . path . join ( self . build_lib , versionfile_build ) <EOL> print ( "<STR_LIT>" % target_versionfile ) <EOL> os . unlink ( target_versionfile ) <EOL> f = open ( target_versionfile , "<STR_LIT:w>" ) <EOL> f . write ( SHORT_VERSION_PY % versions ) <EOL> f . close ( ) <EOL> class cmd_sdist ( _sdist ) : <EOL> def run ( self ) : <EOL> versions = get_versions ( verbose = True ) <EOL> self . _versioneer_generated_versions = versions <EOL> self . distribution . metadata . version = versions [ "<STR_LIT:version>" ] <EOL> return _sdist . run ( self ) <EOL> def make_release_tree ( self , base_dir , files ) : <EOL> _sdist . make_release_tree ( self , base_dir , files ) <EOL> target_versionfile = os . path . join ( base_dir , versionfile_source ) <EOL> print ( "<STR_LIT>" % target_versionfile ) <EOL> os . unlink ( target_versionfile ) <EOL> f = open ( target_versionfile , "<STR_LIT:w>" ) <EOL> f . write ( SHORT_VERSION_PY % self . _versioneer_generated_versions ) <EOL> f . close ( ) <EOL> INIT_PY_SNIPPET = """<STR_LIT>""" <EOL> class cmd_update_files ( Command ) : <EOL> description = "<STR_LIT>" <EOL> user_options = [ ] <EOL> boolean_options = [ ] <EOL> def initialize_options ( self ) : <EOL> pass <EOL> def finalize_options ( self ) : <EOL> pass <EOL> def run ( self ) : <EOL> ipy = os . path . join ( os . path . dirname ( versionfile_source ) , "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" % versionfile_source ) <EOL> f = open ( versionfile_source , "<STR_LIT:w>" ) <EOL> f . write ( LONG_VERSION_PY % { "<STR_LIT>" : "<STR_LIT:$>" , <EOL> "<STR_LIT>" : tag_prefix , <EOL> "<STR_LIT>" : parentdir_prefix , <EOL> "<STR_LIT>" : versionfile_source , <EOL> } ) <EOL> f . close ( ) <EOL> try : <EOL> old = open ( ipy , "<STR_LIT:r>" ) . read ( ) <EOL> except EnvironmentError : <EOL> old = "<STR_LIT>" <EOL> if INIT_PY_SNIPPET not in old : <EOL> print ( "<STR_LIT>" % ipy ) <EOL> f = open ( ipy , "<STR_LIT:a>" ) <EOL> f . write ( INIT_PY_SNIPPET ) <EOL> f . close ( ) <EOL> else : <EOL> print ( "<STR_LIT>" % ipy ) <EOL> do_vcs_install ( versionfile_source , ipy ) <EOL> def get_cmdclass ( ) : <EOL> return { '<STR_LIT:version>' : cmd_version , <EOL> '<STR_LIT>' : cmd_update_files , <EOL> '<STR_LIT>' : cmd_build , <EOL> '<STR_LIT>' : cmd_sdist , <EOL> } </s>
