From 4a7f00a95f8b48d809bc71da206f36dba8fca940 Mon Sep 17 00:00:00 2001
From: David Cournapeau <cournape@gmail.com>
Date: Mon, 2 Nov 2009 23:35:21 +0900
Subject: [PATCH 1/3] REF: factor out function to wrote pywin32.version.txt.

---
 setup.py |   19 +++++++++++--------
 1 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/setup.py b/setup.py
index 294ef4f..195eaf0 100644
--- a/setup.py
+++ b/setup.py
@@ -590,18 +590,21 @@ if do_2to3:
 else:
     my_build_scripts = build_scripts
 
+def write_pywin32_version():
+    # write a pywin32.version.txt.
+    ver_fname = os.path.join(os.environ['temp'], "pywin32.version.txt")
+    try:
+        f = open(ver_fname, "w")
+        f.write("%s\n" % build_id)
+        f.close()
+    except EnvironmentError, why:
+        print "Failed to open '%s': %s" % (ver_fname, why)
+
 # 'build' command
 class my_build(build):
     def run(self):
         build.run(self)
-        # write a pywin32.version.txt.
-        ver_fname = os.path.join(os.environ['temp'], "pywin32.version.txt")
-        try:
-            f = open(ver_fname, "w")
-            f.write("%s\n" % build_id)
-            f.close()
-        except EnvironmentError, why:
-            print "Failed to open '%s': %s" % (ver_fname, why)
+        write_pywin32_version()
 
 class my_build_ext(build_ext):
 
-- 
1.6.4.msysgit.0


From df7cdac7f7646a2884200822c6779ffe89cdd7b5 Mon Sep 17 00:00:00 2001
From: David Cournapeau <cournape@gmail.com>
Date: Mon, 2 Nov 2009 23:35:54 +0900
Subject: [PATCH 2/3] Create a custom bdist_egg command to generate pywin32.version.txt

The build command is not called when the command bdist_egg is executed, to we
make sure to generate the version file in the bdist_egg command  when building
with setuptools. The behavior is unchanged if setup.py is executed by itself
(pure distutils), and only changed when executed from setupegg.py (setuptools).
---
 setup.py |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/setup.py b/setup.py
index 195eaf0..8121557 100644
--- a/setup.py
+++ b/setup.py
@@ -2049,6 +2049,16 @@ cmdclass = { 'install': my_install,
              'build_scripts' : my_build_scripts,
            }
 
+if 'setuptools' in sys.modules:
+    from setuptools.command.bdist_egg import bdist_egg
+
+    class my_bdist_egg(bdist_egg):
+        def run(self):
+            write_pywin32_version()
+            bdist_egg.run(self)
+
+    cmdclass['bdist_egg'] = my_bdist_egg
+
 dist = setup(name="pywin32",
       version=str(build_id),
       description="Python for Window Extensions",
-- 
1.6.4.msysgit.0


From 78ab5ca2e1fa760c20f2809a0b1ef6bcebaf940b Mon Sep 17 00:00:00 2001
From: David Cournapeau <cournape@gmail.com>
Date: Mon, 2 Nov 2009 23:38:29 +0900
Subject: [PATCH 3/3] ENH: add a setupegg to execute the build under setuptools context.

---
 setupegg.py |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
 create mode 100644 setupegg.py

diff --git a/setupegg.py b/setupegg.py
new file mode 100644
index 0000000..cf97861
--- /dev/null
+++ b/setupegg.py
@@ -0,0 +1,4 @@
+#!/usr/bin/env python
+"""Wrapper to run setup.py using setuptools."""
+import setuptools
+execfile('setup.py')
-- 
1.6.4.msysgit.0

