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

Minor fixes

parents 754d22bc 90ebeca3
No related branches found
No related tags found
No related merge requests found
Pipeline #44072 failed
Metadata-Version: 2.1
Name: codesnipper
Version: 0.1.18.15
Version: 0.1.18.16
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
......
......@@ -37,11 +37,11 @@ def block_split(lines, tag):
def get_tag_args(line):
# line = line.strip()
k = line.find(" ")
if 'nodoc' in line:
print("Nodoc!!")
# if 'nodoc' in line:
# print("Nodoc!!")
tag_args = ((line[:k + 1] if k >= 0 else line)[len(tag):] ).strip().split(";")
if 'nodoc' in tag_args:
print("nodoc.")
# if 'nodoc' in tag_args:
# print("nodoc.")
tag_args = [t.strip() for t in tag_args]
# if len(tag_args) == 0:
......
......@@ -69,7 +69,8 @@ def fix_bibtex(lines, bibtex, rst_mode=False):
s = f"{COMMENT}\n{COMMENT}\n" + s
i = s.find(COMMENT, s.find(COMMENT)+1)
all_refs = [" " + r.strip() for r in all_refs]
s = s[:i] + "References:\n" + "\n".join(all_refs) +"\n"+ s[i:]
# Two newlines because of python styleguide.
s = s[:i].rstrip() + "\n\nReferences:\n" + "\n".join(all_refs) +"\n"+ s[i:]
# s = s.replace(cpr, info['code_copyright'])
return s.splitlines()
......
......@@ -23,7 +23,7 @@ def o_block_funlines(lines, art, output, all_lines=None):
return l2
pass
def run_o(lines, file, output,package_base_dir=None, verbose=True):
def run_o(lines, file, output,package_base_dir=None, verbose=True, show_output=False):
# 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"
......@@ -75,21 +75,26 @@ def run_o(lines, file, output,package_base_dir=None, verbose=True):
if verbose:
print(cmd)
if show_output:
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)
# print("[snipper] Obtained output")
# print(s)
if os.path.isfile(output_file):
print("> Then Lets read the output file", output_file)
print("[snipper] Snipper generated output to file", output_file)
if show_output:
with open(output_file, 'r') as f:
print(f.read())
print(">> WAS THAT WHAT YOU EXPECTED???")
else:
print("No output file produced", output_file)
print("[snipper] No output file produced which is quite odd. The terminal output is")
print(s)
print(f"[snipper] No output file produced: {output_file=}")
os.remove(file_run)
......
......@@ -19,7 +19,7 @@ def get_s(lines):
print("asdfasdfs")
if 'nodoc' in c['start_tag_args'] and c['start_tag_args']['nodoc']:
c['block'] = rm_docstring(c['block'])
print("No documentation!")
# print("No documentation!")
blocks[c['name']].append(c)
output = {}
......
......@@ -73,19 +73,17 @@ def snip_dir(source_dir, # Sources
continue
if accept and (str(f).endswith(".py") or str(f).endswith(".rst") or str(f).endswith(".md")):
# if f.endswith("rst"):
# pass
solution_list = []
kwargs = {}
if verbose:
print("Snipper processing", f)
nrem, cut = censor_file(f, run_files=run_files, run_out_dirs=output_dir, cut_files=cut_files,
# solution_list=solution_list,
base_path=dest_dir,
references=references,
license_head=license_head,
censor_files=censor_files,
package_base_dir=package_base_dir,
verbose=verbose,
**kwargs)
if nrem > 0 and verbose:
print(f"{nrem}> {f}")
......
......@@ -47,9 +47,14 @@ def censor_file(file, run_files=True, run_out_dirs=None, cut_files=True,
strict=True,
references=None,
license_head=None,
<<<<<<< HEAD
package_base_dir=None,
update_file=True # Update the file 'file' (i.e., write to it).
):
=======
package_base_dir=None, verbose=False):
>>>>>>> 90ebeca37d37eb3863a0984dba7d5dde2aa7e880
if str(file).endswith("rst"):
assert not run_files and not cut_files and not censor_files
......@@ -93,7 +98,7 @@ def censor_file(file, run_files=True, run_out_dirs=None, cut_files=True,
ofiles[0] = ofiles[0].replace("\\", "/")
if run_files:
run_o(lines, file=file, output=ofiles[0], package_base_dir=package_base_dir)
run_o(lines, file=file, output=ofiles[0], package_base_dir=package_base_dir, verbose=verbose, show_output=False)
run_i(lines, file=file, output=ofiles[0])
if cut_files:
save_s(lines, file_path=os.path.relpath(file, base_path), output_dir=run_out_dirs)
......
__version__ = "0.1.18.15"
__version__ = "0.1.18.16"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment