CI: More complete Python linting

pull/291/head
Phil Howard 2022-03-11 12:20:27 +00:00
rodzic b7061b9dd7
commit dece2aac85
4 zmienionych plików z 134 dodań i 139 usunięć

Wyświetl plik

@ -6,30 +6,25 @@ on:
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}}
name: Python Linting
runs-on: ubuntu-20.04
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}}
run: python3 -m pip install flake8
- name: Lint
- name: Lint micropython/modules_py
shell: bash
run: |
python3 -m flake8 --ignore E501 micropython/modules_py micropython/examples
python3 -m flake8 --ignore E501 micropython/modules_py
- name: Lint micropython/examples
shell: bash
run: |
python3 -m flake8 --ignore E501 micropython/examples
- name: Lint .py tools in C++ examples
shell: bash
run: |
python3 -m flake8 --ignore E501 examples

Wyświetl plik

@ -3,19 +3,16 @@
# converts Hershey fonts into a format easier to consume by the Badger2040
# e-ink badge library - the result can be piped directly into a .hpp file.
import argparse, sys, os, glob
import argparse
from pathlib import Path
parser = argparse.ArgumentParser(
description='Converts Hershey fonts into the format used by Badger2040.')
parser.add_argument('file', nargs="+", help='input files to convert')
description="Converts Hershey fonts into the format used by Badger2040."
)
parser.add_argument("file", nargs="+", help="input files to convert")
options = None
try:
options = parser.parse_args()
except:
parser.print_help()
sys.exit(0)
def convert_font(data):
# parse hershey font data file, the file format contains one record per
@ -49,10 +46,7 @@ def convert_font(data):
# we'll loop, extracting one character per iteration, until all of the
# data is consumed
while(len(data) > 0):
# extract character id
char_id = int(data[0:5])
while len(data) > 0:
char_code = auto_char_code
auto_char_code += 1
@ -67,7 +61,7 @@ def convert_font(data):
char_data[char_code] = {
"width": right - left,
"vertex_count": vertex_count,
"first_vertex_offset": len(vertex_data)
"first_vertex_offset": len(vertex_data),
}
# work out expected total length of character data
@ -75,8 +69,8 @@ def convert_font(data):
# if there are any newlines within this data then remove them before we
# move on the parse the vertices
while data.find('\n', char_data_len) != -1:
data = data.replace('\n', '', 1)
while data.find("\n", char_data_len) != -1:
data = data.replace("\n", "", 1)
for i in range(0, vertex_count):
offset = 10 + (i * 2)
@ -96,11 +90,13 @@ def convert_font(data):
font_name = Path(input_filename).stem
# create code for all of the vertices
vertex_code = '''\
vertex_code = """\
static const int8_t {font_name}_vertices[{count}] = {{
{vertices}
}};
'''.format(font_name=font_name, count=len(vertex_data), vertices=", ".join(vertex_data))
""".format(
font_name=font_name, count=len(vertex_data), vertices=", ".join(vertex_data)
)
# create code for chars and font
#
@ -117,21 +113,24 @@ def convert_font(data):
width=char_data[i]["width"],
vertex_count=char_data[i]["vertex_count"],
font_name=font_name,
offset=char_data[i]["first_vertex_offset"]
))
offset=char_data[i]["first_vertex_offset"],
)
)
else:
chars.append(" {.width=0, .vertex_count=0, .vertices=nullptr}")
# struct hershey_font_t {
# hershey_font_glyph_t chars[95];
# };
font_code = '''\
font_code = """\
static const hershey_font_t {font_name} {{
.chars = {{
{chars}
}}
}};
'''.format(font_name=font_name, chars=",\n".join(chars))
""".format(
font_name=font_name, chars=",\n".join(chars)
)
print(vertex_code)
@ -143,16 +142,18 @@ def convert_font(data):
# create map of font name to font structure
font_list = []
for input_filename in options.file:
input_file = open(input_filename, mode='r')
input_file = open(input_filename, mode="r")
data = input_file.read()
input_file.close()
font_list.append(convert_font(data))
map_code = '''\
map_code = """\
std::map<std::string, const hershey_font_t*> fonts = {{
{font_list}
}};
'''.format(font_list=",\n".join(font_list))
""".format(
font_list=",\n".join(font_list)
)
print(map_code)

Wyświetl plik

@ -68,5 +68,3 @@ static const uint8_t {image_name}[{count}] = {{
'''.format(image_name=image_name, count=len(output_data), byte_data=", ".join(str(b) for b in output_data))
print(image_code)

Wyświetl plik

@ -88,6 +88,7 @@ def data():
"""
def write_func(stream, name, arg):
stream.write('def {}():\n return {}\n\n'.format(name, arg))
@ -123,6 +124,7 @@ def quit(msg):
print(msg)
sys.exit(1)
DESC = """data_to_py.py
Utility to convert an arbitrary binary file to Python source.
Sample usage:
@ -137,7 +139,6 @@ if __name__ == "__main__":
parser.add_argument('outfile', type=str,
help='Path and name of output file. Must have .py extension.')
args = parser.parse_args()
if not os.path.isfile(args.infile):