areusch commented on a change in pull request #10555:
URL: https://github.com/apache/tvm/pull/10555#discussion_r824998131



##########
File path: docs/script_convert.py
##########
@@ -0,0 +1,75 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import argparse
+import pathlib
+
+BASH = "# bash"
+BASH_IGNORE = "# bash-ignore"
+BASH_MULTILINE_COMMENT_START = ": '"
+BASH_MULTILINE_COMMENT_END = "'"
+
+
+def convert(args: argparse.Namespace):
+    src_path = pathlib.Path(args.script)
+    des_path = src_path.parent / f"{src_path.stem}.py"

Review comment:
       can you be a bit more explicit with var name: `dest_path`

##########
File path: docs/script_convert.py
##########
@@ -0,0 +1,75 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import argparse
+import pathlib
+
+BASH = "# bash"
+BASH_IGNORE = "# bash-ignore"
+BASH_MULTILINE_COMMENT_START = ": '"
+BASH_MULTILINE_COMMENT_END = "'"
+
+
+def convert(args: argparse.Namespace):
+    src_path = pathlib.Path(args.script)
+    des_path = src_path.parent / f"{src_path.stem}.py"
+    with open(src_path, "r") as src_f:
+        with open(des_path, "w") as des_f:
+            line = src_f.readline()

Review comment:
       i'd suggest you extract the contents of this `with` to a separate 
function so it can be tested

##########
File path: tests/scripts/task_python_microtvm.sh
##########
@@ -45,9 +45,10 @@ run_pytest ctypes python-microtvm-stm32 tests/micro/stm32
 run_pytest ctypes python-microtvm-common-qemu_x86 tests/micro/common 
--board=qemu_x86
 run_pytest ctypes python-microtvm-common-due tests/micro/common  
--test-build-only --board=due
 
-# # Tutorials running with host CRT
+# Tutorials
 python3 gallery/how_to/work_with_microtvm/micro_tflite.py
 python3 gallery/how_to/work_with_microtvm/micro_autotune.py
+./gallery/how_to/work_with_microtvm/micro_tvmc.sh

Review comment:
       can we add this to `make docs` instead?

##########
File path: docs/script_convert.py
##########
@@ -0,0 +1,75 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import argparse
+import pathlib
+
+BASH = "# bash"
+BASH_IGNORE = "# bash-ignore"
+BASH_MULTILINE_COMMENT_START = ": '"
+BASH_MULTILINE_COMMENT_END = "'"
+
+
+def convert(args: argparse.Namespace):
+    src_path = pathlib.Path(args.script)
+    des_path = src_path.parent / f"{src_path.stem}.py"
+    with open(src_path, "r") as src_f:
+        with open(des_path, "w") as des_f:
+            line = src_f.readline()
+            bash_block = []
+            bash_detected = False
+            bash_ignore_detected = False
+            while line:
+                line = line.strip("\n").strip("\r")
+                if bash_detected:
+                    if line == BASH:
+                        # write the bash block to destination
+                        python_code = "# .. code-block:: bash\n#\n"

Review comment:
       should we run the bash script from this file and include the output? we 
could probably do that by injecting output markers into the script e.g. 
   
   ```
   echo -e "\nSTART OF COMMAND 1 OUTPUT --->"
   tvmc ...
   echo -e "\n<--- START OF COMMAND 1 OUTPUT"
   ```
   
   then we could take the `bash-ignore` commented areas,  extract them into a 
common prelude, and also include stuff like `set -eux` so that people write 
proper bash scripts. we could maybe do this by putting that into a 
`docs/bash_gallery_prelude.sh` and erroring in this script if we don't see a 
line like:
   
   ```
   source docs/bash_gallery_prelude.sh || exit 2
   ```
   
   might need to think about the path a little bit




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to