Skip to content

Commit

Permalink
Add more code examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
vytas7 committed Sep 19, 2024
1 parent c52240f commit 05570ab
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
34 changes: 34 additions & 0 deletions example-code/program.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import typing


def passthrough(method: typing.Callable) -> typing.Callable:
return method


class ExampleClass:
"""This class has a docstring."""

def __init__(self, item):
self._item = item

@passthrough
def print_item(self):
print(self._item)

def try_except(self):
try:
frozenset({self._item})
except Exception as ex:
print(f'Format string: conversion error: {ex}')
finally:
pass


def main():
example = ExampleClass([1, 2, 3])
example.print_item()
example.try_except()


if __name__ == '__main__':
main()
13 changes: 13 additions & 0 deletions example-code/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

set -e

PYTHON_PROGRAM="program.py"
# Prepending `pwd` doesn't do much, it is here for demonstrating highlighting
# of backticks, and a comment.
input_file=`pwd`/$PYTHON_PROGRAM

cat $input_file | while read line
do
echo "| Python | $line"
done
9 changes: 7 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@ deps =
Pillow
commands =
# TODO(vytas): Make font name (auto-) configurable, not hardcoded.
pygmentize example-code/document.md -O 'font_name=SourceCodePro-Medium,font_size=24,style=falconry-dark' -o examples-dark/document.png
pygmentize example-code/document.md -O 'font_name=SourceCodePro-Medium,font_size=24,style=falconry-light' -o examples-light/document.png
pygmentize example-code/document.md -O 'font_name=Ubuntu Mono,font_size=24,style=falconry-dark' -o examples-dark/document.png
pygmentize example-code/program.py -O 'font_name=Ubuntu Mono,font_size=24,style=falconry-dark' -o examples-dark/program.png
pygmentize example-code/script.sh -O 'font_name=Ubuntu Mono,font_size=24,style=falconry-dark' -o examples-dark/script.png

pygmentize example-code/document.md -O 'font_name=Ubuntu Mono,font_size=24,style=falconry-light' -o examples-light/document.png
pygmentize example-code/program.py -O 'font_name=Ubuntu Mono,font_size=24,style=falconry-light' -o examples-light/program.png
pygmentize example-code/script.sh -O 'font_name=Ubuntu Mono,font_size=24,style=falconry-light' -o examples-light/script.png

0 comments on commit 05570ab

Please sign in to comment.