Skip to content

Commit

Permalink
Merge pull request #4 from fonsp/master
Browse files Browse the repository at this point in the history
update from origin
  • Loading branch information
lungben committed Sep 15, 2020
2 parents cd44ccc + a3797ab commit 10d2471
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 41 deletions.
1 change: 0 additions & 1 deletion Comonicon.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ name = "pluto"
completion=true
export_path=true
quiet=false
compile="min"
optimize=2
7 changes: 4 additions & 3 deletions Project.toml
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"
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@ julia> ]
(v1.5) pkg> add https://github.com/fonsp/PlutoUtils.jl
```

then add `~/.julia/bin` to your `PATH`. Or you can use [Comonicon](https://github.com/Roger-luo/Comonicon.jl)
then add `~/.julia/bin` to your `PATH`. Or you can add the path automatically via

```julia
julia> import PlutoUtils
julia> PlutoUtils.Comonicon.BuildTools.install_env_path()
julia> using PlutoUtils; PlutoUtils.comonicon_install_path()
```

to install the `PATH` and auto-completion `FPATH` automatically. If you don't have oh-my-zsh installed,
to enable auto-completion you need to add `~/.julia/completions` to your `FPATH` and then add
To enable auto-completion in ZSH you need to add `~/.julia/completions` to your `FPATH` and then add
`autoload -Uz compinit && compinit` to your `.zshrc`.

## Future
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ENV USER pluto
ENV USER_HOME_DIR /home/${USER}
ENV JULIA_DEPOT_PATH ${USER_HOME_DIR}/.julia
ENV NOTEBOOK_DIR ${USER_HOME_DIR}/notebooks
ENV JULIA_NUM_THREADS = 100
ENV JULIA_NUM_THREADS 100

RUN useradd -m -d ${USER_HOME_DIR} ${USER} \
&& mkdir ${NOTEBOOK_DIR} \
Expand Down
66 changes: 35 additions & 31 deletions src/PlutoUtils.jl
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

0 comments on commit 10d2471

Please sign in to comment.