From 043ee382d3ad3824e344dd8efbee8588fc71c1eb Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Tue, 7 Jun 2022 13:57:32 -0300 Subject: [PATCH] Implemented output priorities - By default `qr_lib` is high priority and `navigate_results`/ `compress` are low priority. - Priorities can be configured. - A command line option disables it. --- CHANGELOG.md | 6 ++ README.md | 65 +++++++++++++++++- kibot/__main__.py | 5 +- kibot/kiplot.py | 95 +++++++++++++++----------- kibot/out_base.py | 6 ++ kibot/out_compress.py | 4 ++ kibot/out_navigate_results.py | 4 ++ kibot/out_qr_lib.py | 4 ++ kibot/pre_base.py | 14 +++- kibot/pre_update_qr.py | 4 +- kibot/registrable.py | 14 ---- tests/yaml_samples/qr_lib_1.kibot.yaml | 28 ++++---- 12 files changed, 177 insertions(+), 72 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d0c2332..2fb8ff7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +- General stuff: + - Outputs now can have priorities, by default is applied. + Use `-n` to disable it. - New outputs: - `navigate_results` creates web pages to browse the generated outputs. - New globals: @@ -20,6 +23,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - KiCad environment variables: more variables detected, native KiCad 6 names, all exported to the environment (#205) +- Consequences of the priorities implementation: + - `qr_lib` outputs are created before others + - `navigate_results` and `compress` outputs are created after others ## [1.1.0] - 2022-05-24 ### Added diff --git a/README.md b/README.md index a97b60fe..ce5c6e53 100644 --- a/README.md +++ b/README.md @@ -1172,6 +1172,8 @@ Next time you need this list just use an alias, like this: * Valid keys: - `output`: [string='%f-%i%I%v.%x'] Filename for the output (%i=boardview, %x=brd). Affected by global options. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * BoM (Bill of Materials) @@ -1362,6 +1364,8 @@ Next time you need this list just use an alias, like this: - `style`: [string='modern-blue'] Head style: modern-blue, modern-green, modern-red and classic. - `title`: [string='KiBot Bill of Materials'] BoM title. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * Archiver (files compressor) @@ -1396,6 +1400,8 @@ Next time you need this list just use an alias, like this: - `output`: [string='%f-%i%I%v.%x'] Name for the generated archive (%i=name of the output %x=according to format). Affected by global options. - *remove_files*: Alias for move_files. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=10] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * Datasheets downloader @@ -1424,6 +1430,8 @@ Next time you need this list just use an alias, like this: It only makes sense if the `output` field makes their output different. - `variant`: [string=''] Board variant to apply. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * DXF (Drawing Exchange Format) @@ -1476,6 +1484,8 @@ Next time you need this list just use an alias, like this: - `use_aux_axis_as_origin`: [boolean=false] Use the auxiliary axis as origin for coordinates. - `variant`: [string=''] Board variant to apply. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * Excellon drill format @@ -1517,6 +1527,8 @@ Next time you need this list just use an alias, like this: - `use_aux_axis_as_origin`: [boolean=false] Use the auxiliary axis as origin for coordinates. - `zeros_format`: [string='DECIMAL_FORMAT'] [DECIMAL_FORMAT,SUPPRESS_LEADING,SUPPRESS_TRAILING,KEEP_ZEROS] How to handle the zeros. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * GenCAD @@ -1543,6 +1555,8 @@ Next time you need this list just use an alias, like this: - `save_origin`: [boolean=false] Save the origin coordinates in the file. - `unique_pin_names`: [boolean=false] Generate unique pin names. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * Gerber drill format @@ -1576,6 +1590,8 @@ Next time you need this list just use an alias, like this: (%i='drill_report' %x='txt'). - `use_aux_axis_as_origin`: [boolean=false] Use the auxiliary axis as origin for coordinates. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * Gerber format @@ -1634,6 +1650,8 @@ Next time you need this list just use an alias, like this: - `use_protel_extensions`: [boolean=false] Use legacy Protel file extensions. - `variant`: [string=''] Board variant to apply. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * HPGL (Hewlett & Packard Graphics Language) @@ -1688,6 +1706,8 @@ Next time you need this list just use an alias, like this: - `uppercase_extensions`: [boolean=false] Use uppercase names for the extensions. - `variant`: [string=''] Board variant to apply. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * IBoM (Interactive HTML BoM) @@ -1763,6 +1783,8 @@ Next time you need this list just use an alias, like this: - `variants_whitelist`: [string=''] List of board variants to include in the BOM. IBoM option, avoid using in conjunction with KiBot variants/filters. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * KiBoM (KiCad Bill of Materials) @@ -1864,6 +1886,8 @@ Next time you need this list just use an alias, like this: variants with the ';' (semicolon) character. This isn't related to the KiBot concept of variants. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * KiCost (KiCad Cost calculator) @@ -1914,6 +1938,8 @@ Next time you need this list just use an alias, like this: - `variant`: [string=''] Board variant to apply. Don't use the `kicost_variant` when using internal variants/filters. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * Navigate Results @@ -1934,6 +1960,8 @@ Next time you need this list just use an alias, like this: - `link_from_root`: [string=''] The name of a file to create at the main output directory linking to the home page. - `output`: [string='%f-%i%I%v.%x'] Filename for the output (%i=html, %x=navigate). Affected by global options. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=10] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * Netlist @@ -1958,6 +1986,8 @@ Next time you need this list just use an alias, like this: testing, is generated from the PCB. - `output`: [string='%f-%i%I%v.%x'] Filename for the output (%i=netlist/IPC-D-356, %x=net/d356). Affected by global options. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * PCB Print @@ -2046,6 +2076,8 @@ Next time you need this list just use an alias, like this: - `variant`: [string=''] Board variant to apply. - `via_color`: [string=''] Color used for through-hole `colored_vias`. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * PcbDraw - Beautiful 2D PCB render @@ -2095,6 +2127,8 @@ Next time you need this list just use an alias, like this: - `vcuts`: [boolean=false] Render V-CUTS on the Cmts.User layer. - `warnings`: [string='visible'] [visible,all,none] Using visible only the warnings about components in the visible side are generated. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * PDF (Portable Document Format) @@ -2168,6 +2202,8 @@ Next time you need this list just use an alias, like this: - `plot_footprint_values`: [boolean=true] Include the footprint values. - `plot_sheet_reference`: [boolean=false] Include the frame and title block. Only available for KiCad 6 and you get a poor result The `pcb_print` output can do a better job for PDF, SVG, PS, EPS and PNG outputs. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. - `tent_vias`: [boolean=true] Cover the vias. - `uppercase_extensions`: [boolean=false] Use uppercase names for the extensions. @@ -2218,6 +2254,8 @@ Next time you need this list just use an alias, like this: If it starts with `+` the text is concatenated. - `variant`: [string=''] Board variant to apply. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * PDF Schematic Print (Portable Document Format) @@ -2245,6 +2283,8 @@ Next time you need this list just use an alias, like this: - `variant`: [string=''] Board variant to apply. Not fitted components are crossed. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * PDF joiner @@ -2275,6 +2315,8 @@ Next time you need this list just use an alias, like this: See the `from_cwd` option. - `use_external_command`: [boolean=false] Use the `pdfunite` tool instead of PyPDF2 Python module. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * Pick & place @@ -2309,6 +2351,8 @@ Next time you need this list just use an alias, like this: - `use_aux_axis_as_origin`: [boolean=true] Use the auxiliary axis as origin for coordinates (KiCad default). - `variant`: [string=''] Board variant to apply. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * PS (Postscript) @@ -2368,6 +2412,8 @@ Next time you need this list just use an alias, like this: - `width_adjust`: [number=0] This width factor is intended to compensate PS printers/plotters that do not strictly obey line width settings. Only used to plot pads and tracks. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * QR_Lib @@ -2406,6 +2452,8 @@ Next time you need this list just use an alias, like this: - `reference`: [string='QR'] The reference prefix. - `use_sch_dir`: [boolean=true] Generate the libs relative to the schematic/PCB dir. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=90] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * 3D render of the PCB @@ -2462,6 +2510,8 @@ Next time you need this list just use an alias, like this: - `zoom`: [number=0] Zoom steps. Use positive to enlarge, get closer, and negative to reduce. Same result as using the mouse wheel in the 3D viewer. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * Design report @@ -2495,6 +2545,8 @@ Next time you need this list just use an alias, like this: - `template`: [string='full'] Name for one of the internal templates (full, full_svg, simple) or a custom template file. Note: when converting to PDF PanDoc can fail on some Unicode values (use `simple_ASCII`). - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * Schematic with variant generator @@ -2518,6 +2570,8 @@ Next time you need this list just use an alias, like this: A short-cut to use for simple cases where a variant is an overkill. - `variant`: [string=''] Board variant to apply. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * STEP (ISO 10303-21 Clear Text Encoding of the Exchange Structure) @@ -2551,6 +2605,8 @@ Next time you need this list just use an alias, like this: - `subst_models`: [boolean=true] Substitute STEP or IGS models with the same name in place of VRML models. - `variant`: [string=''] Board variant to apply. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * SVG (Scalable Vector Graphics) @@ -2604,6 +2660,8 @@ Next time you need this list just use an alias, like this: - `uppercase_extensions`: [boolean=false] Use uppercase names for the extensions. - `variant`: [string=''] Board variant to apply. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * SVG PCB Print (Scalable Vector Graphics) @@ -2652,6 +2710,8 @@ Next time you need this list just use an alias, like this: If it starts with `+` the text is concatenated. - `variant`: [string=''] Board variant to apply. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. * SVG Schematic Print @@ -2678,6 +2738,8 @@ Next time you need this list just use an alias, like this: - `variant`: [string=''] Board variant to apply. Not fitted components are crossed. - `output_id`: [string=''] Text to use for the %I expansion content. To differentiate variations of this output. + - `priority`: [number=50] [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. - `run_by_default`: [boolean=true] When enabled this output will be created when no specific outputs are requested. @@ -3130,7 +3192,7 @@ KiBot: KiCad automation tool for documents generation Usage: kibot [-b BOARD] [-e SCHEMA] [-c CONFIG] [-d OUT_DIR] [-s PRE] - [-q | -v...] [-i] [-C] [-m MKFILE] [-g DEF]... [TARGET...] + [-q | -v...] [-C | -i | -n] [-m MKFILE] [-g DEF]... [TARGET...] kibot [-v...] [-b BOARD] [-e SCHEMA] [-c PLOT_CONFIG] --list kibot [-v...] [-b BOARD] [-d OUT_DIR] [-p | -P] --example kibot [-v...] [--start PATH] [-d OUT_DIR] [--dry] [-t, --type TYPE]... @@ -3158,6 +3220,7 @@ Options: -i, --invert-sel Generate the outputs not listed as targets -l, --list List available outputs (in the config file) -m MKFILE, --makefile MKFILE Generate a Makefile (no targets created) + -n, --no-priority Don't sort targets by priority -p, --copy-options Copy plot options from the PCB file -P, --copy-and-expand As -p but expand the list of layers -q, --quiet Remove information logs diff --git a/kibot/__main__.py b/kibot/__main__.py index 66aa35b3..962ad150 100644 --- a/kibot/__main__.py +++ b/kibot/__main__.py @@ -9,7 +9,7 @@ Usage: kibot [-b BOARD] [-e SCHEMA] [-c CONFIG] [-d OUT_DIR] [-s PRE] - [-q | -v...] [-i] [-C] [-m MKFILE] [-g DEF]... [TARGET...] + [-q | -v...] [-C | -i | -n] [-m MKFILE] [-g DEF]... [TARGET...] kibot [-v...] [-b BOARD] [-e SCHEMA] [-c PLOT_CONFIG] --list kibot [-v...] [-b BOARD] [-d OUT_DIR] [-p | -P] --example kibot [-v...] [--start PATH] [-d OUT_DIR] [--dry] [-t, --type TYPE]... @@ -37,6 +37,7 @@ Options: -i, --invert-sel Generate the outputs not listed as targets -l, --list List available outputs (in the config file) -m MKFILE, --makefile MKFILE Generate a Makefile (no targets created) + -n, --no-priority Don't sort targets by priority -p, --copy-options Copy plot options from the PCB file -P, --copy-and-expand As -p but expand the list of layers -q, --quiet Remove information logs @@ -319,7 +320,7 @@ def main(): generate_makefile(args.makefile, plot_config, outputs) else: # Do all the job (preflight + outputs) - generate_outputs(outputs, args.target, args.invert_sel, args.skip_pre, args.cli_order) + generate_outputs(outputs, args.target, args.invert_sel, args.skip_pre, args.cli_order, args.no_priority) # Print total warnings logger.log_totals() diff --git a/kibot/kiplot.py b/kibot/kiplot.py index 3c1e67c8..0bc5e42f 100644 --- a/kibot/kiplot.py +++ b/kibot/kiplot.py @@ -326,7 +326,7 @@ def get_board_comps_data(comps): c.virtual = True -def preflight_checks(skip_pre): +def preflight_checks(skip_pre, targets): logger.debug("Preflight checks") if skip_pre is not None: @@ -350,7 +350,7 @@ def preflight_checks(skip_pre): else: logger.debug('Skipping `{}`'.format(skip)) o_pre.disable() - BasePreFlight.run_enabled() + BasePreFlight.run_enabled(targets) def get_output_dir(o_dir, obj, dry=False): @@ -411,44 +411,63 @@ def run_output(out, dont_stop=False): raise -def generate_outputs(outputs, target, invert, skip_pre, cli_order, dont_stop=False): +def generate_outputs(outputs, targets, invert, skip_pre, cli_order, no_priority, dont_stop=False): logger.debug("Starting outputs for board {}".format(GS.pcb_file)) - preflight_checks(skip_pre) - # Check if the preflights pulled options - for out in RegOutput.get_prioritary_outputs(): + # Make a list of target outputs + n = len(targets) + if n == 0: + # No targets means all + if invert: + # Skip all targets + logger.debug('Skipping all outputs') + else: + targets = [out for out in RegOutput.get_outputs() if out.run_by_default] + else: + # Check we got a valid list of outputs + for name in targets: + out = RegOutput.get_output(name) + if out is None: + logger.error('Unknown output `{}`'.format(name)) + exit(EXIT_BAD_ARGS) + # Check for CLI+invert inconsistency + if cli_order and invert: + logger.error("CLI order and invert options can't be used simultaneously") + exit(EXIT_BAD_ARGS) + # Now convert the list of names into a list of output objects + if cli_order: + # Add them in the same order found at the command line + targets = [RegOutput.get_output(name) for name in targets] + else: + # Add them in the declared order + new_targets = [] + if invert: + # Invert the selection + for out in RegOutput.get_outputs(): + if (out.name not in targets) and out.run_by_default: + new_targets.append(out) + else: + logger.debug('Skipping `{}` output'.format(out.name)) + else: + # Normal list + for out in RegOutput.get_outputs(): + if out.name in targets: + new_targets.append(out) + else: + logger.debug('Skipping `{}` output'.format(out.name)) + targets = new_targets + logger.debug('Outputs before preflights: {}'.format(targets)) + # Run the preflights + preflight_checks(skip_pre, targets) + logger.debug('Outputs after preflights: {}'.format(targets)) + if not cli_order and not no_priority: + # Sort by priority + targets = sorted(targets, key=lambda o: o.priority, reverse=True) + logger.debug('Outputs after sorting: {}'.format(targets)) + # Configure and run the outputs + for out in targets: if config_output(out, dont_stop=dont_stop): logger.info('- '+str(out)) - run_output(out, dont_stop=dont_stop) - # Check if all must be skipped - n = len(target) - if n == 0 and invert: - # Skip all targets - logger.debug('Skipping all outputs') - return - # Check we got a valid list of outputs - for name in target: - out = RegOutput.get_output(name) - if out is None: - logger.error('Unknown output `{}`'.format(name)) - exit(EXIT_BAD_ARGS) - # Generate outputs - if cli_order and not invert: - # Use the CLI order - for name in target: - out = RegOutput.get_output(name) - if config_output(out, dont_stop=dont_stop): - logger.info('- '+str(out)) - run_output(out, dont_stop) - else: - # Use the declaration order - for out in RegOutput.get_outputs(): - if (((n == 0 or ((out.name not in target) and invert)) and out.run_by_default) or - ((out.name in target) and not invert)): - if config_output(out, dont_stop=dont_stop): - logger.info('- '+str(out)) - run_output(out, dont_stop) - else: - logger.debug('Skipping `%s` output', str(out)) + run_output(out, dont_stop) def adapt_file_name(name): @@ -859,7 +878,7 @@ def generate_targets(config_file): with open(config_file) as cf_file: outputs = cr.read(cf_file) # Do all the job - generate_outputs(outputs, [], False, None, False, dont_stop=True) + generate_outputs(outputs, [], False, None, False, False, dont_stop=True) def _walk(path, depth): diff --git a/kibot/out_base.py b/kibot/out_base.py index 88ab059b..2d4c5bfe 100644 --- a/kibot/out_base.py +++ b/kibot/out_base.py @@ -55,6 +55,9 @@ class BaseOutput(RegOutput): self.category = Optionable """ [string|list(string)=''] The category for this output. If not specified an internally defined category is used. Categories looks like file system paths, i.e. PCB/fabrication/gerber """ + self.priority = 50 + """ [0,100] Priority for this output. High priority outputs are created first. + Internally we use 10 for low priority, 90 for high priority and 50 for most outputs """ if GS.global_dir: self.dir = GS.global_dir self._sch_related = False @@ -150,6 +153,9 @@ class BaseOutput(RegOutput): gb['dir'] = dir return outs + def fix_priority_help(self): + self._help_priority = self._help_priority.replace('[number=50]', '[number={}]'.format(self.priority)) + def run(self, output_dir): self.output_dir = output_dir self.options.run(self.expand_filename(output_dir, self.options.output)) diff --git a/kibot/out_compress.py b/kibot/out_compress.py index 04436264..c3cd02cc 100644 --- a/kibot/out_compress.py +++ b/kibot/out_compress.py @@ -225,10 +225,14 @@ class Compress(BaseOutput): # noqa: F821 This is used to generate groups of files in compressed file format. """ def __init__(self): super().__init__() + # Make it low priority so it gets created after all the other outputs + self.priority = 10 with document: self.options = CompressOptions """ [dict] Options for the `compress` output """ self._none_related = True + # The help is inherited and already mentions the default priority + self.fix_priority_help() def get_dependencies(self): return self.options.get_dependencies() diff --git a/kibot/out_navigate_results.py b/kibot/out_navigate_results.py index 1ee6c63a..0f56b7ee 100644 --- a/kibot/out_navigate_results.py +++ b/kibot/out_navigate_results.py @@ -455,9 +455,13 @@ class Navigate_Results(BaseOutput): # noqa: F821 Generates a web page to navigate the generated outputs """ def __init__(self): super().__init__() + # Make it low priority so it gets created after all the other outputs + self.priority = 10 with document: self.options = Navigate_ResultsOptions """ [dict] Options for the `navigate_results` output """ + # The help is inherited and already mentions the default priority + self.fix_priority_help() @staticmethod def get_conf_examples(name, layers, templates): diff --git a/kibot/out_qr_lib.py b/kibot/out_qr_lib.py index 3090c87e..0feb58e4 100644 --- a/kibot/out_qr_lib.py +++ b/kibot/out_qr_lib.py @@ -529,11 +529,15 @@ class QR_Lib(BaseOutput): # noqa: F821 - To keep them updated add the `update_qr` preflight """ def __init__(self): super().__init__() + # Make it high priority so it gets created before all the other outputs + self.priority = 90 with document: self.options = QR_LibOptions """ [dict] Options for the `boardview` output """ self._both_related = True self._update_mode = False + # The help is inherited and already mentions the default priority + self.fix_priority_help() @staticmethod def get_conf_examples(name, layers, templates): diff --git a/kibot/pre_base.py b/kibot/pre_base.py index d7949d6d..fbd86aa4 100644 --- a/kibot/pre_base.py +++ b/kibot/pre_base.py @@ -17,6 +17,7 @@ class BasePreFlight(Registrable): _registered = {} _in_use = {} _options = {} + _targets = None def __init__(self, name, value): super().__init__() @@ -49,7 +50,18 @@ class BasePreFlight(Registrable): return BasePreFlight._options.get(name) @staticmethod - def run_enabled(): + def insert_target(out): + """ Add a target, at the beginning of the list and with high priority """ + try: + del BasePreFlight._targets[BasePreFlight._targets.index(out)] + except ValueError: + pass + BasePreFlight._targets.insert(0, out) + out.priority = 90 + + @staticmethod + def run_enabled(targets): + BasePreFlight._targets = targets try: for k, v in BasePreFlight._in_use.items(): if v._enabled: diff --git a/kibot/pre_update_qr.py b/kibot/pre_update_qr.py index 5056e50c..d7bd9158 100644 --- a/kibot/pre_update_qr.py +++ b/kibot/pre_update_qr.py @@ -25,8 +25,8 @@ class Update_QR(BasePreFlight): # noqa: F821 self._pcb_related = True def run(self): - for o in list(RegOutput.get_outputs()): # We convert it to a list because we will mutate the dict + for o in RegOutput.get_outputs(): if o.type == 'qr_lib': - RegOutput.make_prioritary(o.name) + BasePreFlight.insert_target(o) # noqa: F821 o._update_mode = True logger.debug('Making {} prioritary'.format(o)) diff --git a/kibot/registrable.py b/kibot/registrable.py index c189f1c3..d1f25d82 100644 --- a/kibot/registrable.py +++ b/kibot/registrable.py @@ -45,8 +45,6 @@ class RegOutput(Optionable, Registrable): _def_variants = {} # List of defined outputs _def_outputs = OrderedDict() - # List of priority outputs - _prio_outputs = OrderedDict() def __init__(self): super().__init__() @@ -59,8 +57,6 @@ class RegOutput(Optionable, Registrable): RegOutput._def_variants = {} # List of defined outputs RegOutput._def_outputs = OrderedDict() - # List of priority outputs - RegOutput._prio_outputs = OrderedDict() @staticmethod def add_variants(variants): @@ -108,20 +104,10 @@ class RegOutput(Optionable, Registrable): def get_outputs(): return RegOutput._def_outputs.values() - @staticmethod - def get_prioritary_outputs(): - return RegOutput._prio_outputs.values() - @staticmethod def get_output(name): return RegOutput._def_outputs.get(name, None) - @staticmethod - def make_prioritary(name): - out = RegOutput._def_outputs[name] - del RegOutput._def_outputs[name] - RegOutput._prio_outputs[name] = out - @staticmethod def check_variant(variant): if variant: diff --git a/tests/yaml_samples/qr_lib_1.kibot.yaml b/tests/yaml_samples/qr_lib_1.kibot.yaml index 7c1a3d3d..8340572a 100644 --- a/tests/yaml_samples/qr_lib_1.kibot.yaml +++ b/tests/yaml_samples/qr_lib_1.kibot.yaml @@ -6,20 +6,6 @@ preflight: update_qr: true outputs: - - name: 'QRCodes' - comment: "Example of QR codes" - type: qr_lib - options: - output: 'qr.%x' - qrs: - - size_sch: 1 - size_pcb: 2 - size_units: inches - layer: copper - - name: QR2 - text: 'https://github.com/INTI-CMNB/KiBot/' - correction_level: 'high' - - name: 'print_sch' comment: "Print schematic (PDF)" type: pdf_sch_print @@ -39,3 +25,17 @@ outputs: layers: - layer: F.SilkS - layer: F.Cu + + - name: 'QRCodes' + comment: "Example of QR codes" + type: qr_lib + options: + output: 'qr.%x' + qrs: + - size_sch: 1 + size_pcb: 2 + size_units: inches + layer: copper + - name: QR2 + text: 'https://github.com/INTI-CMNB/KiBot/' + correction_level: 'high'