[Fixed] Some times we need %V, %v, %S before full config

- So now we solve the variant on-the-fly
This commit is contained in:
Salvador E. Tropea 2022-12-22 12:40:12 -03:00
parent 5ecbbc84fd
commit b2b528e4ec
3 changed files with 25 additions and 9 deletions

View File

@ -246,7 +246,8 @@ class Optionable(object):
""" 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'):
if hasattr(self, 'variant') and self.variant:
self.variant = GS.solve_variant(self.variant)
return self.variant.file_id
return Optionable._find_global_variant()
@ -260,7 +261,8 @@ class Optionable(object):
""" 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'):
if hasattr(self, 'variant') and self.variant:
self.variant = GS.solve_variant(self.variant)
return self.variant.name
return Optionable._find_global_variant_name()
@ -274,8 +276,10 @@ class Optionable(object):
""" Returns the name of the sub-PCB.
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 self.variant._sub_pcb:
return self.variant._sub_pcb.name
if hasattr(self, 'variant') and self.variant:
self.variant = GS.solve_variant(self.variant)
if self.variant._sub_pcb:
return self.variant._sub_pcb.name
return Optionable._find_global_variant()
def expand_filename_common(self, name, parent):

View File

@ -596,11 +596,8 @@ class BoMOptions(BaseOptions):
def _normalize_variant(self):
""" Replaces the name of the variant by an object handling it. """
if self.variant:
if not RegOutput.is_variant(self.variant):
raise KiPlotConfigurationError("Unknown variant name `{}`".format(self.variant))
self.variant = RegOutput.get_variant(self.variant)
else:
self.variant = RegOutput.check_variant(self.variant)
if self.variant is None:
# If no variant is specified use the KiBoM variant class with basic functionality
self.variant = KiBoM()
self.variant.config_field = self.fit_field

View File

@ -5,8 +5,12 @@
# Project: KiBot (formerly KiPlot)
from collections import OrderedDict
from copy import copy
from .gs import GS
from .optionable import Optionable
from .error import KiPlotConfigurationError
from . import log
logger = log.get_logger()
class Registrable(object):
@ -125,6 +129,8 @@ class RegOutput(Optionable, Registrable):
@staticmethod
def check_variant(variant):
if variant:
if isinstance(variant, RegVariant):
return variant
if not RegOutput.is_variant(variant):
raise KiPlotConfigurationError("Unknown variant name `{}`".format(variant))
return RegOutput.get_variant(variant)
@ -167,3 +173,12 @@ class RegDependency(Registrable):
old_reg.roles.extend(aclass.roles)
else:
cl._registered[name] = aclass
def solve_variant(variant):
if isinstance(variant, str):
return RegOutput.check_variant(variant)
return variant
GS.solve_variant = solve_variant