From 962664bbb8564ccd3cff8072f20d56a9bdcf3043 Mon Sep 17 00:00:00 2001 From: Arfrever Frehtes Taifersar Arahesis Date: Sat, 15 Feb 2014 22:35:49 +0100 Subject: Use tempfile.TemporaryDirectory() with Python >=3.2. --- setuptools/svn_utils.py | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) (limited to 'setuptools/svn_utils.py') diff --git a/setuptools/svn_utils.py b/setuptools/svn_utils.py index e1d336e2..d62fecd0 100644 --- a/setuptools/svn_utils.py +++ b/setuptools/svn_utils.py @@ -5,12 +5,12 @@ from distutils import log import xml.dom.pulldom import shlex import shutil -import tempfile import locale import codecs import unicodedata import warnings from setuptools.compat import unicode +from setuptools.py31compat import TemporaryDirectory from xml.sax.saxutils import unescape try: @@ -29,26 +29,6 @@ from subprocess import Popen as _Popen, PIPE as _PIPE # http://stackoverflow.com/questions/5658622/ # python-subprocess-popen-environment-path -class TempDir(object): - """" - Very simple temporary directory context manager. - Will try to delete afterward, but will also ignore OS and similar - errors on deletion. - """ - def __init__(self): - self.path = None - - def __enter__(self): - self.path = tempfile.mkdtemp() - return self - - def __exit__(self, exctype, excvalue, exctrace): - try: - shutil.rmtree(self.path, True) - except OSError: #removal errors are not the only possible - pass - self.path = None - def _run_command(args, stdout=_PIPE, stderr=_PIPE, encoding=None, stream=0): #regarding the shell argument, see: http://bugs.python.org/issue8557 try: @@ -256,9 +236,9 @@ class SvnInfo(object): # This is needed because .svn always creates .subversion and # some operating systems do not handle dot directory correctly. # Real queries in real svn repos with be concerned with it creation - with TempDir() as tempdir: + with TemporaryDirectory() as tempdir: code, data = _run_command(['svn', - '--config-dir', tempdir.path, + '--config-dir', tempdir, '--version', '--quiet']) @@ -282,9 +262,9 @@ class SvnInfo(object): # This is needed because .svn always creates .subversion and # some operating systems do not handle dot directory correctly. # Real queries in real svn repos with be concerned with it creation - with TempDir() as tempdir: + with TemporaryDirectory() as tempdir: code, data = _run_command(['svn', - '--config-dir', tempdir.path, + '--config-dir', tempdir, 'info', normdir]) # Must check for some contents, as some use empty directories -- cgit v1.2.1