Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
ksatirli committed Mar 28, 2024
1 parent 8735327 commit 880a168
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 77 deletions.
77 changes: 21 additions & 56 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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=<screen>`]
$(if $(screen),,$(call missing_argument,screen=<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")
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<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=<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
Expand Down
8 changes: 4 additions & 4 deletions baedge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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"]
Expand Down
6 changes: 3 additions & 3 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
Expand All @@ -293,7 +293,7 @@
"qrcode": {
"content": baedge["wearer"]["link"],
"offset": -0.001
#"coordinates": (120, 60),
# "coordinates": (120, 60),
},
},
}

0 comments on commit 880a168

Please sign in to comment.