Merge pull request #125 from pimoroni/python-linting

Add Python linting
pull/128/head
Philip Howard 2021-04-15 09:58:38 +01:00 zatwierdzone przez GitHub
commit d127f4d299
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
15 zmienionych plików z 255 dodań i 200 usunięć

35
.github/workflows/python.yml vendored 100644
Wyświetl plik

@ -0,0 +1,35 @@
name: Python
on:
push:
pull_request:
jobs:
build:
name: ${{matrix.name}}
strategy:
matrix:
include:
- os: ubuntu-20.04
name: Linux
cache-key: linux
apt-packages: python3 python3-pip
python-packages: flake8
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
# Linux deps
- name: Install deps
if: runner.os == 'Linux'
run: |
sudo apt update && sudo apt install ${{matrix.apt-packages}}
- name: Install Python Deps
run: python3 -m pip install ${{matrix.python-packages}}
- name: Lint
shell: bash
run: |
python3 -m flake8 --ignore E501 micropython/examples

Wyświetl plik

@ -1,4 +1,5 @@
import time, random, math
import time
import math
from breakout_roundlcd import BreakoutRoundLCD
width = BreakoutRoundLCD.WIDTH
@ -11,6 +12,7 @@ display.set_backlight(1.0)
RADIUS = width // 2
def hsv_to_rgb(h, s, v):
if s == 0.0:
return v, v, v
@ -33,7 +35,9 @@ def hsv_to_rgb(h, s, v):
if i == 5:
return v, p, q
t = 0
while True:
display.set_pen(0, 0, 0)
display.clear()
@ -57,9 +61,9 @@ while True:
x = RADIUS + int(distance * math.cos(angle))
y = RADIUS + int(distance * math.sin(angle))
l = ((math.sin(t + angle) + 1) / 2.0) * 10
radius = ((math.sin(t + angle) + 1) / 2.0) * 10
display.set_pen(r, g, b)
display.circle(int(x), int(y), int(l))
display.circle(int(x), int(y), int(radius))
prev_x = x
prev_y = y

Wyświetl plik

@ -8,12 +8,14 @@ buf = bytearray(display.get_width() * display.get_height() * 2)
display.init(buf)
display.set_backlight(0.5)
# sets up a handy function we can call to clear the screen
def clear():
display.set_pen(0, 0, 0)
display.clear()
display.update()
while True:
if display.is_pressed(display.BUTTON_A): # if a button press is detected then...
clear() # clear to black
@ -48,4 +50,3 @@ while True:
display.text("Press any button!", 10, 10, 240, 4)
display.update()
utime.sleep(0.1) # this number is how frequently the Pico checks for button presses

Wyświetl plik

@ -1,4 +1,5 @@
import time, random
import time
import random
import picodisplay as display
width = display.get_width()
@ -19,6 +20,7 @@ class Ball:
self.dy = dy
self.pen = pen
# initialise shapes
balls = []
for i in range(0, 100):

Wyświetl plik

@ -1,4 +1,4 @@
## This example borrows a CircuitPython hsv_to_rgb function to cycle through some rainbows on Pico Display's screen and RGB LED . If you're into rainbows, HSV (Hue, Saturation, Value) is very useful!
# This example borrows a CircuitPython hsv_to_rgb function to cycle through some rainbows on Pico Display's screen and RGB LED . If you're into rainbows, HSV (Hue, Saturation, Value) is very useful!
import utime
import picodisplay as display
@ -8,16 +8,17 @@ buf = bytearray(display.get_width() * display.get_height() * 2)
display.init(buf)
display.set_backlight(0.8)
# From CPython Lib/colorsys.py
def hsv_to_rgb(h, s, v):
if s == 0.0:
return v, v, v
i = int(h*6.0)
f = (h*6.0) - i
p = v*(1.0 - s)
q = v*(1.0 - s*f)
t = v*(1.0 - s*(1.0-f))
i = i%6
i = int(h * 6.0)
f = (h * 6.0) - i
p = v * (1.0 - s)
q = v * (1.0 - s * f)
t = v * (1.0 - s * (1.0 - f))
i = i % 6
if i == 0:
return v, t, p
if i == 1:
@ -31,6 +32,7 @@ def hsv_to_rgb(h, s, v):
if i == 5:
return v, p, q
h = 0
while True:

