Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexpeits/presentationlib
Tool for creating live presentations and evaluating Python code
https://github.com/alexpeits/presentationlib
presentations shell
Last synced: about 1 month ago
JSON representation
Tool for creating live presentations and evaluating Python code
- Host: GitHub
- URL: https://github.com/alexpeits/presentationlib
- Owner: alexpeits
- License: gpl-3.0
- Created: 2016-12-15T20:54:59.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-09-23T08:46:47.000Z (about 5 years ago)
- Last Synced: 2023-03-01T04:15:39.912Z (over 1 year ago)
- Topics: presentations, shell
- Language: Python
- Homepage:
- Size: 18.6 KB
- Stars: 8
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
presentationlib
===============Tool for live coding presentations
----------------------------------**(I will find a better name)**
*presentationlib* is a simple tool for doing presentations via the python REPL.
It was inspired by `these `_ `two
`_ talks by David Beazley.It can easily present text files, but can also execute python files in the
global scope, the same as if the presenter typed in the code or imported it.The usage is simple, import the ``presentation`` function, declare a mapping to
configure the files that are included in the presentation, and run it.The mapping can also include a list. Then, multiple uses of it cycle through
the options.Usage
-----*File structure*::
|
|- run_presentation.py
|- slides/
|- fib.py
|- lorem.txt*run_presentation.py*:
.. code-block:: python
from presentationlib import presentation
mapping = {
'fib': 'fib.py',
'lorem': {'file': 'lorem.txt', 'wrap': True},
'test': '~/file.txt',
'multiple': [
'fib.py',
'~/file.txt',
{'file': 'lorem.txt', 'wrap': True}
]
}if __name__ == '__main__':
presentation(
mapping, location='slides',
heading='My Presentation', subheading='waaaaat'
)*Presentation*::
$ python run_presentation.py
--------------------------------------------------
My Presentation
--------------------------------------------------
waaaaat
>>> 'hello'
'hello'
>>> 'fib'
+------------------------------------------------------------------------------+
| |
| def fibo(lim): |
| a, b = 0, 1 |
| while a <= lim: |
| yield a |
| a, b = b, a+b |
| |
+------------------------------------------------------------------------------+>>> fibo
>>> list(fibo(5))
[0, 1, 1, 2, 3, 5]
>>>
>>> 'lorem'
+------------------------------------------------------------------------------+
| |
| Lorem ipsum dolor sit amet, neque voluptatum pede nulla praesent, arcu |
| neque amet sit, cum libero quis gravida arcu, pellentesque amet per amet |
| mi. Justo sapien sit ut, sit arcu lobortis tincidunt, dolor elit lobortis |
| gravida. At at leo egestas est, alias libero nisl nam id, eleifend |
| interdum sagittis congue eiusmod. Rutrum ante rutrum mauris, lorem aliquet |
| placerat sollicitudin alias, tenetur dignissim accusantium elit eros, dui |
| suscipit lacus ut. Wisi sodales exercitationem nullam, non in nunc eget. |
| Sapien eu volutpat felis ac, nibh cursus elit varius. |
| |
+------------------------------------------------------------------------------+>>> 'multiple'
+------------------------------------------------------------------------------+
| |
| def fibo(lim): |
| a, b = 0, 1 |
| while a <= lim: |
| yield a |
| a, b = b, a+b |
| |
+------------------------------------------------------------------------------+>>> 'multiple'
+------------------------------------------------------------------------------+
| |
| This is a file |
| Yes, this is a file |
| |
+------------------------------------------------------------------------------+>>> 'multiple'
+------------------------------------------------------------------------------+
| |
| Lorem ipsum dolor sit amet, neque voluptatum pede nulla praesent, arcu |
| neque amet sit, cum libero quis gravida arcu, pellentesque amet per amet |
| mi. Justo sapien sit ut, sit arcu lobortis tincidunt, dolor elit lobortis |
| gravida. At at leo egestas est, alias libero nisl nam id, eleifend |
| interdum sagittis congue eiusmod. Rutrum ante rutrum mauris, lorem aliquet |
| placerat sollicitudin alias, tenetur dignissim accusantium elit eros, dui |
| suscipit lacus ut. Wisi sodales exercitationem nullam, non in nunc eget. |
| Sapien eu volutpat felis ac, nibh cursus elit varius. |
| |
+------------------------------------------------------------------------------+Configuration options
---------------------* ``location``: the directory in which all filenames are searched (except for absolute paths)
* ``exec_py``: whether python files are executed to make functions, classes and variables available in the REPL
* ``use_box``: whether to put text inside an ascii box
* ``box_width``: the box width to use, if ``use_box`` is ``True``
* ``banner``: printed on REPL initialization (a default banner is also provided)
* ``heading`` and ``subheading``: ``banner`` can be a template, these are the template optionsHow does it work?
-----------------The printing of file content when the user inputs a simple string works by
patching ``sys.displayhook``. This is a function that is ran in the interactive
REPL whenever a user wants to output something (not when using ``print``).The execution of the python files is made possible by using frame inspection.
The modified displayhook gets the caller's frame, and executes the code inside
the REPL's context. Note that any code outside an ``if __name__ == '__main__'``
guard will be executed.