From 24315e75a4e38152bc08af26a36253f2e4717bc7 Mon Sep 17 00:00:00 2001 From: Benjamin Fuchs Date: Thu, 3 Jan 2019 23:17:29 +0100 Subject: [PATCH 1/2] Replace custom atomicWrite by more robust library call. --- clcache/__main__.py | 13 +++---------- setup.py | 1 + 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/clcache/__main__.py b/clcache/__main__.py index 7b56381b..5396ba63 100644 --- a/clcache/__main__.py +++ b/clcache/__main__.py @@ -6,6 +6,7 @@ # full text of which is available in the accompanying LICENSE file at the # root directory of this project. # +from atomicwrites import atomic_write from collections import defaultdict, namedtuple from ctypes import windll, wintypes from shutil import copyfile, copyfileobj, rmtree, which @@ -117,14 +118,6 @@ def normalizeBaseDir(baseDir): return None -@contextlib.contextmanager -def atomicWrite(fileName): - tempFileName = fileName + '.new' - with open(tempFileName, 'w') as f: - yield f - os.replace(tempFileName, fileName) - - def getCachedCompilerConsoleOutput(path): try: with open(path, 'rb') as f: @@ -198,7 +191,7 @@ def setManifest(self, manifestHash, manifest): manifestPath = self.manifestPath(manifestHash) printTraceStatement("Writing manifest with manifestHash = {} to {}".format(manifestHash, manifestPath)) ensureDirectoryExists(self.manifestSectionDir) - with atomicWrite(manifestPath) as outFile: + with atomic_write(manifestPath, overwrite=True) as outFile: # Converting namedtuple to JSON via OrderedDict preserves key names and keys order entries = [e._asdict() for e in manifest.entries()] jsonobject = {'entries': entries} @@ -662,7 +655,7 @@ def __init__(self, fileName): def save(self): if self._dirty: - with atomicWrite(self._fileName) as f: + with atomic_write(self._fileName, overwrite=True) as f: json.dump(self._dict, f, sort_keys=True, indent=4) def __setitem__(self, key, value): diff --git a/setup.py b/setup.py index 6804caf8..890107bb 100644 --- a/setup.py +++ b/setup.py @@ -16,6 +16,7 @@ install_requires=[ 'typing; python_version < "3.5"', 'subprocess.run; python_version < "3.5"', + 'atomicwrites', 'pymemcache', 'pyuv', ], From e04acc6ea637d60066292922e7efcb10c024e036 Mon Sep 17 00:00:00 2001 From: Benjamin Fuchs Date: Fri, 4 Jan 2019 13:26:09 +0100 Subject: [PATCH 2/2] Reordering imports in __main__.py --- clcache/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clcache/__main__.py b/clcache/__main__.py index 5396ba63..94af73f1 100644 --- a/clcache/__main__.py +++ b/clcache/__main__.py @@ -6,7 +6,6 @@ # full text of which is available in the accompanying LICENSE file at the # root directory of this project. # -from atomicwrites import atomic_write from collections import defaultdict, namedtuple from ctypes import windll, wintypes from shutil import copyfile, copyfileobj, rmtree, which @@ -27,6 +26,7 @@ import threading from tempfile import TemporaryFile from typing import Any, List, Tuple, Iterator +from atomicwrites import atomic_write VERSION = "4.2.0-dev"