sagemath/sage

Creation of temporary files with %attach

Closed this issue · 18 comments

Using sage-5.7.beta4 and sage-5.7.rc0, when attaching a .sage file, sage creates spurious files in the current directory. For example

sage: %attach blah.sage

creates blah.sageYPVh in the current directory.

Depends on #14523

CC: @ppurka @sagetrac-tmonteil @hughrthomas @sagetrac-okazymyrov

Component: user interface

Reviewer: Volker Braun

Issue created by migration from https://trac.sagemath.org/ticket/14149

comment:1

See also #14169.

comment:3

Bump.

It seems like it should be possible to create these temporary files in ~/.sage or something similar. Where is the code for %attach kept? I could possibly start poking around.

comment:8

Fixed in #14523

Author: Volker Braun

comment:9

@Volker: Could you explain where the code was that was producing these funny file names? I'm happy that it's fixed in #14523 (thank you!) but I don't see where it gets fixed. Sorry if the question seems like a waste of time -- I spent a fair while trying to figure out where this was happening, and I couldn't find it. Thanks!

comment:10

The attach debug mode is off by default now (see load_attach_mode?).

comment:11

Replying to @vbraun:

The attach debug mode is off by default now (see load_attach_mode?).

I completely disagree with this fix. See this discussion and #11812.

comment:12

Replying to @mstreng:

I completely disagree with this fix.

In fact, I would just switch "debug mode" back on in my startup file, but I would still want to get rid of the temporary files, so I would not call this a fix at all.

How about doing all of the following?

  • put temporary files in one subfolder (to keep the main folder as clean as possible)
  • remove or overwrite old temporary files when reloading attached files (to keep the folder with temporary files as clean as possible)
  • remove temporary files when exiting sage (obviously)

That only leaves one temporary file for each .sage file. It is there only during the Sage session. It remains afterwards only when Sage exits incorrectly, and it is in a subdirectory, so can be removed easily.

comment:13

If that is the desired outcome then it would have been nice to doctest it.

Littering subdirectories with files in them into the file system is just as bad as spewing random temp files into cwd. Temp files should go into the sage temp directory.

Still, the correct fix is to make execution of in-memory code produce correct tracebacks.

comment:14

Replying to @vbraun:

If that is the desired outcome then it would have been nice to doctest it.

I tried to doctest tracebacks, but could not find a way (see #11812).

Littering subdirectories with files in them into the file system is just as bad as spewing random temp files into cwd. Temp files should go into the sage temp directory.

Originally (before #7514 and again at #11812), temp directories were used for the preparsed .py files. The location changed later. I don't know when or why; maybe at #13579 because of security problems?

Still, the correct fix is to make execution of in-memory code produce correct tracebacks.

Yes, that would be best. Much better than my solution above, and much better than what was done at #11812. But how? I would like to see the name of the .sage file, and multi-line code snippets including line numbers.

comment:15

I've added a doctest for the desired behavior in #14523 (traceback showing source)

comment:16

Anybody who doesn't like temporary files littering the fs feel like reviewing this ticket?

comment:17

There are no attachments. What exactly are we supposed to review?

comment:18

Oops, posted this in the wrong ticket. I meant #14523. This ticket should be closed as duplicate, I think.

comment:19

#14523 does fix creating the temp files.

Changed author from Volker Braun to none

Reviewer: Volker Braun

Dependencies: #14523