Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

harcoded tmp folder prevent windows compatibilty of past module #296

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/past/translation/__init__.py
Expand Up @@ -38,6 +38,7 @@
import os
import sys
import copy
import tempfile
from lib2to3.pgen2.parse import ParseError
from lib2to3.refactor import RefactoringTool

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesnt actually work. The existing code assumes that the futurized_code.py is in the same path as above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 -- it might make sense to call tempfile.mkdtemp() once during test setup, refer to it throughout, and delete on cleanup.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #335

f.write('### Futurized code (from %s)\n%s' %
(self.pathname, source))

Expand Down