Wyświetl plik

@ -4,7 +4,8 @@
# I just changed the import statement to import picoexplorer instaead of picodisplay
import time, random
import time
import random
import picoexplorer as display
width = display.get_width()
@ -25,6 +26,7 @@ class Ball:
self.dy = dy
self.pen = pen
# initialise shapes
balls = []
for i in range(0, 100):
@ -63,4 +65,5 @@ while True:
display.circle(int(ball.x), int(ball.y), int(ball.r))
display.update()
time.sleep(0.01)

Wyświetl plik

@ -7,12 +7,14 @@ import utime
buf = bytearray(display.get_width() * display.get_height() * 2)
display.init(buf)
# sets up a handy function we can call to clear the screen
def clear():
display.set_pen(0, 0, 0)
display.clear()
display.update()
while True:
if display.is_pressed(display.BUTTON_A): # if a button press is detected then...
clear() # clear to black
@ -47,4 +49,3 @@ while True:
display.text("Press any button!", 10, 10, 240, 4)
display.update()
utime.sleep(0.1) # this number is how frequently the Pico checks for button presses

Wyświetl plik

@ -1,4 +1,4 @@
import time, random
import time
import picoexplorer as explorer
width = explorer.get_width()

Wyświetl plik

@ -14,111 +14,115 @@ explorer.set_audio_pin(0)
# this handy list converts notes into frequencies, which you can use with the explorer.set_tone function
tones = {
"B0": 31,
"C1": 33,
"CS1": 35,
"D1": 37,
"DS1": 39,
"E1": 41,
"F1": 44,
"FS1": 46,
"G1": 49,
"GS1": 52,
"A1": 55,
"AS1": 58,
"B1": 62,
"C2": 65,
"CS2": 69,
"D2": 73,
"DS2": 78,
"E2": 82,
"F2": 87,
"FS2": 93,
"G2": 98,
"GS2": 104,
"A2": 110,
"AS2": 117,
"B2": 123,
"C3": 131,
"CS3": 139,
"D3": 147,
"DS3": 156,
"E3": 165,
"F3": 175,
"FS3": 185,
"G3": 196,
"GS3": 208,
"A3": 220,
"AS3": 233,
"B3": 247,
"C4": 262,
"CS4": 277,
"D4": 294,
"DS4": 311,
"E4": 330,
"F4": 349,
"FS4": 370,
"G4": 392,
"GS4": 415,
"A4": 440,
"AS4": 466,
"B4": 494,
"C5": 523,
"CS5": 554,
"D5": 587,
"DS5": 622,
"E5": 659,
"F5": 698,
"FS5": 740,
"G5": 784,
"GS5": 831,
"A5": 880,
"AS5": 932,
"B5": 988,
"C6": 1047,
"CS6": 1109,
"D6": 1175,
"DS6": 1245,
"E6": 1319,
"F6": 1397,
"FS6": 1480,
"G6": 1568,
"GS6": 1661,
"A6": 1760,
"AS6": 1865,
"B6": 1976,
"C7": 2093,
"CS7": 2217,
"D7": 2349,
"DS7": 2489,
"E7": 2637,
"F7": 2794,
"FS7": 2960,
"G7": 3136,
"GS7": 3322,
"A7": 3520,
"AS7": 3729,
"B7": 3951,
"C8": 4186,
"CS8": 4435,
"D8": 4699,
"DS8": 4978
"B0": 31,
"C1": 33,
"CS1": 35,
"D1": 37,
"DS1": 39,
"E1": 41,
"F1": 44,
"FS1": 46,
"G1": 49,
"GS1": 52,
"A1": 55,
"AS1": 58,
"B1": 62,
"C2": 65,
"CS2": 69,
"D2": 73,
"DS2": 78,
"E2": 82,
"F2": 87,
"FS2": 93,
"G2": 98,
"GS2": 104,
"A2": 110,
"AS2": 117,
"B2": 123,
"C3": 131,
"CS3": 139,
"D3": 147,
"DS3": 156,
"E3": 165,
"F3": 175,
"FS3": 185,
"G3": 196,
"GS3": 208,
"A3": 220,
"AS3": 233,
"B3": 247,
"C4": 262,
"CS4": 277,
"D4": 294,
"DS4": 311,
"E4": 330,
"F4": 349,
"FS4": 370,
"G4": 392,
"GS4": 415,
"A4": 440,
"AS4": 466,
"B4": 494,
"C5": 523,
"CS5": 554,
"D5": 587,
"DS5": 622,
"E5": 659,
"F5": 698,
"FS5": 740,
"G5": 784,
"GS5": 831,
"A5": 880,
"AS5": 932,
"B5": 988,
"C6": 1047,
"CS6": 1109,
"D6": 1175,
"DS6": 1245,
"E6": 1319,
"F6": 1397,
"FS6": 1480,
"G6": 1568,
"GS6": 1661,
"A6": 1760,
"AS6": 1865,
"B6": 1976,
"C7": 2093,
"CS7": 2217,
"D7": 2349,
"DS7": 2489,
"E7": 2637,
"F7": 2794,
"FS7": 2960,
"G7": 3136,
"GS7": 3322,
"A7": 3520,
"AS7": 3729,
"B7": 3951,
"C8": 4186,
"CS8": 4435,
"D8": 4699,
"DS8": 4978
}
# put the notes for your song in here!
song = ["F6","F6","E6","F6","F5","P","F5","P","C6","AS5","A5","C6","F6","P","F6","P","G6","FS6","G6","G5","P","G5","P","G6","F6","E6","D6","C6","P","C6","P","D6","E6","F6","E6","D6","C6","D6","C6","AS5","A5","AS5","A5","G5","F5","G5","F5","E5","D5","C5","D5","E5","F5","G5","AS5","A5","G5","A5","F5","P","F5"]
song = ["F6", "F6", "E6", "F6", "F5", "P", "F5", "P", "C6", "AS5", "A5", "C6", "F6", "P", "F6", "P", "G6", "FS6", "G6", "G5", "P", "G5", "P", "G6", "F6", "E6", "D6", "C6", "P", "C6", "P", "D6", "E6", "F6", "E6", "D6", "C6", "D6", "C6", "AS5", "A5", "AS5", "A5", "G5", "F5", "G5", "F5", "E5", "D5", "C5", "D5", "E5", "F5", "G5", "AS5", "A5", "G5", "A5", "F5", "P", "F5"]
def clear(): # this function clears Pico Explorer's screen to black
explorer.set_pen(0,0,0)
explorer.set_pen(0, 0, 0)
explorer.clear()
explorer.update()
def playtone(frequency): # this function tells your program how to make noise
explorer.set_tone(frequency)
def bequiet(): # this function tells your program how not to make noise
explorer.set_tone(-1)
def playsong(song): # this function plays your song
a = 0 # this variable keeps track of the visualiser bars
for i in range(len(song)):
@ -127,7 +131,7 @@ def playsong(song): # this function plays your song
else:
playtone(tones[song[i]])
explorer.set_pen(0, 255, 0) # switch to green pen
explorer.rectangle(a, 240 - (int((tones[song[i]])/21)), 5, 240) # draw a green bar corresponding to the frequency of the note
explorer.rectangle(a, 240 - (int((tones[song[i]]) / 21)), 5, 240) # draw a green bar corresponding to the frequency of the note
a += 7
if a >= 240: # clears the screen if the green bars reach the right hand edge
clear()
@ -136,6 +140,7 @@ def playsong(song): # this function plays your song
utime.sleep(0.15) # change this number if you want to alter how long the notes play for
bequiet()
clear()
playsong(song)
clear()

Wyświetl plik

@ -1,4 +1,4 @@
## This example borrows a CircuitPython hsv_to_rgb function to cycle through some rainbows on Pico Explorer's screen and RGB LED . If you're into rainbows, HSV (Hue, Saturation, Value) is very useful!
# This example borrows a CircuitPython hsv_to_rgb function to cycle through some rainbows on Pico Explorer's screen and RGB LED . If you're into rainbows, HSV (Hue, Saturation, Value) is very useful!
import utime
import picoexplorer as display
@ -7,16 +7,17 @@ import picoexplorer as display
buf = bytearray(display.get_width() * display.get_height() * 2)
display.init(buf)
# From CPython Lib/colorsys.py
def hsv_to_rgb(h, s, v):
if s == 0.0:
return v, v, v
i = int(h*6.0)
f = (h*6.0) - i
p = v*(1.0 - s)
q = v*(1.0 - s*f)
t = v*(1.0 - s*(1.0-f))
i = i%6
i = int(h * 6.0)
f = (h * 6.0) - i
p = v * (1.0 - s)
q = v * (1.0 - s * f)
t = v * (1.0 - s * (1.0 - f))
i = i % 6
if i == 0:
return v, t, p
if i == 1:
@ -30,6 +31,7 @@ def hsv_to_rgb(h, s, v):
if i == 5:
return v, p, q
h = 0
while True:
@ -39,7 +41,7 @@ while True:
display.clear() # Fill the screen with the colour
display.set_pen(0, 0, 0) # Set pen to black
display.text("pico disco!", 25, 20, 240, 6) # Add some text
display.text("\o/ \o/ \o/ \o/ \o/ \o/ \o/ \o/ \o/", 25, 120, 240, 4) # and some more text
display.text("\\o/ \\o/ \\o/ \\o/ \\o/ \\o/ \\o/ \\o/ \\o/", 25, 120, 240, 4) # and some more text
display.text("oontz oontz oontz", 25, 220, 240, 2) # and a bit more tiny text
display.update() # Update the display
utime.sleep(1.0 / 60)

