From 1d0fe128994f431081e8e7983f060666f87124b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 29 Mar 2022 15:17:12 +0200 Subject: [PATCH] build: update setup.py to avoid leaving file descriptors open --- setup.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index 6753680..e8d1279 100644 --- a/setup.py +++ b/setup.py @@ -17,20 +17,19 @@ class eo_sdist(sdist): if os.path.exists('VERSION'): os.remove('VERSION') version = get_version() - version_file = open('VERSION', 'w') - version_file.write(version) - version_file.close() + with open('VERSION', 'w') as fd: + fd.write(version) sdist.run(self) if os.path.exists('VERSION'): os.remove('VERSION') def get_version(): - '''Use the VERSION, if absent generates a version with git describe, if not + """Use the VERSION, if absent generates a version with git describe, if not tag exists, take 0.0- and add the length of the commit log. - ''' + """ if os.path.exists('VERSION'): - with open('VERSION', 'r') as v: + with open('VERSION') as v: return v.read() if os.path.exists('.git'): p = subprocess.Popen(