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
%%script and %%file magics #1855
Conversation
Configurables don't allow positional args to init, and HasTraits classes don't identify as `type`.
Base %%script magic, and add wrappers for a few common interpreters. The list of wrapped magics is configurable.
about I don't see nice workaound, all have drabacks
Also maybe we can add an option to %load that load the file in next cell, without stripping the first two line and prepend I guess the best would be not a %%file magic, but a real file cell, that could compare it's content to the content of a on disk file. |
%%file is implemented at the request of @ellisonbg on the list, and meant for quickly writing csv data, etc. I imagine it would be like %loadpy, in that it's usually a one-time use magic, that likely wouldn't persist across many runs of a notebook. Prompt for overwrite makes the most sense as default action, but the notebook still doesn't support stdin, so it won't help there. |
It does not prevent it from beeing misused by user to write anything on the disk. |
I think that adds a great deal of unnecessary complexity and state with no real benefit. It would also be confusing to use open/close to mean something other than opening and closing files. Prompt to overwrite covers safety and efficiency in a standard, totally expected way. We will just have to wait for the notebook to support stdin before it can behave as well as other Interfaces. |
I still think people will see What made me come with |
I agree that people will probably start using it as a lightweight editor, but I don't much mind them using |
My initial thought is to do away with the |
I could go the same way as %reset, using ask_yes_no, defaulting to yes on StdinNotImplemented. That seems to make the most sense averaging across environments. I don't expect people would use I also agree with @ellisonbg and @takluyver that force overwrite with this magic is not problematic, because intent is clear. |
I added ask_yes_no like %reset, so I also added |
If you read the doc. For me If it is so temporary, maybe it could then write the file to a real temp location, and return a handle or a path to it.
or
If you give the user a magic that takes a filename to write on as argument, they will use it to edit any kind of files, by doing a |
If you give someone a notebook with the cell: with open ("filename", 'w') as f:
f.write('garbage') or You have the exact same data loss problem. Should we disallow write-access to the filesystem? I really don't see a need to protect people from themselves this much.
The file is not temporary, but the use of the magic is, just like %loadpy. %loadpy is a run-once magic for initializing a cell. It doesn't make sense to keep it in your notebook (except for demonstration purposes, after deleting its results). The exact same is true of %file, but in the opposite direction (cell to file, rather than file/url to cell). I think your %%tempfile magic idea is a good one, but it is not what %%file is for.
Where is the data loss? There will be no change in the file unless the user makes edits, in which case those edits are written to the file in place of what was there, exactly as expected. |
How about adding |
My interpretationn of So I think I also like the idea of At the Strata conference, there was a demo from Microsoft of a JS web shell (not full notebook, just more terminal-like flow but in a browser). It wasn't very impressive overall, but it did handle multiple long-running jobs extremely well. Each job would keep a little JS spinner wheel at the end of its stdout/err, cleanly and discreetly indicating the job was still pulling output, and it would update and move the wheel to the end as new output arrived from several jobs. Clean, slick, not distracting and very informative, really good UI/X. Finally, just a thought: I can see the shell one being used a lot. Should we go for purity and call it |
If we go with In favour: if the user has chosen a different default shell, they might reasonably expect 'shell' to refer to that. Against: if I write a notebook and send it to someone with a different default shell, it could break. If we go with |
So should I remove the ask y/n from frontends which support it?
The way we associate outputs with cells makes this impossible. Output is always associated with the most recent cell, so a background command will output to the current cell, whichever that is, totally regardless of which cell originated it. The only sensible option to me is either to suppress the output entirely, or store it in a variable.
There is not a shell one, I don't know what you are referring to. There is already bash, sh, perl, etc. which map directly to their respective commands. The list of exposed script magics is configurable, so it's one line of config to add zsh, any other command line program. I can add shell that maps to $SHELL, but I haven't done this. I don't think we should have sh map to something other than sh though. |
On Sat, Jun 9, 2012 at 5:14 AM, Thomas Kluyver
Good point, and probably enough to shut it down. Every potentially convenient feature that has a silent, surprising and Cheers, f |
On Sat, Jun 9, 2012 at 9:58 AM, Min RK
That would be my vote. In fact, now that we have the notebook so front and center, I've been
That's what I recalled, bummer. I have the sketch of an idea for There may be an intermediate solution for the In the future if we find a cleaner solution, we can always then offer How does this sound?
The advantage of 'shell' would be, I guess, to be a simple way of I agree with you and Thomas on not aliasing sh ambiguously. Cheers, f |
On Jun 9, 2012, at 13:38, Fernando Perezreply@reply.github.com wrote:
Sure, this is exactly what I meant above by "store it in a variable". I will give it a try, and follow the growing convention of --out foo, so storing output is independent of backgrounding.
We already have %sx/! for this, and that can be made available as a cell magic for calling os.system. If we want a longer name, 'system' seems most logical for this one, as opposed to %%script and its descendants, all of which so far are explicit in which interpreter to use.
|
On Sat, Jun 9, 2012 at 3:05 PM, Min RK
Great, thanks!
Back in the terminal days we pushed pretty hard for super-short names There's a twist with the 'system' name: we have our own Cheers, f |
On 9 June 2012 21:38, Fernando Perez
I'm not sure if even the terminal should have the |
I'd be ok with that too. I added |
I actually have @fperez - I do not intend to use the pexpect code for %%script here, so perhaps the istty-based output would be a good reason for people to use %sx/%system instead of %%script in some cases. I'm working on this right now, so just to clarify what I should be doing:
|
On Sun, Jun 10, 2012 at 2:08 PM, Min RK
Let's not forget to warn of this change loudly though, some people may
Sounds good.
All of that sounds perfect. Thanks!! |
* add --out/err for storing output * add --bg for backgrounding scripts
also exposed as aliases %%system and %%!
Okay, I think all bullets are addressed, and demo notebook added. Should be just docs/tests left. |
Beautiful! Merging now, awesome... |
%%script and %%file magics * `%%file` writes to a file (-f to force overwrite) * `%%script` runs a cell with a particular script The ScriptMagics also defines a few common magics that wrap `%%script` with common interpreters, such as `%%bash` by default, and this list, as well as the full path for each, is configurable. For fun, the `%%script` magic is also presented as `%%!`.
%%script and %%file magics * `%%file` writes to a file (-f to force overwrite) * `%%script` runs a cell with a particular script The ScriptMagics also defines a few common magics that wrap `%%script` with common interpreters, such as `%%bash` by default, and this list, as well as the full path for each, is configurable. For fun, the `%%script` magic is also presented as `%%!`.
As discussed on the ML, a few more basic cell magics, as requested:
%%file
writes to a file (-f to force overwrite)%%script
runs a cell with a particular scriptThe ScriptMagics also defines a few common magics that wrap
%%script
with common interpreters, such as%%bash
by default, and this list, as well as the full path for each, is configurable.I still have to do some testing, particularly on Windows, but it seems ready for public eyes anyway.
For fun, the
%%script
magic is also presented as%%!
, but I am happy to remove that if we don't like it.