diff --git a/src/codesnipper.egg-info/PKG-INFO b/src/codesnipper.egg-info/PKG-INFO index 8c998c1e5076da443b7b31a2c967eae1ab4e0ca4..74ef0f8844cc2c329b2c5963bc638b14913305f0 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 5c787112d541fc77a30a38399a1a8f2437edb8c5..6ae3737091a0bdb65726e755b4f57f4fc8b49794 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 73b6561872a8e263bfacec6286628dc53049b0d0..5f0a9b76380c8bca07d8bb3e359a5adc15948e5a 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 b7efbea7fde4118f4fb235a9c196b757123121a9..1ee137cf8577d7ffb7adfdc0e4ad95e7fb13012e 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 da38f5d4ec64b951c0078ad16ec4b30b648723ea..eded487725e5071db44e64d32473dd343a870100 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"