#16827: Use atomic_write in sage-preparse
-------------------------------------+-------------------------------------
Reporter: jdemeyer | Owner:
Type: defect | Status: positive_review
Priority: minor | Milestone: sage-6.4
Component: scripts | Resolution:
Keywords: | Merged in:
Authors: Jeroen Demeyer | Reviewers: Volker Braun
Report Upstream: N/A | Work issues:
Branch: | Commit:
u/jdemeyer/ticket/16827 | 8601fddda9fd3526b7c68c9e1d07485e70e759db
Dependencies: | Stopgaps:
-------------------------------------+-------------------------------------
Comment (by jhpalmieri):
I know this isn't part of this ticket, but there is a long-standing
problem with preparsing that should be easy to fix: if you happen to give
a file the same name as a Python module (which is not hard to do; I've
seen people use "new.sage" and "socket.sage" before), then the preparsed
file can shadow the actual Python module. I think a patch like this ought
to fix it:
{{{
#!diff
diff --git a/src/bin/sage-preparse b/src/bin/sage-preparse
index e2d5e9c..dff9800 100755
--- a/src/bin/sage-preparse
+++ b/src/bin/sage-preparse
@@ -86,7 +86,7 @@ def do_preparse(f, files_before=[]):
print "%s: Unknown file type %s"%(sys.argv[0], f)
sys.exit(1)
- fname = '%s.py'%f[:-5]
+ fname = '%s_preparsed.py'%f[:-5]
if os.path.exists(fname):
if AUTOGEN_MSG not in open(fname).read():
print "Refusing to overwrite existing non-autogenerated file
'%s'."%os.path.abspath(fname)
diff --git a/src/bin/sage-run b/src/bin/sage-run
index 3f2700b..638c770 100755
--- a/src/bin/sage-run
+++ b/src/bin/sage-run
@@ -20,7 +20,7 @@ if fn.startswith('-'):
if fn.endswith('.sage'):
if call(['sage-preparse', fn]) != 0:
sys.exit(1)
- os.execvp('sage-python', ['sage-python', fn[:-5] + '.py'] + opts)
+ os.execvp('sage-python', ['sage-python', fn[:-5] + '_preparsed.py'] +
opts)
elif fn.endswith('.pyx') or fn.endswith('.spyx'):
os.execvp('sage-run-cython', ['sage-run-cython', fn] + opts)
else:
}}}
Alternatively, there is another approach at #11821, which also might
prevent the race conditions discussed here: don't write the preparsed
output to a file, just use standard output.
--
Ticket URL: <http://trac.sagemath.org/ticket/16827#comment:4>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.