Skip to content
Snippets Groups Projects
Commit 30f940a7 authored by tuhe's avatar tuhe
Browse files

Getting ready for 2024

parent 7572308a
No related branches found
No related tags found
No related merge requests found
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
......@@ -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
```
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.
......
......@@ -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)
......
......@@ -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"):
......
__version__ = "0.1.18.9"
__version__ = "0.1.18.11"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment