From 362e8ec003c7177a7dfb21d48169f3f8c051d93f Mon Sep 17 00:00:00 2001 From: Tue Herlau <tuhe@dtu.dk> Date: Mon, 15 Aug 2022 12:02:36 +0200 Subject: [PATCH] snipper upgrade --- 0.1.11 | 10 ++++++++++ setup.py | 2 +- src/codesnipper.egg-info/PKG-INFO | 4 +--- src/codesnipper.egg-info/SOURCES.txt | 1 + src/snipper/load_citations.py | 23 ++++++++++++++++++++++- src/snipper/snip_dir.py | 20 +++++++++++--------- src/snipper/snipper_main.py | 4 ++-- src/snipper/version.py | 5 ++++- 8 files changed, 52 insertions(+), 17 deletions(-) create mode 100644 0.1.11 diff --git a/0.1.11 b/0.1.11 new file mode 100644 index 0000000..b5f99d0 --- /dev/null +++ b/0.1.11 @@ -0,0 +1,10 @@ +Requirement already satisfied: codesnipper in c:\users\tuhe\appdata\local\programs\python\python310\lib\site-packages (0.1.11) +Requirement already satisfied: wexpect in c:\users\tuhe\appdata\local\programs\python\python310\lib\site-packages (from codesnipper) (4.0.0) +Requirement already satisfied: pybtex in c:\users\tuhe\appdata\local\programs\python\python310\lib\site-packages (from codesnipper) (0.24.0) +Requirement already satisfied: pexpect in c:\users\tuhe\appdata\local\programs\python\python310\lib\site-packages (from codesnipper) (4.8.0) +Requirement already satisfied: ptyprocess>=0.5 in c:\users\tuhe\appdata\local\programs\python\python310\lib\site-packages (from pexpect->codesnipper) (0.7.0) +Requirement already satisfied: six in c:\users\tuhe\appdata\local\programs\python\python310\lib\site-packages (from pybtex->codesnipper) (1.16.0) +Requirement already satisfied: latexcodec>=1.0.4 in c:\users\tuhe\appdata\local\programs\python\python310\lib\site-packages (from pybtex->codesnipper) (2.0.1) +Requirement already satisfied: PyYAML>=3.01 in c:\users\tuhe\appdata\local\programs\python\python310\lib\site-packages (from pybtex->codesnipper) (6.0) +Requirement already satisfied: pywin32>=220 in c:\users\tuhe\appdata\local\programs\python\python310\lib\site-packages (from wexpect->codesnipper) (304) +Requirement already satisfied: psutil>=5.0.0 in c:\users\tuhe\appdata\local\programs\python\python310\lib\site-packages (from wexpect->codesnipper) (5.9.1) diff --git a/setup.py b/setup.py index aa492a2..a70db3c 100644 --- a/setup.py +++ b/setup.py @@ -5,10 +5,10 @@ import setuptools import pkg_resources + with open("src/snipper/version.py", "r", encoding="utf-8") as fh: __version__ = fh.read().split(" = ")[1].strip()[1:-1] - with open("README.md", "r", encoding="utf-8") as fh: long_description = fh.read() diff --git a/src/codesnipper.egg-info/PKG-INFO b/src/codesnipper.egg-info/PKG-INFO index f95b07c..1415e4f 100644 --- a/src/codesnipper.egg-info/PKG-INFO +++ b/src/codesnipper.egg-info/PKG-INFO @@ -1,13 +1,12 @@ Metadata-Version: 2.1 Name: codesnipper -Version: 0.1.7 +Version: 0.1.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 Author-email: tuhe@dtu.dk License: MIT Project-URL: Bug Tracker, https://lab.compute.dtu.dk/tuhe/snipper/issues -Platform: UNKNOWN Classifier: Programming Language :: Python :: 3 Classifier: License :: OSI Approved :: MIT License Classifier: Operating System :: OS Independent @@ -405,4 +404,3 @@ raise NotImplementedError('Complete the above program') year={2021}, } ``` - diff --git a/src/codesnipper.egg-info/SOURCES.txt b/src/codesnipper.egg-info/SOURCES.txt index 3188345..20caaa7 100644 --- a/src/codesnipper.egg-info/SOURCES.txt +++ b/src/codesnipper.egg-info/SOURCES.txt @@ -20,4 +20,5 @@ src/snipper/legacy.py src/snipper/load_citations.py src/snipper/snip_dir.py src/snipper/snipper_main.py +src/snipper/test.py src/snipper/version.py \ No newline at end of file diff --git a/src/snipper/load_citations.py b/src/snipper/load_citations.py index 0512cd1..f645b0a 100644 --- a/src/snipper/load_citations.py +++ b/src/snipper/load_citations.py @@ -1,5 +1,6 @@ import os import io +import glob from pybtex import plugin from pybtex.database.input import bibtex from warnings import warn @@ -8,10 +9,30 @@ from warnings import warn def get_aux(auxfile): # paths = get_paths() # auxfile = os.path.join(paths['02450public'], auxfile) + auxfile = os.path.normpath(auxfile) # Unsure if this is required. But had problems finding the auxfile on git. + auxfile = auxfile.replace(os.sep, '/') + if not os.path.exists(auxfile): # print(auxfile) + warn("Could not find bibtex file: " + auxfile + " testing for troubles") + auxdir = os.path.dirname(auxfile) + # os.path.curdir + + print("The current working directory (os.getcwd()) is ", os.getcwd() ) + try: + print("Trying to list files in builds dir") + for f in glob.glob("/builds/02465material/*"): + print(f) + except Exception as e: + print(e) + + if not os.path.dirname(auxdir): + print("Directory for auxfile does not exist:", auxdir) + else: + print("Auxfile did not exist, but directory did. Printing the contents:") + for f in glob.glob(os.path.dirname(auxfile) + "/*"): + print(f) - warn("Could not find bibtex file: "+ auxfile) return {} with open(auxfile, 'r') as f: diff --git a/src/snipper/snip_dir.py b/src/snipper/snip_dir.py index ba98cd7..431ab41 100644 --- a/src/snipper/snip_dir.py +++ b/src/snipper/snip_dir.py @@ -1,12 +1,13 @@ -import os, shutil +import os +import shutil from snipper.snipper_main import censor_file from pathlib import Path import time import fnmatch import tempfile -from line_profiler_pycharm import profile +# from line_profiler_pycharm import profile -@profile +# @profile def snip_dir(source_dir, # Sources dest_dir=None, # Will write to this directory output_dir=None, # Where snippets are going to be stored @@ -16,10 +17,10 @@ def snip_dir(source_dir, # Sources cut_files=True, # censor files. license_head=None, censor_files=True, + verbose=True, ): print("Snipper fixing", source_dir) - if dest_dir == None: dest_dir = tempfile.mkdtemp() print("[snipper]", "no destination dir was specified so using nonsense destination:", dest_dir) @@ -49,8 +50,8 @@ def snip_dir(source_dir, # Sources os.makedirs(dest_dir) out = dest_dir hw = {'base': source_dir} - - print(f"[snipper]: {hw['base']} -> {out}") + if verbose: + print(f"[snipper]: {hw['base']} -> {out}") if os.path.exists(dest_dir): shutil.rmtree(dest_dir) @@ -72,7 +73,8 @@ def snip_dir(source_dir, # Sources if accept: solution_list = [] kwargs = {} - print("Snipper processing", f) + 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, @@ -80,11 +82,11 @@ def snip_dir(source_dir, # Sources license_head=license_head, censor_files=censor_files, **kwargs) - if nrem > 0: + if nrem > 0 and verbose: print(f"{nrem}> {f}") cutouts[str(f)] = cut n += nrem - # print("[snipper]", "removing") + for rm_file, accept in acceptable: rm_file = os.path.abspath(rm_file) if not accept: diff --git a/src/snipper/snipper_main.py b/src/snipper/snipper_main.py index 9e02bfc..1fab5eb 100644 --- a/src/snipper/snipper_main.py +++ b/src/snipper/snipper_main.py @@ -71,8 +71,8 @@ def censor_file(file, run_files=True, run_out_dirs=None, cut_files=True, if censor_files: lines = fix_f(lines, dbug) - if "pacman" in str(file): - print("sdaf") + # if "pacman" in str(file): + # print("sdaf") lines, nB, cut = fix_b(lines) else: nB = 0 diff --git a/src/snipper/version.py b/src/snipper/version.py index 283b03a..6dbb672 100644 --- a/src/snipper/version.py +++ b/src/snipper/version.py @@ -1 +1,4 @@ -__version__ = "0.1.7" \ No newline at end of file +__version__ = "0.1.12" + +# /builds/02465material/02465public +# /builds/02465material/02465public \ No newline at end of file -- GitLab