From 880a1683e34e0a8b4a25386010108e3a78454aa4 Mon Sep 17 00:00:00 2001 From: Kerim Satirli Date: Thu, 28 Mar 2024 10:54:25 +0100 Subject: [PATCH] linting --- Makefile | 77 +++++++++++++++---------------------------------------- README.md | 28 ++++++++++---------- baedge.py | 8 +++--- config.py | 6 ++--- 4 files changed, 42 insertions(+), 77 deletions(-) diff --git a/Makefile b/Makefile index 288a013..5798c12 100644 --- a/Makefile +++ b/Makefile @@ -1,91 +1,56 @@ # Makefile for Baedge Server # configuration -TITLE = 🎫 {BA,E}DGE SERVER -BINARY_PYTHON ?= python3 -FLAKE_CONFIG ?= ".flake8" -FLASK_APP ?= server -FLASK_PORT ?= 2343 -NOMAD_SERVICE ?= "baedge-main" -PYLINT_RCFILE ?= ".pylintrc" +BAEDGE_API = $(shell $(BINARY_NOMAD) service info -t '{{range .}}{{printf "http://%s:%v\n" .Address .Port }}{{end}}' "${NOMAD_SERVICE}") +BINARY_FLASK ?= flask +FLASK_APP ?= server +FLASK_PORT ?= 2343 +NOMAD_SERVICE ?= "baedge-main" +MAKEFILE_TITLE = 🎫 {BA,E}DGE SERVER -# retrieve Baedge Server API information from Nomad -BAEDGE_API = $(shell nomad service info -t '{{range .}}{{printf "http://%s:%v\n" .Address .Port }}{{end}}' "${NOMAD_SERVICE}") include ../tooling/make/configs/shared.mk include ../tooling/make/functions/shared.mk +include ../tooling/make/targets/python.mk +include ../tooling/make/functions/snyk.mk include ../tooling/make/targets/shared.mk -.SILENT .PHONY: deps -deps: # install dependencies [Usage: `make deps`] - pip \ - install \ - --requirement "requirements.txt" - -.SILENT .PHONY: deps-dev -deps-dev: # install development dependencies [Usage: `make deps-dev`] - pip \ - install \ - --requirement "requirements-dev.txt" - -.SILENT .PHONY: fix -fix: # fix Python files using autopep8 [Usage: `make fix`] - autopep8 \ - --in-place \ - *.py \ - -.SILENT .PHONY: lint -lint: # lint Python files using Flake8 and Pylint [Usage: `make lint`] - flake8 \ - --config="${FLAKE_CONFIG}" \ - *.py \ - && \ - pylint \ - --rcfile="${PYLINT_RCFILE}" \ - *.py - -.SILENT .PHONY: snyk -snyk: # check Python files using Snyk [Usage: `make snyk`] - snyk \ - test \ - --command="${BINARY_PYTHON}" \ - --file="requirements.txt" \ - --package-manager=pip \ - -- --allow-missing - .SILENT .PHONY: routes routes: # list Baedge Server routes using Flask [Usage: `make routes`] - flask \ + $(BINARY_FLASK) \ --app="${FLASK_APP}" \ routes .SILENT .PHONY: run run: # run Baedge Server using Flask [Usage: `make run`] - flask \ + $(BINARY_FLASK) \ --app="${FLASK_APP}" \ --debug \ run \ --port="${FLASK_PORT}" -.SILENT .PHONY: env-info -env-info: # print Baedge Environment information [Usage: `make env-info`] - env | \ - grep \ - "BAEDGE_" +.SILENT .PHONY: env +env: # print environment information [Usage: `make env-info`] + $(call print_env,"BAEDGE_") .SILENT .PHONY: gpio-info gpio-info: # print GPIO information using Python [Usage: `make gpio-info`] - ${BINARY_PYTHON} \ + $(BINARY_PYTHON) \ gpio.py .SILENT .PHONY: screen screen: # set Baedge Screen [Usage: `make screen screen=`] $(if $(screen),,$(call missing_argument,screen=)) - echo "Attempting to write screen \`${screen}\` on device...\n" + $(call print_reference,"Attempting to write screen \`${screen}\` on device...\n") - curl \ + $(BINARY_CURL) \ --location \ --request POST \ "${BAEDGE_API}/v1/device/write" \ --form "screen=\"$(screen)\"" + +.SILENT .PHONY: snyk +snyk: # check Python files using Snyk [Usage: `make snyk`] + $(call snyk_test,$(BINARY_PYTHON),$(CONFIG_PIP_REQS),pip,"--allow-missing") + $(call snyk_test,$(BINARY_PYTHON),$(CONFIG_PIP_REQS_DEV),pip,"--allow-missing") diff --git a/README.md b/README.md index b853284..e2c043c 100644 --- a/README.md +++ b/README.md @@ -53,20 +53,20 @@ Running `make` without commands will print out the following help information: ```text 🎫 {BA,E}DGE SERVER -Target Description Usage -deps install dependencies `make deps` -deps-dev install development dependencies `make deps-dev` -fix fix Python files using autopep8 `make fix` -lint lint Python files using Flake8 and Pylint `make lint` -snyk check Python files using Snyk `make snyk` -routes list Baedge Server routes using Flask `make routes` -run run Baedge Server using Flask `make run` -env-info print Baedge Environment information `make env-info` -gpio-info print GPIO information using Python `make gpio-info` -screen set Baedge Screen `make screen screen=` -help display a list of Make Targets `make help` -_listincludes list all included Makefiles and *.mk files `make _listincludes` -_selfcheck lint Makefile `make _selfcheck` +Target Description Usage +routes list Baedge Server routes using Flask `make routes` +run run Baedge Server using Flask `make run` +env print environment information `make env-info` +gpio-info print GPIO information using Python `make gpio-info` +screen set Baedge Screen `make screen screen=` +snyk check Python files using Snyk `make snyk` +deps install Python dependencies using pip `make deps` +deps-dev install Python development dependencies using pip `make deps-dev` +fix fix Python files using autopep8 `make fix` +lint lint Python files using Flake8 and Pylint `make lint` +help display a list of Make Targets `make help` +_listincludes list all included Makefiles and *.mk files `make _listincludes` +_selfcheck lint Makefile `make _selfcheck` ``` ## Notes diff --git a/baedge.py b/baedge.py index 58ca3b2..a57440e 100644 --- a/baedge.py +++ b/baedge.py @@ -144,7 +144,7 @@ def write_screen(epd, screen_name, sleep_screen=False): if "coordinates" in item and "fill" in item and "type" in item: hlp.log_debug('write_screen:shape', "Complete data to write a shape, trying to write it") if item["type"] == "rectangle": - hlp.log_debug('write_screen:shape', "Creating a rectangle") + hlp.log_debug('write_screen:shape', "Creating a rectangle") draw.rectangle(item["coordinates"], fill=item["fill"]) else: hlp.log_debug('write_screen:shape', "Unknown shape type: " + item["type"] + ", skipping") @@ -190,9 +190,9 @@ def write_screen(epd, screen_name, sleep_screen=False): hlp.log_debug("write_scree:text", "Overriding font size to fit on screen") font_size -= 1 text_font = ImageFont.truetype( - screen["font"]["face"], - font_size, - ) + screen["font"]["face"], + font_size, + ) hlp.log_debug("write_screen:text", "Final font size, adjusted for tthe screen size:" + str(font_size)) content = item["content"] coordinates = item["coordinates"] diff --git a/config.py b/config.py index d62017e..edc5091 100644 --- a/config.py +++ b/config.py @@ -67,7 +67,7 @@ "box_size": 3, # `fit` defines wether the image should be made to fit the bounding box - "fit": True, + "fit": True, # `version` is a range between 1 and 40, indicating the size "version": 1, @@ -268,7 +268,7 @@ } }, { - "content": "Allocation ID:" + nomad["allocation"] + "\nAddress: " + nomad["address"] + "\nVersion: " + nomad["version"], + "content": "Allocation ID:" + nomad["allocation"] + "\nAddress: " + nomad["address"] + "\nVersion: " + nomad["version"], "coordinates": (10, 60), "fill": 0, } @@ -293,7 +293,7 @@ "qrcode": { "content": baedge["wearer"]["link"], "offset": -0.001 - #"coordinates": (120, 60), + # "coordinates": (120, 60), }, }, }