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

standardize cell function call names to cell() and cells() #85

Merged
Merged
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
29 changes: 25 additions & 4 deletions src/core/computations/python/run_python.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import GetCellsDB

import sys
import re
import traceback
import pyodide
import asyncio
Expand All @@ -20,11 +21,17 @@


def attempt_fix_await(code):
code = code.replace("getCell", "await getCell")
code = code.replace("await await getCell", "await getCell")
# Insert a "await" keyword between known async functions to improve the UX
code = re.sub(r"([^a-zA-Z0-9]|^)cells\(", r"\1await cells(", code)
code = re.sub(r"([^a-zA-Z0-9]|^)cell\(", r"\1await cell(", code)
code = re.sub(r"([^a-zA-Z0-9]|^)c\(", r"\1await c(", code)
code = re.sub(r"([^a-zA-Z0-9]|^)getCells\(", r"\1await getCells(", code)

code = code.replace("c(", "await c(")
code = code.replace("await await getCell", "await getCell")
code = code.replace("await await c(", "await c(")
code = code.replace("await await cell(", "await cell(")
code = code.replace("await await cells(", "await cells(")

return code


Expand Down Expand Up @@ -168,10 +175,24 @@ async def getCell(p_x, p_y):
else:
return None

# Aliases for common functions
async def c(p0_x, p0_y):
return await getCell(p0_x, p0_y)

globals = {"getCells": getCells, "getCell": getCell, "c": c, "result": None}
async def cell(p0_x, p0_y):
return await getCell(p0_x, p0_y)

async def cells(p0, p1):
return await getCells(p0, p1)

globals = {
"getCells": getCells,
"getCell": getCell,
"c": c,
"result": None,
"cell": cell,
"cells": cells,
}

sout = StringIO()
output_value = None
Expand Down