Demos

More demos, particularly related to building C++, will be added when possible.

custom_log_stage

Simple demo for how to modify the ci_exec defaults to suit user preferences. Go to demo

Demos Program Execution

Wrapper module for executing each respective location from the repository root.

Each individual demo is executable on its own. However, users may also run a demo from repository root doing python demos/ <demo_name>.

By default the programs are not run in “animated” mode. The --animated flag is what is used to record the videos hosted on each individual demo page, which utilizes clear, PAUSE and a delay in calls to type_message(). See mock_shell() for more information.

clear()

Clear the console screen.

pause([amount])

Pause by amount using time.sleep().

type_message(message, *, delay)

Flush message to sys.stdout, sleep by delay after character.

mock_shell(program, *, cwd, delay, animated)

Run a “shell” program from the specified working directory.

run_demo(program, cwd, animated)

Run the specified demo program.

demos.__main__.CI_EXEC_DEMOS_COVERAGE = False

Whether or not this is a coverage run of the demo files.

Warning

This should not be set unless invoking from tox. See notes in [testenv:docs] section of tox.ini at repository root.

demos.__main__.windows_cmd_builtin(builtin)[source]

Return a function that runs the specified builtin.

Note

There is a reason this is not in the main library. To deal with shell builtins requires a significant amount of extra work for little to no benefit. The demos just need "cls" to clear and "type" to cat.

The return is a function that can support:

*args

Any command line arguments to provide to the builtin.

**kwargs

Any keyword arguments to provide to subprocess.run(). This function will add check=True and shell=True unless these keys are already explicitly specified.

Parameters

builtin (str) – Any of the CMD builtins, such as "type" or "cls". No checking is performed!

demos.__main__.clear()[source]

Clear the console screen. Uses cls on Windows, and clear otherwise.

demos.__main__.pause(amount = 3.0)[source]

Pause by amount using time.sleep().

This function exists so that it can be used for PAUSE statements in mock_shell().

Parameters

amount (float) – The amount of time to time.sleep() for. Default: 3.0 seconds.

demos.__main__.type_message(message, *, delay)[source]

Flush message to sys.stdout, sleep by delay after character.

Parameters
  • message (str) – What to type. A trailing newline "\n" will be written at the end.

  • delay (float) – The positive amount to time.sleep() after each character in message is written. Suggested value for simulating typing to the console: 0.05. Use 0.0 to avoid delays.

demos.__main__.mock_shell(program, *, cwd, delay, animated)[source]

Run a “shell” program from the specified working directory.

  • Lines starting with # are “comment” lines, they will be printed to the screen using type_message().

  • Lines starting with "$ " are a command to execute.

    • Commands executed will be printed to the screen using type_message().

There is also a notion of “animated” mode. When animated=True, the following special behavior is enabled:

  • $ clear: calls clear(). In non-animated mode, clear is skipped.

  • PAUSE or PAUSE=X.Y: call pause(), X.Y should be parseable as a float e.g., PAUSE=7.0 would pause for 7 seconds. In non-animated mode this is skipped.

  • Calls to type_message() will have a delay=0.05. In non-animated mode the delay=0.0.

These scripts are not intended to be robust. Features are implemented as needed… this is not intended to be a real shell programming language! See demos/__main__.py for example program’s that can execute.

Parameters
  • program (str) – The “shell” program to execute.

  • cwd (str) – The directory to execute program from.

  • delay (float) – Pass-through parameter for type_message().

  • animated (bool) – Whether or not this is an “animated” shell, meaning commands such as clear or PAUSE should be executed.

demos.__main__.run_demo(program, cwd, animated)[source]

Run the specified demo program.

When animated=True, clear() the screen and sleep for 2 seconds to allow recording to begin. The delay parameter passed-through to type_message() will be set to 0.05. In non-animated mode the screen will not be cleared, and the delay will be 0.0.

Parameters
demos.__main__.main()[source]

Create the argument parser and run the specified demo.