-
-
Notifications
You must be signed in to change notification settings - Fork 293
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
Detect Project.toml in parent dirs and disable PlutoPkg #1281
Conversation
I sometimes have example notebooks in a subdir of a package where I would like to use the new Pluto Pkg feature. These example notebooks usually have different dependencies than the package they are in, therefore the package Project.toml would not be suitable to use. I think opt-in with automatic migration could do it: This would have the advantage to be explicit about the behavior of taking parent Project.tomls (which otherwise would be quite intransparent) and it pushes towards using the new Pkg functionality (which is in most cases the better choice). |
What you mentioned is a (valid) edge case, but this PR will cover a more common use case, right? I think it's fine to not enable the pluto package manager for that edge case, you can still use The goal for PlutoPkg is to make common use cases work automatically, without any extra steps/code, and more specialized use cases require extra code from the user. So I still think this PR is the best way to go. One point you mentioned, that this behaviour is intransparent, is a good one. I think that we should solve this by showing it in the GUI. Something like the current PlutoPkg bubble, except it always says "this notebook is using the environment at ... you can edit it using the Pkg REPL" |
I made that comment regarding VS Code and IJulia behaviour that you refer to, but it was not intended as a suggestion for Pluto to follow the same direction! It’s great that you have a fresh take on the notebook environment, and choosing best defaults is a part of it. Currently, Pluto 0.15 (master) uses the new package manager UI by default with a reasonably clear way of escaping it: the activate(…) function. It’s already easy to use a project from a parent directory with activate(current_project()) – doesn’t require any changes in Pluto. On the other hand, if you switch from the current approach to this PR, there would be no way to use the Pluto package manager when there happens to be a Project.toml file in any higher-level directory. So, I believe keeping the current (master, not this PR) defaults is best along the “reproducible by default” line, and generally for convenience of one-off notebooks. |
I think this PR is required so that Release 0.15 does not break existing notebooks which rely on a Project.toml in the current or a parent directory. But I agree with you that this behavior is not ideal and long-term users should use the new Pluto package management in most cases. I suggest to implement this PR but with a Deprecation Warning each time a Project.toml is used. The warning should give the syntax to explicitly activate the current (or parent) directory for using the Project.toml. |
I use Project.toml files myself, and don't see how Pluto 0.15 can break them - unless the |
I think this is a good idea. Not yet clear to me whether this would still work with nested folders inside
+1 Unfortunately I am a bit at a loss about what is the current behavior. I've looked here: https://github.com/fonsp/Pluto.jl/wiki/%F0%9F%8E%81-Package-management but from what I've read the behavior is to always use the internal Pluto manager. From here https://github.com/fonsp/Pluto.jl/wiki/%F0%9F%8E%81-Package-management#pattern-the-shared-environment if someone calls For notebooks that are part of a ongoing scientific project, where it is unlikely that your analysis would finish within a single notebook, I think it is much more beneficial that their shared environment is activated. Another benefit is when giving paths to data files. Sure, you can put the data file in the same folder as the notebook, but for a real project this will quickly become unfeasible. A sufficiently unique identifier of the entire project folder would be the location of the Project.toml, from which you can branch out to everything you need, including data files, source julia files, or notebooks. (which is how a large part of DrWatson works). |
This is a bit confusing, but because of an implementation bug (#1280), 0.14 did not activate the parent directory in this case. So we do not need this PR for backwards compatibility of this behaviour. |
I agree, but |
An alternative to this PR is:I set the
(no arguments) will activate the parent environment if it exist, the global env otherwise. This means that you don't need to write the complicated |
I think it is perfectly fine to use a Project.toml in the notebook directory itself automatically, this is a behavior which is probably expected by most users. Using a Project.toml from a parent directory may be rather surprising, but fortunately it looks like it is not required to do this for backward compatibility reasons. To take the Project.toml from a parent directory one could also write |
I find this surprising, and interesting. How does your project folder structure look like? Where do you put your data? Do you write your own source code for e.g. analysis functions, or you have everything in a massive notebook file? If you write source code files, where do you put them? Just curious, because coming from a different perspective, I'd find it more natural to group things into data/source/notebook folders. |
Here is something that I would like from a teaching perspective. (And sorry if this functionality is already implied from one of your posts above) I have a folder But I also want my students to be covered if they open the notebook naïvely just dragging the path into Pluto. So, it would be good if Pluto copied the tomls to the You could for example have a pop-up with something like
|
By the way, I encourage everyone to try the Pluto package manager :) Originally, I was somewhat skeptical whether it would be convenient and intuitive compared to project-based directories that are plain Julia envs with I hope that even if this PR gets merged and Pluto pkg manager won't be the default anymore, it would still be possible to override: e.g., |
Perhaps a pop-up is the best way? If Pluto detects whether a notebook is part of a larger project, by finding a |
Not sure if a pop-up on start is the best idea here as it would prevent automatization. So basically I tend to agree with the idea to use If an interactive UI becomes necessary, we could add a "Project Management" UI element to what is now the print panel along with a project status indicator which is always visible close to the |
Thanks for all the input! There is something to say for both directions, so my final decision is:
In the future, we could:
About
|
Just be careful: |
Added an inline widget to communicate the |
@Datseris We set the |
Sure, but I thought a big selling point of Pluto is that its notebooks are also "true" Julia files, i.e. one could in principle run them on e.g. other means. Then not using |
this PR does not work yet, but join the discussion below!
One 'problem' with the new built-in package manager is:
What to do when your notebook's folder or one of its parents has a Project.toml?
For example, you could have a project structured like:
and you want all notebooks to use the same package environment.
Why not one environment per notebook?
Because two notebooks using the same package might produce slightly different results, if they are not created at the same time. This can be very confusing. This is also important when you import code from one notebook in the other.
What happens in
main
?Currently, you need to write
to disable PlutoPkg and enable your shared environment. This is also recommended in our docs: https://github.com/fonsp/Pluto.jl/wiki/%F0%9F%8E%81-Package-management#pattern-the-shared-environment
What happens in
0.14.x
?I only recently discovered that this behaviour is inconsistent (), but:
Solution 1 - this PR
After this PR, when running the notebooks inside the
notebooks/
folder, Pluto will detect that they are part of a shared project environment, and PlutoPkg will be disabled (no inline GUI). The project will be activated.When moving a notebook file in/out of a shared folder, PlutoPkg will be disabled/re-enabled.
This will simulate the
julia --project=@.
behaviour for all notebooks:This matches the behaviour of Jupyter and VS Code: JuliaLang/Pkg.jl#2640 (comment)
TODO
TODO
AbstractPackageManagement
instead ofUnion{PkgContext, Nothing}
ACTIVE_PROJECT[]
or sthTO TEST
Pkg.activate
does not activate the dirnotebook_to_js
contentsreset_notebook_environment
Bonus ideas: