<s> """<STR_LIT>""" <EOL> import sys <EOL> import os <EOL> import re <EOL> from datetime import datetime , date <EOL> from subprocess import Popen , PIPE <EOL> _date_clean_re = re . compile ( r'<STR_LIT>' ) <EOL> def parse_changelog ( ) : <EOL> with open ( '<STR_LIT>' ) as f : <EOL> lineiter = iter ( f ) <EOL> for line in lineiter : <EOL> match = re . search ( '<STR_LIT>' , line . strip ( ) ) <EOL> if match is None : <EOL> continue <EOL> length = len ( match . group ( <NUM_LIT:1> ) ) <EOL> version = match . group ( <NUM_LIT:1> ) . strip ( ) <EOL> if lineiter . next ( ) . count ( '<STR_LIT:->' ) != len ( match . group ( <NUM_LIT:0> ) ) : <EOL> continue <EOL> while <NUM_LIT:1> : <EOL> change_info = lineiter . next ( ) . strip ( ) <EOL> if change_info : <EOL> break <EOL> match = re . search ( r'<STR_LIT>' <EOL> r'<STR_LIT>' , change_info ) <EOL> if match is None : <EOL> continue <EOL> datestr , codename = match . groups ( ) <EOL> return version , parse_date ( datestr ) , codename <EOL> def bump_version ( version ) : <EOL> try : <EOL> parts = map ( int , version . split ( '<STR_LIT:.>' ) ) <EOL> except ValueError : <EOL> fail ( '<STR_LIT>' ) <EOL> if parts [ - <NUM_LIT:1> ] != <NUM_LIT:0> : <EOL> parts [ - <NUM_LIT:1> ] += <NUM_LIT:1> <EOL> else : <EOL> parts [ <NUM_LIT:0> ] += <NUM_LIT:1> <EOL> return '<STR_LIT:.>' . join ( map ( str , parts ) ) <EOL> def parse_date ( string ) : <EOL> string = _date_clean_re . sub ( r'<STR_LIT>' , string ) <EOL> return datetime . strptime ( string , '<STR_LIT>' ) <EOL> def set_filename_version ( filename , version_number , pattern ) : <EOL> changed = [ ] <EOL> def inject_version ( match ) : <EOL> before , old , after = match . groups ( ) <EOL> changed . append ( True ) <EOL> return before + version_number + after <EOL> with open ( filename ) as f : <EOL> contents = re . sub ( r"<STR_LIT>" % pattern , <EOL> inject_version , f . read ( ) ) <EOL> if not changed : <EOL> fail ( '<STR_LIT>' , pattern , filename ) <EOL> with open ( filename , '<STR_LIT:w>' ) as f : <EOL> f . write ( contents ) <EOL> def set_init_version ( version ) : <EOL> info ( '<STR_LIT>' , version ) <EOL> set_filename_version ( '<STR_LIT>' , version , '<STR_LIT>' ) <EOL> def set_setup_version ( version ) : <EOL> info ( '<STR_LIT>' , version ) <EOL> set_filename_version ( '<STR_LIT>' , version , '<STR_LIT:version>' ) <EOL> def build_and_upload ( ) : <EOL> Popen ( [ sys . executable , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) . wait ( ) <EOL> def fail ( message , * args ) : <EOL> print >> sys . stderr , '<STR_LIT>' , message % args <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> def info ( message , * args ) : <EOL> print >> sys . stderr , message % args <EOL> def get_git_tags ( ) : <EOL> return set ( Popen ( [ '<STR_LIT>' , '<STR_LIT>' ] , stdout = PIPE ) . communicate ( ) [ <NUM_LIT:0> ] . splitlines ( ) ) <EOL> def git_is_clean ( ) : <EOL> return Popen ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) . wait ( ) == <NUM_LIT:0> <EOL> def make_git_commit ( message , * args ) : <EOL> message = message % args <EOL> Popen ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , message ] ) . wait ( ) <EOL> def make_git_tag ( tag ) : <EOL> info ( '<STR_LIT>' , tag ) <EOL> Popen ( [ '<STR_LIT>' , '<STR_LIT>' , tag ] ) . wait ( ) <EOL> def main ( ) : <EOL> os . chdir ( os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT:..>' ) ) <EOL> rv = parse_changelog ( ) <EOL> if rv is None : <EOL> fail ( '<STR_LIT>' ) <EOL> version , release_date , codename = rv <EOL> dev_version = bump_version ( version ) + '<STR_LIT>' <EOL> info ( '<STR_LIT>' , <EOL> version , codename , release_date . strftime ( '<STR_LIT>' ) ) <EOL> tags = get_git_tags ( ) <EOL> if version in tags : <EOL> fail ( '<STR_LIT>' , version ) <EOL> if release_date . date ( ) != date . today ( ) : <EOL> fail ( '<STR_LIT>' % ( release_date . date ( ) , date . today ( ) ) ) <EOL> if not git_is_clean ( ) : <EOL> fail ( '<STR_LIT>' ) <EOL> set_init_version ( version ) <EOL> set_setup_version ( version ) <EOL> make_git_commit ( '<STR_LIT>' , version ) <EOL> make_git_tag ( version ) <EOL> build_and_upload ( ) <EOL> set_init_version ( dev_version ) <EOL> set_setup_version ( dev_version ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