Wyświetl plik

@ -22,7 +22,7 @@ while True:
colour_index = 0
else:
button = 0
for find in range (0, NUM_PADS):
for find in range(0, NUM_PADS):
# check if this button is pressed and no other buttons are pressed
if button_states & 0x01 > 0:
if not (button_states & (~0x01)) > 0:
@ -31,7 +31,7 @@ while True:
button_states >>= 1
button += 1
for i in range (0, NUM_PADS):
for i in range(0, NUM_PADS):
if (lit >> i) & 0x01:
if colour_index == 0:
keypad.illuminate(i, 0x00, 0x20, 0x00)

Wyświetl plik

@ -10,8 +10,9 @@ tail = 12
width = scroll.get_width()
height = scroll.get_height()
while True:
scroll.clear();
scroll.clear()
for y in range(0, height):
for x in range(0, width):
if x < 3 and y < 3 and scroll.is_pressed(scroll.BUTTON_A):
@ -28,7 +29,6 @@ while True:
if m == (i + (loop - b)) % loop and b < tail:
scroll.set_pixel(x, y, br_mult * (tail - b))
scroll.update()
i += 1
if i >= loop:

Wyświetl plik

@ -1,19 +1,18 @@
import math
import time
import picounicorn
picounicorn.init()
# From CPython Lib/colorsys.py
def hsv_to_rgb(h, s, v):
if s == 0.0:
return v, v, v
i = int(h*6.0)
f = (h*6.0) - i
p = v*(1.0 - s)
q = v*(1.0 - s*f)
t = v*(1.0 - s*(1.0-f))
i = i%6
i = int(h * 6.0)
f = (h * 6.0) - i
p = v * (1.0 - s)
q = v * (1.0 - s * f)
t = v * (1.0 - s * (1.0 - f))
i = i % 6
if i == 0:
return v, t, p
if i == 1:
@ -27,6 +26,7 @@ def hsv_to_rgb(h, s, v):
if i == 5:
return v, p, q
w = picounicorn.get_width()
h = picounicorn.get_height()