diff --git a/Project.toml b/Project.toml index f105e43..4bc0ce3 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "RemoteREPL" uuid = "1bd9f7bb-701c-4338-bec7-ac987af7c555" authors = ["Chris Foster and contributors"] -version = "0.2.16" +version = "0.2.17" [deps] Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" diff --git a/docs/src/reference.md b/docs/src/reference.md index 896405f..4061fca 100644 --- a/docs/src/reference.md +++ b/docs/src/reference.md @@ -39,6 +39,7 @@ disconnect from the server, leaving the remote operation still running. ```@docs connect_repl serve_repl +connect_remote RemoteREPL.@remote RemoteREPL.remote_eval ``` diff --git a/src/RemoteREPL.jl b/src/RemoteREPL.jl index 82a9e6e..b22427c 100644 --- a/src/RemoteREPL.jl +++ b/src/RemoteREPL.jl @@ -1,6 +1,6 @@ module RemoteREPL -export connect_repl, serve_repl, @remote +export connect_repl, serve_repl, @remote, connect_remote const DEFAULT_PORT = 27754 const PROTOCOL_MAGIC = "RemoteREPL" diff --git a/src/client.jl b/src/client.jl index cd45d21..4c28b2e 100644 --- a/src/client.jl +++ b/src/client.jl @@ -441,18 +441,8 @@ function connect_repl(host=Sockets.localhost, port::Integer=DEFAULT_PORT; namespace::Union{AbstractString,Nothing}=nothing, startup_text::Bool=true, repl=Base.active_repl) - global _repl_client_connection - - if !isnothing(_repl_client_connection) - try - close(_repl_client_connection) - catch exc - @warn "Exception closing connection" exception=(exc,catch_backtrace()) - end - end - conn = Connection(host=host, port=port, tunnel=tunnel, - ssh_opts=ssh_opts, region=region, namespace=namespace) + conn = connect_remote(host, port; tunnel, ssh_opts, region,namespace) out_stream = stdout prompt = ReplMaker.initrepl(c->run_remote_repl_command(conn, out_stream, c), repl = Base.active_repl, @@ -465,13 +455,43 @@ function connect_repl(host=Sockets.localhost, port::Integer=DEFAULT_PORT; completion_provider = RemoteCompletionProvider(conn), startup_text = startup_text ) - # Record the connection which is attached to the REPL - _repl_client_connection = conn prompt end connect_repl(port::Integer) = connect_repl(Sockets.localhost, port) +""" + connect_remote([host=localhost,] port::Integer=$DEFAULT_PORT; + tunnel = (host != localhost) ? :ssh : :none, + ssh_opts = ``) + +Connect to remote server without any REPL integrations. This will allow you to use `@remote`, but not the REPL mode. +Useful in circumstances where no REPL is available, but interactivity is desired like Jupyter or Pluto notebooks. +Otherwise, see `connect_repl`. +""" +function connect_remote(host=Sockets.localhost, port::Integer=DEFAULT_PORT; + tunnel::Symbol = host!=Sockets.localhost ? :ssh : :none, + ssh_opts::Cmd=``, + region::Union{AbstractString,Nothing}=nothing, + namespace::Union{AbstractString,Nothing}=nothing) + + global _repl_client_connection + + if !isnothing(_repl_client_connection) + try + close(_repl_client_connection) + catch exc + @warn "Exception closing connection" exception=(exc,catch_backtrace()) + end + end + conn = RemoteREPL.Connection(host=host, port=port, tunnel=tunnel, + ssh_opts=ssh_opts, region=region, namespace=namespace) + + # Record the connection in a global variable so it's accessible to REPL and `@remote` + _repl_client_connection = conn +end + + """ @remote ex