Created a decorator to register the preflight options
This commit is contained in:
parent
2f0f3f755d
commit
7726732df9
|
|
@ -58,25 +58,40 @@ def document(sentences, to_source, **kw):
|
|||
return sentences
|
||||
|
||||
|
||||
def _do_wrap_class_register(tree, mod, base_class):
|
||||
if isinstance(tree, ClassDef):
|
||||
# Create the register call
|
||||
name = tree.name
|
||||
reg_name = name.lower()
|
||||
# BaseOutput.register member:
|
||||
attr = Attribute(value=Name(id=base_class, ctx=Load()), attr='register', ctx=Load())
|
||||
# Function call to it passing reg_name and name
|
||||
do_register = Expr(value=Call(func=attr, args=[Str(s=reg_name), Name(id=name, ctx=Load())], keywords=[]))
|
||||
|
||||
# Create the import
|
||||
do_import = ImportFrom(module=mod, names=[alias(name=base_class, asname=None)], level=1)
|
||||
|
||||
return [do_import, tree, do_register]
|
||||
return tree
|
||||
|
||||
|
||||
def output_class(tree, **kw):
|
||||
"""A decorator to wraps a class with:
|
||||
"""A decorator to wrap a class with:
|
||||
|
||||
from .out_base import BaseOutput
|
||||
... Class definition
|
||||
BaseOutput.register(CLASS_NAME_LOWER_STRING, CLASS_NAME)
|
||||
|
||||
Allowing to register the class as an output. """
|
||||
if isinstance(tree, ClassDef):
|
||||
# Create the register call
|
||||
name = tree.name
|
||||
reg_name = name.lower()
|
||||
# BaseOutput.register member:
|
||||
attr = Attribute(value=Name(id='BaseOutput', ctx=Load()), attr='register', ctx=Load())
|
||||
# Function call to it passing reg_name and name
|
||||
do_register = Expr(value=Call(func=attr, args=[Str(s=reg_name), Name(id=name, ctx=Load())], keywords=[]))
|
||||
return _do_wrap_class_register(tree, 'out_base', 'BaseOutput')
|
||||
|
||||
# Create the import
|
||||
do_import = ImportFrom(module='out_base', names=[alias(name='BaseOutput', asname=None)], level=1)
|
||||
|
||||
return [do_import, tree, do_register]
|
||||
return tree
|
||||
def pre_class(tree, **kw):
|
||||
"""A decorator to wrap a class with:
|
||||
|
||||
from .pre_base import BasePreFlight
|
||||
... Class definition
|
||||
BasePreFlight.register(CLASS_NAME_LOWER_STRING, CLASS_NAME)
|
||||
|
||||
Allowing to register the class as an output. """
|
||||
return _do_wrap_class_register(tree, 'pre_base', 'BasePreFlight')
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
from .pre_base import (BasePreFlight)
|
||||
from .error import (KiPlotConfigurationError)
|
||||
from kiplot.macros import macros, pre_class # noqa: F401
|
||||
|
||||
|
||||
class CheckZoneFills(BasePreFlight):
|
||||
@pre_class
|
||||
class Check_Zone_Fills(BasePreFlight): # noqa: F821
|
||||
""" [boolean=false] Zones are filled before doing any operation involving PCB layers """
|
||||
def __init__(self, name, value):
|
||||
super().__init__(name, value)
|
||||
|
|
@ -15,8 +16,4 @@ class CheckZoneFills(BasePreFlight):
|
|||
pass
|
||||
|
||||
def apply(self):
|
||||
BasePreFlight._set_option('check_zone_fills', self._enabled)
|
||||
|
||||
|
||||
# Register it
|
||||
BasePreFlight.register('check_zone_fills', CheckZoneFills)
|
||||
BasePreFlight._set_option('check_zone_fills', self._enabled) # noqa: F821
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from sys import (exit)
|
||||
from subprocess import (call)
|
||||
from .pre_base import (BasePreFlight)
|
||||
from kiplot.macros import macros, pre_class # noqa: F401
|
||||
from .error import (KiPlotConfigurationError)
|
||||
from .kiplot import (GS, check_script)
|
||||
from .misc import (CMD_PCBNEW_RUN_DRC, URL_PCBNEW_RUN_DRC, DRC_ERROR)
|
||||
|
|
@ -9,7 +9,8 @@ from .log import (get_logger)
|
|||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
class DRC(BasePreFlight):
|
||||
@pre_class
|
||||
class Run_DRC(BasePreFlight): # noqa: F821
|
||||
""" [boolean=false] Runs the DRC (Distance Rules Check). To ensure we have a valid PCB """
|
||||
def __init__(self, name, value):
|
||||
super().__init__(name, value)
|
||||
|
|
@ -28,7 +29,7 @@ class DRC(BasePreFlight):
|
|||
if GS.debug_enabled:
|
||||
cmd.insert(1, '-vv')
|
||||
cmd.insert(1, '-r')
|
||||
if BasePreFlight.get_option('ignore_unconnected'):
|
||||
if BasePreFlight.get_option('ignore_unconnected'): # noqa: F821
|
||||
cmd.insert(1, '-i')
|
||||
logger.info('- Running the DRC')
|
||||
logger.debug('Executing: '+str(cmd))
|
||||
|
|
@ -42,7 +43,3 @@ class DRC(BasePreFlight):
|
|||
|
||||
def apply(self):
|
||||
pass
|
||||
|
||||
|
||||
# Register it
|
||||
BasePreFlight.register('run_drc', DRC)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from sys import (exit)
|
||||
from subprocess import (call)
|
||||
from .pre_base import (BasePreFlight)
|
||||
from kiplot.macros import macros, pre_class # noqa: F401
|
||||
from .kiplot import (GS, check_eeschema_do)
|
||||
from .error import (KiPlotConfigurationError)
|
||||
from .misc import (CMD_EESCHEMA_DO, ERC_ERROR)
|
||||
|
|
@ -9,7 +9,8 @@ from .log import (get_logger)
|
|||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
class ERC(BasePreFlight):
|
||||
@pre_class
|
||||
class Run_ERC(BasePreFlight): # noqa: F821
|
||||
""" [boolean=false] Runs the ERC (Electrical Rules Check). To ensure the schematic is electrically correct """
|
||||
def __init__(self, name, value):
|
||||
super().__init__(name, value)
|
||||
|
|
@ -40,7 +41,3 @@ class ERC(BasePreFlight):
|
|||
|
||||
def apply(self):
|
||||
pass
|
||||
|
||||
|
||||
# Register it
|
||||
BasePreFlight.register('run_erc', ERC)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
import os
|
||||
from .kiplot import (GS)
|
||||
from .pre_base import (BasePreFlight)
|
||||
from kiplot.macros import macros, pre_class # noqa: F401
|
||||
|
||||
|
||||
class Filters(BasePreFlight):
|
||||
@pre_class
|
||||
class Filters(BasePreFlight): # noqa: F821
|
||||
""" A list of entries to filter out ERC/DRC messages. Keys: `filter`, `number` and `regex` """
|
||||
def __init__(self, name, value):
|
||||
super().__init__(name, value)
|
||||
|
|
@ -17,7 +18,3 @@ class Filters(BasePreFlight):
|
|||
GS.filter_file = os.path.join(GS.out_dir, 'kiplot_errors.filter')
|
||||
with open(GS.filter_file, 'w') as f:
|
||||
f.write(self._value)
|
||||
|
||||
|
||||
# Register it
|
||||
BasePreFlight.register('filters', Filters)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
from .pre_base import (BasePreFlight)
|
||||
from kiplot.macros import macros, pre_class # noqa: F401
|
||||
from .error import (KiPlotConfigurationError)
|
||||
|
||||
|
||||
class IgnoreUnconnected(BasePreFlight):
|
||||
@pre_class
|
||||
class Ignore_Unconnected(BasePreFlight): # noqa: F821
|
||||
""" [boolean=false] Option for `run_drc`. Ignores the unconnected nets. Useful if you didn't finish the routing """
|
||||
def __init__(self, name, value):
|
||||
super().__init__(name, value)
|
||||
|
|
@ -15,8 +16,4 @@ class IgnoreUnconnected(BasePreFlight):
|
|||
pass
|
||||
|
||||
def apply(self):
|
||||
BasePreFlight._set_option('ignore_unconnected', self._enabled)
|
||||
|
||||
|
||||
# Register it
|
||||
BasePreFlight.register('ignore_unconnected', IgnoreUnconnected)
|
||||
BasePreFlight._set_option('ignore_unconnected', self._enabled) # noqa: F821
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from sys import (exit)
|
||||
from subprocess import (call)
|
||||
from .pre_base import (BasePreFlight)
|
||||
from kiplot.macros import macros, pre_class # noqa: F401
|
||||
from .error import (KiPlotConfigurationError)
|
||||
from .kiplot import (GS, check_eeschema_do)
|
||||
from .misc import (CMD_EESCHEMA_DO, BOM_ERROR)
|
||||
|
|
@ -9,7 +9,8 @@ from .log import (get_logger)
|
|||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
class UpdateXML(BasePreFlight):
|
||||
@pre_class
|
||||
class Update_XML(BasePreFlight): # noqa: F821
|
||||
""" [boolean=false] Update the XML version of the BoM (Bill of Materials). To ensure our generated BoM is up to date """
|
||||
def __init__(self, name, value):
|
||||
super().__init__(name, value)
|
||||
|
|
@ -34,7 +35,3 @@ class UpdateXML(BasePreFlight):
|
|||
|
||||
def apply(self):
|
||||
pass
|
||||
|
||||
|
||||
# Register it
|
||||
BasePreFlight.register('update_xml', UpdateXML)
|
||||
|
|
|
|||
Loading…
Reference in New Issue