setup: use try/except/finally
authorMatt Mackall <mpm@selenic.com>
Fri, 15 May 2015 10:00:46 -0500
changeset 25089 c6427cd45760
parent 25088 754df8e932d3
child 25090 252412e24551
setup: use try/except/finally This will raise a syntax error for people who attempt to use Py2.4, but that's already going to fail and we have no way to keep other 2.6isms from creeping in since we've removed the check-code rules and the buildbot.
setup.py
--- a/setup.py	Fri May 15 09:58:21 2015 -0500
+++ b/setup.py	Fri May 15 10:00:46 2015 -0500
@@ -106,25 +106,24 @@
     tmpdir = tempfile.mkdtemp(prefix='hg-install-')
     devnull = oldstderr = None
     try:
-        try:
-            fname = os.path.join(tmpdir, 'funcname.c')
-            f = open(fname, 'w')
-            f.write('int main(void) {\n')
-            f.write('    %s();\n' % funcname)
-            f.write('}\n')
-            f.close()
-            # Redirect stderr to /dev/null to hide any error messages
-            # from the compiler.
-            # This will have to be changed if we ever have to check
-            # for a function on Windows.
-            devnull = open('/dev/null', 'w')
-            oldstderr = os.dup(sys.stderr.fileno())
-            os.dup2(devnull.fileno(), sys.stderr.fileno())
-            objects = cc.compile([fname], output_dir=tmpdir)
-            cc.link_executable(objects, os.path.join(tmpdir, "a.out"))
-        except Exception:
-            return False
+        fname = os.path.join(tmpdir, 'funcname.c')
+        f = open(fname, 'w')
+        f.write('int main(void) {\n')
+        f.write('    %s();\n' % funcname)
+        f.write('}\n')
+        f.close()
+        # Redirect stderr to /dev/null to hide any error messages
+        # from the compiler.
+        # This will have to be changed if we ever have to check
+        # for a function on Windows.
+        devnull = open('/dev/null', 'w')
+        oldstderr = os.dup(sys.stderr.fileno())
+        os.dup2(devnull.fileno(), sys.stderr.fileno())
+        objects = cc.compile([fname], output_dir=tmpdir)
+        cc.link_executable(objects, os.path.join(tmpdir, "a.out"))
         return True
+    except Exception:
+        return False
     finally:
         if oldstderr is not None:
             os.dup2(oldstderr, sys.stderr.fileno())