From 7c7d3aff0b401ceff0e36b814874a87c39930c85 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Mon, 8 Jan 2024 10:31:15 -0300 Subject: [PATCH] [CLI][Added] defs-from-env allows using environment vars for substitution Closes #549 --- CHANGELOG.md | 1 + docs/source/configuration/substitution.rst | 2 ++ docs/source/usage.txt | 9 ++++++--- kibot/__main__.py | 11 ++++++++--- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbbbba38e..b5a46bf38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `--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) + - `--defs-from-env` allows using environment vars for substitution (#549) - Global options: - `remove_solder_mask_for_dnp` similar to `remove_solder_paste_for_dnp` but applied to the solder mask apertures. (#476) diff --git a/docs/source/configuration/substitution.rst b/docs/source/configuration/substitution.rst index 3a4a34228..96efee357 100644 --- a/docs/source/configuration/substitution.rst +++ b/docs/source/configuration/substitution.rst @@ -24,6 +24,8 @@ files. You can use ``-E`` as many times as you need. +Also note that the ``--def-from-env`` option adds all the environment +variables as definitions. .. index:: pair: definitions; default diff --git a/docs/source/usage.txt b/docs/source/usage.txt index bdbdcaffd..caf9484be 100644 --- a/docs/source/usage.txt +++ b/docs/source/usage.txt @@ -3,10 +3,11 @@ KiBot: KiCad automation tool for documents generation Usage: kibot [-b BOARD] [-e SCHEMA] [-c CONFIG] [-d OUT_DIR] [-s PRE] [-q | -v...] [-L LOGFILE] [-C | -i | -n] [-m MKFILE] [-A] [-g DEF] ... - [-E DEF] ... [-w LIST] [-D | -W] [--banner N] [TARGET...] + [-E DEF] ... [--defs-from-env] [-w LIST] [-D | -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 + [-E DEF] ... [--defs-from-env] [--config-outs] + [--only-pre|--only-groups] [--only-names] [--output-name-first] --list kibot [-v...] [-c PLOT_CONFIG] [--banner N] [-E DEF] ... [--only-names] --list-variants kibot [-v...] [-b BOARD] [-d OUT_DIR] [-p | -P] [--banner N] --example @@ -39,6 +40,8 @@ Options: --config-outs Configure all outputs before listing them -d OUT_DIR, --out-dir OUT_DIR The output directory [default: .] -D, --dont-stop Try to continue if an output fails + --defs-from-env Use the environment vars as preprocessor + values -e SCHEMA, --schematic SCHEMA The schematic file (.sch/.kicad_sch) -E DEF, --define DEF Define preprocessor value (VAR=VAL) -g DEF, --global-redef DEF Overwrite a global value (VAR=VAL) diff --git a/kibot/__main__.py b/kibot/__main__.py index a6655a23f..7dee3fefd 100644 --- a/kibot/__main__.py +++ b/kibot/__main__.py @@ -10,10 +10,11 @@ Usage: kibot [-b BOARD] [-e SCHEMA] [-c CONFIG] [-d OUT_DIR] [-s PRE] [-q | -v...] [-L LOGFILE] [-C | -i | -n] [-m MKFILE] [-A] [-g DEF] ... - [-E DEF] ... [-w LIST] [-D | -W] [--banner N] [TARGET...] + [-E DEF] ... [--defs-from-env] [-w LIST] [-D | -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 + [-E DEF] ... [--defs-from-env] [--config-outs] + [--only-pre|--only-groups] [--only-names] [--output-name-first] --list kibot [-v...] [-c PLOT_CONFIG] [--banner N] [-E DEF] ... [--only-names] --list-variants kibot [-v...] [-b BOARD] [-d OUT_DIR] [-p | -P] [--banner N] --example @@ -46,6 +47,8 @@ --config-outs Configure all outputs before listing them -d OUT_DIR, --out-dir OUT_DIR The output directory [default: .] -D, --dont-stop Try to continue if an output fails + --defs-from-env Use the environment vars as preprocessor + values -e SCHEMA, --schematic SCHEMA The schematic file (.sch/.kicad_sch) -E DEF, --define DEF Define preprocessor value (VAR=VAL) -g DEF, --global-redef DEF Overwrite a global value (VAR=VAL) @@ -340,6 +343,8 @@ def detect_kicad(): def parse_defines(args): + if args.defs_from_env: + GS.cli_defines.update(os.environ) for define in args.define: if '=' not in define: GS.exit_with_error(f'Malformed `define` option, must be VARIABLE=VALUE ({define})', EXIT_BAD_ARGS)