Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support notebooks #1410

Merged
merged 92 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
623d832
feat: sql notebook
saravmajestic Jul 24, 2024
2eb7d78
fix: autocomplete, new actions
saravmajestic Jul 24, 2024
f3b3615
fix: save notebook
saravmajestic Jul 24, 2024
5501f2c
wip: perspective
saravmajestic Jul 24, 2024
3aaa2cc
fix: minor issues
saravmajestic Jul 25, 2024
2e0ad0f
fix: renderer rendering
saravmajestic Jul 26, 2024
4b263a1
Merge branch 'master' into poc/notebook
saravmajestic Jul 26, 2024
d7b389b
fix: panels build
saravmajestic Jul 26, 2024
cc3fe6e
fix: jupyter integration
saravmajestic Jul 29, 2024
f462f5a
chore: python integration
saravmajestic Jul 31, 2024
f4792c4
fix: execute python
saravmajestic Jul 31, 2024
56dc43a
fix: new cell on execution
saravmajestic Jul 31, 2024
0d14a81
fix: python execution with altimate kernel and sharing between cells
saravmajestic Aug 1, 2024
aedbaef
fix: repeated execution
saravmajestic Aug 1, 2024
3100261
fix: reference jinja output in python cell
saravmajestic Aug 1, 2024
f65e355
fix: flow
saravmajestic Aug 1, 2024
6d1ccc9
Merge branch 'master' into poc/notebook
saravmajestic Aug 1, 2024
dded39a
fix: pandas display
saravmajestic Aug 2, 2024
d1251fb
chore: cleanup
saravmajestic Aug 2, 2024
fce2d19
fix: kernel timeouts
saravmajestic Aug 2, 2024
1a07e6c
Merge branch 'master' into poc/notebook
saravmajestic Aug 5, 2024
48e4e17
WIP: profile integration
saravmajestic Aug 6, 2024
0cae916
wip: kernel client
saravmajestic Aug 7, 2024
5b787b8
fix: using jupyter style code with web sockets
saravmajestic Aug 8, 2024
4c53598
fix: almost there
saravmajestic Aug 8, 2024
db99de4
fix: working version with ipywidgets
saravmajestic Aug 9, 2024
e1ab49a
Merge branch 'master' into poc/notebook
saravmajestic Aug 9, 2024
d74950d
Merge branch 'master' into poc/notebook
saravmajestic Aug 13, 2024
53600a2
fix: minor updates
saravmajestic Aug 13, 2024
783f828
chore: add telemetry
saravmajestic Aug 13, 2024
3f016b6
fix: notebook dependencies
saravmajestic Aug 13, 2024
5ca98e5
chore: notebook kernel client cleanup
saravmajestic Aug 13, 2024
607549b
chore: cleanup raw kernel client
saravmajestic Aug 14, 2024
5c205d4
Merge branch 'master' into poc/notebook
saravmajestic Aug 14, 2024
06a0119
chore: cleanup renderer
saravmajestic Aug 14, 2024
d383d0d
chore: python kernel cleanup
saravmajestic Aug 14, 2024
1bb038d
chore: controller cleanup
saravmajestic Aug 14, 2024
cd08c96
chore: dependency cleanup
saravmajestic Aug 14, 2024
f117961
chore: custom save
saravmajestic Aug 14, 2024
a257bd2
fix: consolidate open notebook with marketplace notebooks
saravmajestic Aug 15, 2024
c745dff
fix: custom file system provider for notebooks
saravmajestic Aug 15, 2024
8853b4e
fix: install ipywidgets
saravmajestic Aug 15, 2024
1646e8f
Merge branch 'master' into poc/notebook
saravmajestic Aug 15, 2024
3b54e2b
fix: show installed after complete
saravmajestic Aug 16, 2024
c6a99b1
refactor: serialize
saravmajestic Aug 16, 2024
c9fa0ff
fix: saving untitled file
saravmajestic Aug 16, 2024
d176053
fix: move notebooks to insights
saravmajestic Aug 16, 2024
96dd638
revert: unnecessary changes
saravmajestic Aug 16, 2024
91e339b
fix: renderer build
saravmajestic Aug 16, 2024
c964db1
fix: bundling extension and dont ignore dist/node_modules directory i…
saravmajestic Aug 17, 2024
fc761fd
feat: from components
saravmajestic Aug 19, 2024
a2077e2
fix: config updates
saravmajestic Aug 19, 2024
5227b84
chore: remove ipywidgets
saravmajestic Aug 20, 2024
0babd04
chore: revert unnecessary changes
saravmajestic Aug 20, 2024
b106530
chore: revert unnecessary changes
saravmajestic Aug 20, 2024
0bbecf5
chore: fixes
saravmajestic Aug 21, 2024
5b78209
update API calls
svipulrao98 Aug 31, 2024
a1a4db0
fix: postinstall file name
saravmajestic Sep 2, 2024
3cd6125
fix: use alias for notebook lib
saravmajestic Sep 2, 2024
2ad8299
fix: debug
saravmajestic Sep 2, 2024
c8bf9e0
chore: ignore directories and setup prebuild
saravmajestic Sep 3, 2024
92a4c1a
Merge branch 'master' into poc/notebook
saravmajestic Sep 3, 2024
524e5e3
fix: add postinstall in gha
saravmajestic Sep 3, 2024
5c63361
Support context
mdesmet Sep 9, 2024
31339c5
fix: ghost cell fix
saravmajestic Sep 9, 2024
320b009
fix: dbt packages install
saravmajestic Sep 10, 2024
0e4a816
feat: separate pre configured list & normal list
svipulrao98 Sep 10, 2024
565ecf3
Merge branch 'poc/notebook' of https://github.com/AltimateAI/vscode-d…
svipulrao98 Sep 10, 2024
0654935
feat: export DBTProject
svipulrao98 Sep 10, 2024
4517136
fix: notebook list & open
svipulrao98 Sep 10, 2024
784d553
fix: update notebook
svipulrao98 Sep 10, 2024
c80141d
WIP: update notebook privacy
svipulrao98 Sep 10, 2024
e6f7e37
WIP: update notebook privacy
svipulrao98 Sep 10, 2024
d08e030
fix: return the response
svipulrao98 Sep 10, 2024
693cc90
WIP: pre configured notebook
svipulrao98 Sep 11, 2024
a0f09f2
fix: preconfigured notebooks execution
saravmajestic Sep 11, 2024
8a56c7c
fix: pre configured listing
svipulrao98 Sep 11, 2024
f3165da
Merge branch 'master' into poc/notebook
saravmajestic Sep 11, 2024
cf48692
Merge branch 'poc/notebook' of https://github.com/AltimateAI/vscode-d…
saravmajestic Sep 11, 2024
76cae61
fix: update components
saravmajestic Sep 11, 2024
027cb07
fix: execute after install
saravmajestic Sep 11, 2024
6889324
notebook listing
svipulrao98 Sep 11, 2024
175941a
Merge branch 'poc/notebook' of https://github.com/AltimateAI/vscode-d…
svipulrao98 Sep 11, 2024
70ccfbb
fix: update components
saravmajestic Sep 11, 2024
844d63a
fix: listing, add public notebooks section
svipulrao98 Sep 11, 2024
231eb4d
Merge branch 'poc/notebook' of https://github.com/AltimateAI/vscode-d…
svipulrao98 Sep 11, 2024
ca86f01
fix: minor UI/UX
svipulrao98 Sep 11, 2024
3bf7a23
fix: saved notebook open
saravmajestic Sep 12, 2024
6d74c67
fix: minor UI/UX issues
svipulrao98 Sep 12, 2024
36c6ebf
fix: ntoebooks in multiproject ws
saravmajestic Sep 12, 2024
4086eb6
Merge branch 'master' into poc/notebook
mdesmet Sep 12, 2024
28ac020
Update action.yml
saravmajestic Sep 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/actions/common-build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ runs:
- run: npm install
shell: bash # Explicitly define the shell
working-directory: ./webview_panels
- run: npm run postinstall
shell: bash

