From 7ba7794a14c1c9525e175cdc7b4dfb8f3ca76ecd Mon Sep 17 00:00:00 2001 From: Henning Kleen Date: Fri, 8 Jul 2022 14:46:52 +0200 Subject: [PATCH 1/3] Allow expansion of environment variables in paths --- kibot/config_reader.py | 1 + kibot/out_kibom.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/kibot/config_reader.py b/kibot/config_reader.py index dfb7291a..f3bc4215 100644 --- a/kibot/config_reader.py +++ b/kibot/config_reader.py @@ -357,6 +357,7 @@ class CfgYamlReader(object): config_error("`import` entry without `file` ({})".format(str(entry))) else: config_error("`import` items must be strings or dicts ({})".format(str(entry))) + fn = os.path.expandvars(os.path.expanduser(fn)) if not os.path.isabs(fn): fn = os.path.join(dir, fn) if not os.path.isfile(fn): diff --git a/kibot/out_kibom.py b/kibot/out_kibom.py index 59d98bd3..8b3f69d1 100644 --- a/kibot/out_kibom.py +++ b/kibot/out_kibom.py @@ -378,7 +378,9 @@ class KiBoMOptions(BaseOptions): kibom_command = self.ensure_tool('KiBoM') format = self.format.lower() prj = GS.sch_no_ext - config = os.path.join(GS.sch_dir, self.conf) + config = os.path.expandvars(os.path.expanduser(self.conf)) + if not os.path.isabs(config): + config = os.path.join(GS.sch_dir, config) if self.output: force_output = True output = name From 209248ae8d01ef4690f7579f0bb8cdc3ada25a88 Mon Sep 17 00:00:00 2001 From: Henning Kleen Date: Mon, 11 Jul 2022 15:21:27 +0200 Subject: [PATCH 2/3] also expand environment variables in design report template path --- kibot/out_report.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kibot/out_report.py b/kibot/out_report.py index fecbeefd..8d0f4ddc 100644 --- a/kibot/out_report.py +++ b/kibot/out_report.py @@ -212,6 +212,8 @@ class ReportOptions(BaseOptions): if self.template.lower() in ('full', 'simple', 'full_svg'): self.template = os.path.abspath(os.path.join(os.path.dirname(__file__), 'report_templates', 'report_'+self.template.lower()+'.txt')) + if not os.path.isabs(self.template): + self.template = os.path.expandvars(os.path.expanduser(self.template)) if not os.path.isfile(self.template): raise KiPlotConfigurationError("Missing report template: `{}`".format(self.template)) m = re.match(r'(\d+)([A-F])', self.eurocircuits_class_target) From 139ee82bdc11e878e8848b425c381b11c8777258 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Mon, 11 Jul 2022 12:41:23 -0300 Subject: [PATCH 3/3] Documented the added features. --- README.md | 3 ++- docs/samples/generic_plot.kibot.yaml | 3 ++- kibot/out_kibom.py | 2 +- kibot/out_report.py | 1 + 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 57983516..3aa7217a 100644 --- a/README.md +++ b/README.md @@ -1844,7 +1844,7 @@ Notes: - **`format`**: [string='HTML'] [HTML,CSV,XML,XLSX] Format for the BoM. - **`number`**: [number=1] Number of boards to build (components multiplier). - **`output`**: [string='%f-%i%I%v.%x'] Filename for the output (%i=bom). Affected by global options. - - `conf`: [string|dict] BoM configuration file, relative to PCB. + - `conf`: [string|dict] BoM configuration file, relative to PCB. Environment variables and ~ allowed. You can also define the configuration here, will be stored in `config.kibom.ini`. * Valid keys: - **`columns`**: [list(dict)|list(string)] List of columns to display. @@ -2588,6 +2588,7 @@ Notes: In Debian/Ubuntu environments: install `pandoc`, `texlive-latex-base` and `texlive-latex-recommended`. - **`output`**: [string='%f-%i%I%v.%x'] Output file name (%i='report', %x='txt'). Affected by global options. - **`template`**: [string='full'] Name for one of the internal templates (full, full_svg, simple) or a custom template file. + Environment variables and ~ are allowed. Note: when converting to PDF PanDoc can fail on some Unicode values (use `simple_ASCII`). - `convert_from`: [string='markdown'] Original format for the report conversion. Current templates are `markdown`. See `do_convert`. - `converted_output`: [string='%f-%i%I%v.%x'] Converted output file name (%i='report', %x=`convert_to`). diff --git a/docs/samples/generic_plot.kibot.yaml b/docs/samples/generic_plot.kibot.yaml index 34d9b093..8d5d87bf 100644 --- a/docs/samples/generic_plot.kibot.yaml +++ b/docs/samples/generic_plot.kibot.yaml @@ -797,7 +797,7 @@ outputs: type: 'kibom' dir: 'Example/kibom_dir' options: - # [string|dict] BoM configuration file, relative to PCB. + # [string|dict] BoM configuration file, relative to PCB. Environment variables and ~ allowed. # You can also define the configuration here, will be stored in `config.kibom.ini` conf: # [list(dict)|list(string)] List of columns to display. @@ -1546,6 +1546,7 @@ outputs: # [string='%f-%i%I%v.%x'] Output file name (%i='report', %x='txt'). Affected by global options output: '%f-%i%I%v.%x' # [string='full'] Name for one of the internal templates (full, full_svg, simple) or a custom template file. + # Environment variables and ~ are allowed. # Note: when converting to PDF PanDoc can fail on some Unicode values (use `simple_ASCII`) template: 'full' # Schematic with variant generator: diff --git a/kibot/out_kibom.py b/kibot/out_kibom.py index 8b3f69d1..70bfb589 100644 --- a/kibot/out_kibom.py +++ b/kibot/out_kibom.py @@ -342,7 +342,7 @@ class KiBoMOptions(BaseOptions): variants with the ';' (semicolon) character. This isn't related to the KiBot concept of variants """ self.conf = KiBoMConfig - """ [string|dict] BoM configuration file, relative to PCB. + """ [string|dict] BoM configuration file, relative to PCB. Environment variables and ~ allowed. You can also define the configuration here, will be stored in `config.kibom.ini` """ self.separator = ',' """ CSV Separator """ diff --git a/kibot/out_report.py b/kibot/out_report.py index 8d0f4ddc..39925126 100644 --- a/kibot/out_report.py +++ b/kibot/out_report.py @@ -177,6 +177,7 @@ class ReportOptions(BaseOptions): """ *Output file name (%i='report', %x='txt') """ self.template = 'full' """ *Name for one of the internal templates (full, full_svg, simple) or a custom template file. + Environment variables and ~ are allowed. Note: when converting to PDF PanDoc can fail on some Unicode values (use `simple_ASCII`) """ self.convert_from = 'markdown' """ Original format for the report conversion. Current templates are `markdown`. See `do_convert` """