You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.rst
+18-38Lines changed: 18 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,10 +14,11 @@ Features
14
14
--------
15
15
16
16
* **Write low overhead sketch files:** For a functioning sketch you only have to define the interpreter and at one of `setup()`, `loop()`, or `cleanup()` and you're ready to code.
17
-
* **Automatic imports:** Sketches will automatically import a selection of commonly used libraries at runtime, meaning you don't have to worry about your import statements.
18
-
* **Argument Preparsing:** Sketches will before running your code check the input arguments to ensure the right number of arguments are passed to your script, so you don't have to write code to check they're all there. Simply define the arguments you want as the parameters of your `setup()` function.
19
-
* **Clean crashing:** When your code is stopped by user interupt, or otherwise crashes `cleanup()` is run, giving you the opportunity to safely end your program.
17
+
* **Automatic Imports:** Sketches will automatically import a selection of commonly used libraries at runtime, meaning you don't have to worry about your import statements.
18
+
* **Argument Preparsing:** Sketches will check the input arguments to your script, and cast them automatically, so you don't have to write code to check they're all there. Simply define the arguments you want as the parameters of your `setup()` function.
19
+
* **Clean Crashing:** When your code is stopped by user interupt, or otherwise crashes `cleanup()` is run, giving you the opportunity to safely end your program.
20
20
* **Error Reporting:** Errors your code throws are printed back to the terminal so you can see where it broke.
21
+
* **Automatic Help Generation:** Pysketch reads the module's docstring and hints for the setup() function to provide automatic help text.
21
22
22
23
Examples
23
24
--------
@@ -28,10 +29,10 @@ The best way to demonstrate this is probably with an example. Read the comments
28
29
29
30
#!/usr/bin/pysketch
30
31
31
-
#Blinky.py - Sketch to blink an LED on an RPi
32
-
#This script assumes you have an LED connected from pin 12 to GND. (Via a resistor plz)
33
-
34
-
defsetup(argv): # This code is automatically executed when the sketch starts.
32
+
'''Blinky.py - Sketch to blink an LED on an RPi
33
+
This script assumes you have an LED connected from pin 18 to GND. (Via a resistor plz)'''
34
+
35
+
defsetup(): # This code is automatically executed when the sketch starts.
35
36
GPIO.setmode(GPIO.BCM) # The RPi.GPIO Library is automatically loaded in.
36
37
GPIO.setup(18, GPIO.OUT)
37
38
@@ -42,41 +43,13 @@ The best way to demonstrate this is probably with an example. Read the comments
42
43
defcleanup(): # This is called at the end, regardless of how loop() exits, even if it crashes.
43
44
GPIO.cleanup()
44
45
45
-
46
-
Now look at the equivalent vanilla python:
47
-
48
-
.. code:: python
49
-
50
-
#!/usr/bin/python3
51
-
52
-
# Blinky.py - Script to blink an LED on an RPi
53
-
# This script assumes you have an LED connected from pin 12 to GND. (Via a resistor plz)
54
-
55
-
import time
56
-
import RPi.GPIOasGPIO
57
-
58
-
GPIO.setmode(GPIO.BCM)
59
-
GPIO.setup(18, GPIO.OUT)
60
-
61
-
try
62
-
while true:
63
-
GPIO.output(18, 1-GPIO.input(18))
64
-
time.sleep(1)
65
-
except keyboardInterrupt:
66
-
print("Keyboard Interrupt: Exiting")
67
-
except:
68
-
raise
69
-
finally:
70
-
GPIO.cleanup()
71
-
72
-
(Ignoring comments and whitespace) The vanilla python script is 15 lines of code, the sketch is only 9. There are 5 lines of functional code in these programs, meaning in the sketch there is only 4 lines of boilerplate code, in the simple blink program there are 10*.
73
-
74
-
*Ironically to eliminate those 10 lines the interpreter is over 120 lines long.
46
+
This short and clear script will blink an LED. Pysketch takes care of error handling and most of the boring work, leaving just the functional parts of the program.
75
47
76
48
Installation:
77
49
-------------
78
50
79
-
Sketches is packaged at PyPI (Python Package Index), so install it using `pip3`. This package is only provided for python 3 (3.4 officially supported)
51
+
Sketches is packaged at PyPI (Python Package Index), so install it using `pip3`. This package is only provided for python 3 (3.6 officially supported).
52
+
Sketches has no dependancies.
80
53
81
54
Install:
82
55
``` bash
@@ -90,6 +63,8 @@ Add `#!/usr/bin/pysketch` to the top of your file, then run `./<filename> [args]
90
63
91
64
Or run `pysketch <filename> [args]`
92
65
66
+
See Sketch Formatting for information on how to write sketches.
67
+
93
68
Why?
94
69
----
95
70
@@ -99,3 +74,8 @@ In my day job I found myself writing a large number of scripts on the Raspberry
99
74
- on keyboard exception: clean up resources.
100
75
101
76
I wondered if there was a framework to automate away a lot of the boilerplate. When I didn't find one I wrote a template python file. As that started to get long, I wrote Sketches.
0 commit comments