From 6c336371bd889ac920ef682cf756c6f130ca714a Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Mon, 18 Dec 2023 10:36:51 -0300 Subject: [PATCH] [Diff][Fixed] Problems with `current` mode - didn't apply global variants - didn't honor KiCad native DNP flags, they need a filter --- CHANGELOG.md | 6 +++--- docs/samples/generic_plot.kibot.yaml | 8 ++++++++ docs/source/configuration/outputs/diff.rst | 7 +++++++ kibot/out_diff.py | 21 ++++++++++++++------- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a7791712..81c64cb97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -119,9 +119,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 temporal, generating problems with the plot outputs, like pcb_print - Project options not preserved, i.e. set_text_variables failing - Bottom QRs should be mirrored in the Y axis -- ERC: - - Problems creating report files without extension (KiCad 7 odd behavior) - (#529) +- Diff + - `current`: didn't apply global variants + - `current`: didn't honor KiCad native DNP flags, they need a filter ## [1.6.3] - 2023-06-26 diff --git a/docs/samples/generic_plot.kibot.yaml b/docs/samples/generic_plot.kibot.yaml index d3af46f23..d5d7054a7 100644 --- a/docs/samples/generic_plot.kibot.yaml +++ b/docs/samples/generic_plot.kibot.yaml @@ -762,6 +762,9 @@ outputs: # The `stats` mode is used to meassure the amount of difference. In this mode all # changes are red, but you can abort if the difference is bigger than certain threshold diff_mode: 'red_green' + # [string|list(string)='_none'] Name of the filter to mark components as not fitted. + # A short-cut to use for simple cases where a variant is an overkill + dnf_filter: '_none' # [boolean=false] When `old_type` and/or `new_type` are `git` KiBot will checkout the indicated point. # Before doing it KiBot will stash any change. Under some circumstances git could fail # to do a checkout, even after stashing, this option can workaround the problem. @@ -803,6 +806,9 @@ outputs: output: '%f-%i%I%v.%x' # [boolean=true] Compare the PCB, otherwise compare the schematic pcb: true + # [string|list(string)='_none'] Name of the filter to transform fields before applying other filters. + # A short-cut to use for simple cases where a variant is an overkill + pre_transform: '_none' # [number=0] [0,1000000] Error threshold for the `stats` mode, 0 is no error. When specified a # difference bigger than the indicated value will make the diff fail. # KiBot will return error level 29 and the diff generation will be aborted @@ -810,6 +816,8 @@ outputs: # [boolean=false] When creating the link name of an output file related to a variant use the variant # `file_id` instead of its name use_file_id: false + # [string=''] Board variant to apply + variant: '' layers: all # Datasheets downloader: - name: 'download_datasheets_example' diff --git a/docs/source/configuration/outputs/diff.rst b/docs/source/configuration/outputs/diff.rst index 5fb3ca1ac..578db8c5a 100644 --- a/docs/source/configuration/outputs/diff.rst +++ b/docs/source/configuration/outputs/diff.rst @@ -49,6 +49,9 @@ Parameters: - ``diff_mode`` :index:`: ` [string='red_green'] [red_green,stats] In the `red_green` mode added stuff is green and red when removed. The `stats` mode is used to meassure the amount of difference. In this mode all changes are red, but you can abort if the difference is bigger than certain threshold. + - ``dnf_filter`` :index:`: ` [string|list(string)='_none'] Name of the filter to mark components as not fitted. + A short-cut to use for simple cases where a variant is an overkill. + - ``force_checkout`` :index:`: ` [boolean=false] When `old_type` and/or `new_type` are `git` KiBot will checkout the indicated point. Before doing it KiBot will stash any change. Under some circumstances git could fail to do a checkout, even after stashing, this option can workaround the problem. @@ -79,11 +82,15 @@ Parameters: Note that when no differeces are found we get a page saying *No diff*. - ``only_first_sch_page`` :index:`: ` [boolean=false] Compare only the main schematic page (root page). - ``pcb`` :index:`: ` [boolean=true] Compare the PCB, otherwise compare the schematic. + - ``pre_transform`` :index:`: ` [string|list(string)='_none'] Name of the filter to transform fields before applying other filters. + A short-cut to use for simple cases where a variant is an overkill. + - ``threshold`` :index:`: ` [number=0] [0,1000000] Error threshold for the `stats` mode, 0 is no error. When specified a difference bigger than the indicated value will make the diff fail. KiBot will return error level 29 and the diff generation will be aborted. - ``use_file_id`` :index:`: ` [boolean=false] When creating the link name of an output file related to a variant use the variant `file_id` instead of its name. + - ``variant`` :index:`: ` [string=''] Board variant to apply. - **type** :index:`: ` [string=''] Type of output. - ``category`` :index:`: ` [string|list(string)=''] The category for this output. If not specified an internally defined category is used. diff --git a/kibot/out_diff.py b/kibot/out_diff.py index d2a1ac072..f444ec4eb 100644 --- a/kibot/out_diff.py +++ b/kibot/out_diff.py @@ -31,7 +31,6 @@ from .kiplot import load_any_sch, run_command, config_output, get_output_dir, run_output from .layer import Layer from .misc import DIFF_TOO_BIG, FAILED_EXECUTE -from .optionable import BaseOptions from .out_base import VariantOptions from .registrable import RegOutput from .macros import macros, document, output_class # noqa: F401 @@ -41,7 +40,7 @@ STASH_MSG = 'KiBot_Changes_Entry' -class DiffOptions(BaseOptions): +class DiffOptions(VariantOptions): def __init__(self): with document: self.output = GS.def_global_output @@ -458,12 +457,20 @@ def cache_output(self, name): def cache_current(self): """ The file as we interpreted it """ if self.pcb: - fname, dir_name = VariantOptions.save_tmp_dir_board('diff') + fname, dir_name = self.save_tmp_dir_board('diff') + self.dirs_to_remove.append(dir_name) else: - dir_name = mkdtemp() - fname = GS.sch.save_variant(dir_name) - GS.copy_project_sch(dir_name) - self.dirs_to_remove.append(dir_name) + if self._comps: + # We have a variant/filter applied + dir_name = mkdtemp() + fname = GS.sch.save_variant(dir_name) + GS.copy_project_sch(dir_name) + self.dirs_to_remove.append(dir_name) + else: + # Just use the current file + # Note: The KiCad 7 DNP field needs some filter to be honored + dir_name = GS.sch_dir + fname = os.path.basename(GS.sch_file) res = self.cache_file(os.path.join(dir_name, fname)) self.git_hash = 'Current' return res