4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ dist
.DS_Store
.idea
.history
__pycache__/
__pycache__/

src/lib/notebooks/
8 changes: 8 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@
out/**
src/**
**/node_modules
!dist/node_modules/**
.gitignore
vsc-extension-quickstart.md
**/tsconfig.json
**/.eslintrc.json
**/*.map
**/*.ts
.github
lineage_panel
new_lineage_panel
!new_lineage_panel/dist
webview_panels
!webview_panels/dist
query_panel
206 changes: 206 additions & 0 deletions altimate_notebook_kernel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
import json
import re
from datetime import datetime
import jupyter_client
import queue

class CustomDecoder(json.JSONDecoder):
def __init__(self, *args, **kwargs):
super().__init__(object_hook=self.object_hook, *args, **kwargs)
def object_hook(self, obj):
for key, value in obj.items():
if value == 'null':
obj[key] = None
return obj


# Notebook kernel which will responsible for creating kernel executors for each notebook
# should shut down kernel after notebook is closed
# also store the cell outputs/data and use it for further executions
# TODO: implement as required - extract to separate file


# a method which will be called once a notebook is open, create an instance of this class
# save doc uri as unique identifier for the notebook
# initialize a jupyter kernel executor on notebook open and shutdown on close
# store results of each cell execution and update after each execution
# handle cell deletions
# destroy this instance when notebook is closed

class JupyterKernelExecutor:
def __init__(self):
self.kernel_manager = jupyter_client.KernelManager()
self.kernel_manager.start_kernel()
self.kernel_client = self.kernel_manager.client()
self.kernel_client.start_channels()
print('session pid', self.kernel_client.session.pid)
# print('ip', self.kernel_manager.connection_file.split('-')[1])
# Get the connection file
connection_file = self.kernel_manager.connection_file
# Load connection info
connection_info = jupyter_client.find_connection_file(connection_file)
with open(connection_info) as f:
connection_data = json.load(f)

