Skip to content

Commit

Permalink
[CLI] Added option to stop on warnings
Browse files Browse the repository at this point in the history
Closes #545
  • Loading branch information
set-soft committed Jan 4, 2024
1 parent e9ddb02 commit 5bf6ae7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Command line:
- `--help-list-offsets` to list footprint offsets (JLCPCB)
- `--help-list-rotations` to list footprint rotations (JLCPCB)
- `--stop-on-warnings` (`-W`) to stop on warnings (#545)
- Global options:
- `remove_solder_mask_for_dnp` similar to `remove_solder_paste_for_dnp` but
applied to the solder mask apertures. (#476)
Expand Down
4 changes: 3 additions & 1 deletion kibot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Usage:
kibot [-b BOARD] [-e SCHEMA] [-c CONFIG] [-d OUT_DIR] [-s PRE] [-D]
[-q | -v...] [-L LOGFILE] [-C | -i | -n] [-m MKFILE] [-A] [-g DEF] ...
[-E DEF] ... [-w LIST] [--banner N] [TARGET...]
[-E DEF] ... [-w LIST] [-W] [--banner N] [TARGET...]
kibot [-v...] [-b BOARD] [-e SCHEMA] [-c PLOT_CONFIG] [--banner N]
[-E DEF] ... [--config-outs] [--only-pre|--only-groups] [--only-names]
[--output-name-first] --list
Expand Down Expand Up @@ -72,6 +72,7 @@
-v, --verbose Show debugging information
-V, --version Show program's version number and exit
-w, --no-warn LIST Exclude the mentioned warnings (comma sep)
-W, --stop-on-warnings Stop on warnings
-x, --example Create a template configuration file
Quick start options:
Expand Down Expand Up @@ -410,6 +411,7 @@ def main():
# The log setup finished, this is our first log message
logger.debug('KiBot {} verbose level: {} started on {}'.format(__version__, args.verbose, datetime.now()))
apply_warning_filter(args)
log.stop_on_warnings = args.stop_on_warnings
# Now we have the debug level set we can check (and optionally inform) KiCad info
detect_kicad()
detect_windows()
Expand Down
5 changes: 5 additions & 0 deletions kibot/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import sys
import traceback
import logging
from .misc import WARN_AS_ERROR
no_colorama = False
try:
from colorama import init as colorama_init, Fore, Back, Style
Expand All @@ -30,6 +31,7 @@
root_logger = None
visual_level = None
debug_level = 0
stop_on_warnings = False


def get_logger(name=None, indent=None):
Expand Down Expand Up @@ -106,6 +108,9 @@ def warning(self, msg, *args, **kwargs):
super().warning(buf, stacklevel=2, **kwargs) # pragma: no cover (Py38)
else:
super().warning(buf, **kwargs)
if stop_on_warnings:
self.error('Warnings treated as errors')
sys.exit(WARN_AS_ERROR)

def log(self, level, msg, *args, **kwargs):
if level < self.getEffectiveLevel():
Expand Down
4 changes: 3 additions & 1 deletion kibot/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
HPGL_SCH_PRINT = 33
CORRUPTED_PRO = 34
BLENDER_ERROR = 35
WARN_AS_ERROR = 36
error_level_to_name = ['NONE',
'INTERNAL_ERROR',
'WRONG_ARGUMENTS',
Expand Down Expand Up @@ -81,7 +82,8 @@
'DXF_SCH_PRINT',
'HPGL_SCH_PRINT',
'CORRUPTED_PRO',
'BLENDER_ERROR'
'BLENDER_ERROR',
'WARN_AS_ERROR'
]
KICOST_SUBMODULE = '../submodules/KiCost/src/kicost'
EXAMPLE_CFG = 'example_template.kibot.yaml'
Expand Down

0 comments on commit 5bf6ae7

Please sign in to comment.