Skip to content

Commit

Permalink
[Added] More information about wrong configs
Browse files Browse the repository at this point in the history
When trying to use more than one YAML document for definitions

See #559
  • Loading branch information
set-soft committed Jan 18, 2024
1 parent 4ec3b34 commit c04067d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 11 additions & 3 deletions kibot/config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from .error import KiPlotConfigurationError, config_error
from .misc import (NO_YAML_MODULE, EXIT_BAD_ARGS, EXAMPLE_CFG, WONT_OVERWRITE, W_NOOUTPUTS, W_UNKOUT, W_NOFILTERS,
W_NOVARIANTS, W_NOGLOBALS, TRY_INSTALL_CHECK, W_NOPREFLIGHTS, W_NOGROUPS, W_NEWGROUP, error_level_to_name,
DEFAULT_ROTATIONS, DEFAULT_OFFSETS)
DEFAULT_ROTATIONS, DEFAULT_OFFSETS, W_EXTRADOCS)
from .gs import GS
from .registrable import RegOutput, RegVariant, RegFilter, RegDependency
from .pre_base import BasePreFlight
Expand Down Expand Up @@ -563,7 +563,7 @@ def _parse_import(self, imp, name, collected_definitions, apply=True, depth=0):
raise KiPlotConfigurationError("`import` items must be strings or dicts ({})".format(str(entry)))
fn, is_internal = self.check_import_file_name(dir_name, fn, is_external)
fn_rel = os.path.relpath(fn)
# Create a new dict for definitions applying the new ones and nake it the last
# Create a new dict for definitions applying the new ones and make it the last
cur_definitions = deepcopy(collected_definitions[-1])
cur_definitions.update(local_defs)
collected_definitions.append(cur_definitions)
Expand Down Expand Up @@ -609,13 +609,19 @@ def load_yaml(self, fstream, collected_definitions, file_name=None):
content = fstream.read()
docs = re.split(r"^\.\.\.$", content, flags=re.M)
local_defs = None
if len(docs) > 1:
n_docs = len(docs)
if n_docs > 1:
if n_docs > 2:
logger.warning(W_EXTRADOCS+f'found {n_docs} YAML documents, KiBot can handle just 2')
definitions = None
content = None
for doc in docs:
if re.search(r"^kibot:\s*$", doc, flags=re.M):
content = doc
elif re.search(r"^definitions:\s*$", doc, flags=re.M):
definitions = doc
if content is None:
raise KiPlotConfigurationError("No `kibot` section")
if definitions:
logger.debug("Found local definitions")
try:
Expand All @@ -632,6 +638,8 @@ def load_yaml(self, fstream, collected_definitions, file_name=None):
local_defs.update(collected_definitions[-1])
collected_definitions[-1] = local_defs
logger.debug("- Updated definitions: "+str(collected_definitions[-1]))
else:
logger.warning(W_EXTRADOCS+f'found {n_docs} YAML documents, but no `definitions`')
# Apply the definitions
if GS.cli_defines or collected_definitions[-1]:
logger.debug('Applying preprocessor definitions')
Expand Down
1 change: 1 addition & 0 deletions kibot/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@
W_BUG16418 = '(W137) '
W_NOTHCMP = '(W138) '
W_KEEPTMP = '(W139) '
W_EXTRADOCS = '(W140) '
# Somehow arbitrary, the colors are real, but can be different
PCB_MAT_COLORS = {'fr1': "937042", 'fr2': "949d70", 'fr3': "adacb4", 'fr4': "332B16", 'fr5': "6cc290"}
PCB_FINISH_COLORS = {'hal': "8b898c", 'hasl': "8b898c", 'imag': "8b898c", 'enig': "cfb96e", 'enepig': "cfb96e",
Expand Down

0 comments on commit c04067d

Please sign in to comment.