diff --git a/CHANGELOG.md b/CHANGELOG.md index cfb8015a..5da192cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - remove_adhesive_for_dnp - remove_solder_paste_for_dnp - hide_excluded (default value) + - Mechanism to give more priority to local globals. (See #291) - Diff: mechanism to compare using a variant (See #278) - Sch Variant: - Option to copy the project. Needed for text variables. diff --git a/README.md b/README.md index 18c993ad..dfcaa78c 100644 --- a/README.md +++ b/README.md @@ -3523,6 +3523,16 @@ import: This will import all outputs and filters, but not variants or globals. Also note that imported globals has more precedence than the ones defined in the same file. +If you want give more priority to the local values use: + +``` +kibot: + version: 1 + imported_global_has_less_priority: true + +import: +... +``` ### Doing YAML substitution or preprocessing diff --git a/docs/README.in b/docs/README.in index 41a3e049..f765a226 100644 --- a/docs/README.in +++ b/docs/README.in @@ -1201,6 +1201,16 @@ import: This will import all outputs and filters, but not variants or globals. Also note that imported globals has more precedence than the ones defined in the same file. +If you want give more priority to the local values use: + +``` +kibot: + version: 1 + imported_global_has_less_priority: true + +import: +... +``` ### Doing YAML substitution or preprocessing diff --git a/kibot/config_reader.py b/kibot/config_reader.py index 436f2164..61204f0e 100644 --- a/kibot/config_reader.py +++ b/kibot/config_reader.py @@ -56,6 +56,7 @@ class CollectedImports(object): self.variants = {} self.globals = {} self.preflights = [] + self.imported_global_has_less_priority = False class CfgYamlReader(object): @@ -75,6 +76,14 @@ class CfgYamlReader(object): raise KiPlotConfigurationError("Unknown KiBot config version: "+str(version)) return version + def _check_globals_priority(self, v): + ops = 'imported_global_has_less_priority' + if ops in v: + value = v[ops] + if not isinstance(value, bool): + raise KiPlotConfigurationError(ops+" must be boolean") + self.imported_global_has_less_priority = value + def _parse_output(self, o_tree): try: name = str(o_tree['name']) @@ -208,7 +217,11 @@ class CfgYamlReader(object): if not isinstance(gb, dict): raise KiPlotConfigurationError("Incorrect `global` section (must be a dict)") if self.imported_globals: - gb.update(self.imported_globals) + if self.imported_global_has_less_priority: + self.imported_globals.update(gb) + gb = self.imported_globals + else: + gb.update(self.imported_globals) logger.debug("Global options + imported: {}".format(gb)) # Parse all keys inside it glb = GS.class_for_global_opts() @@ -483,8 +496,9 @@ class CfgYamlReader(object): raise KiPlotConfigurationError("Use `kibot` or `kiplot` but not both.") if not v1 and not v2: raise KiPlotConfigurationError("YAML config needs `kibot.version`.") - if v1 or v2: - self._check_version(v1 or v2) + main_sec = v1 or v2 + self._check_version(main_sec) + self._check_globals_priority(main_sec) # Look for imports v1 = data.get('import', None) if v1: diff --git a/tests/yaml_samples/drc.kibot.yaml b/tests/yaml_samples/drc.kibot.yaml index 72fe7c4e..e8b8760c 100644 --- a/tests/yaml_samples/drc.kibot.yaml +++ b/tests/yaml_samples/drc.kibot.yaml @@ -1,6 +1,7 @@ # Example KiBot config file kibot: version: 1 + imported_global_has_less_priority: true global: dir: 'def_dir'