Skip to content

Commit

Permalink
[DOCs][Added] Notes about using booleans in definitions
Browse files Browse the repository at this point in the history
Also a warning for complex data types

See #762
  • Loading branch information
set-soft committed Jan 6, 2025
1 parent 321bb4c commit 487c9c9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/source/configuration/substitution.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ Note that from the YAML point this is two documents in the same file.
The second document is used to provide default values for the
definitions. As defaults they have the lowest precedence.

.. warning::
Be careful about using booleans in definitions. Note that `on`, `off`, `yes`, `no`, etc. are
usually interpreted as booleans in YAML. Use quotes in the definition and/or in the place
where the value is expanded to avoid ambiguity.

.. index::
pair: definitions; during import
Expand Down
11 changes: 9 additions & 2 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, W_EXTRADOCS, RE_LEN)
DEFAULT_ROTATIONS, DEFAULT_OFFSETS, W_EXTRADOCS, RE_LEN, W_DEFNOSTR)
from .gs import GS
from .registrable import RegOutput, RegVariant, RegFilter, RegDependency
from .pre_base import BasePreFlight
Expand Down Expand Up @@ -80,7 +80,14 @@ def do_replace(k, v, content, replaced):
# Handle empty definitions keeping YAML's "null"
if v is None:
v = 'null'
logger.debugl(2, '- Replacing {} -> {}'.format(key, v))
if isinstance(v, bool):
v = str(v).lower() # True/False is also valid
if isinstance(v, (int, float)):
v = str(v)
if not isinstance(v, str):
logger.warning(W_DEFNOSTR+f'Please only use simple data types for definitions (`{k}` contains `{v}`'
f' which is `{type(v).__name__}` type)')
logger.debugl(2, f'- Replacing {key} -> {v} ({type(v)})')
content = content.replace(key, str(v))
replaced = True
return content, replaced
Expand Down
1 change: 1 addition & 0 deletions kibot/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@
W_NOBOMOPS = '(W169) '
W_NODRILL = '(W170) '
W_NOPCBTB = '(W171) '
W_DEFNOSTR = '(W172) '
# 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 487c9c9

Please sign in to comment.