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

Support for Pkg mode #39

Open
MikeInnes opened this issue Oct 23, 2018 · 8 comments
Open

Support for Pkg mode #39

MikeInnes opened this issue Oct 23, 2018 · 8 comments

Comments

@MikeInnes
Copy link

MikeInnes commented Oct 23, 2018

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

@fredrikekre
Copy link
Owner

fredrikekre commented Oct 23, 2018

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

@MikeInnes
Copy link
Author

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

@fredrikekre
Copy link
Owner

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?

@MikeInnes
Copy link
Author

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.

@fredrikekre
Copy link
Owner

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...

@KristofferC
Copy link
Collaborator

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

@fredrikekre
Copy link
Owner

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

@KristofferC
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants