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

Suggest importing package when using an undefined function #2833

Open
aplavin opened this issue Feb 29, 2024 · 3 comments
Open

Suggest importing package when using an undefined function #2833

aplavin opened this issue Feb 29, 2024 · 3 comments
Labels
package manager Pluto's built-in package manager

Comments

@aplavin
Copy link
Contributor

aplavin commented Feb 29, 2024

Pluto pioneered automatic package installation in Julia: just type using PackageName, and it's already there!

Over the recent years, Julia REPL got features that make even more seamless exploratory experience possible. Julia itself provides auto-installation now (with a confirmation prompt), and autoloading can be added with a short startup.jl.
Here's mine startup.jl, and below is a realtime recording of how it works. All installations are done into a temp env.

Would be nice if an undefined function/macro name is detected, Pluto looked up a list of common packages and symbols, and suggest to add using ThisPackage to the notebook!

asciicast

@Pangoraw Pangoraw added the package manager Pluto's built-in package manager label Mar 1, 2024
@fonsp
Copy link
Owner

fonsp commented Mar 7, 2024

Nice! I think it's good to have a curated list of packages that can be auto-installed (instead of an auto search of all registered packages), just like in your case:

        :StaticArrays => [:SVector, Symbol("@SVector")],
        :Statistics => [:mean, :median, :std, :cor, :cov, :quantile],

How should we go about writing this list? How do we decide what goes in and what doesn't?

In your case the feature gives a faster dev experience in the REPL "for the pros", but what I find most exciting is that it can help Julia beginners. I think it's common to copy-paste a code snippet (eg from ChatGPT) that contains a call to a popular function like plot or mean and it would be cool if Pluto could help with that, instead of just "plot not defined, did you mean splat?"

@fonsp fonsp changed the title Even better package autoinstallation Suggest importing package when using an undefined function Mar 7, 2024
@aplavin
Copy link
Contributor Author

aplavin commented Mar 7, 2024

plot is one of the best/worst examples here, depending on how you look at it :) There are so many options: Plots, Makie (Cairo or WGL), PyPlot, ....

I think this autoinstall feature has to involve a prompt anyway, it shouldn't be fully automatic. So, if I type plot() or weights(), I don't really want to wait for some package installation – maybe I just want to define a function with this name myself in the notebook.
Then the question is, what should be in that prompt.

  • Just a confirmation prompt? Then there needs to be a list of packages + symbols, and in this scenario functions like plot() are clearly out of scope. The list can just be defined in Pluto code as a function, and users would be able to customize it by overriding Pluto.autoinstall_package_symbols() = [... my list ...] before Pluto.run().
  • Selection prompt, sometimes with multiple options? Then we can be more liberal, and add a few most common packages to the list for "ambiguous" function names. Configuration is probably less important in this case, but it doesn't cost anything to define the list in Pluto as a function and allow overriding anyways.

@aplavin
Copy link
Contributor Author

aplavin commented Mar 7, 2024

Maybe, "prompt" could be as simple as Pluto adding a cell above the executed one, with the content like

using StatsBase
using # Plots, CairoMakie, WGLMakie, PyPlot, PythonPlot – uncomment one name here

The cell should just be added automatically, but not executed. Then the user either just checks it and runs, or decides which of the "ambiguous" packages they want and then runs the cell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package manager Pluto's built-in package manager
Projects
None yet
Development

No branches or pull requests

3 participants