-
-
Notifications
You must be signed in to change notification settings - Fork 294
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
Package environment #142
Comments
Hi z, Very good point! I have been thinking a lot about this lately - I think that every Pluto notebook should start in its own package environment, and there should be a GUI for loading packages, or this can be done with The other thing here is that a Pluto notebook should contain that package info! That way a |
Also, you can use let
import Pkg
Pkg.activate(".")
Pkg.add("XXX")
end as you first cell, and it should also be the first cell to run. Does that work? |
Ah! Thank you Fons!, I gave up when reading the error message that 'using' must be top level; didn't expect to find that there a re more top levels than I thought. :-) Yes, a let/end or begin/end block seems to do it. (Assuming that my single experiment showed characteristic behavior.) Thank you! I'll comment with thoughts on a general solution in the next hours. Kind greetings, z |
Some thoughts. Creating a directory (to put the environment in), and installing packages is potentially dangerous. What we can do is check for the right content of the current environment. So, a possible way, not thinking about environments yet: An environment is a directory with configuration files, or at least that's all I know In a way, using environments is the more heavy duty way to use Julia. So I think it better Maybe I continue above, where I said "offers to do the install". Pluto can ask for a Or: Just print a note how to create an environment, and what to install there, and how to Note, one reason why I am reluctant to install: I regularly have difficulties Kind greetings, z. |
My thoughts were that a notebook will get a directory in The first time you use In the existing Pkg environment case, it is exactly like it is today. A self-contained environment means that you never interact with the package manager - calling When you open a self-contained notebook, Pluto will create a clean env and 'install' everything needed. Remember that Julia has a global cache! If you add a package to a new environment, it only downloads and builds that package if it has never been used on your machine before. Otherwise, it just adds one line to Oh and you said that it could be dangerous, what do you mean by that? Isn't the dangerous part the running-arbitrary-julia-code-from-a-notebook, not the package install? |
Hahaha, right. Hm. What I was pondering, rather technically than cyber security wise, is notebooks installing things that don't really work. Like for me in the last days, where Plots/GR only worked after some massage. So your plan sounds good for a ideal situation. I just rarely see it :-) |
Hm 😕 do you also have those issues when starting from an empty package environment? And is it just the crazy python packages that break? I would love to know more about the Pluto-admin-install problem! Just the system info would also be helpful! It only has 2 dependencies and doesn't do anything wild to install, so perhaps it's the required (It would be great if you could report these issues to the Plots package!) |
Is the solution suggested above still expected to work? When I run this as my first cell begin
using Pkg
Pkg.activate(".")
end I kind of expected the files Project.toml and Manifest.toml to be created in the director containing the current notebook. However, no such files are created. |
Hi Roger,
Kind greetings, z. |
Hi, |
Yep, what to do with the working directory is another issue... (In particular, after changing the notebook path - some cells can implicitly depend on the |
By the way, here is a more complicated example of setting up an environment begin
cd("/mnt/c/dev/julia/margo_tests/") # see edit below
import Pkg
Pkg.activate(".")
using ClimateMARGO
using Plots
using LaTeXStrings
using Colors
end This works - but of course this should not be necessary - it's on the todo list! When figuring out the "run all" order, cells that contain a Edit: Pluto now does |
In the interest of reproducibility, it would be ideal if we could still provide a Project.toml (with |
Thanks for pointing it out - I'm thinking that Pluto should detect whether you are in a package environment (by going up the file tree and looking for |
That would also mirror IJulia's behavior: JuliaLang/IJulia.jl#820 |
I find currently Pluto will use whatever the environment Julia uses when running |
Not sure, maybe it depends on the Julia version. Currently, the best way to set up in environments is to copy the setup from the PlutoUI sample, but I want to make this a lot more smooth soon! |
@Roger-luo how did you get Pluto to pick up on a local project environment? I just tested with 0.11.0 and it still defaults to the global env? |
@ToucheSir I'm not sure I just start it using |
Perfect, that did the trick! Not sure why, but |
I think this is because when you pass |
I really like the idea to include the environment into the notebook file! Some suggestions:
|
I played around a bit with Pkg and have a suggestion (or rather a rough draft).
A further enhancement could be the option to integrate the .env directory (the content of the toml files) directly into the notebook.jl file and to extract them from the notebook.jl file again. I think this behavior should be opt-in, e.g. in a keyword argument to What do you think? |
Right now, I always include the following inside the notebook: begin
import Pkg
Pkg.activate(mktempdir())
end in one cell (mktempdir docs), and whenever I need begin
Pkg.add("Example")
import Example
end or if I want to specify the version begin
Pkg.add(Pkg.PackageSpec(name="Example", version=v"1.2.3"))
import Example
end This way, running the notebook always starts in a clean package environment (no state!). So it's just like what you proposed, except we purposely don't save the environment in a separate file, but completely describe the environment inside the notebook! This is pretty much what I want Pluto to do automatically in the future - the first cell will be built in, and you get the third cell when typing: import Example @ 1.2.3 with nice autocomplete to help you. (Just |
I was working on a design doc to receive feedback on about the |
@garrison just an update, in v0.12, you can specify which project to use via Pluto.run(;project="@.") will look for closest julia There is also per notebook environment variable settings built internally, but it's not exposed publicly. @fonsp I'm wondering how do you serialize this in to the notebook file currently, should we just have an inline TOML in the comments? I can experiment this feature for normal Julia scripts in IonCLI as one more thing I'm thinking is that I guess it's actually possible to not create a |
For inline TOML see also #421 ... |
💯 I feel very strongly that this is the correct way forward. In fact, I investigated doing this very thing for normal Julia scripts in https://github.com/c42f/CodeEnvironments.jl (though at the time I implemented that, I seemed unable to convince anyone that it was very worthwhile!). (BTW, the encoding of the Manifest in CodeEnvironments is not inherent, but partly a workaround for UI considerations in jupyter, and in text editors.) I know I'm just echoing what @fonsp said already! But I feel that managing environments (let alone understanding git) adds intolerable accidental complexity for casual users. Also that having the manifest and project separate from the notebook file will immediately lead to these files getting separated as they're copied around. |
I'm just curious - why does Pluto "disrespect" the currently active Julia project and start the notebook in the default environment? I'm aware that there may be a well thought-out reason behind this, but it did surprise me quite a bit (not being in the env I thought I was). I would actually love Pluto to pick up an environment (Project.toml and Manifest.toml) found in the same directory as the notebook automatically (like IJulia does with defaults). [Edit: Pluto does this now, see below.] |
One thing regarding |
Well, on the Julia package management console, "@myenv" means "myenv" in the default environments directory. |
That's not the package API unless Pkg.jl changes its API I don't think Pluto should use a different convention |
See here, though: JuliaLang/julia#35354 |
If that PR is merged it will automatically work on Pluto side Pluto does nothing extra but just forward the project path to Julia compiler API. |
Oh, right! :-) |
Sorry, didn't consider that. |
Regarding default environment, though - I'd like to plead for Pluto to use the environment it's been started with for notebooks as well, instead of starting them in the default environment. Novice users often won't use environments, so for them it won't matter - they'll start Pluto in the default environment. But if a user explicitly starts Pluto from another environment, wouldn't the intuitive expectation be that notebooks will run in the same env? |
I have to apologize, I didn't realize that Pluto does this already, via
Maybe not, in that case - respecting either the current environment or picking up the environment of the notebook's directory would lead to muddled semantics. |
@oschulz Please take a couple of minutes time before writing a quick reply, and consider switching to email/slack/zulip if you want to chat. Take a look at #844. This is where we are headed, we try to make the notebook the unit of reproducibility, and the environment used to launch Pluto is not used on purpose (unless PlutoPkg is disabled using |
My apologies - I actually didn't intend to write a quick reply: I did propose that Pluto should pick up environments next to the notebook or use the current default env. I had overlooked that Pluto already uses Sorry for the noise, I will be more careful with Pluto GitHub issues in the future. |
@oschulz No worries, thanks for understanding, I am sure you mean well! I definitely do not want to discourage you from contributing in the future! I always try to moderate slightly too early, instead of slightly too late. You are right that it's difficult to correct an earlier comment in github issues. Definitely take a look at #844 and take that future behaviour into account, and perhaps we should open a new Discussion about the semantics of keyword arguments passed to the Pluto server vs command line arguments passed to its Julia process. (I also have some questions about this.) |
Hi @oschulz, As the person who thumbs-uped your comment, I should probably take responsibility for the retraction :) Having read through (and politely debated with @fonsp about) package environments on GH and Zulip, I think this could've been avoided if #844 was linked earlier. For example, I'm suscribed to this thread but not Pluto in general, and wasn't aware that PR existed (and, more importantly, provided an escape hatch). |
Yes, I read #844 now and I do like the concept a lot (simplicity, but being able to opt out and use full environments when necessary). |
This issue was closed by releasing the Built-in package manager! To leave feedback, please open a new Issue or Discussion. 🎉 |
Hi,
I try and use many different libraries, and only some of them I keep. So, to start a project that uses a certain set of libraries, I enter a new directory, and in Julia I say
] activate "."
And now, I have a clean environment.
Pluto, on the other hand, starts its Notebooks in the standard environment (thus, for me, doesn't find any library).
So I added some cells before my "using XXX" lines:
using Pkg
Pkg.activate("myPath")
Side note: This isn't very portable. If there'd be a better way, I'm happy.
When writing the notebook, everything went fine. When reloading it, the ordering by Pluto kicked in, and all packages were loaded up front, and thus not found (or so I interpret what I saw).
This reordering seeems sensible to me in all cases except when working with environments :-)
I have no good idea where to put such meta information. Somehow I either
Both makes Pluto more complex, I'm afraid.
As "using XXX" has to be on the top level, I don't see a way to put this into functions, like, I mean
Any ideas?
Kind greetings, z.
The text was updated successfully, but these errors were encountered: