Skip to content

Commit

Permalink
Add connect_remote (#42)
Browse files Browse the repository at this point in the history
* add connect_remote

* export `connect_remote`

* bump version

* Update client.jl

* fix accidental paste

* typo

* add `connect_remote` to reference docs
  • Loading branch information
MasonProtter authored Nov 8, 2022
1 parent 3bdbfcd commit 6ba76ec
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "RemoteREPL"
uuid = "1bd9f7bb-701c-4338-bec7-ac987af7c555"
authors = ["Chris Foster <[email protected]> and contributors"]
version = "0.2.16"
version = "0.2.17"

[deps]
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Expand Down
1 change: 1 addition & 0 deletions docs/src/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
2 changes: 1 addition & 1 deletion src/RemoteREPL.jl
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
46 changes: 33 additions & 13 deletions src/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down

3 comments on commit 6ba76ec

@MasonProtter
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/71861

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.17 -m "<description of version>" 6ba76ec9f9c31b70c8fa654fc64f844b5560bede
git push origin v0.2.17

@c42f
Copy link
Collaborator

@c42f c42f commented on 6ba76ec Nov 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for pushing out a release too! ❤️

Please sign in to comment.