The rst_code_example_pipeline package contains scripts to extract, build and run the code blocks from the ReST files. These are the main entry points:
-
extract-codeextracts all code blocks and stores into the specified build directory; -
check-codechecks each code block from the specified build directory; -
check-blockchecks a single (previously extracted) code block.
The package is installed in editable mode as part of the VM provisioning:
pip install -e frontend/python/rst_code_example_pipelineTo build and run the source-code examples from a course, just run
extract-code followed by check-code. For example, to test
the source-code examples from the
Introduction to Ada course, run:
extract-code \
--build-dir test_output \
$(find ../content/courses/intro-to-ada/ -name '*.rst')
check-code \
--build-dir test_outputWhen extract-code runs, it creates a JSON file called block_info.json
for each code block (source-code example) that is extracted from the ReST files.
check-code looks for all block_info.json files in the build directory
and checks the source-code example described in each of those JSON files.
All the scripts have a --verbose / -v switch. For example:
extract-code \
--verbose \
--build-dir test_output \
$(find ../content/courses/intro-to-ada/ -name '*.rst')
check-code \
--verbose \
--build-dir test_outputIt's possible to store the list of extracted projects into a JSON file and use that file for checking the projects. For example, to build the source-code examples from the Introduction to Ada course, run:
extract-code \
--extracted_projects test_output/extracted_projects.json \
$(find ../content/courses/intro-to-ada/ -name '*.rst')
check-code \
--extracted_projects test_output/extracted_projects.jsonTo build the source-code examples extracted from a single ReST file:
extract-code \
--extracted_projects test_output/extracted_projects.json \
../content/courses/intro-to-ada/chapters/imperative_language.rst
check-code \
--extracted_projects test_output/extracted_projects.jsonIf only --extracted_projects is specified without --build-dir, then the
build directory corresponds to the path to the JSON file. For example, if
--extracted_projects test_output/extracted_projects.json is specified, then
the build directory is test_output.
To store the JSON file completely separate from the build directory, use
both --extracted_projects and --build-dir switches and specify different
paths. For example:
extract-code \
--build-dir test_output \
--extracted_projects extracted_projects.json \
$(find ../content/courses/intro-to-ada/ -name '*.rst')
check-code \
--build-dir test_output \
--extracted_projects extracted_projects.jsonWhen extracting the source-code examples from the ReST files, a JSON file
called block_info.json is created for each code block. It's possible to check
a single code block by using check-block and indicating this JSON file.
For example:
check-block \
test_output/projects/Courses/Intro_To_Ada/Imperative_Language/Greet/cba89a34b87c9dfa71533d982d05e6ab/block_info.jsonTo force checking of a specific code block, use the --force switch:
check-block \
--force \
test_output/projects/Courses/Intro_To_Ada/Imperative_Language/Greet/cba89a34b87c9dfa71533d982d05e6ab/block_info.jsonTo test just a single code block from an ReST file, use the --code-block-at
switch:
extract-code \
--code-block-at=28 \
--extracted_projects test_output/extracted_projects.json \
../content/courses/intro-to-ada/chapters/imperative_language.rst
check-code \
--extracted_projects test_output/extracted_projects.jsonTo ensure that a maximum limit of 80 columns per line is respected in the code
examples, use the --max-columns switch.
For example, using check-code:
check-code \
--max-columns 80 \
--extracted_projects test_output/extracted_projects.jsonFor example, using check-block:
check-block \
--max-columns 80 \
test_output/projects/Courses/Intro_To_Ada/Imperative_Language/Greet/cba89a34b87c9dfa71533d982d05e6ab/block_info.json