diff --git a/dist/codesnipper-0.0.1-py3-none-any.whl b/dist/codesnipper-0.0.1-py3-none-any.whl deleted file mode 100644 index aaf5ead48e7a089977e5499028f603aea1e06382..0000000000000000000000000000000000000000 Binary files a/dist/codesnipper-0.0.1-py3-none-any.whl and /dev/null differ diff --git a/dist/codesnipper-0.0.1.tar.gz b/dist/codesnipper-0.0.1.tar.gz deleted file mode 100644 index 10f2113f9f53428f684c11322062001fb42571d2..0000000000000000000000000000000000000000 Binary files a/dist/codesnipper-0.0.1.tar.gz and /dev/null differ diff --git a/dist/codesnipper-0.0.2-py3-none-any.whl b/dist/codesnipper-0.0.2-py3-none-any.whl deleted file mode 100644 index a3de71167725d94f82ba94271db109d7a5baa198..0000000000000000000000000000000000000000 Binary files a/dist/codesnipper-0.0.2-py3-none-any.whl and /dev/null differ diff --git a/dist/codesnipper-0.0.2.tar.gz b/dist/codesnipper-0.0.2.tar.gz deleted file mode 100644 index 128343f9db99e65419e5a8c62fb3bed6fa91d662..0000000000000000000000000000000000000000 Binary files a/dist/codesnipper-0.0.2.tar.gz and /dev/null differ diff --git a/dist/codesnipper-0.1.0-py3-none-any.whl b/dist/codesnipper-0.1.0-py3-none-any.whl deleted file mode 100644 index 6a40a848dbbdcd930c9b26f93d7ea63b54415ddd..0000000000000000000000000000000000000000 Binary files a/dist/codesnipper-0.1.0-py3-none-any.whl and /dev/null differ diff --git a/dist/codesnipper-0.1.0.tar.gz b/dist/codesnipper-0.1.0.tar.gz deleted file mode 100644 index 1f0d98c592749c17e942663ab1539c9d850006eb..0000000000000000000000000000000000000000 Binary files a/dist/codesnipper-0.1.0.tar.gz and /dev/null differ diff --git a/docs/README.jinja.md b/docs/README.jinja.md index cccf8a1dffa34a52d1cf2067ff886e4893a874b9..6c2263beab26db0f9c7f7e41b3daefe58c57b22c 100644 --- a/docs/README.jinja.md +++ b/docs/README.jinja.md @@ -58,6 +58,11 @@ Is compiled into: ``` This allows you to cut out text across scopes, but still allows you to insert exceptions. +### Extra arguments + + - `silent`: No output + - `nolines`: Don't printn umber of removed lines + - `noerror`: Don't raise Exceptions (useful in top-level code blocks) ## The #!s-tag @@ -188,4 +193,4 @@ The final example displays half of the proposed solution: # Citing ```bibtex {{bibtex}} -``` \ No newline at end of file +``` diff --git a/src/codesnipper.egg-info/PKG-INFO b/src/codesnipper.egg-info/PKG-INFO index d5931d00bc7c2f5a0aa7261c29a3c9a9ffb77e74..2b2b8f1deb87a526571b7b975747a0f805b1ccac 100644 --- a/src/codesnipper.egg-info/PKG-INFO +++ b/src/codesnipper.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: codesnipper -Version: 0.1.18.9 +Version: 0.1.18.11 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 @@ -13,6 +13,8 @@ Classifier: Operating System :: OS Independent Requires-Python: >=3.8 Description-Content-Type: text/markdown License-File: LICENSE +Requires-Dist: pybtex +Requires-Dist: numpy # Snipper A lightweight framework for removing code from student solutions. diff --git a/src/snipper/fix_o.py b/src/snipper/fix_o.py index e92b4ff8cf80263c7e46b116fe5cfd307355deb2..5c787112d541fc77a30a38399a1a8f2437edb8c5 100644 --- a/src/snipper/fix_o.py +++ b/src/snipper/fix_o.py @@ -5,14 +5,18 @@ import sys import subprocess -def o_block_funlines(lines, art, output): +def o_block_funlines(lines, art, output, all_lines=None): id = indent(lines[0]) if not os.path.isdir(os.path.dirname(output)): os.makedirs(os.path.dirname(output)) # art = name outf = output + ("_" + art if art is not None and art != "" else "") + ".txt" l2 = [] - l2 += [id + "import sys", id + f"sys.stdout = open('{outf}', 'w')"] + # Only import sys if not top level import. + if len([l for l in all_lines if l.rstrip() == 'import sys']) == 0: + l2 += [id + "import sys"] + + l2 += [id + f"sys.stdout = open('{outf}', 'w')"] l2 += lines l2 += [indent(lines[-1]) + "sys.stdout = sys.__stdout__"] return l2 @@ -45,7 +49,8 @@ def run_o(lines, file, output,package_base_dir=None): break # ex = b['name'] # o_block_fun(b['block'], None, ) - l2 = o_block_funlines( b['block'], b['name'], output) + l2 = o_block_funlines( b['block'], b['name'], output, all_lines=lines) + lines2 = b['first'] + l2 + b['last'] lines = b['first'] + b['block'] + b['last'] fp, ex = os.path.splitext(file) diff --git a/src/snipper/snipper_main.py b/src/snipper/snipper_main.py index 96834f2ded29243c6824de678652e42c8145ba83..1e818f0c7d992ae7a284ca520c1cb4ff9872b2a3 100644 --- a/src/snipper/snipper_main.py +++ b/src/snipper/snipper_main.py @@ -19,6 +19,12 @@ def rem_nonprintable_ctrl_chars(txt): print(exception) return txt +def fix_tags(lines): + for k, l in enumerate(lines): + # if l.find(" # !") > 0: + # print(f"{file}:{k}> bad snipper tag, fixing") + lines[k] = l.replace("# !", "#!") + return lines def censor_code(lines, keep=True): dbug = True @@ -50,10 +56,12 @@ def censor_file(file, run_files=True, run_out_dirs=None, cut_files=True, s = f.read() s = s.lstrip() lines = s.split("\n") - for k, l in enumerate(lines): - # if l.find(" # !") > 0: - # print(f"{file}:{k}> bad snipper tag, fixing") - lines[k] = l.replace("# !", "#!") + + lines = fix_tags(lines) + # for k, l in enumerate(lines): + # # if l.find(" # !") > 0: + # # print(f"{file}:{k}> bad snipper tag, fixing") + # lines[k] = l.replace("# !", "#!") try: # if str(file).endswith("rst"): diff --git a/src/snipper/version.py b/src/snipper/version.py index 77ad3aeb93a2026d30fa7bc2d177d484e5766287..742f628c35fca09e99a85a4ed896d5d0fead1084 100644 --- a/src/snipper/version.py +++ b/src/snipper/version.py @@ -1 +1 @@ -__version__ = "0.1.18.9" +__version__ = "0.1.18.11"