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

Minor fixes

parents 754d22bc 90ebeca3
Branches
No related tags found
No related merge requests found
Pipeline #44072 failed
Metadata-Version: 2.1 Metadata-Version: 2.1
Name: codesnipper 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 Summary: A lightweight framework for censoring student solutions files and extracting code + output
Home-page: https://lab.compute.dtu.dk/tuhe/snipper Home-page: https://lab.compute.dtu.dk/tuhe/snipper
Author: Tue Herlau Author: Tue Herlau
......
...@@ -37,11 +37,11 @@ def block_split(lines, tag): ...@@ -37,11 +37,11 @@ def block_split(lines, tag):
def get_tag_args(line): def get_tag_args(line):
# line = line.strip() # line = line.strip()
k = line.find(" ") k = line.find(" ")
if 'nodoc' in line: # if 'nodoc' in line:
print("Nodoc!!") # print("Nodoc!!")
tag_args = ((line[:k + 1] if k >= 0 else line)[len(tag):] ).strip().split(";") tag_args = ((line[:k + 1] if k >= 0 else line)[len(tag):] ).strip().split(";")
if 'nodoc' in tag_args: # if 'nodoc' in tag_args:
print("nodoc.") # print("nodoc.")
tag_args = [t.strip() for t in tag_args] tag_args = [t.strip() for t in tag_args]
# if len(tag_args) == 0: # if len(tag_args) == 0:
......
...@@ -69,7 +69,8 @@ def fix_bibtex(lines, bibtex, rst_mode=False): ...@@ -69,7 +69,8 @@ def fix_bibtex(lines, bibtex, rst_mode=False):
s = f"{COMMENT}\n{COMMENT}\n" + s s = f"{COMMENT}\n{COMMENT}\n" + s
i = s.find(COMMENT, s.find(COMMENT)+1) i = s.find(COMMENT, s.find(COMMENT)+1)
all_refs = [" " + r.strip() for r in all_refs] 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']) # s = s.replace(cpr, info['code_copyright'])
return s.splitlines() return s.splitlines()
......
...@@ -23,7 +23,7 @@ def o_block_funlines(lines, art, output, all_lines=None): ...@@ -23,7 +23,7 @@ def o_block_funlines(lines, art, output, all_lines=None):
return l2 return l2
pass 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): # def block_fun(lines, start_extra, end_extra, art, output, **kwargs):
# id = indent(lines[0]) # id = indent(lines[0])
# outf = output + ("_" + art if art is not None else "") + ".txt" # 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): ...@@ -75,21 +75,26 @@ def run_o(lines, file, output,package_base_dir=None, verbose=True):
if verbose: if verbose:
print(cmd) print(cmd)
if show_output:
print("File that will be run contains:", file_run) print("File that will be run contains:", file_run)
with open(file_run, 'r') as f: with open(file_run, 'r') as f:
print(f.read()) print(f.read())
s = subprocess.check_output(cmd, shell=True) s = subprocess.check_output(cmd, shell=True)
if verbose: if verbose:
print("> After I ran it I got the output") # print("[snipper] Obtained output")
print(s) # print(s)
if os.path.isfile(output_file): 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: with open(output_file, 'r') as f:
print(f.read()) print(f.read())
print(">> WAS THAT WHAT YOU EXPECTED???") print(">> WAS THAT WHAT YOU EXPECTED???")
else: 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) os.remove(file_run)
......
...@@ -19,7 +19,7 @@ def get_s(lines): ...@@ -19,7 +19,7 @@ def get_s(lines):
print("asdfasdfs") print("asdfasdfs")
if 'nodoc' in c['start_tag_args'] and c['start_tag_args']['nodoc']: if 'nodoc' in c['start_tag_args'] and c['start_tag_args']['nodoc']:
c['block'] = rm_docstring(c['block']) c['block'] = rm_docstring(c['block'])
print("No documentation!") # print("No documentation!")
blocks[c['name']].append(c) blocks[c['name']].append(c)
output = {} output = {}
......
...@@ -73,19 +73,17 @@ def snip_dir(source_dir, # Sources ...@@ -73,19 +73,17 @@ def snip_dir(source_dir, # Sources
continue continue
if accept and (str(f).endswith(".py") or str(f).endswith(".rst") or str(f).endswith(".md")): if accept and (str(f).endswith(".py") or str(f).endswith(".rst") or str(f).endswith(".md")):
# if f.endswith("rst"):
# pass
solution_list = [] solution_list = []
kwargs = {} kwargs = {}
if verbose: if verbose:
print("Snipper processing", f) print("Snipper processing", f)
nrem, cut = censor_file(f, run_files=run_files, run_out_dirs=output_dir, cut_files=cut_files, 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, base_path=dest_dir,
references=references, references=references,
license_head=license_head, license_head=license_head,
censor_files=censor_files, censor_files=censor_files,
package_base_dir=package_base_dir, package_base_dir=package_base_dir,
verbose=verbose,
**kwargs) **kwargs)
if nrem > 0 and verbose: if nrem > 0 and verbose:
print(f"{nrem}> {f}") print(f"{nrem}> {f}")
......
...@@ -47,9 +47,14 @@ def censor_file(file, run_files=True, run_out_dirs=None, cut_files=True, ...@@ -47,9 +47,14 @@ def censor_file(file, run_files=True, run_out_dirs=None, cut_files=True,
strict=True, strict=True,
references=None, references=None,
license_head=None, license_head=None,
<<<<<<< HEAD
package_base_dir=None, package_base_dir=None,
update_file=True # Update the file 'file' (i.e., write to it). update_file=True # Update the file 'file' (i.e., write to it).
): ):
=======
package_base_dir=None, verbose=False):
>>>>>>> 90ebeca37d37eb3863a0984dba7d5dde2aa7e880
if str(file).endswith("rst"): if str(file).endswith("rst"):
assert not run_files and not cut_files and not censor_files 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, ...@@ -93,7 +98,7 @@ def censor_file(file, run_files=True, run_out_dirs=None, cut_files=True,
ofiles[0] = ofiles[0].replace("\\", "/") ofiles[0] = ofiles[0].replace("\\", "/")
if run_files: 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]) run_i(lines, file=file, output=ofiles[0])
if cut_files: if cut_files:
save_s(lines, file_path=os.path.relpath(file, base_path), output_dir=run_out_dirs) 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