[Global Ops] Added mechanism to give more priority to local globals.
- `imported_global_has_less_priority` in the KiBot section Related to #291
This commit is contained in:
parent
488f2dcbc2
commit
e49cbc2b93
|
|
@ -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.
|
||||
|
|
|
|||
10
README.md
10
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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
# Example KiBot config file
|
||||
kibot:
|
||||
version: 1
|
||||
imported_global_has_less_priority: true
|
||||
|
||||
global:
|
||||
dir: 'def_dir'
|
||||
|
|
|
|||
Loading…
Reference in New Issue