From 2d93460791a94e835ba4446b0518cd4c7ba2c51e Mon Sep 17 00:00:00 2001 From: Kevin Bogusch Date: Mon, 23 Dec 2024 08:46:09 -0500 Subject: [PATCH] Disable run button if no c compiler --- week4/day4.ipynb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/week4/day4.ipynb b/week4/day4.ipynb index f140b92..12a9abe 100644 --- a/week4/day4.ipynb +++ b/week4/day4.ipynb @@ -519,7 +519,7 @@ " my_compiler = [\"Windows\", \"GCC\", [\"cmd\", \"/c\", \"gcc\", f\"{filename_base}.cpp\"]]\n", "\n", " if not my_compiler:\n", - " my_compiler=[my_platform, \"Unknown\", []]\n", + " my_compiler=[my_platform, \"Unavailable\", []]\n", " \n", " elif my_platform == \"Linux\":\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", " \n", " if not my_compiler:\n", - " my_compiler=[my_platform, \"Unknown\", []]\n", + " my_compiler=[my_platform, \"Unavailable\", []]\n", "\n", " elif my_platform == \"Darwin\":\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", "\n", " if not my_compiler:\n", - " my_compiler=[my_platform, \"Unknown\", []]\n", + " my_compiler=[my_platform, \"Unavailable\", []]\n", "\n", " if my_compiler:\n", " return my_compiler\n", " else:\n", - " return [\"Unknown\", \"Unknown\", []]\n" + " return [\"Unknown\", \"Unavailable\", []]\n" ] }, { @@ -576,14 +576,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 107, "id": "77f3ab5d-fcfb-4d3f-8728-9cacbf833ea6", "metadata": {}, "outputs": [], "source": [ "def execute_cpp(code):\n", " write_output(code)\n", - " print(f\"DEBUG. execute_cpp. compiler_cmd[2]=\\\"{compiler_cmd[2]}\\\"\")\n", " try:\n", " compile_result = subprocess.run(compiler_cmd[2], check=True, text=True, capture_output=True)\n", " run_cmd = [\"./optimized\"]\n", @@ -786,7 +785,10 @@ " convert = gr.Button(\"Convert code\")\n", " with gr.Row():\n", " python_run = gr.Button(\"Run Python\")\n", - " cpp_run = gr.Button(\"Run C++\")\n", + " if not compiler_cmd[1] == \"Unavailable\":\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", " python_out = gr.TextArea(label=\"Python result:\", elem_classes=[\"python\"])\n", " cpp_out = gr.TextArea(label=\"C++ result:\", elem_classes=[\"cpp\"])\n",