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
usingtime.sleep()
.
type_message
(message, *, delay)Flush
message
tosys.stdout
, sleep bydelay
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 oftox.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"
tocat
.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 addcheck=True
andshell=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__.
pause
(amount = 3.0)[source]¶ Pause by
amount
usingtime.sleep()
.This function exists so that it can be used for
PAUSE
statements inmock_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
tosys.stdout
, sleep bydelay
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 inmessage
is written. Suggested value for simulating typing to the console:0.05
. Use0.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 usingtype_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
: callsclear()
. In non-animated mode,clear
is skipped.PAUSE
orPAUSE=X.Y
: callpause()
,X.Y
should be parseable as afloat
e.g.,PAUSE=7.0
would pause for 7 seconds. In non-animated mode this is skipped.Calls to
type_message()
will have adelay=0.05
. In non-animated mode thedelay=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 exampleprogram
’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
orPAUSE
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. Thedelay
parameter passed-through totype_message()
will be set to0.05
. In non-animated mode the screen will not be cleared, and the delay will be0.0
.- Parameters
program (str) – The “shell” program to execute with
mock_shell()
.cwd (str) – Pass-through parameter to
mock_shell()
.animated (bool) – Pass-through parameter to
mock_shell()
.