Skip to content

Commit 5184d48

Browse files
diningPhilosopher64prabhakk-mw
authored andcommitted
Addressed review comments
1 parent 5be8041 commit 5184d48

File tree

14 files changed

+90
-29
lines changed

14 files changed

+90
-29
lines changed

src/jupyter_matlab_kernel/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023-2024 The MathWorks, Inc.
1+
# Copyright 2023-2025 The MathWorks, Inc.
22
# Use ipykernel infrastructure to launch the MATLAB Kernel.
33

44
if __name__ == "__main__":

src/jupyter_matlab_kernel/kernels/base_kernel.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ def _get_parent_pid(logger) -> int:
9292
"""
9393
parent_pid = os.getppid()
9494

95-
logger.info("Type ", type(parent_pid), " parent pid ", parent_pid)
96-
9795
# Note: conda environments do not require this, and for these environments
9896
# sys.prefix == sys.base_prefix
9997
is_virtual_env = sys.prefix != sys.base_prefix

src/jupyter_matlab_kernel/kernels/jsp_kernel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 The MathWorks, Inc.
1+
# Copyright 2024-2025 The MathWorks, Inc.
22

33
"""This module contains derived class implementation of MATLABKernel that uses
44
Jupyter Server to manage interactions with matlab-proxy & MATLAB.

src/jupyter_matlab_kernel/kernels/labextension_comm/communication.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,7 @@ def comm_open(self, stream, ident, msg):
2323

2424
async def comm_msg(self, stream, ident, msg):
2525
"""Handler to execute when labextension sends a message with 'comm_msg' type."""
26-
27-
content = msg["content"]
28-
data = content["data"]
29-
action_type = data["action"]
30-
payload = data["data"]
31-
comm_id = content["comm_id"]
32-
comm = self.comms.get(comm_id)
33-
34-
if not comm:
35-
self.log.error(
36-
"Received comm_msg but no communication channel is available"
37-
)
38-
raise Exception("No Communcation channel available")
39-
40-
self.log.debug(
41-
f"Received action_type:{action_type} with data:{payload} from the lab extension"
42-
)
26+
pass
4327

4428
def comm_close(self, stream, ident, msg):
4529
"""Handler to execute when labextension sends a message with 'comm_close' type."""

src/jupyter_matlab_kernel/mwi_comm_helpers.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ async def send_shutdown_request_to_matlab(self):
179179
)
180180

