From f871b746be265edd1167aa913f0d90f7a843c1bd Mon Sep 17 00:00:00 2001
From: Tue Herlau <tuhe@dtu.dk>
Date: Fri, 28 Jun 2024 17:36:09 +0200
Subject: [PATCH] updates

---
 src/codesnipper.egg-info/PKG-INFO |  6 +-----
 src/snipper/fix_o.py              | 36 ++++++++++++++++++-------------
 src/snipper/fix_s.py              | 23 ++------------------
 src/snipper/snipper_main.py       |  7 +++---
 src/snipper/version.py            |  6 +-----
 5 files changed, 29 insertions(+), 49 deletions(-)

diff --git a/src/codesnipper.egg-info/PKG-INFO b/src/codesnipper.egg-info/PKG-INFO
index 8c998c1..74ef0f8 100644
--- a/src/codesnipper.egg-info/PKG-INFO
+++ b/src/codesnipper.egg-info/PKG-INFO
@@ -1,10 +1,6 @@
 Metadata-Version: 2.1
 Name: codesnipper
-<<<<<<< HEAD
-Version: 0.1.18.11
-=======
-Version: 0.1.18.10
->>>>>>> 6fce20d6e5d8194b6a072056a9a906939d4ee070
+Version: 0.1.18.15
 Summary: A lightweight framework for censoring student solutions files and extracting code + output
 Home-page: https://lab.compute.dtu.dk/tuhe/snipper
 Author: Tue Herlau
diff --git a/src/snipper/fix_o.py b/src/snipper/fix_o.py
index 5c78711..6ae3737 100644
--- a/src/snipper/fix_o.py
+++ b/src/snipper/fix_o.py
@@ -18,11 +18,12 @@ def o_block_funlines(lines, art, output, all_lines=None):
 
     l2 += [id + f"sys.stdout = open('{outf}', 'w')"]
     l2 += lines
+    l2 += [indent(lines[-1]) + "sys.stdout.close()"]
     l2 += [indent(lines[-1]) + "sys.stdout = sys.__stdout__"]
     return l2
     pass
 
-def run_o(lines, file, output,package_base_dir=None):
+def run_o(lines, file, output,package_base_dir=None, verbose=True):
     # def block_fun(lines, start_extra, end_extra, art, output, **kwargs):
     #     id = indent(lines[0])
     #     outf = output + ("_" + art if art is not None else "") + ".txt"
@@ -50,6 +51,8 @@ def run_o(lines, file, output,package_base_dir=None):
             # ex = b['name']
             # o_block_fun(b['block'], None, )
             l2 = o_block_funlines( b['block'], b['name'], output, all_lines=lines)
+            art = b['name']
+            output_file = output + ("_" + art if art is not None and art != "" else "") + ".txt"
 
             lines2 = b['first'] + l2 + b['last']
             lines = b['first'] + b['block'] + b['last']
@@ -61,6 +64,7 @@ def run_o(lines, file, output,package_base_dir=None):
             else:
                 with open(file_run, 'w', encoding="utf-8") as f:
                     f.write("\n".join(lines2))
+
                 python = sys.executable
                 if package_base_dir is None:
                     cmd = f"cd {os.path.dirname(file_run)} && {python} {os.path.basename(file_run)}"
@@ -69,8 +73,23 @@ def run_o(lines, file, output,package_base_dir=None):
                     rp = os.path.relpath(file_run, package_base_dir).replace("\\", "/").replace("/", ".")[:-3]
                     cmd = f"cd {package_base_dir} && {python} -m {rp}"
 
-                print(cmd)
+                if verbose:
+                    print(cmd)
+                    print("File that will be run contains:", file_run)
+                    with open(file_run, 'r') as f:
+                        print(f.read())
                 s = subprocess.check_output(cmd, shell=True)
+                if verbose:
+                    print("> After I ran it I got the output")
+                    print(s)
+
+                    if os.path.isfile(output_file):
+                        print("> Then Lets read the output file", output_file)
+                        with open(output_file, 'r') as f:
+                            print(f.read())
+                        print(">> WAS THAT WHAT YOU EXPECTED???")
+                    else:
+                        print("No output file produced", output_file)
                 os.remove(file_run)
 
 
