-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from fonsp/master
update from origin
- Loading branch information
Showing
5 changed files
with
43 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,4 @@ name = "pluto" | |
completion=true | ||
export_path=true | ||
quiet=false | ||
compile="min" | ||
optimize=2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
name = "PlutoUtils" | ||
uuid = "a5ec66cb-57bb-4ae5-9259-3342d9ed6c94" | ||
license = "Unlicense" | ||
authors = ["Fons van der Plas <fonsvdplas@gmail.com>"] | ||
version = "0.0.1" | ||
authors = ["Fons van der Plas <fonsvdplas@gmail.com> and contributors"] | ||
version = "0.1.0" | ||
|
||
[deps] | ||
Comonicon = "863f3e99-da2a-4334-8734-de3dacbe5542" | ||
Pluto = "c3e4b0f8-55cb-11ea-2926-15256bba5781" | ||
|
||
[compat] | ||
Comonicon = "0.5.6, 0.6" | ||
Comonicon = "0.6, 0.7" | ||
Pluto = "0.11" | ||
julia = "1.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,56 @@ | ||
module PlutoUtils | ||
|
||
using Comonicon | ||
|
||
# run(host, port::Integer; launchbrowser::Bool=false, session=ServerSession()) | ||
using Pluto | ||
|
||
""" | ||
Pluto CLI - Lightweight reactive notebooks for Julia | ||
open a Pluto notebook at given path. | ||
# Arguments | ||
- `host`: default is 127.0.0.1 (localhost) | ||
- `file`: file path of the Pluto notebook. | ||
# Options | ||
- `--host <ip>`: default is 127.0.0.1 (localhost) | ||
- `-p,--port <int>`: port you want to specify, default is 1234 | ||
- `--project <path>`: notebook project path, default is Julia's default global environment. | ||
# Flags | ||
- `-l,--launchbrowser`: add this flag to launch browser. | ||
""" | ||
@cast function open(file; host="127.0.0.1", port::Int=1234, launchbrowser::Bool=false, project=nothing) | ||
isfile(file) || error("file $file does not exist!") | ||
s = Pluto.ServerSession() | ||
config = Pluto.ServerConfiguration(launch_browser=launchbrowser) | ||
|
||
nb = Pluto.SessionActions.open(s, file; project=project) | ||
println("you can open the notebook at: http://localhost:$port/edit?id=$(nb.notebook_id)") | ||
Pluto.run(host, port;configuration=config, session=s) | ||
return | ||
end | ||
|
||
""" | ||
start Pluto notebook server. | ||
# Options | ||
- `--host <ip>`: default is 127.0.0.1 (localhost) | ||
- `-p,--port <int>`: port you want to specify, default is 1234 | ||
- `--project <path>`: custom project path, default is Julia's default global environment. | ||
# Flags | ||
- `-l,--launchbrowser`: add this flag to launch browser. | ||
""" | ||
@main function pluto(;host="127.0.0.1", port::Int=1234, launchbrowser::Bool=false) | ||
# workaround the package environment problem | ||
# might be resolved by Pluto#142 | ||
julia = joinpath(Sys.BINDIR::String, Base.julia_exename()) | ||
script = """ | ||
try | ||
import Pluto | ||
catch e | ||
if e isa ArgumentError | ||
print("Pluto not found, install Pluto? [Y/n]") | ||
x = read(stdin, Char) | ||
if x in ['Y', 'y', '\n'] | ||
using Pkg | ||
Pkg.add("Pluto") | ||
import Pluto | ||
else | ||
exit(0) | ||
end | ||
end | ||
end | ||
Pluto.run("$host", $port; launchbrowser=$launchbrowser) | ||
""" | ||
|
||
|
||
PLUTO_ENV = filter(x->x.first!="JULIA_PROJECT", ENV) | ||
run(setenv(`$julia -e "$script"`, PLUTO_ENV)) | ||
@cast function run(;host="127.0.0.1", port::Int=1234, launchbrowser::Bool=false, project=nothing) | ||
config = Pluto.ServerConfiguration(launch_browser=launchbrowser) | ||
s = ServerSession(default_environment_path=project) | ||
Pluto.run(host, port; configuration=config, session=s) | ||
end | ||
|
||
|
||
@main name="pluto" doc="Pluto CLI - Lightweight reactive notebooks for Julia" | ||
|
||
end |