181181
async def send_interrupt_request_to_matlab(self):
182+
"""Send an interrupt request to MATLAB to stop current execution.
183+
184+
The interrupt request is sent through the control channel using a specific message format.
185+
186+
Raises:
187+
HTTPError: If the interrupt request fails or matlab-proxy communication errors occur
188+
"""
182189
self.logger.debug("Sending interrupt request to MATLAB")
183190
req_body = {
184191
"messages": {
@@ -201,6 +208,24 @@ async def send_interrupt_request_to_matlab(self):
201208
resp.raise_for_status()
202209

203210
async def _send_feval_request_to_matlab(self, http_client, fname, nargout, *args):
211+
"""Execute a MATLAB function call (feval) through the matlab-proxy.
212+
213+
Sends a function evaluation request to MATLAB, handling path setup and synchronous execution.
214+
215+
Args:
216+
http_client (aiohttp.ClientSession): HTTP client for sending the request
217+
fname (str): Name of the MATLAB function to call
218+
nargout (int): Number of output arguments expected
219+
*args: Variable arguments to pass to the MATLAB function
220+
221+
Returns:
222+
list: Results from the MATLAB function execution if successful
223+
Empty list if no outputs or nargout=0
224+
225+
Raises:
226+
MATLABConnectionError: If MATLAB connection is lost or response is invalid
227+
Exception: If function execution fails or is interrupted by user
228+
"""
204229
self.logger.debug("Sending FEval request to MATLAB")
205230
# Add the MATLAB code shipped with kernel to the Path
206231
path = [str(pathlib.Path(__file__).parent / "matlab")]
@@ -265,9 +290,35 @@ async def _send_feval_request_to_matlab(self, http_client, fname, nargout, *args
265290
raise resp.raise_for_status()
266291

267292
async def send_eval_request_to_matlab(self, mcode):
293+
"""Send an evaluation request to MATLAB using the shell client.
294+
295+
Args:
296+
mcode (str): MATLAB code to be evaluated
297+
298+
Returns:
299+
dict: The evaluation response from MATLAB containing results or error information
300+
301+
Raises:
302+
MATLABConnectionError: If MATLAB connection is not available
303+
HTTPError: If there is an error in communication with matlab-proxy
304+
"""
268305
return await self._send_eval_request_to_matlab(self._http_shell_client, mcode)
269306

270307
async def _send_eval_request_to_matlab(self, http_client, mcode):
308+
"""Internal method to send and process an evaluation request to MATLAB.
309+
310+
Args:
311+
http_client (aiohttp.ClientSession): HTTP client to use for the request
312+
mcode (str): MATLAB code to be evaluated
313+
314+
Returns:
315+
dict: The evaluation response containing results or error information
316+
from the MATLAB execution
317+
318+
Raises:
319+
MATLABConnectionError: If MATLAB connection is not available or response is invalid
320+
HTTPError: If there is an error in communication with matlab-proxy
321+
"""
271322
self.logger.debug("Sending Eval request to MATLAB")
272323
# Add the MATLAB code shipped with kernel to the Path
273324
path = str(pathlib.Path(__file__).parent / "matlab")
@@ -307,6 +358,20 @@ async def _send_eval_request_to_matlab(self, http_client, mcode):
307358
raise resp.raise_for_status()
308359

309360
async def _send_jupyter_request_to_matlab(self, request_type, inputs, http_client):
361+
"""Process and send a Jupyter request to MATLAB using either feval or eval execution.
362+
363+
Args:
364+
request_type (str): Type of request (execute, complete, shutdown)
365+
inputs (list): List of input arguments for the request
366+
http_client (aiohttp.ClientSession): HTTP client to use for the request
367+
368+
Returns:
369+
dict: Response from MATLAB containing results of the request execution
370+
371+
Raises:
372+
MATLABConnectionError: If MATLAB connection is not available
373+
Exception: If request execution fails or is interrupted
374+
"""
310375
execution_request_type = "feval"
311376

312377
inputs.insert(0, request_type)
@@ -347,6 +412,18 @@ async def _send_jupyter_request_to_matlab(self, request_type, inputs, http_clien
347412
return resp
348413

349414
async def _read_eval_response_from_file(self, eval_response):
415+
"""Read and process MATLAB evaluation results from a response file.
416+
417+
Args:
418+
eval_response (dict): Response dictionary from MATLAB eval request containing
419+
file path and error information
420+
421+
Returns:
422+
dict: JSON decoded results from the response file
423+
424+
Raises:
425+
Exception: If evaluation failed or was interrupted by user
426+
"""
350427
# If the eval request succeeded, return the json decoded result.
351428
if not eval_response["isError"]:
352429
result_filepath = eval_response["responseStr"].strip()

src/jupyter_matlab_labextension/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023-2024 The MathWorks, Inc.
1+
// Copyright 2023-2025 The MathWorks, Inc.
22

33
import { JupyterFrontEndPlugin } from '@jupyterlab/application';
44
import { matlabToolbarButtonPlugin } from './plugins/matlabToolbarButton';

src/jupyter_matlab_labextension/src/plugins/matlabCM6Mode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023-2024 The MathWorks, Inc.
1+
// Copyright 2023-2025 The MathWorks, Inc.
22

33
// Set up CodeMirror for the MATLAB language.
44

src/jupyter_matlab_labextension/src/plugins/matlabFiles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023-2024 The MathWorks, Inc.
1+
// Copyright 2023-2025 The MathWorks, Inc.
22

33
// Create a command to open a new .m file.
44
// Add this command to the Launcher (under "Other"),

src/jupyter_matlab_labextension/src/tests/jest-setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 The MathWorks, Inc.
1+
// Copyright 2025 The MathWorks, Inc.
22

33
// Mock global objects that might not be available in the Node.js environment
44

src/jupyter_matlab_labextension/src/tests/matlabToolbarButton.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 The MathWorks, Inc.
1+
// Copyright 2025 The MathWorks, Inc.
22

33
// Mock the icons module
44
jest.mock('../icons', () => ({

0 commit comments

Comments
 (0)