From f9a2aac01bc183518a3e56b2ee7e7cb4fbe1a015 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Mon, 22 Nov 2021 16:22:52 -0300 Subject: [PATCH] Changed %v/%V to also icnlude the global variant Closes #104 --- CHANGELOG.md | 3 +++ README.md | 4 ++-- docs/README.in | 4 ++-- kibot/config_reader.py | 3 +++ kibot/gs.py | 1 + kibot/optionable.py | 14 ++++++++++++++ 6 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7a28dd2..ce0177dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - JLCPCB example, to match current recommendations (g200kg/kicad-gerberzipper#11) - Internal BoM: the field used for variants doesn't produce conflicts. (#100) +- The `%v/%V` expansion patterns now expand to the global variant when used in + a context not related to variants. I.e. when a `compress` target expands + `%v`. ### Fixed - Position files now defaults to use the auxiliar origin as KiCad. diff --git a/README.md b/README.md index 28267a0d..836ebd2c 100644 --- a/README.md +++ b/README.md @@ -209,8 +209,8 @@ The pattern uses the following expansions: - **%r** revision from pcb/sch metadata. - **%T** time the script was started. - **%x** a suitable extension for the output type. -- **%v** the `file_id` of the current variant. -- **%V** the `name` of the current variant. +- **%v** the `file_id` of the current variant, or the global variant if outside a variant scope. +- **%V** the `name` of the current variant, or the global variant if outside a variant scope. They are compatible with the ones used by IBoM. The default value for `global.output` is `%f-%i.%x`. diff --git a/docs/README.in b/docs/README.in index 0f106398..9bf26eca 100644 --- a/docs/README.in +++ b/docs/README.in @@ -188,8 +188,8 @@ The pattern uses the following expansions: - **%r** revision from pcb/sch metadata. - **%T** time the script was started. - **%x** a suitable extension for the output type. -- **%v** the `file_id` of the current variant. -- **%V** the `name` of the current variant. +- **%v** the `file_id` of the current variant, or the global variant if outside a variant scope. +- **%V** the `name` of the current variant, or the global variant if outside a variant scope. They are compatible with the ones used by IBoM. The default value for `global.output` is `%f-%i.%x`. diff --git a/kibot/config_reader.py b/kibot/config_reader.py index 620863a5..cac29cb8 100644 --- a/kibot/config_reader.py +++ b/kibot/config_reader.py @@ -355,6 +355,9 @@ class CfgYamlReader(object): config_error('Unknown section `{}` in config.'.format(k)) if version is None: config_error("YAML config needs `kibot.version`.") + # Solve the global variant + if GS.global_variant: + GS.solved_global_variant = RegOutput.check_variant(GS.global_variant) return outputs diff --git a/kibot/gs.py b/kibot/gs.py index 2cc282bb..c7e6aa8f 100644 --- a/kibot/gs.py +++ b/kibot/gs.py @@ -72,6 +72,7 @@ class GS(object): global_output = None global_dir = None global_variant = None + solved_global_variant = None global_kiauto_wait_start = None global_kiauto_time_out_scale = None global_opts_class = None diff --git a/kibot/optionable.py b/kibot/optionable.py index a9165fa1..df8dbfcf 100644 --- a/kibot/optionable.py +++ b/kibot/optionable.py @@ -190,21 +190,29 @@ class Optionable(object): def _find_variant(self): """ Returns the text to add for the current variant. + Also try with the globally defined variant. If no variant is defined an empty string is returned. """ if hasattr(self, 'variant') and self.variant and hasattr(self.variant, 'file_id'): return self.variant.file_id + if GS.solved_global_variant: + return GS.solved_global_variant.file_id return '' def _find_variant_name(self): """ Returns the name for the current variant. + Also try with the globally defined variant. If no variant is defined an empty string is returned. """ if hasattr(self, 'variant') and self.variant and hasattr(self.variant, 'name'): return self.variant.name + if GS.solved_global_variant: + return GS.solved_global_variant.name return '' def expand_filename_pcb(self, name): """ Expands %* values in filenames. Uses data from the PCB. """ + if GS.debug_level > 3: + logger.debug('Expanding `{}` in PCB context for {} parent: {}'.format(name, self, self._parent)) if GS.board: GS.load_pcb_title_block() # Do the replacements @@ -223,11 +231,15 @@ class Optionable(object): # sanitize the name to avoid characters illegal in file systems name = name.replace('\\', '/') name = re.sub(r'[?%*:|"<>]', '_', name) + if GS.debug_level > 3: + logger.debug('Expanded `{}`'.format(name)) return name def expand_filename_sch(self, name): """ Expands %* values in filenames. Uses data from the SCH. """ + if GS.debug_level > 3: + logger.debug('Expanding `{}` in sch context for {}'.format(name, self)) if GS.sch_file: GS.load_sch_title_block() # Do the replacements @@ -246,6 +258,8 @@ class Optionable(object): # sanitize the name to avoid characters illegal in file systems name = name.replace('\\', '/') name = re.sub(r'[?%*:|"<>]', '_', name) + if GS.debug_level > 3: + logger.debug('Expanded `{}`'.format(name)) return name @staticmethod