Skip to content

Commit 3a6eb76

Browse files
committed
improved Editor capabilities
1 parent 623d571 commit 3a6eb76

File tree

4 files changed

+79
-43
lines changed

4 files changed

+79
-43
lines changed

public/pyworker/runRobot.py

+41-27
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,30 @@
1010
from importlib import import_module, reload
1111
from io import StringIO
1212

13+
14+
def log(message):
15+
js.postMessage(json.dumps({"std_output": message}))
16+
17+
18+
requirements_list = json.loads(requirements)
19+
1320
try:
1421
import robot
1522
from robot.libdocpkg import LibraryDocumentation
1623
except ImportError:
17-
js.postMessage(json.dumps({"std_output": f"Install Robot Framework"}))
24+
log(f"Install Robot Framework")
1825
rf_version = f"=={version}" if version else ""
1926
try:
20-
await micropip.install(f"robotframework{rf_version}")
27+
await micropip.install(requirements_list or f"robotframework{rf_version}")
2128
time.sleep(1)
2229
import robot
2330
from robot.libdocpkg import LibraryDocumentation
2431
except Exception as e:
2532
js.console.log(f"Robot Run Exception: {e}")
2633
js.console.log(traceback.format_exc())
27-
js.postMessage(json.dumps({"std_output": f" = version {robot.__version__}\n"}))
28-
34+
log(f" = version {robot.__version__}\n")
35+
if requirements_list:
36+
log(f"Installed Requirements: {requirements_list}\n")
2937

3038
os.chdir("/")
3139
dirname = "robot_files"
@@ -43,7 +51,7 @@ class Listener:
4351
ROBOT_LISTENER_API_VERSION = 2
4452

4553
def _post_message(self):
46-
js.postMessage(json.dumps({"std_output": sys.stdout.getvalue()}))
54+
log(sys.stdout.getvalue())
4755
sys.__stdout__.truncate(0)
4856

4957
def library_import(self, name, attrs):
@@ -90,6 +98,7 @@ def write_file(file):
9098
f.writelines(file["content"])
9199

92100
file_list = json.loads(file_catalog)
101+
robot_arguments = json.loads(robot_args)
93102

94103
for file in file_list:
95104
write_file(file)
@@ -104,14 +113,13 @@ def write_file(file):
104113
kwargs = {}
105114
testcli = ""
106115

107-
js.postMessage(
108-
json.dumps(
109-
{
110-
"std_output": f"> robot --loglevel TRACE:INFO --exclude EXCL --skip SKIP\n"
111-
f" --removekeywords tag:REMOVE --flattenkeywords tag:FLAT{testcli} .\n"
112-
}
113-
)
114-
)
116+
if robot_arguments:
117+
log(f"Robot Run Arguments: {robot_args}\n")
118+
log(f"\nRunning Robot Framework:\n")
119+
else:
120+
log(f"> robot --loglevel TRACE:INFO --exclude EXCL --skip SKIP\n"
121+
f" --removekeywords tag:REMOVE --flattenkeywords tag:FLAT{testcli} .\n")
122+
115123
org_stdout = sys.__stdout__
116124
org_stderr = sys.__stderr__
117125
sys.stdout = sys.__stdout__ = StringIO()
@@ -124,19 +132,25 @@ def write_file(file):
124132
js.console.log(f'reimporting: {file["fileName"]}')
125133
m = import_module(file_name)
126134
m = reload(m)
127-
128-
result = robot.run(
129-
".",
130-
consolecolors="ansi",
131-
listener=[Listener()], # "RobotStackTracer",
132-
loglevel="TRACE:INFO",
133-
# include="INCL",
134-
exclude="EXCL",
135-
skip="SKIP",
136-
removekeywords="tag:REMOVE",
137-
flattenkeywords="tag:FLAT",
138-
**kwargs,
139-
)
135+
if robot_arguments:
136+
robot_arguments["listener"] = [Listener()] + robot_arguments.get("listener", [])
137+
robot_arguments["consolecolors"] = "ansi"
138+
result = robot.run(
139+
".",
140+
**robot_arguments
141+
)
142+
else:
143+
result = robot.run(
144+
".",
145+
consolecolors="ansi",
146+
listener=[Listener()],
147+
loglevel="TRACE:INFO",
148+
exclude="EXCL",
149+
skip="SKIP",
150+
removekeywords="tag:REMOVE",
151+
flattenkeywords="tag:FLAT",
152+
**kwargs,
153+
)
140154
js.console.log(f"result: {result}")
141155
except Exception as e:
142156
js.console.log(f"Robot Run Exception: {e}")
@@ -146,7 +160,7 @@ def write_file(file):
146160
std_output = sys.__stdout__.getvalue()
147161
sys.__stdout__ = org_stdout
148162
sys.stdout = sys.__stdout__
149-
js.postMessage(json.dumps({"std_output": std_output}))
163+
log(std_output)
150164

151165
with open("/log.html", "r", encoding="UTF-8") as f:
152166
log_html = str(f.read())

src/components/EmbeddedEditor.vue

+9-1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ export default {
195195
copyMessage: null,
196196
RFVersions: [],
197197
selectedRFVersion: '',
198+
robotArgs: {},
199+
requirements: [],
198200
reinstallRF: false,
199201
versionDropdownOpen: false
200202
}),
@@ -264,6 +266,12 @@ export default {
264266
if (project.robotVersion) {
265267
this.selectedRFVersion = project.robotVersion
266268
}
269+
if (project.robotArgs) {
270+
this.robotArgs = project.robotArgs
271+
}
272+
if (project.requirements) {
273+
this.requirements = project.requirements
274+
}
267275
this.setActiveFile(activeFileName || project.files[0].fileName)
268276
this.editorStatus.projectModified = false
269277
this.copyMessage = null
@@ -325,7 +333,7 @@ export default {
325333
})
326334
this.editorStatus.running = true
327335
const init = this.reinstallRF
328-
setTimeout(() => { runRobot(files, init, tcName, this.selectedRFVersion) }, 0)
336+
setTimeout(() => { runRobot(files, init, tcName, this.selectedRFVersion, this.robotArgs, this.requirements) }, 0)
329337
this.reinstallRF = false
330338
})
331339
}

src/js/code/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ const getProject = async(projectUrl) => {
3535
if (configFile.robotVersion) {
3636
project.robotVersion = configFile.robotVersion
3737
}
38+
if (configFile.robotArgs) {
39+
project.robotArgs = configFile.robotArgs
40+
}
41+
if (configFile.requirements) {
42+
project.requirements = configFile.requirements
43+
}
3844
const descriptionFileName = configFile.description
3945
if (descriptionFileName) {
4046
project.description = await fetch(projectUrl + '/' + descriptionFileName)

src/js/code/pyodide.js

+23-15
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,30 @@ function asyncRun(script, context, onMessage, initialize) {
7575
})
7676
}
7777

78-
export async function runRobot(files, initialize, testCaseName = '', version = '') {
78+
export async function runRobot(files, initialize, testCaseName = '', version = '', robotArgs = {}, requirements = []) {
7979
console.log(`init: ${initialize}`)
8080
clearOutput()
8181
writeToOutput('Initializing...\n')
82-
await asyncRun(pythonProgram, { file_catalog: JSON.stringify(files), test_case_name: testCaseName, version: version }, (data) => {
83-
data = JSON.parse(data)
84-
writeToOutput(data.std_output)
85-
if (Object.prototype.hasOwnProperty.call(data, 'log_html')) {
86-
updateLogHtml(data.log_html)
87-
}
88-
if (Object.prototype.hasOwnProperty.call(data, 'report_html')) {
89-
updateReportHtml(data.report_html)
90-
}
91-
if (Object.prototype.hasOwnProperty.call(data, 'libdocJson')) {
92-
addLibraryEvent.libdoc = data.libdocJson
93-
window.dispatchEvent(addLibraryEvent)
94-
}
95-
}, initialize)
82+
await asyncRun(
83+
pythonProgram, {
84+
file_catalog: JSON.stringify(files),
85+
test_case_name: testCaseName,
86+
version: version,
87+
robot_args: JSON.stringify(robotArgs),
88+
requirements: JSON.stringify(requirements)
89+
}, (data) => {
90+
data = JSON.parse(data)
91+
writeToOutput(data.std_output)
92+
if (Object.prototype.hasOwnProperty.call(data, 'log_html')) {
93+
updateLogHtml(data.log_html)
94+
}
95+
if (Object.prototype.hasOwnProperty.call(data, 'report_html')) {
96+
updateReportHtml(data.report_html)
97+
}
98+
if (Object.prototype.hasOwnProperty.call(data, 'libdocJson')) {
99+
addLibraryEvent.libdoc = data.libdocJson
100+
window.dispatchEvent(addLibraryEvent)
101+
}
102+
}, initialize
103+
)
96104
}

0 commit comments

Comments
 (0)