1. pygame
  2. Untitled project
  3. pygame

Commits

Lenard Lindstrom  committed ea8244e

Automatically generate the version module with setup.py

The version.py module is now written by setup.py during a build. This means,
for the Pygame code, only the 'version' tag within setup.py needs to be
changed. Also, a revision number, 'rev', is added to the version module.
This gives the hg identifier of the build. It is automatically determined
by setup.py.

  • Participants
  • Parent commits a6f8974
  • Branches default

Comments (0)

Files changed (6)

File .hgignore

View file
  • Ignore whitespace
 docs/index.html
 docs/ref/*.html
 docs/tut/SpriteIntro.html
+lib/version.py

File docs/reST/ref/pygame.rst

View file
  • Ignore whitespace
 
    .. ## pygame.version.vernum ##
 
+.. data:: rev
+
+   | :sl:`repository revision of the build`
+   | :sg:`rev = 'a6f89747b551+'`
+
+   The Mercurial node identifier of the repository checkout from which this
+   package was built. If the identifier ends with a plus sign '+' then the
+   package contains uncommitted changes. Please include this revision number
+   in bug reports, especially for non-release Pygame builds.
+
 .. ## pygame.version ##
 
 .. ## pygame ##

File lib/version.py

  • Ignore whitespace
-##    pygame - Python Game Library
-##    Copyright (C) 2000-2003  Pete Shinners
-##
-##    This library is free software; you can redistribute it and/or
-##    modify it under the terms of the GNU Library General Public
-##    License as published by the Free Software Foundation; either
-##    version 2 of the License, or (at your option) any later version.
-##
-##    This library is distributed in the hope that it will be useful,
-##    but WITHOUT ANY WARRANTY; without even the implied warranty of
-##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-##    Library General Public License for more details.
-##
-##    You should have received a copy of the GNU Library General Public
-##    License along with this library; if not, write to the Free
-##    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-##
-##    Pete Shinners
-##    pete@shinners.org
-
-"""Simply the current installed pygame version. The version information is
-stored in the regular pygame module as 'pygame.ver'. Keeping the version
-information also available in a separate module allows you to test the
-pygame version without importing the main pygame module.
-
-The python version information should always compare greater than any previous
-releases. (hmm, until we get to versions > 10)
-"""
-
-ver =   '1.9.2a0'
-vernum = 1,9,2

File setup.py

View file
  • Ignore whitespace
 from distutils.extension import read_setup_file
 from distutils.command.install_data import install_data
 
+# Retrieve the repository revision (HG node identifier), if possible.
+def get_hg_identifier():
+    from subprocess import Popen, PIPE
+
+    ident = ""
+    try:
+        p = Popen(['hg', 'identify', '-i'], stdout=PIPE, stderr=PIPE)
+        stdout, stderr = p.communicate()
+        if stdout and not stderr:
+            ident = stdout.decode('ascii').rstrip('\n')
+    except Exception:
+        pass
+    return ident
+
+revision = get_hg_identifier()
+
 # Python 3.0 patch
 if sys.version_info[0:2] == (3, 0):
     import distutils.version
                         ['*.txt',
                          ['ref',
                             ['*.txt']]]]]])
+
+#generate the version module
+def parse_version(ver):
+    from re import findall
+    return ', '.join(s for s in findall('\d+', ver)[0:3])
+
+def write_version_module(pygame_version, revision):
+    vernum = parse_version(pygame_version)
+    with open('version.py.in', 'r') as header_file:
+        header = header_file.read()
+    with open(os.path.join('lib', 'version.py'), 'w') as version_file:
+        version_file.write(header)
+        version_file.write('ver = "' + pygame_version + '"\n')
+        version_file.write('vernum = ' + vernum + '\n')
+        version_file.write('rev = "' + revision + '"\n')
+
+write_version_module(METADATA['version'], revision)
               
 #required. This will be filled if doing a Windows build.
 cmdclass = {}

File src/doc/pygame_doc.h

View file
  • Ignore whitespace
 
 #define DOC_PYGAMEVERSIONVERNUM "vernum = (1, 5, 3)\ntupled integers of the version"
 
+#define DOC_PYGAMEVERSIONREV "rev = 'a6f89747b551+'\nrepository revision of the build"
+
 
 
 /* Docs in a comment... slightly easier to read. */
  vernum = (1, 5, 3)
 tupled integers of the version
 
+pygame.version.rev
+ rev = 'a6f89747b551+'
+repository revision of the build
+
 */

File version.py.in

View file
  • Ignore whitespace
+##    pygame - Python Game Library
+##    Copyright (C) 2000-2003  Pete Shinners
+##
+##    This library is free software; you can redistribute it and/or
+##    modify it under the terms of the GNU Library General Public
+##    License as published by the Free Software Foundation; either
+##    version 2 of the License, or (at your option) any later version.
+##
+##    This library is distributed in the hope that it will be useful,
+##    but WITHOUT ANY WARRANTY; without even the implied warranty of
+##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+##    Library General Public License for more details.
+##
+##    You should have received a copy of the GNU Library General Public
+##    License along with this library; if not, write to the Free
+##    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+##
+##    Pete Shinners
+##    pete@shinners.org
+
+"""Simply the current installed pygame version. The version information is
+stored in the regular pygame module as 'pygame.ver'. Keeping the version
+information also available in a separate module allows you to test the
+pygame version without importing the main pygame module.
+
+The python version information should always compare greater than any previous
+releases. (hmm, until we get to versions > 10)
+"""
+