Browse Source

Disable run button if no c compiler

pull/63/head
Kevin Bogusch 5 months ago
parent
commit
2d93460791
  1. 14
      week4/day4.ipynb

14
week4/day4.ipynb

@ -519,7 +519,7 @@
" my_compiler = [\"Windows\", \"GCC\", [\"cmd\", \"/c\", \"gcc\", f\"{filename_base}.cpp\"]]\n", " my_compiler = [\"Windows\", \"GCC\", [\"cmd\", \"/c\", \"gcc\", f\"{filename_base}.cpp\"]]\n",
"\n", "\n",
" if not my_compiler:\n", " if not my_compiler:\n",
" my_compiler=[my_platform, \"Unknown\", []]\n", " my_compiler=[my_platform, \"Unavailable\", []]\n",
" \n", " \n",
" elif my_platform == \"Linux\":\n", " elif my_platform == \"Linux\":\n",
" if os.path.isfile(\"./simple\"):\n", " if os.path.isfile(\"./simple\"):\n",
@ -538,7 +538,7 @@
" my_compiler = [\"Linux\", \"CLang\", [\"clang\", f\"{filename_base}.cpp\", \"-o\", f\"{filename_base}\"]]\n", " my_compiler = [\"Linux\", \"CLang\", [\"clang\", f\"{filename_base}.cpp\", \"-o\", f\"{filename_base}\"]]\n",
" \n", " \n",
" if not my_compiler:\n", " if not my_compiler:\n",
" my_compiler=[my_platform, \"Unknown\", []]\n", " my_compiler=[my_platform, \"Unavailable\", []]\n",
"\n", "\n",
" elif my_platform == \"Darwin\":\n", " elif my_platform == \"Darwin\":\n",
" if os.path.isfile(\"./simple\"):\n", " if os.path.isfile(\"./simple\"):\n",
@ -549,12 +549,12 @@
" my_compiler = [\"Linux\", \"CLang\", [\"clang++\", \"-Ofast\", \"-std=c++17\", \"-march=armv8.5-a\", \"-mtune=apple-m1\", \"-mcpu=apple-m1\", \"-o\", f\"{filename_base}\", f\"{filename_base}.cpp\"]]\n", " my_compiler = [\"Linux\", \"CLang\", [\"clang++\", \"-Ofast\", \"-std=c++17\", \"-march=armv8.5-a\", \"-mtune=apple-m1\", \"-mcpu=apple-m1\", \"-o\", f\"{filename_base}\", f\"{filename_base}.cpp\"]]\n",
"\n", "\n",
" if not my_compiler:\n", " if not my_compiler:\n",
" my_compiler=[my_platform, \"Unknown\", []]\n", " my_compiler=[my_platform, \"Unavailable\", []]\n",
"\n", "\n",
" if my_compiler:\n", " if my_compiler:\n",
" return my_compiler\n", " return my_compiler\n",
" else:\n", " else:\n",
" return [\"Unknown\", \"Unknown\", []]\n" " return [\"Unknown\", \"Unavailable\", []]\n"
] ]
}, },
{ {
@ -576,14 +576,13 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 107,
"id": "77f3ab5d-fcfb-4d3f-8728-9cacbf833ea6", "id": "77f3ab5d-fcfb-4d3f-8728-9cacbf833ea6",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"def execute_cpp(code):\n", "def execute_cpp(code):\n",
" write_output(code)\n", " write_output(code)\n",
" print(f\"DEBUG. execute_cpp. compiler_cmd[2]=\\\"{compiler_cmd[2]}\\\"\")\n",
" try:\n", " try:\n",
" compile_result = subprocess.run(compiler_cmd[2], check=True, text=True, capture_output=True)\n", " compile_result = subprocess.run(compiler_cmd[2], check=True, text=True, capture_output=True)\n",
" run_cmd = [\"./optimized\"]\n", " run_cmd = [\"./optimized\"]\n",
@ -786,7 +785,10 @@
" convert = gr.Button(\"Convert code\")\n", " convert = gr.Button(\"Convert code\")\n",
" with gr.Row():\n", " with gr.Row():\n",
" python_run = gr.Button(\"Run Python\")\n", " python_run = gr.Button(\"Run Python\")\n",
" if not compiler_cmd[1] == \"Unavailable\":\n",
" cpp_run = gr.Button(\"Run C++\")\n", " cpp_run = gr.Button(\"Run C++\")\n",
" else:\n",
" cpp_run = gr.Button(\"No compiler to run C++\", interactive=False)\n",
" with gr.Row():\n", " with gr.Row():\n",
" python_out = gr.TextArea(label=\"Python result:\", elem_classes=[\"python\"])\n", " python_out = gr.TextArea(label=\"Python result:\", elem_classes=[\"python\"])\n",
" cpp_out = gr.TextArea(label=\"C++ result:\", elem_classes=[\"cpp\"])\n", " cpp_out = gr.TextArea(label=\"C++ result:\", elem_classes=[\"cpp\"])\n",

Loading…
Cancel
Save