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

Set the current directory for Elixir executable #93

Closed
josevalim opened this issue Mar 20, 2021 · 6 comments · Fixed by #95
Closed

Set the current directory for Elixir executable #93

josevalim opened this issue Mar 20, 2021 · 6 comments · Fixed by #95

Comments

@josevalim
Copy link
Contributor

I have been playing with Livebook to give my presentation on Nx and MNIST and I noticed a problem related to the current working directory. For the Elixir executable, we are running it on the Livebook server directory but in this case I think it makes the most sense for it to be the in the same directory as the Livebook file itself.

This will work fine for when you open up an existing Livebook, but what to do when you start with the Livebook in memory and then you save it? Should we change cwd of the existing evaluator? I would say so.

For the Mix evaluator, we will document the root is the Mix project root. For the distributed one, it is whatever the existing node is in.

@josevalim josevalim added this to the v0.1 milestone Mar 20, 2021
@jonatanklosko
Copy link
Member

Changing the directory can lead to unexpected results. Imagine you go to /project and start Livebook server. Then you create notebook in memory, work on stuff and use File.write/read (so you naturally work within /project). Now you save the notebook somewhere else (just to have the notebook persisted). If we switch cwd, then the existing code will start writing/reading into different place and they user may not even notice that.

By default I'd expect cwd to reflect wherever I start the Livebook server, and it's more that Mix and Attached are very specific cases, where cwd is different by their nature.

@josevalim
Copy link
Contributor Author

josevalim commented Mar 20, 2021

@jonatanklosko here is the issue: imagine I want to ship some livebook with some data. I can put it all on a zip file and I can tell folks to unpack and run it. How to do so? :)

Do we at least ensure that ENV.file today points to the livebook.md? Because if it does, I guess we can use Path.join(__DIR__, "file/foo/bar")?

@jonatanklosko
Copy link
Member

jonatanklosko commented Mar 20, 2021

Do we at least ensure that ENV.file today points to the livebook.md? Because if it does, I guess we can use Path.join(DIR, "file/foo/bar")?

We don't, but this sounds like an option. This way we could also put File.cd!(__DIR__) at the top to achieve what we want? One detail I'm not sure about is that for cell errors we would report notebook.livemd:n, whereas it's actually this_specific_cell:n.

@josevalim
Copy link
Contributor Author

This way we could also put File.cd!(DIR) at the top to achieve what we want?

It would, yeah. So let's go with setting the file name to the livebook path. And if it is memory, we set it to "in-memory.livemd"?

I am not sure if the specific cell matters, because we always show errors close to the cell anyway and all of the cell IDs are private?

@jonatanklosko
Copy link
Member

jonatanklosko commented Mar 20, 2021

I am not sure if the specific cell matters, because we always show errors close to the cell anyway and all of the cell IDs are private?

Yeah, my only point was that we would say notebook.livemd:3, but the 3 refers to the line in the cell, rather than line 3 in notebook.livemd.

@josevalim
Copy link
Contributor Author

@jonatanklosko oh, I see. We could set the file to something like "notebook.livemd#cell:3" but it means __ENV__.file will be wrong but __DIR__ is still right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants