## Question Authors' Forum

### Creating YAML/Python questions

by James Scheibner -
Number of replies: 4

Hi there,

I am currently teaching a course in which law students learn how to create simple legal applications using Docassemble. Docassemble runs on a server which allows users to log in and create applications in YAML files where users can insert Python code blocks. Users can then run these YAML interview files or install the application on the server, so that the interviews are publicly available to use from a web interface.

For a while I have been contemplating what strategies I can use to help encourage formative learning amongst my students. In particular, the students I teach have a variable range of experiences when it comes to coding, and I would like to provide them with a tool that gives them instantaneous feedback. Therefore, I thought that CodeRunner quizzes could be a good strategy to teach students to create small code snippets. However, having played around with CodeRunner, I have been able to create Python quizzes, but not quizzes using the variant of Python that Docassemble uses (if that makes sense). How can I adapt CodeRunner for a slightly different variant of Python? Thank you.

### Re: Creating YAML/Python questions

by Richard Lobb -
I don't know anything about Docassemble, but I think you'll have to treat it as a completely different language from standard Python. The documentation Supporting or implementing new languages explains how to go about providing a question type to run any new language, assuming it's already installed on Jobe.

Work through those instructions step by step, modifying the template so it runs docassemble rather than C. You won't need to include a compile step, so your template will be something like the following, where I've assumed an extension of .yam for Docassemble files and the command docass to run a .yam file:

import subprocess, sys

# Write the student code to a file prog.c
with open("prog.yam", "w") as src:

# Run the code. Since this is a per-test template,
# stdin is already set up for the stdin text specified in the test case,
# so we can run the compiled program directly.

try:
output = subprocess.check_output(["docass", "prog.yam"], universal_newlines=True)
print(output)
except subprocess.CalledProcessError as e:
if e.returncode > 0:
# Ignore non-zero positive return codes
if e.output:
print(e.output)
else:
# But negative return codes are signals - abort
if e.output:
print(e.output, file=sys.stderr)
if e.returncode < 0:
print("Task failed with signal", -e.returncode, file=sys.stderr)
print("** Further testing aborted **", file=sys.stderr)


You'll also want to change the question type to (say) docassemble rather than c_via_python and the question name to PROTOTYPE_docassemble. And you'll have to set the Ace language to something that does reasonable syntax highlighting of your combination python/yaml code. Perhaps just leave it empty to get python syntax colouring? Or maybe 'yaml' works to give yaml highlighting? Otherwise enter some rubbish non-existent language and Ace will turn off syntax highlighting altogether.

### Re: Creating YAML/Python questions

by James Scheibner -
Dear Richard, thank you for your reply. The only challenge is that I do not think I have access to my institution's Moodle administration to be able to install a language to Jobe. In addition, Docassemble uses YAML so I imagine I would be installing YAML on Jobe. I am also asking the Docassemble development team the same question, and will report back with an answer. Thank you.

### Re: Creating YAML/Python questions

by Richard Lobb -
I just had a quick look at docassemble and the installation instructions. I see it's a large complex system - much more than just a language. It requires a database server, messaging services, and SMTP server and several other things I know nothing about. While I like to claim you can do anything with CodeRunner, using it with docassemble looks to be extremely challenging. Docassemble seems to expect to be able to process an interview script in a series of interaction with a user via a web interface.

While it may be possible to strip out all the interactive aspects from docassemble, this would require specialist knowledge and my first impressions are that it's unlikely to be worth the effort and cost. And even after stripping it down to its bare essentials, you'd still need to be able to install it on a Jobe server so you could run it. If you don't have access to the institution's Jobe server, you'd have to build your own, probably by installing Jobe on a docassemble system rather than vice versa. It is possible to specify that a particular question uses a different Jobe server from the standard configured into Moodle, but the Moodle server firewall would need to allow that alternative connection. And of course you'd need to maintain that alternative Jobe server.

All in all, this looks too hard, unless you're very keen and either have the necessary technical expertise to do all this difficult work or have the research funds to pay a support team to develop it. :-(  Which is a shame, because it looks like a really fun idea.

I should have looked up docassemble before replying earlier. Sorry - I thought it was just another language.