build: update setup.py to avoid leaving file descriptors open

This commit is contained in:
Frédéric Péters 2022-03-29 15:17:12 +02:00
parent bd19ef12ad
commit 1d0fe12899
1 changed files with 5 additions and 6 deletions

View File

@ -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(