Skip to content

Commit

Permalink
Add language support via argument
Browse files Browse the repository at this point in the history
  • Loading branch information
teemulehtinen committed Jan 7, 2024
1 parent 81a35e6 commit 5110c0c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM apluslms/grade-python:3.9-4.8-4.5

ARG GRADE_QLC_VER=v1.0.3
ARG QLCPY_VER=1.0.13
ARG GRADE_QLC_VER=v1.0.4
ARG QLCPY_VER=1.0.14

RUN pip_install \
# Manipulates grader output
Expand Down
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ container:

qlc:
# Command to produce QLC json, see qlcpy --help
cmd: ["qlcpy", "--json", "submitted.py"]
cmd: ["qlcpy", "--json", "-un", "5", submitted.py"]

# Optional files to display (default: all files submitted)
files:
Expand All @@ -93,4 +93,16 @@ qlc:
# (tool replaces %n with the current path components)
post_url: "%0/%1/module/chapter/hidden_exercise/"
post_field: log_json
```
```
#### Usage
```
qlc_wrap [-LANGUAGE_CODE] grading command
```
If the first argument starts with `-`, it signals a language code. The
configured `qlc.cmd` parts can include `$LANG` that is replaced with the
language code, `en` by default.

The suggested QLC generators support a plentiful amount of options that are
described in their documentation.
2 changes: 1 addition & 1 deletion aplus_followups/followups.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ function FollowUpInit(exDiv) {
const button = mkElement(
'button',
{class: 'btn btn-primary', type: 'submit'},
'Grade'
exForm.getAttribute("data-grade")
);
button.addEventListener('click', evt => {
evt.preventDefault();
Expand Down
14 changes: 9 additions & 5 deletions grader_qlc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

from .files import read_output, read_config, read_file, rewrite_output

def run_qlc(config):
res = subprocess.run(config.get('cmd'), capture_output=True)
def run_qlc(config, qlc_lang='en'):
cmd = list(p if p != '$LANG' else qlc_lang for p in config.get('cmd'))
res = subprocess.run(cmd, capture_output=True)
data = {
'qlcs': json.loads(res.stdout),
'files': list([name, read_file(name)] for name in config.get('files', [])),
Expand All @@ -15,16 +16,19 @@ def run_qlc(config):
data[key] = config[key]
return data

def run_wrapped(cmd_list):
def run_wrapped(cmd_list, qlc_lang='en'):
subprocess.run(cmd_list)
output = read_output()
if output['points'] >= output['max_points']:
config = read_config()
data = run_qlc(config)
data = run_qlc(config, qlc_lang)
rewrite_output(config.get('lang'), output, data, 'post_url' in data)

def wrap():
if len(sys.argv) < 2:
print('qlc_wrap must preceed grading command on the line')
sys.exit(1)
run_wrapped(sys.argv[1:])
if sys.argv[1].startswith('-'):
run_wrapped(sys.argv[2:], sys.argv[1][1:])
else:
run_wrapped(sys.argv[1:])
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = grader_qlc
version = 1.0.3
version = 1.0.4
author = Teemu Lehtinen
author_email = [email protected]
description = Augments existing programming assessments with QLCs
Expand Down

0 comments on commit 5110c0c

Please sign in to comment.