Skip to content

Commit 1c45c32

Browse files
committed
Mass rename of jupyter-comm-layer related functions
The following changes are made: `jupyter-initialize-connection` -> `jupyter-comm-initialize` `jupyter-connect-client` -> `jupyter-comm-add-handler` `jupyter-disconnect-client` -> `jupyter-comm-remove-handler` `jupyter-comm-client-loop` -> `jupyter-comm-handler-loop` * README.org: Do it. * jupyter-channel-ioloop-comm: Do it. * jupyter-client.el: Do it. * jupyter-comm-layer.el: Do it. (jupyter-comm-layer): Rename `clients` slot to `handlers`. Update all uses. * jupyter-kernel-process-manager.el: Do it. * jupyter-repl.el: Do it. * jupyter-server.el: Do it. * jupyter-zmq-channel-comm.el: Do it. * test/jupyter-server-test.el: Do it. * test/jupyter-test.el: Do it.
1 parent b66ddf5 commit 1c45c32

10 files changed

+90
-71
lines changed

README.org

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -842,14 +842,14 @@ Methods that require a message type as an argument such as
842842
For a =jupyter-kernel-client= to start communicating with a kernel, the
843843
following steps are taken:
844844

845-
1. Initialize the connection using =jupyter-initialize-connection=
845+
1. Initialize the connection using =jupyter-comm-initialize=
846846
2. Start listening on the client's channels with =jupyter-start-channels=
847847

848848
When starting a local kernel process, both steps are taken care of in
849849
=jupyter-start-new-kernel=.
850850

851851
For remote kernels, you will have to manually supply the connection JSON file
852-
to =jupyter-initialize-connection= and start the kernel channels.
852+
to =jupyter-comm-initialize= and start the kernel channels.
853853
**** Sending messages
854854

855855
Once a connection is initialized, messages can be sent to the kernel using the
@@ -880,7 +880,7 @@ user and sends it to the kernel.
880880
Represents a client connected to a Jupyter kernel.
881881
*** Initializing a connection
882882

