setup.py

changeset 7785
9978016560ec
parent 7781
607a6098cb44
child 7800
96fae5353698
--- a/setup.py	Tue Oct 13 19:02:26 2020 +0200
+++ b/setup.py	Wed Oct 14 17:50:39 2020 +0200
@@ -145,16 +145,14 @@
         hgOut = hgOut.strip()
         if hgOut.endswith("+"):
             hgOut = hgOut[:-1]
-        f = open(fileName + ".orig", "r", encoding="utf-8")
-        text = f.read()
-        f.close()
+        with open(fileName + ".orig", "r", encoding="utf-8") as f:
+            text = f.read()
         text = (
             text.replace("@@REVISION@@", hgOut)
             .replace("@@VERSION@@", version)
         )
-        f = open(fileName, "w")
-        f.write(text)
-        f.close()
+        with open(fileName, "w") as f:
+            f.write(text)
     else:
         shutil.copy(fileName + ".orig", fileName)
 
@@ -173,16 +171,14 @@
         os.rename(fileName, fileName + ".orig")
     except EnvironmentError:
         pass
-    f = open(fileName + ".orig", "r", encoding="utf-8")
-    text = f.read()
-    f.close()
+    with open(fileName + ".orig", "r", encoding="utf-8") as f:
+        text = f.read()
     text = (
         text.replace("@VERSION@", version)
         .replace("@DATE@", datetime.date.today().isoformat())
     )
-    f = open(fileName, "w")
-    f.write(text)
-    f.close()
+    with open(fileName, "w") as f:
+        f.write(text)
 
 
 def cleanupSource(dirName):

eric ide

mercurial