3131def parse_mailmap (mailmap = '.mailmap' ):
3232 mapping = {}
3333 if os .path .exists (mailmap ):
34- fp = open (mailmap , 'r' )
35- for l in fp :
36- l = l .strip ()
37- if not l .startswith ('#' ) and ' ' in l :
38- canonical_email , alias = ['%s>' % x . strip () for x in
39- l . split ( '>' )][: 2 ]
40- mapping [alias ] = canonical_email
34+ with open (mailmap , 'r' ) as fp :
35+ for l in fp :
36+ l = l .strip ()
37+ if not l .startswith ('#' ) and ' ' in l :
38+ canonical_email , alias = [x for x in l . split ( ' ' )
39+ if x . startswith ( '<' ) ]
40+ mapping [alias ] = canonical_email
4141 return mapping
4242
4343
@@ -52,10 +52,10 @@ def canonicalize_emails(changelog, mapping):
5252
5353# Get requirements from the first file that exists
5454def get_reqs_from_files (requirements_files ):
55- reqs_in = []
5655 for requirements_file in requirements_files :
5756 if os .path .exists (requirements_file ):
58- return open (requirements_file , 'r' ).read ().split ('\n ' )
57+ with open (requirements_file , 'r' ) as fil :
58+ return fil .read ().split ('\n ' )
5959 return []
6060
6161
@@ -117,12 +117,8 @@ def write_requirements():
117117
118118
119119def _run_shell_command (cmd ):
120- if os .name == 'nt' :
121- output = subprocess .Popen (["cmd.exe" , "/C" , cmd ],
122- stdout = subprocess .PIPE )
123- else :
124- output = subprocess .Popen (["/bin/sh" , "-c" , cmd ],
125- stdout = subprocess .PIPE )
120+ output = subprocess .Popen (["/bin/sh" , "-c" , cmd ],
121+ stdout = subprocess .PIPE )
126122 out = output .communicate ()
127123 if len (out ) == 0 :
128124 return None
@@ -143,8 +139,14 @@ def _get_git_next_version_suffix(branch_name):
143139 if not milestonever :
144140 milestonever = ""
145141 post_version = _get_git_post_version ()
146- revno = post_version .split ("." )[- 1 ]
147- return "%s~%s.%s%s" % (milestonever , datestamp , revno_prefix , revno )
142+ # post version should look like:
143+ # 0.1.1.4.gcc9e28a
144+ # where the bit after the last . is the short sha, and the bit between
145+ # the last and second to last is the revno count
146+ (revno , sha ) = post_version .split ("." )[- 2 :]
147+ first_half = "%s~%s" % (milestonever , datestamp )
148+ second_half = "%s%s.%s" % (revno_prefix , revno , sha )
149+ return "." .join ((first_half , second_half ))
148150
149151
150152def _get_git_current_tag ():
@@ -166,39 +168,48 @@ def _get_git_post_version():
166168 cmd = "git --no-pager log --oneline"
167169 out = _run_shell_command (cmd )
168170 revno = len (out .split ("\n " ))
171+ sha = _run_shell_command ("git describe --always" )
169172 else :
170173 tag_infos = tag_info .split ("-" )
171174 base_version = "-" .join (tag_infos [:- 2 ])
172- revno = tag_infos [- 2 ]
173- return "%s.%s" % (base_version , revno )
175+ ( revno , sha ) = tag_infos [- 2 : ]
176+ return "%s.%s.%s " % (base_version , revno , sha )
174177
175178
176179def write_git_changelog ():
177180 """Write a changelog based on the git changelog."""
178- if os .path .isdir ('.git' ):
179- git_log_cmd = 'git log --stat'
180- changelog = _run_shell_command (git_log_cmd )
181- mailmap = parse_mailmap ()
182- with open ("ChangeLog" , "w" ) as changelog_file :
183- changelog_file .write (canonicalize_emails (changelog , mailmap ))
181+ new_changelog = 'ChangeLog'
182+ if not os .getenv ('SKIP_WRITE_GIT_CHANGELOG' ):
183+ if os .path .isdir ('.git' ):
184+ git_log_cmd = 'git log --stat'
185+ changelog = _run_shell_command (git_log_cmd )
186+ mailmap = parse_mailmap ()
187+ with open (new_changelog , "w" ) as changelog_file :
188+ changelog_file .write (canonicalize_emails (changelog , mailmap ))
189+ else :
190+ open (new_changelog , 'w' ).close ()
184191
185192
186193def generate_authors ():
187194 """Create AUTHORS file using git commits."""
188- jenkins_email = 'jenkins@review.openstack.org'
195+ jenkins_email = 'jenkins@review.( openstack|stackforge) .org'
189196 old_authors = 'AUTHORS.in'
190197 new_authors = 'AUTHORS'
191- if os .path .isdir ('.git' ):
192- # don't include jenkins email address in AUTHORS file
193- git_log_cmd = ("git log --format='%aN <%aE>' | sort -u | "
194- "grep -v " + jenkins_email )
195- changelog = _run_shell_command (git_log_cmd )
196- mailmap = parse_mailmap ()
197- with open (new_authors , 'w' ) as new_authors_fh :
198- new_authors_fh .write (canonicalize_emails (changelog , mailmap ))
199- if os .path .exists (old_authors ):
200- with open (old_authors , "r" ) as old_authors_fh :
201- new_authors_fh .write ('\n ' + old_authors_fh .read ())
198+ if not os .getenv ('SKIP_GENERATE_AUTHORS' ):
199+ if os .path .isdir ('.git' ):
200+ # don't include jenkins email address in AUTHORS file
201+ git_log_cmd = ("git log --format='%aN <%aE>' | sort -u | "
202+ "egrep -v '" + jenkins_email + "'" )
203+ changelog = _run_shell_command (git_log_cmd )
204+ mailmap = parse_mailmap ()
205+ with open (new_authors , 'w' ) as new_authors_fh :
206+ new_authors_fh .write (canonicalize_emails (changelog , mailmap ))
207+ if os .path .exists (old_authors ):
208+ with open (old_authors , "r" ) as old_authors_fh :
209+ new_authors_fh .write ('\n ' + old_authors_fh .read ())
210+ else :
211+ open (new_authors , 'w' ).close ()
212+
202213
203214_rst_template = """%(heading)s
204215%(underline)s
@@ -212,7 +223,7 @@ def generate_authors():
212223
213224def read_versioninfo (project ):
214225 """Read the versioninfo file. If it doesn't exist, we're in a github
215- zipball, and there's really know way to know what version we really
226+ zipball, and there's really no way to know what version we really
216227 are, but that should be ok, because the utility of that should be
217228 just about nil if this code path is in use in the first place."""
218229 versioninfo_path = os .path .join (project , 'versioninfo' )
@@ -226,7 +237,8 @@ def read_versioninfo(project):
226237
227238def write_versioninfo (project , version ):
228239 """Write a simple file containing the version of the package."""
229- open (os .path .join (project , 'versioninfo' ), 'w' ).write ("%s\n " % version )
240+ with open (os .path .join (project , 'versioninfo' ), 'w' ) as fil :
241+ fil .write ("%s\n " % version )
230242
231243
232244def get_cmdclass ():
@@ -317,7 +329,8 @@ def get_git_branchname():
317329
318330
319331def get_pre_version (projectname , base_version ):
320- """Return a version which is based"""
332+ """Return a version which is leading up to a version that will
333+ be released in the future."""
321334 if os .path .isdir ('.git' ):
322335 current_tag = _get_git_current_tag ()
323336 if current_tag is not None :
@@ -329,10 +342,10 @@ def get_pre_version(projectname, base_version):
329342 version_suffix = _get_git_next_version_suffix (branch_name )
330343 version = "%s~%s" % (base_version , version_suffix )
331344 write_versioninfo (projectname , version )
332- return version . split ( '~' )[ 0 ]
345+ return version
333346 else :
334347 version = read_versioninfo (projectname )
335- return version . split ( '~' )[ 0 ]
348+ return version
336349
337350
338351def get_post_version (projectname ):
0 commit comments