<s> """<STR_LIT>""" <EOL> import errno <EOL> import os <EOL> import re <EOL> import subprocess <EOL> import sys <EOL> def get_keywords ( ) : <EOL> """<STR_LIT>""" <EOL> git_refnames = "<STR_LIT>" <EOL> git_full = "<STR_LIT>" <EOL> keywords = { "<STR_LIT>" : git_refnames , "<STR_LIT>" : git_full } <EOL> return keywords <EOL> class VersioneerConfig : <EOL> """<STR_LIT>""" <EOL> def get_config ( ) : <EOL> """<STR_LIT>""" <EOL> cfg = VersioneerConfig ( ) <EOL> cfg . VCS = "<STR_LIT>" <EOL> cfg . style = "<STR_LIT>" <EOL> cfg . tag_prefix = "<STR_LIT>" <EOL> cfg . parentdir_prefix = "<STR_LIT:None>" <EOL> cfg . versionfile_source = "<STR_LIT>" <EOL> cfg . verbose = False <EOL> return cfg <EOL> class NotThisMethod ( Exception ) : <EOL> """<STR_LIT>""" <EOL> LONG_VERSION_PY = { } <EOL> HANDLERS = { } <EOL> def register_vcs_handler ( vcs , method ) : <EOL> """<STR_LIT>""" <EOL> def decorate ( f ) : <EOL> """<STR_LIT>""" <EOL> if vcs not in HANDLERS : <EOL> HANDLERS [ vcs ] = { } <EOL> HANDLERS [ vcs ] [ method ] = f <EOL> return f <EOL> return decorate <EOL> def run_command ( commands , args , cwd = None , verbose = False , hide_stderr = False ) : <EOL> """<STR_LIT>""" <EOL> assert isinstance ( commands , list ) <EOL> p = None <EOL> for c in commands : <EOL> try : <EOL> dispcmd = str ( [ c ] + args ) <EOL> p = subprocess . Popen ( [ c ] + args , cwd = cwd , stdout = subprocess . PIPE , <EOL> stderr = ( subprocess . PIPE if hide_stderr <EOL> else None ) ) <EOL> break <EOL> except EnvironmentError : <EOL> e = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> if e . errno == errno . ENOENT : <EOL> continue <EOL> if verbose : <EOL> print ( "<STR_LIT>" % dispcmd ) <EOL> print ( e ) <EOL> return None <EOL> else : <EOL> if verbose : <EOL> print ( "<STR_LIT>" % ( commands , ) ) <EOL> return None <EOL> stdout = p . communicate ( ) [ <NUM_LIT:0> ] . strip ( ) <EOL> if sys . version_info [ <NUM_LIT:0> ] >= <NUM_LIT:3> : <EOL> stdout = stdout . decode ( ) <EOL> if p . returncode != <NUM_LIT:0> : <EOL> if verbose : <EOL> print ( "<STR_LIT>" % dispcmd ) <EOL> return None <EOL> return stdout <EOL> def versions_from_parentdir ( parentdir_prefix , root , verbose ) : <EOL> """<STR_LIT>""" <EOL> dirname = os . path . basename ( root ) <EOL> if not dirname . startswith ( parentdir_prefix ) : <EOL> if verbose : <EOL> print ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( root , dirname , parentdir_prefix ) ) <EOL> raise NotThisMethod ( "<STR_LIT>" ) <EOL> return { "<STR_LIT:version>" : dirname [ len ( parentdir_prefix ) : ] , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT>" : False , "<STR_LIT:error>" : None } <EOL> @ register_vcs_handler ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> def git_get_keywords ( versionfile_abs ) : <EOL> """<STR_LIT>""" <EOL> keywords = { } <EOL> try : <EOL> f = open ( versionfile_abs , "<STR_LIT:r>" ) <EOL> for line in f . readlines ( ) : <EOL> if line . strip ( ) . startswith ( "<STR_LIT>" ) : <EOL> mo = re . search ( r'<STR_LIT>' , line ) <EOL> if mo : <EOL> keywords [ "<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> keywords [ "<STR_LIT>" ] = mo . group ( <NUM_LIT:1> ) <EOL> f . close ( ) <EOL> except EnvironmentError : <EOL> pass <EOL> return keywords <EOL> @ register_vcs_handler ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> def git_versions_from_keywords ( keywords , tag_prefix , verbose ) : <EOL> """<STR_LIT>""" <EOL> if not keywords : <EOL> raise NotThisMethod ( "<STR_LIT>" ) <EOL> refnames = keywords [ "<STR_LIT>" ] . strip ( ) <EOL> if refnames . startswith ( "<STR_LIT>" ) : <EOL> if verbose : <EOL> print ( "<STR_LIT>" ) <EOL> raise NotThisMethod ( "<STR_LIT>" ) <EOL> refs = set ( [ r . strip ( ) for r in refnames . strip ( "<STR_LIT>" ) . split ( "<STR_LIT:U+002C>" ) ] ) <EOL> TAG = "<STR_LIT>" <EOL> tags = set ( [ r [ len ( TAG ) : ] for r in refs if r . startswith ( TAG ) ] ) <EOL> if not tags : <EOL> tags = set ( [ r for r in refs if re . search ( r'<STR_LIT>' , r ) ] ) <EOL> if verbose : <EOL> print ( "<STR_LIT>" % "<STR_LIT:U+002C>" . join ( refs - tags ) ) <EOL> if verbose : <EOL> print ( "<STR_LIT>" % "<STR_LIT:U+002C>" . join ( sorted ( tags ) ) ) <EOL> for ref in sorted ( tags ) : <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>" : keywords [ "<STR_LIT>" ] . strip ( ) , <EOL> "<STR_LIT>" : False , "<STR_LIT:error>" : None <EOL> } <EOL> if verbose : <EOL> print ( "<STR_LIT>" ) <EOL> return { "<STR_LIT:version>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : keywords [ "<STR_LIT>" ] . strip ( ) , <EOL> "<STR_LIT>" : False , "<STR_LIT:error>" : "<STR_LIT>" } <EOL> @ register_vcs_handler ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> def git_pieces_from_vcs ( tag_prefix , root , verbose , run_command = run_command ) : <EOL> """<STR_LIT>""" <EOL> if not os . path . exists ( os . path . join ( root , "<STR_LIT>" ) ) : <EOL> if verbose : <EOL> print ( "<STR_LIT>" % root ) <EOL> raise NotThisMethod ( "<STR_LIT>" ) <EOL> GITS = [ "<STR_LIT>" ] <EOL> if sys . platform == "<STR_LIT:win32>" : <EOL> GITS = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> describe_out = run_command ( GITS , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" % tag_prefix ] , <EOL> cwd = root ) <EOL> if describe_out is None : <EOL> raise NotThisMethod ( "<STR_LIT>" ) <EOL> describe_out = describe_out . strip ( ) <EOL> full_out = run_command ( GITS , [ "<STR_LIT>" , "<STR_LIT>" ] , cwd = root ) <EOL> if full_out is None : <EOL> raise NotThisMethod ( "<STR_LIT>" ) <EOL> full_out = full_out . strip ( ) <EOL> pieces = { } <EOL> pieces [ "<STR_LIT>" ] = full_out <EOL> pieces [ "<STR_LIT>" ] = full_out [ : <NUM_LIT:7> ] <EOL> pieces [ "<STR_LIT:error>" ] = None <EOL> git_describe = describe_out <EOL> dirty = git_describe . endswith ( "<STR_LIT>" ) <EOL> pieces [ "<STR_LIT>" ] = dirty <EOL> if dirty : <EOL> git_describe = git_describe [ : git_describe . rindex ( "<STR_LIT>" ) ] <EOL> if "<STR_LIT:->" in git_describe : <EOL> mo = re . search ( r'<STR_LIT>' , git_describe ) <EOL> if not mo : <EOL> pieces [ "<STR_LIT:error>" ] = ( "<STR_LIT>" <EOL> % describe_out ) <EOL> return pieces <EOL> full_tag = mo . group ( <NUM_LIT:1> ) <EOL> if not full_tag . startswith ( tag_prefix ) : <EOL> if verbose : <EOL> fmt = "<STR_LIT>" <EOL> print ( fmt % ( full_tag , tag_prefix ) ) <EOL> pieces [ "<STR_LIT:error>" ] = ( "<STR_LIT>" <EOL> % ( full_tag , tag_prefix ) ) <EOL> return pieces <EOL> pieces [ "<STR_LIT>" ] = full_tag [ len ( tag_prefix ) : ] <EOL> pieces [ "<STR_LIT>" ] = int ( mo . group ( <NUM_LIT:2> ) ) <EOL> pieces [ "<STR_LIT>" ] = mo . group ( <NUM_LIT:3> ) <EOL> else : <EOL> pieces [ "<STR_LIT>" ] = None <EOL> count_out = run_command ( GITS , [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> cwd = root ) <EOL> pieces [ "<STR_LIT>" ] = int ( count_out ) <EOL> return pieces <EOL> def plus_or_dot ( pieces ) : <EOL> """<STR_LIT>""" <EOL> if "<STR_LIT:+>" in pieces . get ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> return "<STR_LIT:.>" <EOL> return "<STR_LIT:+>" <EOL> def render_pep440 ( pieces ) : <EOL> """<STR_LIT>""" <EOL> if pieces [ "<STR_LIT>" ] : <EOL> rendered = pieces [ "<STR_LIT>" ] <EOL> if pieces [ "<STR_LIT>" ] or pieces [ "<STR_LIT>" ] : <EOL> rendered += plus_or_dot ( pieces ) <EOL> rendered += "<STR_LIT>" % ( pieces [ "<STR_LIT>" ] , pieces [ "<STR_LIT>" ] ) <EOL> if pieces [ "<STR_LIT>" ] : <EOL> rendered += "<STR_LIT>" <EOL> else : <EOL> rendered = "<STR_LIT>" % ( pieces [ "<STR_LIT>" ] , <EOL> pieces [ "<STR_LIT>" ] ) <EOL> if pieces [ "<STR_LIT>" ] : <EOL> rendered += "<STR_LIT>" <EOL> return rendered <EOL> def render_pep440_pre ( pieces ) : <EOL> """<STR_LIT>""" <EOL> if pieces [ "<STR_LIT>" ] : <EOL> rendered = pieces [ "<STR_LIT>" ] <EOL> if pieces [ "<STR_LIT>" ] : <EOL> rendered += "<STR_LIT>" % pieces [ "<STR_LIT>" ] <EOL> else : <EOL> rendered = "<STR_LIT>" % pieces [ "<STR_LIT>" ] <EOL> return rendered <EOL> def render_pep440_post ( pieces ) : <EOL> """<STR_LIT>""" <EOL> if pieces [ "<STR_LIT>" ] : <EOL> rendered = pieces [ "<STR_LIT>" ] <EOL> if pieces [ "<STR_LIT>" ] or pieces [ "<STR_LIT>" ] : <EOL> rendered += "<STR_LIT>" % pieces [ "<STR_LIT>" ] <EOL> if pieces [ "<STR_LIT>" ] : <EOL> rendered += "<STR_LIT>" <EOL> rendered += plus_or_dot ( pieces ) <EOL> rendered += "<STR_LIT>" % pieces [ "<STR_LIT>" ] <EOL> else : <EOL> rendered = "<STR_LIT>" % pieces [ "<STR_LIT>" ] <EOL> if pieces [ "<STR_LIT>" ] : <EOL> rendered += "<STR_LIT>" <EOL> rendered += "<STR_LIT>" % pieces [ "<STR_LIT>" ] <EOL> return rendered <EOL> def render_pep440_old ( pieces ) : <EOL> """<STR_LIT>""" <EOL> if pieces [ "<STR_LIT>" ] : <EOL> rendered = pieces [ "<STR_LIT>" ] <EOL> if pieces [ "<STR_LIT>" ] or pieces [ "<STR_LIT>" ] : <EOL> rendered += "<STR_LIT>" % pieces [ "<STR_LIT>" ] <EOL> if pieces [ "<STR_LIT>" ] : <EOL> rendered += "<STR_LIT>" <EOL> else : <EOL> rendered = "<STR_LIT>" % pieces [ "<STR_LIT>" ] <EOL> if pieces [ "<STR_LIT>" ] : <EOL> rendered += "<STR_LIT>" <EOL> return rendered <EOL> def render_git_describe ( pieces ) : <EOL> """<STR_LIT>""" <EOL> if pieces [ "<STR_LIT>" ] : <EOL> rendered = pieces [ "<STR_LIT>" ] <EOL> if pieces [ "<STR_LIT>" ] : <EOL> rendered += "<STR_LIT>" % ( pieces [ "<STR_LIT>" ] , pieces [ "<STR_LIT>" ] ) <EOL> else : <EOL> rendered = pieces [ "<STR_LIT>" ] <EOL> if pieces [ "<STR_LIT>" ] : <EOL> rendered += "<STR_LIT>" <EOL> return rendered <EOL> def render_git_describe_long ( pieces ) : <EOL> """<STR_LIT>""" <EOL> if pieces [ "<STR_LIT>" ] : <EOL> rendered = pieces [ "<STR_LIT>" ] <EOL> rendered += "<STR_LIT>" % ( pieces [ "<STR_LIT>" ] , pieces [ "<STR_LIT>" ] ) <EOL> else : <EOL> rendered = pieces [ "<STR_LIT>" ] <EOL> if pieces [ "<STR_LIT>" ] : <EOL> rendered += "<STR_LIT>" <EOL> return rendered <EOL> def render ( pieces , style ) : <EOL> """<STR_LIT>""" <EOL> if pieces [ "<STR_LIT:error>" ] : <EOL> return { "<STR_LIT:version>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : pieces . get ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT:error>" : pieces [ "<STR_LIT:error>" ] } <EOL> if not style or style == "<STR_LIT:default>" : <EOL> style = "<STR_LIT>" <EOL> if style == "<STR_LIT>" : <EOL> rendered = render_pep440 ( pieces ) <EOL> elif style == "<STR_LIT>" : <EOL> rendered = render_pep440_pre ( pieces ) <EOL> elif style == "<STR_LIT>" : <EOL> rendered = render_pep440_post ( pieces ) <EOL> elif style == "<STR_LIT>" : <EOL> rendered = render_pep440_old ( pieces ) <EOL> elif style == "<STR_LIT>" : <EOL> rendered = render_git_describe ( pieces ) <EOL> elif style == "<STR_LIT>" : <EOL> rendered = render_git_describe_long ( pieces ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" % style ) <EOL> return { "<STR_LIT:version>" : rendered , "<STR_LIT>" : pieces [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : pieces [ "<STR_LIT>" ] , "<STR_LIT:error>" : None } <EOL> def get_versions ( ) : <EOL> """<STR_LIT>""" <EOL> cfg = get_config ( ) <EOL> verbose = cfg . verbose <EOL> try : <EOL> return git_versions_from_keywords ( get_keywords ( ) , cfg . tag_prefix , <EOL> verbose ) <EOL> except NotThisMethod : <EOL> pass <EOL> try : <EOL> root = os . path . realpath ( __file__ ) <EOL> for i in cfg . versionfile_source . split ( '<STR_LIT:/>' ) : <EOL> root = os . path . dirname ( root ) <EOL> except NameError : <EOL> return { "<STR_LIT:version>" : "<STR_LIT>" , "<STR_LIT>" : None , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT:error>" : "<STR_LIT>" } <EOL> try : <EOL> pieces = git_pieces_from_vcs ( cfg . tag_prefix , root , verbose ) <EOL> return render ( pieces , cfg . style ) <EOL> except NotThisMethod : <EOL> pass <EOL> try : <EOL> if cfg . parentdir_prefix : <EOL> return versions_from_parentdir ( cfg . parentdir_prefix , root , verbose ) <EOL> except NotThisMethod : <EOL> pass <EOL> return { "<STR_LIT:version>" : "<STR_LIT>" , "<STR_LIT>" : None , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT:error>" : "<STR_LIT>" } </s>