883-
=jupyter-initialize-connection= takes a client and a connection file as
883+
=jupyter-comm-initialize= takes a client and a connection file as
884884
arguments and configures the client to communicate with the kernel whose
885885
connection information is contained in the [[http://jupyter-client.readthedocs.io/en/stable/kernels.html#connection-files][connection file]].
886886

@@ -889,11 +889,11 @@ After initializing a connection, to begin communicating with a kernel call
889889

890890
#+BEGIN_SRC elisp
891891
(let ((client (jupyter-kernel-client)))
892-
(jupyter-initialize-connection client "kernel1234.json")
892+
(jupyter-comm-initialize client "kernel1234.json")
893893
(jupyter-start-channels client))
894894
#+END_SRC
895895

896-
=jupyter-initialize-connection= is mainly useful when initializing a remote
896+
=jupyter-comm-initialize= is mainly useful when initializing a remote
897897
connection or connecting to an existing kernel. In order to start a new kernel
898898
on the =localhost= use =jupyter-start-new-kernel=
899899

jupyter-channel-ioloop-comm.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
;;
3939
;; Initializing the connection
4040
;;
41-
;; The `jupyter-initialize-connection' method should be called before calling
41+
;; The `jupyter-comm-initialize' method should be called before calling
4242
;; `jupyter-comm-start' and should be passed a `jupyter-session' object used to
4343
;; initialize the `jupyter-channel-ioloop' object.
4444

@@ -70,7 +70,7 @@
7070
(jupyter-session-id (oref comm session))
7171
9 nil nil "")))
7272

73-
(cl-defmethod jupyter-initialize-connection ((comm jupyter-channel-ioloop-comm)
73+
(cl-defmethod jupyter-comm-initialize ((comm jupyter-channel-ioloop-comm)
7474
(session jupyter-session))
7575
(cl-call-next-method)
7676
(let ((endpoints (jupyter-session-endpoints session)))

jupyter-client.el

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ CLIENT defaults to `jupyter-current-client'."
294294

295295
(defun jupyter--connection-info (info-or-session)
296296
"Return the connection plist according to INFO-OR-SESSION.
297-
See `jupyter-initialize-connection'."
297+
See `jupyter-comm-initialize'."
298298
(cond
299299
((jupyter-session-p info-or-session)
300300
(jupyter-session-conn-info info-or-session))
@@ -312,7 +312,7 @@ See `jupyter-initialize-connection'."
312312

313313
;; FIXME: This requires that CLIENT is communicating with a kernel using a
314314
;; `jupyter-channel-ioloop-comm' object.
315-
(cl-defmethod jupyter-initialize-connection ((client jupyter-kernel-client) info-or-session)
315+
(cl-defmethod jupyter-comm-initialize ((client jupyter-kernel-client) info-or-session)
316316
"Initialize CLIENT with connection INFO-OR-SESSION.
317317
INFO-OR-SESSION can be a file name, a plist, or a
318318
`jupyter-session' object that will be used to initialize CLIENT's
@@ -348,7 +348,7 @@ http://jupyter-client.readthedocs.io/en/latest/kernels.html#connection-files."
348348
(jupyter-session
349349
:key (plist-get conn-info :key)
350350
:conn-info conn-info)))
351-
(jupyter-initialize-connection
351+
(jupyter-comm-initialize
352352
(oref client kcomm)
353353
(oref client session))))
354354

@@ -525,12 +525,12 @@ back."
525525
;;; Starting communication with a kernel
526526

527527
(cl-defmethod jupyter-start-channels ((client jupyter-kernel-client))
528-
(jupyter-connect-client (oref client kcomm) client))
528+
(jupyter-comm-add-handler (oref client kcomm) client))
529529

530530
(cl-defmethod jupyter-stop-channels ((client jupyter-kernel-client))
531531
"Stop any running channels of CLIENT."
532532
(when (slot-boundp client 'kcomm)
533-
(jupyter-disconnect-client (oref client kcomm) client)))
533+
(jupyter-comm-remove-handler (oref client kcomm) client)))
534534

535535
(cl-defmethod jupyter-channels-running-p ((client jupyter-kernel-client))
536536
"Are any channels of CLIENT running?"

jupyter-comm-layer.el

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
;; A specific kernel communication layer (kcomm for short) is implemented by
3232
;; extending the methods: `jupyter-comm-start', `jupyter-comm-stop',
3333
;; `jupyter-comm-alive-p',`jupyter-event-handler', `jupyter-send', and possibly
34-
;; `jupyter-initialize-connection'.
34+
;; `jupyter-comm-initialize'.
3535
;;
36-
;; A client registers with the kcomm by calling `jupyter-connect-client' and
37-
;; de-registers with `jupyter-disconnect-client'. The communication layer deals
36+
;; A client registers with the kcomm by calling `jupyter-comm-add-handler' and
37+
;; de-registers with `jupyter-comm-remove-handler'. The communication layer deals
3838
;; with "events" which are just lists with an identifying symbol as the head
3939
;; element. Events that occur on the communication layer meant for clients,
4040
;; e.g. a message received by a kernel or notification that a message was sent
@@ -63,16 +63,16 @@
6363
:group 'jupyter)
6464

6565
(defclass jupyter-comm-layer ()
66-
((clients :type list :initform nil))
66+
((handlers :type list :initform nil))
6767
:abstract t)
6868

69-
(defmacro jupyter-comm-client-loop (comm client &rest body)
70-
"Loop over COMM's clients, binding each to CLIENT before evaluating BODY."
69+
(defmacro jupyter-comm-handler-loop (comm handler &rest body)
70+
"Loop over COMM's handlers, binding each to HANDLER before evaluating BODY."
7171
(declare (indent 2))
72-
(let ((clients (make-symbol "clients")))
73-
`(let ((,clients (oref ,comm clients)))
74-
(while ,clients
75-
(when-let* ((,client (jupyter-weak-ref-resolve (pop ,clients))))
72+
(let ((handlers (make-symbol "handlers")))
73+
`(let ((,handlers (oref ,comm handlers)))
74+
(while ,handlers
75+
(when-let* ((,handler (jupyter-weak-ref-resolve (pop ,handlers))))
7676
,@body)))))
7777

7878
;;; `jupyter-comm-layer'
@@ -86,14 +86,26 @@
8686
(cl-defgeneric jupyter-comm-alive-p ((comm jupyter-comm-layer))
8787
"Return non-nil if communication has started on COMM.")
8888

89-
(cl-defgeneric jupyter-connect-client ((comm jupyter-comm-layer) obj)
89+
(define-obsolete-function-alias 'jupyter-connect-client 'jupyter-comm-add-handler "0.8.2"
9090
"Register OBJ to receive events from COMM.
9191
By default, on the first OBJ connected, `jupyter-comm-start' is
9292
called if needed. This means that a call to
93-
`jupyter-initialize-connection' should precede a call to
94-
`jupyter-connect-client'.")
93+
`jupyter-comm-initialize' should precede a call to
94+
`jupyter-add-handler'.")
9595

96-
(cl-defgeneric jupyter-disconnect-client ((comm jupyter-comm-layer) obj)
96+
(cl-defgeneric jupyter-comm-add-handler ((comm jupyter-comm-layer) obj)
97+
"Register OBJ to receive events from COMM.
98+
By default, on the first OBJ connected, `jupyter-comm-start' is
99+
called if needed. This means that a call to
100+
`jupyter-comm-initialize' should precede a call to
101+
`jupyter-add-handler'.")
102+
103+
(define-obsolete-function-alias 'jupyter-disconnect-client 'jupyter-comm-remove-handler "0.8.2"
104+
"De-register OBJ from receiving events from COMM.
105+
By default, on the last OBJ removed, `jupyter-comm-stop' is
106+
called if needed.")
107+
108+
(cl-defgeneric jupyter-comm-remove-handler ((comm jupyter-comm-layer) obj)
97109
"De-register OBJ from receiving events from COMM.
98110
By default, on the last OBJ removed, `jupyter-comm-stop' is
99111
called if needed.")
@@ -112,10 +124,17 @@ buffer.")
112124
"Send EVENT to the underlying kernel using COMM."
113125
(error "Subclasses need to override this method"))
114126

115-
(cl-defgeneric jupyter-initialize-connection ((comm jupyter-comm-layer) &rest _ignore)
127+
(define-obsolete-function-alias 'jupyter-initialize-connection 'jupyter-comm-initialize "0.8.2"
128+
"Register OBJ to receive events from COMM.
129+
By default, on the first OBJ connected, `jupyter-comm-start' is
130+
called if needed. This means that a call to
131+
`jupyter-comm-initialize' should precede a call to
132+
`jupyter-add-handler'.")
133+
134+
(cl-defgeneric jupyter-comm-initialize ((comm jupyter-comm-layer) &rest _ignore)
116135
"Initialize communication on COMM.")
117136

118-
(cl-defmethod jupyter-initialize-connection ((comm jupyter-comm-layer) &rest _ignore)
137+
(cl-defmethod jupyter-comm-initialize ((comm jupyter-comm-layer) &rest _ignore)
119138
"Raise an error if COMM is already alive."
120139
(when (jupyter-comm-alive-p comm)
121140
(error "Can't initialize a live comm")))
@@ -131,42 +150,42 @@ buffer.")
131150
(cl-defmethod jupyter-channel-alive-p ((_comm jupyter-comm-layer) _channel)
132151
(error "Need to implement"))
133152

134-
(cl-defmethod jupyter-connect-client ((comm jupyter-comm-layer) obj)
135-
(unless (cl-loop for ref in (oref comm clients)
153+
(cl-defmethod jupyter-comm-add-handler ((comm jupyter-comm-layer) obj)
154+
(unless (cl-loop for ref in (oref comm handlers)
136155
thereis (eq (jupyter-weak-ref-resolve ref) obj))
137-
(push (jupyter-weak-ref obj) (oref comm clients)))
138-
;; Remove any garbage collected clients
139-
(oset comm clients
156+
(push (jupyter-weak-ref obj) (oref comm handlers)))
157+
;; Remove any garbage collected handlers
158+
(oset comm handlers
140159
(cl-remove-if-not #'jupyter-weak-ref-resolve
141-
(oref comm clients)))
160+
(oref comm handlers)))
142161
(unless (jupyter-comm-alive-p comm)
143162
(jupyter-comm-start comm)))
144163

145-
(cl-defmethod jupyter-disconnect-client ((comm jupyter-comm-layer) obj)
146-
(oset comm clients
164+
(cl-defmethod jupyter-comm-remove-handler ((comm jupyter-comm-layer) obj)
165+
(oset comm handlers
147166
(cl-remove-if (lambda (ref)
148167
(let ((deref (jupyter-weak-ref-resolve ref)))
149168
(or (eq deref obj) (null deref))))
150-
(oref comm clients))))
169+
(oref comm handlers))))
151170

152171
(cl-defmethod jupyter-event-handler ((comm jupyter-comm-layer) event)
153-
"Broadcast EVENT to all clients registered to receive them on COMM."
154-
;; TODO: Dynamically cleanup list of garbage collected clients when looping
172+
"Broadcast EVENT to all handlers registered to receive them on COMM."
173+
;; TODO: Dynamically cleanup list of garbage collected handlers when looping
155174
;; over it.
156-
(jupyter-comm-client-loop comm client
157-
(run-at-time 0 nil #'jupyter-event-handler client event)))
175+
(jupyter-comm-handler-loop comm handler
176+
(run-at-time 0 nil #'jupyter-event-handler handler event)))
158177

159178
;;; `jupyter-comm-autostop'
160179

161180
(defclass jupyter-comm-autostop ()
162181
()
163182
:abstract t
164-
:documentation "Stop the comm when the last client disconnects.")
183+
:documentation "Stop the comm when the last handler disconnects.")
165184

166-
(cl-defmethod jupyter-disconnect-client :after ((comm jupyter-comm-autostop) _client)
167-
"Stop COMM when there are no clients."
185+
(cl-defmethod jupyter-comm-remove-handler :after ((comm jupyter-comm-autostop) _handler)
186+
"Stop COMM when there are no handlers."
168187
(when (and (jupyter-comm-alive-p comm)
169-
(zerop (length (oref comm clients))))
188+
(zerop (length (oref comm handlers))))
170189
(jupyter-comm-stop comm)))
171190

172191
;;; `jupyter-hb-comm'

jupyter-kernel-process-manager.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ connect to MANAGER's kernel."
234234
(oset client kcomm (make-instance
235235
'jupyter-channel-ioloop-comm
236236
:ioloop-class 'jupyter-zmq-channel-ioloop))
237-
(jupyter-initialize-connection client (oref kernel session))))))
237+
(jupyter-comm-initialize client (oref kernel session))))))
238238

239239
(cl-defmethod jupyter-start-kernel :after ((manager jupyter-kernel-process-manager) &rest _args)
240240
(with-slots (kernel) manager

jupyter-repl.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2236,7 +2236,7 @@ interactively, DISPLAY the new REPL buffer as well."
22362236
(oset client kcomm (make-instance
22372237
'jupyter-channel-ioloop-comm
22382238
:ioloop-class 'jupyter-zmq-channel-ioloop))
2239-
(jupyter-initialize-connection client file-or-plist)
2239+
(jupyter-comm-initialize client file-or-plist)
22402240
(jupyter-start-channels client)
22412241
(jupyter-hb-unpause client)
22422242
(jupyter-bootstrap-repl client repl-name associate-buffer display)))

jupyter-server.el

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ ID. Send EVENT, with the kernel ID excluded, to a client whose
274274
kernel has a matching ID."
275275
(let ((kernel-id (cadr event)))
276276
(setq event (cons (car event) (cddr event)))
277-
(jupyter-comm-client-loop comm client
277+
(jupyter-comm-handler-loop comm client
278278
(when (equal kernel-id (oref (oref client kernel) id))
279279
;; TODO: Since the event handlers of CLIENT will eventually call the
280280
;; `jupyter-handle-message' of a `jupyter-kernel-client' we really
@@ -333,14 +333,14 @@ with default `jupyter-api-authentication-method'"))
333333
:ws-headers (jupyter-api-auth-headers comm)))
334334
(cl-call-next-method)))
335335

336-
(cl-defmethod jupyter-connect-client ((comm jupyter-server)
336+
(cl-defmethod jupyter-comm-add-handler ((comm jupyter-server)
337337
(kcomm jupyter-server-kernel-comm))
338338
(cl-call-next-method)
339339
(with-slots (id) (oref kcomm kernel)
340340
(unless (jupyter-server-kernel-connected-p comm id)
341341
(jupyter-server--connect-channels comm id))))
342342

343-
(cl-defmethod jupyter-disconnect-client ((comm jupyter-server)
343+
(cl-defmethod jupyter-comm-remove-handler ((comm jupyter-server)
344344
(kcomm jupyter-server-kernel-comm))
345345
(with-slots (id) (oref kcomm kernel)
346346
(when (jupyter-server-kernel-connected-p comm id)
@@ -400,11 +400,11 @@ kernel associated with COMM, then COMM's `jupyter-event-handler'
400400
will receive those events."
401401
(with-slots (server) (oref comm kernel)
402402
(jupyter-comm-start server)
403-
(jupyter-connect-client server comm)))
403+
(jupyter-comm-add-handler server comm)))
404404

405405
(cl-defmethod jupyter-comm-stop ((comm jupyter-server-kernel-comm) &rest _ignore)
406406
"Disconnect COMM from receiving server events."
407-
(jupyter-disconnect-client (oref (oref comm kernel) server) comm))
407+
(jupyter-comm-remove-handler (oref (oref comm kernel) server) comm))
408408

409409
(cl-defmethod jupyter-send ((comm jupyter-server-kernel-comm) event-type &rest event)
410410
"Use COMM to send an EVENT to the server with type, EVENT-TYPE.
@@ -422,7 +422,7 @@ ID of the kernel associated with COMM."
422422
(oref kernel server)
423423
(oref kernel id))
424424
(catch 'member
425-
(jupyter-comm-client-loop (oref kernel server) client
425+
(jupyter-comm-handler-loop (oref kernel server) client
426426
(when (eq client comm)
427427
(throw 'member t)))))))
428428

@@ -660,7 +660,7 @@ see ‘jupyter-make-client’."
660660
(manager (jupyter-server-kernel-manager :kernel kernel)))
661661
;; Needs to be started before calling `jupyter-make-client' since that
662662
;; method will send a request to start a websocket channel to the kernel.
663-
;; FIXME: This should be done in a `jupyter-initialize-connection' method,
663+
;; FIXME: This should be done in a `jupyter-comm-initialize' method,
664664
;; but first that method needs to be generalize in `jupyter-client.el'
665665
(unless (jupyter-kernel-alive-p manager)
666666
(jupyter-start-kernel manager))

jupyter-zmq-channel-comm.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
(if (eq channel :hb) (jupyter-start-channel (oref comm hb))
127127
(jupyter-start-channel (plist-get (oref comm channels) channel)))))
128128

129-
(cl-defmethod jupyter-initialize-connection ((comm jupyter-zmq-channel-comm)
129+
(cl-defmethod jupyter-comm-initialize ((comm jupyter-zmq-channel-comm)
130130
(session jupyter-session))
131131
(cl-call-next-method)
132132
(let ((endpoints (jupyter-session-endpoints session)))

test/jupyter-server-test.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@
277277
(let ((kcomm (jupyter-server-kernel-comm
278278
:kernel kernel)))
279279
(should-not (jupyter-server-kernel-connected-p server id))
280-
(jupyter-connect-client server kcomm)
280+
(jupyter-comm-add-handler server kcomm)
281281
(should (jupyter-server-kernel-connected-p server id))
282282
(should (jupyter-comm-alive-p kcomm))
283283
(jupyter-comm-stop kcomm)
@@ -386,7 +386,7 @@
386386
(should (jupyter-comm-alive-p (oref manager comm)))
387387
(should (slot-boundp client 'kcomm))
388388
(should (eq (oref manager comm) (oref client kcomm)))
389-
(jupyter-comm-client-loop (oref client kcomm) c
389+
(jupyter-comm-handler-loop (oref client kcomm) c
390390
(should (eq c client)))
391391
(should (equal (jupyter-eval "1 + 1") "2")))
392392
(jupyter-shutdown-kernel manager)))))

0 commit comments

Comments
 (0)