diff --git a/kibot/macros.py b/kibot/macros.py index 47037b53..21777ac7 100644 --- a/kibot/macros.py +++ b/kibot/macros.py @@ -10,7 +10,8 @@ from .gs import GS # noqa: F401 from ast import (Assign, Name, Attribute, Expr, Num, Str, NameConstant, Load, Store, UnaryOp, USub, ClassDef, Call, ImportFrom, copy_location, alias) from .mcpyrate import unparse - +# from .mcpyrate.quotes import macros, q, u, n, a +# from . import mcpyrate def document(sentences, **kw): """ This macro takes literal strings and converts them into: @@ -19,9 +20,8 @@ def document(sentences, **kw): ID is the first target of the last assignment. type_hint is the assigned type and default value (only works for a few types) STRING is the literal string """ - for n in range(len(sentences)): - s = sentences[n] - if not n: + for index, s in enumerate(sentences): + if not index: prev = s continue # The whole sentence is a string? @@ -72,6 +72,14 @@ def document(sentences, **kw): elif isinstance(val, str): type_hint = "[string='{}']".format(val) post_hint += '. Affected by global options' + +# if is_attr: +# doc_id = 'self.'+doc_id +# target = q[n[doc_id]] +# with q as quoted: # block mode, produces a `list` +# a[target] = u[type_hint + s.value.s.rstrip() + post_hint] +# sentences[index] = quoted[0] + # Transform the string into an assign for _help_ID if is_attr: target = Attribute(value=Name(id='self', ctx=Load()), attr=doc_id, ctx=Store()) @@ -80,10 +88,10 @@ def document(sentences, **kw): # Reuse the s.value Str help_str = s.value help_str.s = type_hint+s.value.s.rstrip()+post_hint - sentences[n] = Assign(targets=[target], value=help_str) + sentences[index] = Assign(targets=[target], value=help_str) # Copy the line number from the original docstring copy_location(target, s) - copy_location(sentences[n], s) + copy_location(sentences[index], s) prev = s # Return the modified AST return sentences diff --git a/kibot/mcpyrate/quotes.py b/kibot/mcpyrate/quotes.py index 7fcf58db..0c53a677 100644 --- a/kibot/mcpyrate/quotes.py +++ b/kibot/mcpyrate/quotes.py @@ -373,6 +373,10 @@ def n(tree, *, syntax, **kw): if _quotelevel.value < 1: raise SyntaxError("`n` encountered while quotelevel < 1") with _quotelevel.changed_by(-1): + ret = ASTLiteral(astify(ast.Name(id=ASTLiteral(tree)))) + print(tree.__dict__) + print(ret.body.func.value.value.value.__dict__) + print(unparse(ret)) return ASTLiteral(astify(ast.Name(id=ASTLiteral(tree)))) diff --git a/kibot/out_pcbdraw.py b/kibot/out_pcbdraw.py index 9673f3fc..abd4c43b 100644 --- a/kibot/out_pcbdraw.py +++ b/kibot/out_pcbdraw.py @@ -17,6 +17,8 @@ from .optionable import Optionable from .out_base import VariantOptions from .macros import macros, document, output_class # noqa: F401 from . import log +from .mcpyrate.debug import macros, step_expansion + logger = log.get_logger(__name__) SVG2PNG = 'rsvg-convert' @@ -28,27 +30,28 @@ class PcbDrawStyle(Optionable): def __init__(self): super().__init__() - with document: - self.copper = "#417e5a" - """ color for the copper zones (covered by solder mask) """ - self.board = "#4ca06c" - """ color for the board without copper (covered by solder mask) """ - self.silk = "#f0f0f0" - """ color for the silk screen """ - self.pads = "#b5ae30" - """ color for the exposed pads (metal finish) """ - self.outline = "#000000" - """ color for the outline """ - self.clad = "#9c6b28" - """ color for the PCB core (not covered by solder mask) """ - self.vcut = "#bf2600" - """ color for the V-CUTS """ - self.highlight_on_top = False - """ highlight over the component (not under) """ - self.highlight_style = "stroke:none;fill:#ff0000;opacity:0.5;" - """ SVG code for the highlight style """ - self.highlight_padding = 1.5 - """ [0,1000] how much the highlight extends around the component [mm] """ + with step_expansion: + with document: + self.copper = "#417e5a" + """ color for the copper zones (covered by solder mask) """ + self.board = "#4ca06c" + """ color for the board without copper (covered by solder mask) """ + self.silk = "#f0f0f0" + """ color for the silk screen """ + self.pads = "#b5ae30" + """ color for the exposed pads (metal finish) """ + self.outline = "#000000" + """ color for the outline """ + self.clad = "#9c6b28" + """ color for the PCB core (not covered by solder mask) """ + self.vcut = "#bf2600" + """ color for the V-CUTS """ + self.highlight_on_top = False + """ highlight over the component (not under) """ + self.highlight_style = "stroke:none;fill:#ff0000;opacity:0.5;" + """ SVG code for the highlight style """ + self.highlight_padding = 1.5 + """ [0,1000] how much the highlight extends around the component [mm] """ def validate_color(self, name): color = getattr(self, name) @@ -107,36 +110,37 @@ def _run_command(cmd, tmp_remap=False, tmp_style=False): class PcbDrawOptions(VariantOptions): def __init__(self): - with document: - self.style = PcbDrawStyle - """ [string|dict] PCB style (colors). An internal name, the name of a JSON file or the style options """ - self.libs = Optionable - """ [list(string)=[]] list of libraries """ - self.placeholder = False - """ show placeholder for missing components """ - self.remap = PcbDrawRemap - """ [dict|None] replacements for PCB references using components (lib:component) """ - self.no_drillholes = False - """ do not make holes transparent """ - self.bottom = False - """ render the bottom side of the board (default is top side) """ - self.mirror = False - """ mirror the board """ - self.highlight = Optionable - """ [list(string)=[]] list of components to highlight """ - self.show_components = Optionable - """ [list(string)|string=none] [none,all] list of components to draw, can be also a string for none or all. - The default is none """ - self.vcuts = False - """ render V-CUTS on the Cmts.User layer """ - self.warnings = 'visible' - """ [visible,all,none] using visible only the warnings about components in the visible side are generated """ - self.dpi = 300 - """ [10,1200] dots per inch (resolution) of the generated image """ - self.format = 'svg' - """ [svg,png,jpg] output format. Only used if no `output` is specified """ - self.output = GS.def_global_output - """ name for the generated file """ + with step_expansion: + with document: + self.style = PcbDrawStyle + """ [string|dict] PCB style (colors). An internal name, the name of a JSON file or the style options """ + self.libs = Optionable + """ [list(string)=[]] list of libraries """ + self.placeholder = False + """ show placeholder for missing components """ + self.remap = PcbDrawRemap + """ [dict|None] replacements for PCB references using components (lib:component) """ + self.no_drillholes = False + """ do not make holes transparent """ + self.bottom = False + """ render the bottom side of the board (default is top side) """ + self.mirror = False + """ mirror the board """ + self.highlight = Optionable + """ [list(string)=[]] list of components to highlight """ + self.show_components = Optionable + """ [list(string)|string=none] [none,all] list of components to draw, can be also a string for none or all. + The default is none """ + self.vcuts = False + """ render V-CUTS on the Cmts.User layer """ + self.warnings = 'visible' + """ [visible,all,none] using visible only the warnings about components in the visible side are generated """ + self.dpi = 300 + """ [10,1200] dots per inch (resolution) of the generated image """ + self.format = 'svg' + """ [svg,png,jpg] output format. Only used if no `output` is specified """ + self.output = GS.def_global_output + """ name for the generated file """ super().__init__() def config(self): @@ -297,6 +301,8 @@ class PcbDraw(BaseOutput): # noqa: F821 Can also render the components if the 2D models are available """ def __init__(self): super().__init__() - with document: - self.options = PcbDrawOptions - """ [dict] Options for the `pcbdraw` output """ + with step_expansion: + with document: + self.options = PcbDrawOptions + """ [dict] Options for the `pcbdraw` output """ +