Skip to content
Permalink
Browse files

Python 2.7 doesn't have TemporaryDirectory

  • Loading branch information...
RobinD42 committed Jun 22, 2019
1 parent a2f6c4b commit ef81730d8a157d650bf484f0fc8fb0c2edde5eb3
Showing with 22 additions and 3 deletions.
  1. +4 −3 build.py
  2. +18 −0 buildtools/config.py
@@ -34,7 +34,8 @@
phoenixDir, wxDir, copyIfNewer, copyFile, \
macSetLoaderNames, \
getVcsRev, runcmd, textfile_open, getSipFiles, \
getVisCVersion, getToolsPlatformName, updateLicenseFiles
getVisCVersion, getToolsPlatformName, updateLicenseFiles, \
TemporaryDirectory

import buildtools.version as version

@@ -837,7 +838,7 @@ def do_regenerate_sysconfig():
TODO: Can this be done in a way that doesn't require overwriting a file in
the environment?
"""
with tempfile.TemporaryDirectory() as td:
with TemporaryDirectory() as td:
pwd = pushDir(td)

# generate a new sysconfig data file
@@ -846,7 +847,7 @@ def do_regenerate_sysconfig():

# On success the new data module will have been written to a subfolder
# of the current folder, which is recorded in ./pybuilddir.tx
with open('pybuilddir.txt', 'r', encoding='utf-8') as fp:
with open('pybuilddir.txt', 'r') as fp:
pybd = fp.read()

# grab the file in that folder and copy it into the Python lib
@@ -970,3 +970,21 @@ def updateLicenseFiles(cfg):
text += f.read() + '\n\n'
with open('LICENSE.txt', 'w') as f:
f.write(text)

try:
from tempfile import TemporaryDirectory
except ImportError:
from tempfile import mkdtemp

class TemporaryDirectory(object):
def __init__(self, suffix='', prefix='tmp', dir=None):
self.name = mkdtemp(suffix, prefix, dir)

def __enter__(self):
return self.name

def __exit__(self, exc, value, tb):
self.cleanup()

def cleanup(self):
shutil.rmtree(self.name)

0 comments on commit ef81730

Please sign in to comment.
You can’t perform that action at this time.