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

App mode fix #139

Merged
merged 7 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = zero-true
description = A collaborative notebook built for data scientists
long_description = file: README.md
long_description_content_type = text/markdown
version = 0.0.dev38
version = 0.0.dev39

[options]
include_package_data = true
Expand Down
1 change: 1 addition & 0 deletions zt_backend/models/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Cell(BaseModel):
code: str
defined_names: List[str]
loaded_names: List[str]
loaded_modules: List[str] = []
child_cells: List[int] = []
parent_cells: List[int] = []
previous_child_cells: List[int] = []
Expand Down
20 changes: 17 additions & 3 deletions zt_backend/runner/code_cell_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import re
import logging
import traceback
from zt_backend.config import settings


logger = logging.getLogger("__name__")

Expand All @@ -23,7 +25,14 @@ def get_functions(module) -> Tuple[List[str], List[str]]:
return function_names, argument_names

def get_defined_names(module) -> List[str]:
defined_names = [target.name for defnode in module.nodes_of_class(astroid.Assign) for target in defnode.targets if hasattr(target, 'name')]
defined_names = []
for defnode in module.nodes_of_class(astroid.Assign):
for target in defnode.targets:
if hasattr(target, 'name'): # Directly has a name (e.g., AssignName)
defined_names.append(target.name)
elif isinstance(target, astroid.Subscript): # Is a subscript
if hasattr(target.value, 'name'):
defined_names.append(target.value.name)
func_def_names = [arg.name for func in module.nodes_of_class(astroid.FunctionDef) for arg in func.args.args]
return list(set(defined_names) - set(func_def_names))

Expand Down Expand Up @@ -67,7 +76,10 @@ def generate_sql_code(cell, uuid_value, db_file='my_database.db'):

else:
# If variable_name is not provided, directly use the SQL execution
data_frame_conversion = f"zt.DataFrame.from_dataframe(id='{uuid_value}', df={sql_execution})"
if settings.run_mode == 'app':
data_frame_conversion = ''
else:
data_frame_conversion = f"zt.DataFrame.from_dataframe(id='{uuid_value}', df={sql_execution})"

full_code = f"{base_code}\n{db_init}\n{data_frame_conversion}"

Expand All @@ -93,6 +105,7 @@ def parse_cells(request: Request) -> CodeDict:
cell_dict[cell.id] = Cell(**{
'code': cell.code,
'defined_names': defined_names,
'loaded_modules':get_imports(module),
'loaded_names': list(set(loaded_names))})
except Exception as e:
logger.error("Error while parsing cells, returning empty names lists: %s", traceback.format_exc())
Expand Down Expand Up @@ -123,7 +136,8 @@ def find_child_cells(cell: Cell, code_dictionary: CodeDict, idx: int) -> List[st
for next_key in list(code_dictionary.cells.keys())[idx + 1:]:
next_cell = code_dictionary.cells[next_key]
next_loaded_names = next_cell.loaded_names
if set(names).intersection(set(next_loaded_names)):
next_loaded_modules = next_cell.loaded_modules
if set(names).intersection(set(next_loaded_names)-set(next_loaded_modules)):
child_cells.append(next_key)
return child_cells

Expand Down
10 changes: 5 additions & 5 deletions zt_backend/tests/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ def extract_code_cell_info(code_cell, driver):

def wait_for_load(driver):
driver.get("http://localhost:1326")
WebDriverWait(driver, 10).until(
WebDriverWait(driver, 60).until(
EC.presence_of_element_located((By.ID, "appBar")))

WebDriverWait(driver, 10).until(
WebDriverWait(driver, 60).until(
EC.presence_of_element_located((By.XPATH, "//div[contains(@id, 'codeCard')]")))

def clear_codemirror_and_send_text(driver,codemirror_input,text):
Expand All @@ -115,9 +115,9 @@ def clear_codemirror_and_send_text(driver,codemirror_input,text):

def wait_for_coderun(driver):
# Wait for the code run
WebDriverWait(driver, 30).until(
WebDriverWait(driver, 60).until(
EC.presence_of_element_located((By.ID, "codeRunProgress")))
WebDriverWait(driver, 30).until(
WebDriverWait(driver, 60).until(
EC.invisibility_of_element_located((By.ID, "codeRunProgress")))

def test_notebook_content(driver):
Expand Down Expand Up @@ -158,7 +158,7 @@ def test_adding_new_code_cell(driver):
cell_info = extract_code_cell_info(code_cells[0],driver)
add_icon = cell_info["elements"]["add_cell"]
add_icon.click()
WebDriverWait(driver, 10).until(
WebDriverWait(driver, 60).until(
EC.presence_of_element_located((By.ID, f"addCell_Code_{cell_info['cell_id']}")))
assert driver.find_element(By.ID, f"addCell_Code_{cell_info['cell_id']}"), "Add code cell below not found"
add_code_cell = driver.find_element(By.ID,f"addCell_Code_{cell_info['cell_id']}")
Expand Down
3 changes: 2 additions & 1 deletion zt_frontend/src/components/CodeComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ export default {
{
key: "Ctrl-Enter",
run: () => {
handleCtrlEnter();
if (this.$devMode){
handleCtrlEnter()};
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion zt_frontend/src/components/EditorComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default {
init: {
plugins: "autoresize",
toolbar:
"undo redo | bold italic underline strikethrough | fontselect fontsizeselect formatselect | alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist | forecolor backcolor removeformat | pagebreak | charmap emoticons | fullscreen preview save print | insertfile image media template link anchor codesample | ltr rtl",
"undo redo | bold italic underline strikethrough | fontfamily fontsize blocks | alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist | forecolor backcolor removeformat | pagebreak | charmap emoticons | fullscreen preview save print | insertfile image media template link anchor codesample | ltr rtl",
branding: false,
menubar: false,
statusbar: false,
Expand Down
12 changes: 9 additions & 3 deletions zt_frontend/src/components/SQLComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@
View Source Code
</v-expansion-panel-title>
<v-expansion-panel-text>
<v-text-field
v-model="cellData.variable_name"
label="Enter SQL variable name"
density="compact"
:readonly="true"
/>
<codemirror
v-if="$devMode"
v-model="cellData.code"
:style="{ height: '400px' }"
:autofocus="true"
Expand All @@ -55,7 +60,7 @@
<p class="text-caption text-disabled text-right">
CTRL+Enter to run</p>
</div>
<v-container v-for="component in cellData.components" :key="component.id">
<v-container v-if="$devMode" v-for="component in cellData.components" :key="component.id">
<component
:is="component.component"
v-bind="component"
Expand Down Expand Up @@ -109,7 +114,8 @@ export default {
{
key: "Ctrl-Enter",
run: () => {
handleCtrlEnter();
if (this.$devMode){
handleCtrlEnter()};
return true;
}
}
Expand Down