Skip to content

Commit

Permalink
fix(bug-solve): fix the minor issues in functionalities (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
priyakanabar-crest authored Nov 11, 2024
1 parent 9adb51d commit 196c752
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 19 deletions.
72 changes: 72 additions & 0 deletions mintlify-docs/Components/FileInput.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
icon: "rectangle-code"
iconType: "solid"
---



<Info>Below are the various attributes you can assign to the component. Utilizing them can allow for modifications to the pre-created object.</Info>

<ResponseField name="zero_true.FileInput" type="Zero True Component">
<Expandable title="properties">
<AccordionGroup>
<Accordion title="id">
**id (string):** Unique identifier for the file input component
</Accordion>
<Accordion title="accept">
**accept (string):** Accepted file types (e.g., '.png, .jpg, .pdf'). Default: "*"
</Accordion>
<Accordion title="placeholder">
**placeholder (string):** Placeholder text shown before file selection. Default: "Select file(s)"
</Accordion>
<Accordion title="label">
**label (string):** Label text for the file input
</Accordion>
<Accordion title="multiple">
**multiple (boolean):** If true, allows multiple file uploads. Default: False
</Accordion>
<Accordion title="show_size">
**show_size (boolean):** If true, displays the file size. Default: True
</Accordion>
<Accordion title="readonly">
**readonly (boolean):** If true, the input is read-only. Default: False
</Accordion>
<Accordion title="disabled">
**disabled (boolean):** If true, the input is disabled. Default: False
</Accordion>
<Accordion title="clearable">
**clearable (boolean):** If true, allows clearing of selected files. Default: True
</Accordion>
<Accordion title="counter">
**counter (boolean):** If true, shows a file count indicator. Default: False
</Accordion>
</AccordionGroup>
</ResponseField>

<Card title="Example Usage" icon="code">
```python
import zero_true as zt

sample_fileinput = zt.FileInput(
id='sample_fileinput', # Unique identifier for the component
accept='.pdf, .docx, .txt', # Accepted file types
placeholder='Drop files here', # Placeholder text
label='Document Upload', # Label for the file input
multiple=True, # Allow multiple file uploads
show_size=True, # Show file sizes
readonly=False, # Not read-only
disabled=False, # Not disabled
clearable=True, # Allow clearing of selection
counter=True, # Show file count
)

# Accessing uploaded files
if sample_fileinput.value:
# Get list of file names
file_names = sample_fileinput.get_file_names()

# Get a specific file
pdf_file = sample_fileinput.get_file("document.pdf")

```
</Card>
49 changes: 40 additions & 9 deletions zt_backend/utils/linting.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@

# Constants
DEBOUNCE_TIME = 0.5 # seconds
RUFF_COMMAND = ['ruff', 'check', '--output-format=json', '-']
RUFF_COMMAND = [
'ruff',
'check',
'--output-format=json',
'--extend-ignore=E402', # Ignore import position errors
'-'
]

# Setup logging
logging.basicConfig(level=logging.INFO)
Expand Down Expand Up @@ -42,6 +48,13 @@ def get_severity(code: str) -> str:
if not code:
return 'error' # Treat empty codes as syntax errors

if code == 'F401':
return 'warning'

# Special handling for F8 series, excluding F82
if code.startswith('F8') and not code.startswith('F82'):
return 'warning'

severity_map = {
'E': 'error',
'F': 'error',
Expand All @@ -54,11 +67,6 @@ def get_severity(code: str) -> str:
'R': 'info', # Refactoring suggestions
'S': 'warning', # Security issues
}

# Special handling for F8 series, excluding F82
if code.startswith('F8') and not code.startswith('F82'):
return 'warning'

return severity_map.get(code[0], 'warning')

def transform_ruff_results(lint_errors: List[Dict], cell_line_count: int) -> List[Dict]:
Expand Down Expand Up @@ -95,9 +103,32 @@ def transform_ruff_results(lint_errors: List[Dict], cell_line_count: int) -> Lis

async def queued_get_cell_linting(cell_id: str, text: str, code_w_context: str) -> Dict[str, List[Dict]]:
try:
context_lines = code_w_context.split('\n')
cell_lines = text.split('\n')
cell_start_line = context_lines.index(cell_lines[0])
context_lines = code_w_context.strip().split('\n')
cell_lines = text.strip().split('\n')

# More robust way to find the cell start line
cell_first_line = cell_lines[0].strip()
cell_start_line = -1

# Look for the first line of the cell in the context, ignoring whitespace
for i, line in enumerate(context_lines):
if line.strip() == cell_first_line:
# Verify this is actually the start of our cell by checking subsequent lines
matches = True
for j, cell_line in enumerate(cell_lines):
if i + j >= len(context_lines) or context_lines[i + j].strip() != cell_line.strip():
matches = False
break
if matches:
cell_start_line = i
break

if cell_start_line == -1:
# If we can't find the cell in context, just lint the cell directly
logger.warning(f"Could not find cell content in context for cell {cell_id}, linting cell directly")
lint_errors = await run_ruff_linting(text)
transformed_messages = transform_ruff_results(lint_errors, len(cell_lines))
return {cell_id: transformed_messages}

# Prepare context-aware cell text
preceding_context = '\n'.join(context_lines[:cell_start_line])
Expand Down
4 changes: 2 additions & 2 deletions zt_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def app(
os.environ["WS_URL"] = f"ws://{host}:{port}/"
os.environ["LOCAL_URL"] = f"http://{host}:{port}/"

uvicorn.run("zt_backend.main:app", host=host, port=port, ws_max_size=52428800, log_config=log_config_dict)
uvicorn.run("zt_backend.main:app", host=host, port=port, ws_max_size=209715200, log_config=log_config_dict)


@cli_app.command()
Expand Down Expand Up @@ -226,7 +226,7 @@ def notebook(
os.environ["WS_URL"] = f"ws://{host}:{port}/"
os.environ["LOCAL_URL"] = f"http://{host}:{port}/"

uvicorn.run("zt_backend.main:app", host=host, port=port, ws_max_size=52428800, log_config=log_config_dict)
uvicorn.run("zt_backend.main:app", host=host, port=port, ws_max_size=209715200, log_config=log_config_dict)


@cli_app.command()
Expand Down
4 changes: 2 additions & 2 deletions zt_dev_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def app(
backend_cmd = [
"uvicorn",
"zt_backend.main:app",
"--ws-max-size=52428800",
"--ws-max-size=209715200",
"--reload",
f"--log-config={log_path}",
]
Expand Down Expand Up @@ -103,7 +103,7 @@ def notebook(
backend_cmd = [
"uvicorn",
"zt_backend.main:app",
"--ws-max-size=52428800",
"--ws-max-size=209715200",
"--reload",
f"--log-config={log_path}",
]
Expand Down
52 changes: 50 additions & 2 deletions zt_frontend/src/components/ComponentWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,24 @@
v-else-if="component.component === 'v-file-input'"
:is="component.component"
v-bind="componentBind(component)"
:error="errors[component.id]?.hasError"
:error-messages="errors[component.id]?.message"
:key="`${component.id}-${Date.now()}`"
@update:model-value="
async (newValue: File[]) => {
component.value = await createFormData(newValue);
async (newValue: any) => {
if (!newValue) return;
const files = Array.isArray(newValue) ? newValue : [newValue];
const totalSize = files.reduce((acc, file) => acc + file.size, 0);
const maxSize = 50 * 1024 * 1024; // 50 MB in bytes
if (totalSize > maxSize) {
setError(component.id, 'Total file size must not exceed 50 MB');
return;
}
// Clear any existing error
clearError(component.id);
component.value = await createFormData(files);
runCode(true, component.id, component.value);
}
"
Expand Down Expand Up @@ -66,6 +81,7 @@ import {
import { VDataTable } from "vuetify/components/VDataTable";
import TextComponent from "@/components/TextComponent.vue";
import PlotlyPlot from "@/components/PlotlyComponent.vue";
import { Console } from "console";
export default {
components: {
Expand Down Expand Up @@ -96,6 +112,36 @@ export default {
required: true,
},
},
setup() {
const errors = ref<Record<string, { hasError: boolean; message: string }>>({});
const setError = (componentId: string, message: string) => {
errors.value[componentId] = {
hasError: true,
message: message
};
return {
errors,
setError,
clearError,
};
};
const clearError = (componentId: string) => {
if (errors.value[componentId]) {
errors.value[componentId] = {
hasError: false,
message: ''
};
}
};
return {
errors,
setError,
clearError
};
},
methods: {
componentBind(component: any) {
if (
Expand Down Expand Up @@ -180,9 +226,11 @@ export default {
async createFormData(files: Array<File>) {
const fileList: { [key: string]: any } = {};
for (const file of files) {
if (file) {
const fileb64 = await this.fileToBase64(file);
fileList[file.name] = fileb64;
}
}
return fileList;
},
},
Expand Down
7 changes: 6 additions & 1 deletion zt_frontend/src/components/FileExplorer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
<v-spacer />
<FileFolderCreator :current-path="currentPath" @item-created="refreshFiles" />
<FileUploader :current-path="currentPath" @file-uploaded="refreshFiles" />
<v-btn
color="bluegrey-darken-4"
icon="mdi-refresh"
@click="refreshFiles"
/>
<v-btn
color="bluegrey-darken-4"
icon="mdi-close"
Expand Down Expand Up @@ -135,7 +140,7 @@ export default defineComponent({
const errorMessage = ref("");
const showError = ref(false);
// Define the list of protected files
const protectedFiles = ref(["requirements.txt", "notebook.ztnb"]);
const protectedFiles = ref(["requirements.txt", "notebook.ztnb","zt_db.db","zt_db.db.wal"]);
// Function to check if a file is protected
const isProtectedFile = (filename: string) => {
Expand Down
5 changes: 2 additions & 3 deletions zt_frontend/src/components/MarkdownComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,15 @@ export default {
/* Headings */
.markdown-content :deep(h1),.markdown-content :deep(h2), .markdown-content :deep(h3), .markdown-content :deep(h4), .markdown-content :deep(h5), .markdown-content :deep(h6) {
margin-top: 1.5em;
margin-bottom: 0.5em;
margin-bottom: 0.2em;
font-weight: bold;
line-height: 1.3;
}
/* Paragraphs */
.markdown-content :deep(p) {
margin-top: 0;
margin-bottom: 1em;
margin-bottom: 0.2em;
}
/* Lists */
Expand Down

0 comments on commit 196c752

Please sign in to comment.