Skip to content

Commit 3b39410

Browse files
committed
1.1rc1 Release
1 parent 6d957b4 commit 3b39410

File tree

4 files changed

+49
-40
lines changed

4 files changed

+49
-40
lines changed

README.rst

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ Features
1414
--------
1515

1616
* **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.
2020
* **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.
2122

2223
Examples
2324
--------
@@ -28,10 +29,10 @@ The best way to demonstrate this is probably with an example. Read the comments
2829
2930
#!/usr/bin/pysketch
3031
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-
def setup(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+
def setup(): # This code is automatically executed when the sketch starts.
3536
GPIO.setmode(GPIO.BCM) # The RPi.GPIO Library is automatically loaded in.
3637
GPIO.setup(18, GPIO.OUT)
3738
@@ -42,41 +43,13 @@ The best way to demonstrate this is probably with an example. Read the comments
4243
def cleanup(): # This is called at the end, regardless of how loop() exits, even if it crashes.
4344
GPIO.cleanup()
4445
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.GPIO as GPIO
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.
7547

7648
Installation:
7749
-------------
7850

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.
8053

8154
Install:
8255
``` bash
@@ -90,6 +63,8 @@ Add `#!/usr/bin/pysketch` to the top of your file, then run `./<filename> [args]
9063

9164
Or run `pysketch <filename> [args]`
9265

66+
See Sketch Formatting for information on how to write sketches.
67+
9368
Why?
9469
----
9570

@@ -99,3 +74,8 @@ In my day job I found myself writing a large number of scripts on the Raspberry
9974
- on keyboard exception: clean up resources.
10075

10176
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.
77+
78+
Licence
79+
-------
80+
GPL 3.0
81+
See LICENCE file for more information.

examples/cutter.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env pysketch
2+
3+
""" Cut the lines of very long files """
4+
5+
fin = None
6+
fout = None
7+
l = 0
8+
9+
def setup(filename, length: int, output = None):
10+
global fin, fout, l
11+
fin = open(filename, 'r')
12+
if not output:
13+
output = "{}.{}.cut".format(filename,length)
14+
fout = open(output, 'w')
15+
l = length
16+
17+
def loop():
18+
global fin, fout, l
19+
line = fin.readline()[:l]
20+
if line == '':
21+
exit()
22+
if line[-1] != '\n':
23+
line += '\n'
24+
fout.write(line)
25+
26+
def cleanup():
27+
global fin, fout
28+
fin.close()
29+
fout.close()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
'Intended Audience :: Education',
1919
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
2020
'Natural Language :: English',
21-
'Programming Language :: Python :: 3.4',
21+
'Programming Language :: Python :: 3.6',
2222
'Programming Language :: Python :: 3 :: Only',
2323
'Topic :: Software Development :: Interpreters',
2424
'Topic :: Education', ],

sketches/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from sys import argv
66
from typing import List, Tuple
77

8-
__version__ = '1.1beta1'
8+
__version__ = '1.1rc1'
99

1010
class SketchRunner:
1111
__default_package_list = [('sys', 'sys'), ('time', 'time'), ('math', 'math'), ('RPi.GPIO', 'GPIO','sketches.fakeGPIO')]

0 commit comments

Comments
 (0)