diff --git a/src/past/translation/__init__.py b/src/past/translation/__init__.py index 7b21d9f5..73b25746 100644 --- a/src/past/translation/__init__.py +++ b/src/past/translation/__init__.py @@ -38,6 +38,7 @@ import os import sys import copy +import tempfile from lib2to3.pgen2.parse import ParseError from lib2to3.refactor import RefactoringTool @@ -219,20 +220,20 @@ def detect_python2(source, pathname): if source != str(tree)[:-1]: # remove added newline # The above fixers made changes, so we conclude it's Python 2 code logger.debug('Detected Python 2 code: {0}'.format(pathname)) - with open('/tmp/original_code.py', 'w') as f: + with open(os.path.join(tempfile.mkdtemp(),'original_code.py'), 'w') as f: f.write('### Original code (detected as py2): %s\n%s' % (pathname, source)) - with open('/tmp/py2_detection_code.py', 'w') as f: + with open(os.path.join(tempfile.mkdtemp(),'py2_detection_code.py'), 'w') as f: f.write('### Code after running py3 detection (from %s)\n%s' % (pathname, str(tree)[:-1])) return True else: logger.debug('Detected Python 3 code: {0}'.format(pathname)) - with open('/tmp/original_code.py', 'w') as f: + with open(os.path.join(tempfile.mkdtemp(),'original_code.py'), 'w') as f: f.write('### Original code (detected as py3): %s\n%s' % (pathname, source)) try: - os.remove('/tmp/futurize_code.py') + os.remove(os.path.join(tempfile.mkdtemp(),'futurize_code.py')) except OSError: pass return False @@ -395,7 +396,7 @@ def load_module(self, fullname): if detect_python2(source, self.pathname): source = self.transform(source) - with open('/tmp/futurized_code.py', 'w') as f: + with open(os.path.join(tempfile.mkdtemp(),'futurized_code.py'), 'w') as f: f.write('### Futurized code (from %s)\n%s' % (self.pathname, source))