@@ -80,16 +99,3 @@ def run_o(lines, file, output,package_base_dir=None):
         print("I was cutting the #!o tag")
         print("\n".join( lines) )
         raise(e)
-
-    # if didfind:
-    #     fp, ex = os.path.splitext(file)
-    #     file_run = fp + "_RUN_OUTPUT_CAPTURE" +ex
-    #     if os.path.exists(file_run):
-    #         print("file found mumble...")
-    #     else:
-    #         with open(file_run, 'w', encoding="utf-8") as f:
-    #             f.write("\n".join(lines2) )
-    #         cmd = "python " + file_run
-    #         import subprocess
-    #         s = subprocess.check_output(cmd, shell=True)
-    #         os.remove(file_run)
\ No newline at end of file
diff --git a/src/snipper/fix_s.py b/src/snipper/fix_s.py
index 73b6561..5f0a9b7 100644
--- a/src/snipper/fix_s.py
+++ b/src/snipper/fix_s.py
@@ -17,7 +17,6 @@ def get_s(lines):
             pass
         if 'dse' in c['start_tag_args']:
             print("asdfasdfs")
-        # print(c['start_tag_args'])
         if 'nodoc' in c['start_tag_args'] and c['start_tag_args']['nodoc']:
             c['block'] = rm_docstring(c['block'])
             print("No documentation!")
@@ -26,25 +25,6 @@ def get_s(lines):
     output = {}
     for name, co in blocks.items():
         slines = [l for c in co for l in c['block']]
-        # full_strip("")
-        # c['block']['args']
-        # slines = slines[ 23]
-        # co.
-
-
-
-        # if slines[f.lineno].strip().startswith('"' * 3):
-        #     print("got a docstrnig")
-        #     for k in range(f.lineno, f.end_lineno + 1):
-        #         l = slines[k] if k != f.lineno else slines[k].strip()[3:]
-        #         if l.find('"' * 3) >= 0:
-        #             break
-        # else:
-        #     k = -1
-        # if k > 0:
-        #     print("Docstring detected")
-        #     for i in range(f.lineno, k + 1):
-        #         ll2[i] = None
         output[name] = slines
     return output
 
@@ -59,7 +39,8 @@ def rm_docstring(lines):
     ll2 = slines.copy()
 
     def rm_ds(f, ll2):
-        if slines[f.lineno].strip().startswith('"' * 3):
+        lstart = slines[f.lineno].strip()
+        if lstart.startswith('"' * 3) or lstart.startswith('r' + '"' * 3):
             # print("got a docstrnig")
             for k in range(f.lineno-1, f.end_lineno + 1):
                 l = slines[k] if k != f.lineno else slines[k].strip()[3:]
diff --git a/src/snipper/snipper_main.py b/src/snipper/snipper_main.py
index b7efbea..1ee137c 100644
--- a/src/snipper/snipper_main.py
+++ b/src/snipper/snipper_main.py
@@ -49,9 +49,10 @@ def censor_file(file, run_files=True, run_out_dirs=None, cut_files=True,
                 package_base_dir=None):
     if str(file).endswith("rst"):
         assert not run_files and not cut_files and not censor_files
-        # print(file)
-    # if str(file).endswith("md"):
-    #     assert not run_files and not cut_files
+
+    if str(file).endswith(".md"):
+        license_head=None
+
 
     if references == None:
         references = {}
diff --git a/src/snipper/version.py b/src/snipper/version.py
index da38f5d..eded487 100644
--- a/src/snipper/version.py
+++ b/src/snipper/version.py
@@ -1,5 +1 @@
-<<<<<<< HEAD
-__version__ = "0.1.18.11"
-=======
-__version__ = "0.1.18.10"
->>>>>>> 6fce20d6e5d8194b6a072056a9a906939d4ee070
+__version__ = "0.1.18.15"
-- 
GitLab