tox for local CI, with coverage and bandit checks added
This commit is contained in:
parent
e6f6a888a5
commit
d31c451d0c
@ -10,6 +10,28 @@ FOOTER_SIZE = 12
|
|||||||
FOOTER_MAGIC = b'\x65\xe3\xf1\xd2'
|
FOOTER_MAGIC = b'\x65\xe3\xf1\xd2'
|
||||||
|
|
||||||
|
|
||||||
|
###############
|
||||||
|
# LIB METHODS #
|
||||||
|
###############
|
||||||
|
|
||||||
|
|
||||||
|
def get_config(content: bytes) -> dict:
|
||||||
|
"""Read the config from a GP2040-CE storage section.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
content: bytes from a GP2040-CE board's storage section
|
||||||
|
Returns:
|
||||||
|
the parsed configuration
|
||||||
|
"""
|
||||||
|
size, _, _ = get_config_footer(content)
|
||||||
|
|
||||||
|
config_pb2 = get_config_pb2()
|
||||||
|
config = config_pb2.Config()
|
||||||
|
config.ParseFromString(content[-(size + FOOTER_SIZE):-FOOTER_SIZE])
|
||||||
|
logger.debug("parsed: %s", config)
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
def get_config_footer(content: bytes) -> tuple[int, int, str]:
|
def get_config_footer(content: bytes) -> tuple[int, int, str]:
|
||||||
"""Confirm and retrieve the config footer from a series of bytes of GP2040-CE storage.
|
"""Confirm and retrieve the config footer from a series of bytes of GP2040-CE storage.
|
||||||
|
|
||||||
@ -40,21 +62,9 @@ def get_config_footer(content: bytes) -> tuple[int, int, str]:
|
|||||||
return config_size, config_crc, config_magic
|
return config_size, config_crc, config_magic
|
||||||
|
|
||||||
|
|
||||||
def get_config(content: bytes) -> dict:
|
############
|
||||||
"""Read the config from a GP2040-CE storage section.
|
# COMMANDS #
|
||||||
|
############
|
||||||
Args:
|
|
||||||
content: bytes from a GP2040-CE board's storage section
|
|
||||||
Returns:
|
|
||||||
the parsed configuration
|
|
||||||
"""
|
|
||||||
size, _, _ = get_config_footer(content)
|
|
||||||
|
|
||||||
config_pb2 = get_config_pb2()
|
|
||||||
config = config_pb2.Config()
|
|
||||||
config.ParseFromString(content[-(size+FOOTER_SIZE):-FOOTER_SIZE])
|
|
||||||
logger.debug("parsed: %s", config)
|
|
||||||
return config
|
|
||||||
|
|
||||||
|
|
||||||
def visualize():
|
def visualize():
|
||||||
|
@ -14,18 +14,25 @@ dependencies = ["grpcio-tools"]
|
|||||||
dynamic = ["version"]
|
dynamic = ["version"]
|
||||||
|
|
||||||
[project.optional-dependencies]
|
[project.optional-dependencies]
|
||||||
dev = ["decorator", "flake8", "flake8-blind-except", "flake8-builtins", "flake8-docstrings", "flake8-executable",
|
dev = ["bandit", "decorator", "flake8", "flake8-blind-except", "flake8-builtins", "flake8-docstrings",
|
||||||
"flake8-fixme", "flake8-isort", "flake8-logging-format", "flake8-mutable", "flake8-pyproject", "mypy",
|
"flake8-executable", "flake8-fixme", "flake8-isort", "flake8-logging-format", "flake8-mutable",
|
||||||
"pip-tools", "pytest", "setuptools-scm"]
|
"flake8-pyproject", "mypy", "pip-tools", "pytest", "pytest-cov", "setuptools-scm", "tox"]
|
||||||
|
|
||||||
[project.scripts]
|
[project.scripts]
|
||||||
visualize-storage = "gp2040ce_bintools.storage:visualize"
|
visualize-storage = "gp2040ce_bintools.storage:visualize"
|
||||||
|
|
||||||
[tool.flake8]
|
[tool.flake8]
|
||||||
|
enable-extensions = "G,M"
|
||||||
|
exclude = [".tox/", "venv/", "_version.py", "tests/test-files/"]
|
||||||
|
extend-ignore = "T101"
|
||||||
|
max-complexity = 10
|
||||||
max-line-length = 120
|
max-line-length = 120
|
||||||
|
|
||||||
[tool.mypy]
|
[tool.mypy]
|
||||||
ignore_missing_imports = true
|
ignore_missing_imports = true
|
||||||
|
|
||||||
|
[tool.pytest]
|
||||||
|
python_files = ["*_tests.py", "tests.py", "test_*.py"]
|
||||||
|
|
||||||
[tool.setuptools_scm]
|
[tool.setuptools_scm]
|
||||||
write_to = "gp2040ce_bintools/_version.py"
|
write_to = "gp2040ce_bintools/_version.py"
|
||||||
|
@ -4,14 +4,30 @@
|
|||||||
#
|
#
|
||||||
# pip-compile --extra=dev --output-file=requirements/requirements-dev.txt
|
# pip-compile --extra=dev --output-file=requirements/requirements-dev.txt
|
||||||
#
|
#
|
||||||
|
bandit==1.7.5
|
||||||
|
# via gp2040ce-binary-tools (pyproject.toml)
|
||||||
build==0.10.0
|
build==0.10.0
|
||||||
# via pip-tools
|
# via pip-tools
|
||||||
|
cachetools==5.3.1
|
||||||
|
# via tox
|
||||||
|
chardet==5.1.0
|
||||||
|
# via tox
|
||||||
click==8.1.3
|
click==8.1.3
|
||||||
# via pip-tools
|
# via pip-tools
|
||||||
|
colorama==0.4.6
|
||||||
|
# via tox
|
||||||
|
coverage[toml]==7.2.7
|
||||||
|
# via pytest-cov
|
||||||
decorator==5.1.1
|
decorator==5.1.1
|
||||||
# via gp2040ce-binary-tools (pyproject.toml)
|
# via gp2040ce-binary-tools (pyproject.toml)
|
||||||
|
distlib==0.3.6
|
||||||
|
# via virtualenv
|
||||||
exceptiongroup==1.1.1
|
exceptiongroup==1.1.1
|
||||||
# via pytest
|
# via pytest
|
||||||
|
filelock==3.12.2
|
||||||
|
# via
|
||||||
|
# tox
|
||||||
|
# virtualenv
|
||||||
flake8==6.0.0
|
flake8==6.0.0
|
||||||
# via
|
# via
|
||||||
# flake8-builtins
|
# flake8-builtins
|
||||||
@ -39,6 +55,10 @@ flake8-mutable==1.2.0
|
|||||||
# via gp2040ce-binary-tools (pyproject.toml)
|
# via gp2040ce-binary-tools (pyproject.toml)
|
||||||
flake8-pyproject==1.2.3
|
flake8-pyproject==1.2.3
|
||||||
# via gp2040ce-binary-tools (pyproject.toml)
|
# via gp2040ce-binary-tools (pyproject.toml)
|
||||||
|
gitdb==4.0.10
|
||||||
|
# via gitpython
|
||||||
|
gitpython==3.1.31
|
||||||
|
# via bandit
|
||||||
grpcio==1.54.2
|
grpcio==1.54.2
|
||||||
# via grpcio-tools
|
# via grpcio-tools
|
||||||
grpcio-tools==1.54.2
|
grpcio-tools==1.54.2
|
||||||
@ -47,8 +67,12 @@ iniconfig==2.0.0
|
|||||||
# via pytest
|
# via pytest
|
||||||
isort==5.12.0
|
isort==5.12.0
|
||||||
# via flake8-isort
|
# via flake8-isort
|
||||||
|
markdown-it-py==3.0.0
|
||||||
|
# via rich
|
||||||
mccabe==0.7.0
|
mccabe==0.7.0
|
||||||
# via flake8
|
# via flake8
|
||||||
|
mdurl==0.1.2
|
||||||
|
# via markdown-it-py
|
||||||
mypy==1.4.0
|
mypy==1.4.0
|
||||||
# via gp2040ce-binary-tools (pyproject.toml)
|
# via gp2040ce-binary-tools (pyproject.toml)
|
||||||
mypy-extensions==1.0.0
|
mypy-extensions==1.0.0
|
||||||
@ -56,12 +80,22 @@ mypy-extensions==1.0.0
|
|||||||
packaging==23.1
|
packaging==23.1
|
||||||
# via
|
# via
|
||||||
# build
|
# build
|
||||||
|
# pyproject-api
|
||||||
# pytest
|
# pytest
|
||||||
# setuptools-scm
|
# setuptools-scm
|
||||||
|
# tox
|
||||||
|
pbr==5.11.1
|
||||||
|
# via stevedore
|
||||||
pip-tools==6.13.0
|
pip-tools==6.13.0
|
||||||
# via gp2040ce-binary-tools (pyproject.toml)
|
# via gp2040ce-binary-tools (pyproject.toml)
|
||||||
|
platformdirs==3.7.0
|
||||||
|
# via
|
||||||
|
# tox
|
||||||
|
# virtualenv
|
||||||
pluggy==1.0.0
|
pluggy==1.0.0
|
||||||
# via pytest
|
# via
|
||||||
|
# pytest
|
||||||
|
# tox
|
||||||
protobuf==4.23.3
|
protobuf==4.23.3
|
||||||
# via grpcio-tools
|
# via grpcio-tools
|
||||||
pycodestyle==2.10.0
|
pycodestyle==2.10.0
|
||||||
@ -70,25 +104,49 @@ pydocstyle==6.3.0
|
|||||||
# via flake8-docstrings
|
# via flake8-docstrings
|
||||||
pyflakes==3.0.1
|
pyflakes==3.0.1
|
||||||
# via flake8
|
# via flake8
|
||||||
|
pygments==2.15.1
|
||||||
|
# via rich
|
||||||
|
pyproject-api==1.5.2
|
||||||
|
# via tox
|
||||||
pyproject-hooks==1.0.0
|
pyproject-hooks==1.0.0
|
||||||
# via build
|
# via build
|
||||||
pytest==7.3.2
|
pytest==7.3.2
|
||||||
|
# via
|
||||||
|
# gp2040ce-binary-tools (pyproject.toml)
|
||||||
|
# pytest-cov
|
||||||
|
pytest-cov==4.1.0
|
||||||
# via gp2040ce-binary-tools (pyproject.toml)
|
# via gp2040ce-binary-tools (pyproject.toml)
|
||||||
|
pyyaml==6.0
|
||||||
|
# via bandit
|
||||||
|
rich==13.4.2
|
||||||
|
# via bandit
|
||||||
setuptools-scm==7.1.0
|
setuptools-scm==7.1.0
|
||||||
# via gp2040ce-binary-tools (pyproject.toml)
|
# via gp2040ce-binary-tools (pyproject.toml)
|
||||||
|
smmap==5.0.0
|
||||||
|
# via gitdb
|
||||||
snowballstemmer==2.2.0
|
snowballstemmer==2.2.0
|
||||||
# via pydocstyle
|
# via pydocstyle
|
||||||
|
stevedore==5.1.0
|
||||||
|
# via bandit
|
||||||
tomli==2.0.1
|
tomli==2.0.1
|
||||||
# via
|
# via
|
||||||
# build
|
# build
|
||||||
|
# coverage
|
||||||
# flake8-pyproject
|
# flake8-pyproject
|
||||||
# mypy
|
# mypy
|
||||||
|
# pyproject-api
|
||||||
|
# pyproject-hooks
|
||||||
# pytest
|
# pytest
|
||||||
# setuptools-scm
|
# setuptools-scm
|
||||||
|
# tox
|
||||||
|
tox==4.6.3
|
||||||
|
# via gp2040ce-binary-tools (pyproject.toml)
|
||||||
typing-extensions==4.6.3
|
typing-extensions==4.6.3
|
||||||
# via
|
# via
|
||||||
# mypy
|
# mypy
|
||||||
# setuptools-scm
|
# setuptools-scm
|
||||||
|
virtualenv==20.23.1
|
||||||
|
# via tox
|
||||||
wheel==0.40.0
|
wheel==0.40.0
|
||||||
# via pip-tools
|
# via pip-tools
|
||||||
|
|
||||||
|
68
tox.ini
Normal file
68
tox.ini
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
# tox (https://tox.readthedocs.io/) is a tool for running tests
|
||||||
|
# in multiple virtualenvs. This configuration file will run the
|
||||||
|
# test suite on all supported python versions. To use it, "pip install tox"
|
||||||
|
# and then run "tox" from this directory.
|
||||||
|
|
||||||
|
[tox]
|
||||||
|
isolated_build = true
|
||||||
|
envlist = begin,py39,py310,py311,coverage,bandit,lint
|
||||||
|
|
||||||
|
[testenv]
|
||||||
|
allow_externals = pytest, coverage
|
||||||
|
|
||||||
|
deps =
|
||||||
|
-rrequirements/requirements-dev.txt
|
||||||
|
|
||||||
|
[testenv:begin]
|
||||||
|
# clean up potential previous coverage runs
|
||||||
|
skip_install = true
|
||||||
|
commands = coverage erase
|
||||||
|
|
||||||
|
[testenv:py39]
|
||||||
|
# run pytest with coverage
|
||||||
|
commands =
|
||||||
|
pytest --cov-append --cov={envsitepackagesdir}/gp2040ce_bintools/ --cov-branch
|
||||||
|
|
||||||
|
[testenv:py310]
|
||||||
|
# run pytest with coverage
|
||||||
|
commands =
|
||||||
|
pytest --cov-append --cov={envsitepackagesdir}/gp2040ce_bintools/ --cov-branch
|
||||||
|
|
||||||
|
[testenv:py311]
|
||||||
|
# run pytest with coverage
|
||||||
|
commands =
|
||||||
|
pytest --cov-append --cov={envsitepackagesdir}/gp2040ce_bintools/ --cov-branch
|
||||||
|
|
||||||
|
[testenv:coverage]
|
||||||
|
# report on coverage runs from above
|
||||||
|
skip_install = true
|
||||||
|
commands =
|
||||||
|
coverage report --fail-under=80 --show-missing
|
||||||
|
|
||||||
|
[testenv:bandit]
|
||||||
|
commands =
|
||||||
|
bandit ./gp2040ce_bintools/ -r
|
||||||
|
|
||||||
|
; dep hell, can't install safety at the moment
|
||||||
|
; [testenv:safety]
|
||||||
|
; skip_install = true
|
||||||
|
; isolated_build = false
|
||||||
|
; commands =
|
||||||
|
; safety check -r requirements/requirements-dev.txt
|
||||||
|
|
||||||
|
[testenv:lint]
|
||||||
|
# run style checks
|
||||||
|
commands =
|
||||||
|
flake8
|
||||||
|
- flake8 --disable-noqa --ignore= --select=E,W,F,C,D,A,G,B,I,T,M,DUO
|
||||||
|
|
||||||
|
[coverage:paths]
|
||||||
|
source =
|
||||||
|
./
|
||||||
|
.tox/**/site-packages/
|
||||||
|
|
||||||
|
[coverage:run]
|
||||||
|
branch = True
|
||||||
|
|
||||||
|
omit =
|
||||||
|
**/_version.py
|
Loading…
x
Reference in New Issue
Block a user