Skip to content

Commit c273759

Browse files
authored
Merge pull request #55 from filchristou/sharedsessions
Support shared sessions
2 parents e89cf05 + 90f115c commit c273759

File tree

13 files changed

+340
-67
lines changed

13 files changed

+340
-67
lines changed

.github/workflows/CI.yml

-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ jobs:
8383
version: '1.6'
8484
- run: julia --project=docs -e '
8585
using Pkg;
86-
Pkg.develop(PackageSpec(; path=pwd()));
8786
Pkg.instantiate();'
8887
- run: julia --project=docs docs/make.jl
8988
env:

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/Manifest.toml
2+
docs/build/

Project.toml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
1010
ReplMaker = "b873ce64-0db9-51f5-a568-4457d8e49576"
1111
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
1212
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
13+
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
1314

1415
[compat]
1516
OpenSSH_jll = "8.1, 9"

bin/julia-r

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ atreplinit() do repl
1919
# Run one command as part of connection setup to trigger compilation
2020
# This makes the REPL more immediately responsive after it prints the
2121
# welcome message.
22-
RemoteREPL.run_remote_repl_command(RemoteREPL._repl_client_connection,
22+
remotecmd(RemoteREPL._repl_client_connection,
2323
stdout, "\"hi\"")
2424
println("""
2525
Connected to $host

docs/Manifest.toml

+138-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# This file is machine-generated - editing it directly is not advised
22

3+
[[ANSIColoredPrinters]]
4+
git-tree-sha1 = "574baf8110975760d391c710b6341da1afa48d8c"
5+
uuid = "a4c015fc-c6ff-483c-b24f-f7ea428134e9"
6+
version = "0.0.1"
7+
8+
[[ArgTools]]
9+
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
10+
version = "1.1.1"
11+
12+
[[Artifacts]]
13+
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
14+
315
[[Base64]]
416
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
517

@@ -9,54 +21,125 @@ uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
921

1022
[[DocStringExtensions]]
1123
deps = ["LibGit2"]
12-
git-tree-sha1 = "a32185f5428d3986f47c2ab78b1f216d5e6cc96f"
24+
git-tree-sha1 = "2fb1e02f2b635d0845df5d7c167fec4dd739b00d"
1325
uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
14-
version = "0.8.5"
26+
version = "0.9.3"
1527

1628
[[Documenter]]
17-
deps = ["Base64", "Dates", "DocStringExtensions", "IOCapture", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"]
18-
git-tree-sha1 = "621850838b3e74dd6dd047b5432d2e976877104e"
29+
deps = ["ANSIColoredPrinters", "Base64", "Dates", "DocStringExtensions", "IOCapture", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"]
30+
git-tree-sha1 = "58fea7c536acd71f3eef6be3b21c0df5f3df88fd"
1931
uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
20-
version = "0.27.2"
32+
version = "0.27.24"
33+
34+
[[Downloads]]
35+
deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"]
36+
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
37+
version = "1.6.0"
38+
39+
[[FileWatching]]
40+
uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"
2141

2242
[[IOCapture]]
2343
deps = ["Logging", "Random"]
24-
git-tree-sha1 = "f7be53659ab06ddc986428d3a9dcc95f6fa6705a"
44+
git-tree-sha1 = "d75853a0bdbfb1ac815478bacd89cd27b550ace6"
2545
uuid = "b5f81e59-6552-4d32-b1f0-c071b021bf89"
26-
version = "0.2.2"
46+
version = "0.2.3"
2747

2848
[[InteractiveUtils]]
2949
deps = ["Markdown"]
3050
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
3151

52+
[[JLLWrappers]]
53+
deps = ["Preferences"]
54+
git-tree-sha1 = "abc9885a7ca2052a736a600f7fa66209f96506e1"
55+
uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
56+
version = "1.4.1"
57+
3258
[[JSON]]
3359
deps = ["Dates", "Mmap", "Parsers", "Unicode"]
34-
git-tree-sha1 = "81690084b6198a2e1da36fcfda16eeca9f9f24e4"
60+
git-tree-sha1 = "31e996f0a15c7b280ba9f76636b3ff9e2ae58c9a"
3561
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
36-
version = "0.21.1"
62+
version = "0.21.4"
63+
64+
[[LibCURL]]
65+
deps = ["LibCURL_jll", "MozillaCACerts_jll"]
66+
uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21"
67+
version = "0.6.3"
68+
69+
[[LibCURL_jll]]
70+
deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"]
71+
uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0"
72+
version = "7.84.0+0"
3773

3874
[[LibGit2]]
3975
deps = ["Base64", "NetworkOptions", "Printf", "SHA"]
4076
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"
4177

78+
[[LibSSH2_jll]]
79+
deps = ["Artifacts", "Libdl", "MbedTLS_jll"]
80+
uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8"
81+
version = "1.10.2+0"
82+
83+
[[Libdl]]
84+
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
85+
4286
[[Logging]]
4387
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
4488

4589
[[Markdown]]
4690
deps = ["Base64"]
4791
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
4892

93+
[[MbedTLS_jll]]
94+
deps = ["Artifacts", "Libdl"]
95+
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
96+
version = "2.28.2+0"
97+
4998
[[Mmap]]
5099
uuid = "a63ad114-7e13-5084-954f-fe012c677804"
51100

101+
[[MozillaCACerts_jll]]
102+
uuid = "14a3606d-f60d-562e-9121-12d972cd8159"
103+
version = "2022.10.11"
104+
52105
[[NetworkOptions]]
53106
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
107+
version = "1.2.0"
108+
109+
[[OpenSSH_jll]]
110+
deps = ["Artifacts", "JLLWrappers", "Libdl", "OpenSSL_jll", "Pkg", "Zlib_jll"]
111+
git-tree-sha1 = "1b2f042897343a9dfdcc9366e4ecbd3d00780c49"
112+
uuid = "9bd350c2-7e96-507f-8002-3f2e150b4e1b"
113+
version = "8.9.0+1"
114+
115+
[[OpenSSL_jll]]
116+
deps = ["Artifacts", "JLLWrappers", "Libdl"]
117+
git-tree-sha1 = "1aa4b74f80b01c6bc2b89992b861b5f210e665b5"
118+
uuid = "458c3c95-2e84-50aa-8efc-19380b2a3a95"
119+
version = "1.1.21+0"
54120

55121
[[Parsers]]
56-
deps = ["Dates"]
57-
git-tree-sha1 = "c8abc88faa3f7a3950832ac5d6e690881590d6dc"
122+
deps = ["Dates", "PrecompileTools", "UUIDs"]
123+
git-tree-sha1 = "4b2e829ee66d4218e0cef22c0a64ee37cf258c29"
58124
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
59-
version = "1.1.0"
125+
version = "2.7.1"
126+
127+
[[Pkg]]
128+
deps = ["Artifacts", "Dates", "Downloads", "FileWatching", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]
129+
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
130+
version = "1.9.0"
131+
132+
[[PrecompileTools]]
133+
deps = ["Preferences"]
134+
git-tree-sha1 = "9673d39decc5feece56ef3940e5dafba15ba0f81"
135+
uuid = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
136+
version = "1.1.2"
137+
138+
[[Preferences]]
139+
deps = ["TOML"]
140+
git-tree-sha1 = "7eb1686b4f04b82f96ed7a4ea5890a4f0c7a09f1"
141+
uuid = "21216c6a-2e73-6563-6e65-726566657250"
142+
version = "1.4.0"
60143

61144
[[Printf]]
62145
deps = ["Unicode"]
@@ -67,21 +150,63 @@ deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"]
67150
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
68151

69152
[[Random]]
70-
deps = ["Serialization"]
153+
deps = ["SHA", "Serialization"]
71154
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
72155

156+
[[RemoteREPL]]
157+
deps = ["Logging", "OpenSSH_jll", "REPL", "ReplMaker", "Serialization", "Sockets", "UUIDs"]
158+
path = ".."
159+
uuid = "1bd9f7bb-701c-4338-bec7-ac987af7c555"
160+
version = "0.2.17"
161+
162+
[[ReplMaker]]
163+
deps = ["REPL", "Unicode"]
164+
git-tree-sha1 = "f8bb680b97ee232c4c6591e213adc9c1e4ba0349"
165+
uuid = "b873ce64-0db9-51f5-a568-4457d8e49576"
166+
version = "0.2.7"
167+
73168
[[SHA]]
74169
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
170+
version = "0.7.0"
75171

76172
[[Serialization]]
77173
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
78174

79175
[[Sockets]]
80176
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"
81177

178+
[[TOML]]
179+
deps = ["Dates"]
180+
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
181+
version = "1.0.3"
182+
183+
[[Tar]]
184+
deps = ["ArgTools", "SHA"]
185+
uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"
186+
version = "1.10.0"
187+
82188
[[Test]]
83189
deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
84190
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
85191

192+
[[UUIDs]]
193+
deps = ["Random", "SHA"]
194+
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
195+
86196
[[Unicode]]
87197
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
198+
199+
[[Zlib_jll]]
200+
deps = ["Libdl"]
201+
uuid = "83775a58-1f1d-513f-b197-d71354ab007a"
202+
version = "1.2.13+0"
203+
204+
[[nghttp2_jll]]
205+
deps = ["Artifacts", "Libdl"]
206+
uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d"
207+
version = "1.48.0+0"
208+
209+
[[p7zip_jll]]
210+
deps = ["Artifacts", "Libdl"]
211+
uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"
212+
version = "17.4.0+0"

docs/Project.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[deps]
22
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
RemoteREPL = "1bd9f7bb-701c-4338-bec7-ac987af7c555"

docs/src/howto.md

+68
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,26 @@ julia@localhost> a_variable
107107
1
108108
```
109109

110+
111+
## Use common session among different clients
112+
A session, as implemented in `ServerSideSession`, describes the display properties and the module under which commands are evaluated.
113+
Multiple clients can share same such properties by using the same `session_id`. For example:
114+
115+
```julia
116+
julia> session_id = UUID("f03aec15-3e14-4d58-bcfa-82f8d33c9f9a")
117+
118+
julia> connect_repl(; session_id=session_id)
119+
```
120+
121+
## Pass a command non-interactively
122+
To programmatically pass a command to the remote julia kernel use [`remotecmd`](@ref). For example:
123+
124+
```julia
125+
julia> con2server = connect_remote(Sockets.localhost, 9093) # connect to port 9093 in localhost
126+
127+
julia> remotecmd(con2server, "myvar = 1") # define a new var
128+
```
129+
110130
## Use alternatives to SSH
111131

112132
### AWS Session Manager
@@ -128,6 +148,53 @@ connect_remote();
128148
```
129149
which will allow you to use `@remote` without the REPL mode.
130150

151+
### More on Pluto
152+
Pluto presents a peculiarity as the default module is constantly changing.
153+
In order to closely track the newest notebook state, you will need to tap into the client's session and update the module.
154+
You could write the following code in the pluto notebook that updates the module every second (if you have a better event-driven update solution, please raise an issue!).
155+
156+
```julia
157+
using PlutoLinks, PlutoHooks
158+
159+
using RemoteREPL, Sockets, UUIDs
160+
161+
server = Sockets.listen(Sockets.localhost, 27765)
162+
163+
@async serve_repl(server)
164+
165+
session_id = UUID("f03aec15-3e14-4d58-bcfa-82f8d33c9f9a")
166+
167+
con2server = connect_remote(Sockets.localhost, 27765; session_id=session_id)
168+
169+
takemodulesymbol() = Symbol("workspace#" ,PlutoRunner.moduleworkspace_count[])
170+
171+
let # update module in RemoteREPL every 1 sec
172+
count, set_count = @use_state(1)
173+
@use_task([]) do
174+
new_count = count
175+
while true
176+
sleep(1.0)
177+
new_count += 1
178+
set_count(new_count) # (this will trigger a re-run)
179+
end
180+
end
181+
mod = eval(takemodulesymbol())
182+
#@eval(@remoterepl $"%module $mod")
183+
remote_module!(mod)
184+
end
185+
```
186+
187+
Then open a repl and do:
188+
189+
```julia
190+
julia> using RemoteREPL, Sockets, UUIDs
191+
192+
julia> connect_repl(Sockets.localhost, 27765; session_id=UUID("f03aec15-3e14-4d58-bcfa-82f8d33c9f9a"))
193+
```
194+
195+
Since the session's module is being regularly updated by the Pluto notebook, your REPL will be in sync with the notebook's state.
196+
197+
131198
## Troubleshooting connection issues
132199
Sometimes errors will be encountered. This section aims to show some errors experienced by users, and what the underlying problem was. We will use some terms in this section, introduced in the table below.
133200
|Term|Explanation|
@@ -153,3 +220,4 @@ any group or other users. On a linux system, this is accomplished by running the
153220
chmod go-w /home/username/.ssh/*
154221
```
155222
If you are using a different operating system, please google how to remove write permissions on files, and try to do the same thing.
223+

docs/src/reference.md

+2
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,7 @@ serve_repl
4242
connect_remote
4343
RemoteREPL.@remote
4444
RemoteREPL.remote_eval
45+
RemoteREPL.remotecmd
46+
RemoteREPL.remote_module!
4547
```
4648

src/RemoteREPL.jl

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
module RemoteREPL
22

3-
export connect_repl, serve_repl, @remote, connect_remote
3+
using REPL, ReplMaker
4+
using Sockets, Serialization
5+
using UUIDs, Logging
6+
using OpenSSH_jll
7+
8+
export connect_repl, serve_repl, @remote, connect_remote, remotecmd, remote_module!
49

510
const DEFAULT_PORT = 27754
611
const PROTOCOL_MAGIC = "RemoteREPL"
7-
const PROTOCOL_VERSION = UInt32(1)
12+
const PROTOCOL_VERSION = UInt32(2)
813

914
const STDOUT_PLACEHOLDER = Symbol("#RemoteREPL_STDOUT_PLACEHOLDER")
1015

0 commit comments

Comments
 (0)