Literate.jl icon indicating copy to clipboard operation
Literate.jl copied to clipboard

Support for Pkg mode

Open MikeInnes opened this issue 7 years ago • 8 comments

Lines beginning with ] could be considered "Pkg mode" and evaluated as if in that repl mode; this follows what IJulia does when this is in a cell. Currently this just causes an error.

cc @dhairyagandhi96

MikeInnes avatar Oct 23 '18 14:10 MikeInnes

Yea I have thought about that too. And same with ? which could splice in a docstring.

fredrikekre avatar Oct 23 '18 14:10 fredrikekre

Shell mode via ; would be nice too, if that doesn't work already.

MikeInnes avatar Oct 23 '18 14:10 MikeInnes

On second thought, this would deviate from one of the original ideas with the package, that the source files should be valid julia code. There exist functional API's for Pkg, docs and shell so maybe better to use those?

Also, why do you want to invoke Pkg in the files? Would it be better with an option to instantiate a provided Project.toml and running the script in that environment instead?

fredrikekre avatar Oct 24 '18 06:10 fredrikekre

There are various reasons you might want to do this, for example if you want to make notebook-based tutorials for the package manager. I take the point about valid Julia code, but having this certainly doesn't prevent people from doing that, and given the various issues with notebooks it's reasonable to want to use Literate even if notebooks are the only valid target.

To elaborate a bit on our particular use case: We are doing exactly what you suggest, but just automating the process by adding ] activate .; instantiate to the header of the script (during notebook preprocessing). We could well use the Pkg API for that, but especially for new users I'd prefer to avoid presenting a non-standard way of using the package manager.

MikeInnes avatar Oct 24 '18 07:10 MikeInnes

Fair enough, although I wouldn't call

using Pkg
Pkg.activate(".")
Pkg.instantiate()

a "non-standard way" of using the package manager, it is actually the prefered method of using Pkg in scripts. Using ] in notebooks looks kinda weird, and there is no indication of that you are invoking the package manager (since you don't get the pkg> prompt etc.). Compare e.g.

screenshot from 2018-10-24 10-59-55

IMO the first one is much more clear on what is going on. Note also that you can't copy-paste e.g. ]status and have that work in the REPL. Personally I would use the functional interface to Pkg in notebooks but...

fredrikekre avatar Oct 24 '18 09:10 fredrikekre

You can also use the Pkg string macro pkg"instantiate".

KristofferC avatar Oct 24 '18 12:10 KristofferC

Right, that kinda emulates the pkg> prompt too, and works without any changes.

fredrikekre avatar Oct 24 '18 14:10 fredrikekre

My personal opinion is that it is quite nice that Literate files are actual julia files. Also, the API of Pkg is arguably the "official" way of interacting with the package manager from scripts while the REPL mode is for interactive use and tries to have a "do what I mean" philosophy.

KristofferC avatar Oct 24 '18 14:10 KristofferC