Skip to content

Commit 6ba76ec

Browse files
authored
Add connect_remote (#42)
* add connect_remote * export `connect_remote` * bump version * Update client.jl * fix accidental paste * typo * add `connect_remote` to reference docs
1 parent 3bdbfcd commit 6ba76ec

File tree

4 files changed

+36
-15
lines changed

4 files changed

+36
-15
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "RemoteREPL"
22
uuid = "1bd9f7bb-701c-4338-bec7-ac987af7c555"
33
authors = ["Chris Foster <[email protected]> and contributors"]
4-
version = "0.2.16"
4+
version = "0.2.17"
55

66
[deps]
77
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"

docs/src/reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ disconnect from the server, leaving the remote operation still running.
3939
```@docs
4040
connect_repl
4141
serve_repl
42+
connect_remote
4243
RemoteREPL.@remote
4344
RemoteREPL.remote_eval
4445
```

src/RemoteREPL.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module RemoteREPL
22

3-
export connect_repl, serve_repl, @remote
3+
export connect_repl, serve_repl, @remote, connect_remote
44

55
const DEFAULT_PORT = 27754
66
const PROTOCOL_MAGIC = "RemoteREPL"

src/client.jl

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -441,18 +441,8 @@ function connect_repl(host=Sockets.localhost, port::Integer=DEFAULT_PORT;
441441
namespace::Union{AbstractString,Nothing}=nothing,
442442
startup_text::Bool=true,
443443
repl=Base.active_repl)
444-
global _repl_client_connection
445-
446-
if !isnothing(_repl_client_connection)
447-
try
448-
close(_repl_client_connection)
449-
catch exc
450-
@warn "Exception closing connection" exception=(exc,catch_backtrace())
451-
end
452-
end
453444

454-
conn = Connection(host=host, port=port, tunnel=tunnel,
455-
ssh_opts=ssh_opts, region=region, namespace=namespace)
445+
conn = connect_remote(host, port; tunnel, ssh_opts, region,namespace)
456446
out_stream = stdout
457447
prompt = ReplMaker.initrepl(c->run_remote_repl_command(conn, out_stream, c),
458448
repl = Base.active_repl,
@@ -465,13 +455,43 @@ function connect_repl(host=Sockets.localhost, port::Integer=DEFAULT_PORT;
465455
completion_provider = RemoteCompletionProvider(conn),
466456
startup_text = startup_text
467457
)
468-
# Record the connection which is attached to the REPL
469-
_repl_client_connection = conn
470458
prompt
471459
end
472460

473461
connect_repl(port::Integer) = connect_repl(Sockets.localhost, port)
474462

463+
"""
464+
connect_remote([host=localhost,] port::Integer=$DEFAULT_PORT;
465+
tunnel = (host != localhost) ? :ssh : :none,
466+
ssh_opts = ``)
467+
468+
Connect to remote server without any REPL integrations. This will allow you to use `@remote`, but not the REPL mode.
469+
Useful in circumstances where no REPL is available, but interactivity is desired like Jupyter or Pluto notebooks.
470+
Otherwise, see `connect_repl`.
471+
"""
472+
function connect_remote(host=Sockets.localhost, port::Integer=DEFAULT_PORT;
473+
tunnel::Symbol = host!=Sockets.localhost ? :ssh : :none,
474+
ssh_opts::Cmd=``,
475+
region::Union{AbstractString,Nothing}=nothing,
476+
namespace::Union{AbstractString,Nothing}=nothing)
477+
478+
global _repl_client_connection
479+
480+
if !isnothing(_repl_client_connection)
481+
try
482+
close(_repl_client_connection)
483+
catch exc
484+
@warn "Exception closing connection" exception=(exc,catch_backtrace())
485+
end
486+
end
487+
conn = RemoteREPL.Connection(host=host, port=port, tunnel=tunnel,
488+
ssh_opts=ssh_opts, region=region, namespace=namespace)
489+
490+
# Record the connection in a global variable so it's accessible to REPL and `@remote`
491+
_repl_client_connection = conn
492+
end
493+
494+
475495
"""
476496
@remote ex
477497

0 commit comments

Comments
 (0)