[Python-checkins] distutils2: Refactoring the way we write the distutils setup.py.

tarek.ziade python-checkins at python.org
Wed Feb 16 22:23:55 CET 2011


tarek.ziade pushed c0ca4120182c to distutils2:

http://hg.python.org/distutils2/rev/c0ca4120182c
changeset:   989:c0ca4120182c
parent:      976:69240ad43f64
user:        Julien Miotte <miotte.julien at gmail.com>
date:        Mon Jan 31 17:32:43 2011 +0100
summary:
  Refactoring the way we write the distutils setup.py.

Using the :
    handle = open()
    try:
        ...
    finally:
        handle.close()
as advised by Eric Araujo.

Also, instead of several calling to handle.write(), use a multi-line string.

files:
  distutils2/util.py

diff --git a/distutils2/util.py b/distutils2/util.py
--- a/distutils2/util.py
+++ b/distutils2/util.py
@@ -1156,12 +1156,18 @@
         raise DistutilsFileError("A pre existing setup.py file exists")
 
     handle = open("setup.py", "w")
-    handle.write("# Distutils script using distutils2 setup.cfg to call the\n")
-    handle.write("# distutils.core.setup() with the right args.\n\n\n")
-    handle.write("import os\n")
-    handle.write("from distutils.core import setup\n")
-    handle.write("from ConfigParser import RawConfigParser\n\n")
-    handle.write(getsource(generate_distutils_kwargs_from_setup_cfg))
-    handle.write("\n\nkwargs = generate_distutils_kwargs_from_setup_cfg()\n")
-    handle.write("setup(**kwargs)")
-    handle.close()
+    try:
+        handle.write(
+            "# Distutils script using distutils2 setup.cfg to call the\n"
+            "# distutils.core.setup() with the right args.\n\n"
+            "import os\n"
+            "from distutils.core import setup\n"
+            "from ConfigParser import RawConfigParser\n\n"
+            "" + getsource(generate_distutils_kwargs_from_setup_cfg) + "\n\n"
+            "kwargs = generate_distutils_kwargs_from_setup_cfg()\n"
+            "setup(**kwargs)\n"
+        )
+    finally:
+        handle.close()
+
+generate_distutils_setup_py()

--
Repository URL: http://hg.python.org/distutils2


More information about the Python-checkins mailing list