JuliaLang / Pkg.jl

Pkg - Package manager for the Julia programming language
https://pkgdocs.julialang.org
Other
616 stars 258 forks source link

Split REPLMode into an package extension called REPLExt #3724

Closed mkitti closed 6 months ago

mkitti commented 8 months ago

This PR separates Pkg.REPLMode into an package extension called PkgREPLMode.

IanButterworth commented 8 months ago

Also, nit but it's a "package extension" not an "extension package"

mkitti commented 8 months ago

This requires coordination with https://github.com/JuliaLang/julia/pull/52467

IanButterworth commented 8 months ago

Would this break usage like this?

julia -e 'import Pkg; pkg"add Foo"'
mkitti commented 8 months ago

Would this break usage like this?\n\njulia -e 'import Pkg; pkg\"add Foo\"'

Yes. Although I think it has been quite clear that this is not the intended use.

julia -e 'using Pkg; pkg"status"'
┌ Warning: The Pkg REPL mode is intended for interactive use only, and should not be used from scripts. It is recommended to use the functional API instead.

To make it work, they would need to load it as follows.

julia -e 'using Pkg, REPL; pkg"status"'
mkitti commented 8 months ago

Since it is a macro, could we just add @eval using REPL to the top of the macro?

IanButterworth commented 8 months ago

I think that breakage is very reasonable tbh just might come up in pkgeval

fredrikekre commented 8 months ago

Does anything in that code path even use REPL though? Why hinge this functionality on whether REPL is loaded?

mkitti commented 8 months ago

Does anything in that code path even use REPL though? Why hinge this functionality on whether REPL is loaded?

Yes, it is very dependent on the REPL.

From master, https://github.com/JuliaLang/Pkg.jl/blob/f7f222f28e929dda69e4f5b1d660fc51a133fe09/src/REPLMode/REPLMode.jl#L459-L470

This branch, https://github.com/JuliaLang/Pkg.jl/blob/4a784ae943a3dda391479a1dc439ee1616ae28a8/ext/REPLExt/REPLExt.jl#L458-L492

fredrikekre commented 8 months ago

Thats surprising, looks like it is only for the help view though, perhaps it could be refactored.

On another note, typically the entry point to the extension code is some type that you pass to the function, but in this case it will just magically work if REPL happen to be loaded, right?

mkitti commented 8 months ago

The pkg"" commands go through the Pkg REPL mode interface and are thus meant to take advantage of the "interactive" code. I personally think the the macro should be @pkg_cmd rather than @pkg_str but there might be historical reasons for this.

On another note, typically the entry point to the extension code is some type that you pass to the function, but in this case it will just magically work if REPL happen to be loaded, right?

Yes. There are actually hooks on both sides. I just did some refactoring in 03a7da0 to make the initialization a bit more robust.

Also there is a hook on the REPL side that needs some modification for this pull request to work. https://github.com/JuliaLang/julia/pull/52467

I kept the name PkgREPLMode in REPL because referring to REPLExt inside REPL seems confusing and silly. https://github.com/JuliaLang/julia/blob/f115ef7d66aa8261d199e642281bf6f4e70cda0b/stdlib/REPL/src/REPL.jl#L1138-L1144

mkitti commented 8 months ago

Maintaining this branch as other pull requests get merged is going to be a challenge since so many files are affected.

KristofferC commented 8 months ago

Regarding the pkg"" stuff, it should be possible I think with some tweaks to make that work without a REPL. I don't think there is anything that is really needs from the REPL module. Some packages (unfortunately) use the pkg"" way to inform users how to install their package, e.g. https://github.com/bat/BAT.jl/blob/v2.0.5/docs/src/installation.md#installing-batjl-and-related-julia-packages.

Avoiding having to load the REPL for Pkg will be a very nice thing.

KristofferC commented 6 months ago

Subsumed by https://github.com/JuliaLang/Pkg.jl/pull/3777