# Extract WebSocket URL
websocket_url = f"ws://{connection_data['ip']}:{connection_data['shell_port']}/api/kernels/{self.kernel_manager.kernel_id}/channels"
print(connection_data, self.kernel_manager.kernel_name, self.kernel_manager.kernel_spec.name)

def execute(self, code, user_expressions=None):
self.kernel_client.wait_for_ready()

# print("Executing code:", code, user_expressions)
# Execute the code
self.kernel_client.execute(code, silent=False, store_history=True, user_expressions=user_expressions)

# Capture and return the output
output = []
start_time = datetime.now()
while True:
try:
msg = self.kernel_client.get_iopub_msg(timeout=1)
def datetime_converter(o):
if isinstance(o, datetime):
return o.__str__()

# Print formatted JSON
# print("msg", msg)

if msg['msg_type'] == 'stream':
# for stdout
output.append({'mime': 'text/plain', 'value': msg['content']['text']})
break
elif msg['msg_type'] == 'comm_open':
state = msg['content']['data']['state']
state['model_id'] = msg['content']['comm_id']
# Handle comm_open messages
output.append({'mime': 'application/vnd.jupyter.widget-view+json', 'value': state})
elif msg['msg_type'] == 'execute_result' or msg['msg_type'] == 'display_data':
# Flag to check if any key other than 'text/plain' exists
other_keys_exist = False

# Iterate over the keys in msg['content']['data']
for key, value in msg['content']['data'].items():
# Check if the key is not 'text/plain'
if key != 'text/plain':
# Append the dictionary to the output list
output.append({'mime': key, 'value': value})
other_keys_exist = True

# If no other keys exist, add the 'text/plain' value
if not other_keys_exist:
output.append({'mime': 'text/plain', 'value': msg['content']['data']['text/plain']})
break
elif msg['msg_type'] == 'error':
output.append({'mime': 'text/plain', 'value': '\n'.join(msg['content']['traceback'])})
break
elif msg['msg_type'] == 'status' and msg['content']['execution_state'] == 'idle':
break
except queue.Empty:
if (datetime.now() - start_time).total_seconds() > 30: # Timeout after 30 seconds
break
return output

def shutdown(self):
# Shutdown the kernel client and kernel manager
self.kernel_client.stop_channels()
self.kernel_manager.shutdown_kernel()
del self.kernel_client

class AltimateNotebookKernel:
def __init__(self, doc_uri):
"""
Initialize the AltimateNotebookKernel instance.

Parameters:
doc_uri (str): The unique identifier for the notebook.
"""
self.doc_uri = doc_uri
self.kernel_executor = self.initialize_kernel_executor()
self.cell_results = {}

def get_session_id(self):
return self.kernel_executor.kernel_client.session.pid

def close_notebook(self):
"""
Method to be called when the notebook is closed.
Shuts down the Jupyter kernel executor.
"""
if self.kernel_executor:
self.shutdown_kernel_executor()
self.kernel_executor = None
print(f"Notebook {self.doc_uri} closed and kernel shut down.")

def get_connection_file(self):
return self.kernel_executor.kernel_manager.connection_file

def initialize_kernel_executor(self):
"""
Initializes the Jupyter kernel executor.

Returns:
kernel_executor: The initialized kernel executor.
"""
kernel_executor = JupyterKernelExecutor()
return kernel_executor

def shutdown_kernel_executor(self):
"""
Shuts down the Jupyter kernel executor.
"""
# Placeholder for actual kernel shutdown logic
print("Kernel executor shut down.")

def get_sql_result_by_cell(self, cell_id):
code = f"cell_{cell_id}"
return self.kernel_executor.execute(code)

def store_sql_result(self, cell_id, result):
"""
Stores the result of a cell execution.

Parameters:
cell_id (str): The unique identifier for the cell.
result: The result of the cell execution.
"""
resultJson = json.loads(result)

# Construct the code to store the result in the Jupyter kernel
code = f"""
cell_{cell_id} = {resultJson}
"""
self.execute_python(code)

def execute_python(self, code):
"""
Executes a cell and stores the result.

Parameters:
cell_id (str): The unique identifier for the cell.
code (str): The code to be executed in the cell.

Returns:
result: The result of the cell execution.
"""
response = self.kernel_executor.execute(code)
return response

def delete_cell(self, cell_id):
"""
Handles cell deletion.

Parameters:
cell_id (str): The unique identifier for the cell to be deleted.
"""
if cell_id in self.cell_results:
del self.cell_results[cell_id]
print(f"Cell {cell_id} deleted.")

def destroy_instance(self):
"""
Destroys the instance when the notebook is closed.
"""
self.close_notebook()
self.cell_results.clear()
print(f"Instance for notebook {self.doc_uri} destroyed.")
Loading