From 584ef5354ba1f648fd949689e63779f5f135772a Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Fri, 9 Sep 2022 09:42:06 -0300 Subject: [PATCH] [Diff] Added mechanism to compare using a variant Related to #278 --- CHANGELOG.md | 1 + README.md | 8 ++--- docs/samples/generic_plot.kibot.yaml | 8 ++--- kibot/out_diff.py | 39 ++++++++++++++++----- tests/yaml_samples/pcb_variant_1.kibot.yaml | 10 ++++++ 5 files changed, 50 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6e1fd13..993bdcc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - PCB_Variant: saves a PCB with filters and variants applied. - Support for Eurocircuits drill adjust to fix small OARs. Option `eurocircuits_reduce_holes`. (#227) +- Diff: mechanism to compare using a variant (See #278) ### Fixed - Problems to compress netlists. (#287) diff --git a/README.md b/README.md index 43ec74f3..1812f9f7 100644 --- a/README.md +++ b/README.md @@ -1521,16 +1521,16 @@ Notes: read https://stackoverflow.com/questions/1248029/git-pull-error-entry-foo-not-uptodate-cannot-merge. - `fuzz`: [number=5] [0,100] Color tolerance (fuzzyness) for the `stats` mode. - `new`: [string=''] The file you want to compare. Leave it blank for the current PCB/SCH. - - `new_type`: [string='file'] [git,file] How to interpret the `new` name. Use `git` for a git hash, branch, etc. - Use `file` for a file name. + - `new_type`: [string='file'] [git,file,output] How to interpret the `new` name. Use `git` for a git hash, branch, etc. + Use `file` for a file name. Use `output` to specify the name of a `pcb_variant` output. - `old`: [string='HEAD'] Reference file. When using git use `HEAD` to refer to the last commit. Use `HEAD~` to refer the previous to the last commit. As `HEAD` is for the whole repo you can use `KIBOT_LAST-n` to make reference to the changes in the PCB/SCH. The `n` value is how many changes in the history you want to go back. A 0 is the same as `HEAD`, a 1 means the last time the PCB/SCH was changed, etc. - - `old_type`: [string='git'] [git,file] How to interpret the `old` name. Use `git` for a git hash, branch, etc. - Use `file` for a file name. + - `old_type`: [string='git'] [git,file,output] How to interpret the `old` name. Use `git` for a git hash, branch, etc. + Use `file` for a file name. Use `output` to specify the name of a `pcb_variant` output. - `pcb`: [boolean=true] Compare the PCB, otherwise compare the schematic. - `threshold`: [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. diff --git a/docs/samples/generic_plot.kibot.yaml b/docs/samples/generic_plot.kibot.yaml index ff4f5adb..5c892061 100644 --- a/docs/samples/generic_plot.kibot.yaml +++ b/docs/samples/generic_plot.kibot.yaml @@ -439,8 +439,8 @@ outputs: fuzz: 5 # [string=''] The file you want to compare. Leave it blank for the current PCB/SCH new: '' - # [string='file'] [git,file] How to interpret the `new` name. Use `git` for a git hash, branch, etc. - # Use `file` for a file name + # [string='file'] [git,file,output] How to interpret the `new` name. Use `git` for a git hash, branch, etc. + # Use `file` for a file name. Use `output` to specify the name of a `pcb_variant` output new_type: 'file' # [string='HEAD'] Reference file. When using git use `HEAD` to refer to the last commit. # Use `HEAD~` to refer the previous to the last commit. @@ -449,8 +449,8 @@ outputs: # changes in the history you want to go back. A 0 is the same as `HEAD`, # a 1 means the last time the PCB/SCH was changed, etc old: 'HEAD' - # [string='git'] [git,file] How to interpret the `old` name. Use `git` for a git hash, branch, etc. - # Use `file` for a file name + # [string='git'] [git,file,output] How to interpret the `old` name. Use `git` for a git hash, branch, etc. + # Use `file` for a file name. Use `output` to specify the name of a `pcb_variant` output old_type: 'git' # [string='%f-%i%I%v.%x'] Filename for the output (%i=diff_pcb/diff_sch, %x=pdf). Affected by global options output: '%f-%i%I%v.%x' diff --git a/kibot/out_diff.py b/kibot/out_diff.py index e74a809a..8d12105a 100644 --- a/kibot/out_diff.py +++ b/kibot/out_diff.py @@ -27,9 +27,10 @@ from subprocess import CalledProcessError from tempfile import mkdtemp, NamedTemporaryFile from .error import KiPlotConfigurationError from .gs import GS -from .kiplot import load_any_sch, run_command +from .kiplot import load_any_sch, run_command, config_output, get_output_dir, run_output from .layer import Layer from .optionable import BaseOptions +from .registrable import RegOutput from .macros import macros, document, output_class # noqa: F401 from . import log @@ -52,13 +53,13 @@ class DiffOptions(BaseOptions): changes in the history you want to go back. A 0 is the same as `HEAD`, a 1 means the last time the PCB/SCH was changed, etc """ self.old_type = 'git' - """ [git,file] How to interpret the `old` name. Use `git` for a git hash, branch, etc. - Use `file` for a file name """ + """ [git,file,output] How to interpret the `old` name. Use `git` for a git hash, branch, etc. + Use `file` for a file name. Use `output` to specify the name of a `pcb_variant` output """ self.new = '' """ The file you want to compare. Leave it blank for the current PCB/SCH """ self.new_type = 'file' - """ [git,file] How to interpret the `new` name. Use `git` for a git hash, branch, etc. - Use `file` for a file name """ + """ [git,file,output] How to interpret the `new` name. Use `git` for a git hash, branch, etc. + Use `file` for a file name. Use `output` to specify the name of a `pcb_variant` output """ self.cache_dir = '' """ Directory to cache the intermediate files. Leave it blank to disable the cache """ self.diff_mode = 'red_green' @@ -293,9 +294,29 @@ class DiffOptions(BaseOptions): self.undo_git() return hash + def cache_output(self, name): + logger.debugl(2, 'From output `{}`'.format(name)) + out = RegOutput.get_output(name) + if out is None: + raise KiPlotConfigurationError('Unknown output `{}`'.format(name)) + if out.type != 'pcb_variant': + raise KiPlotConfigurationError('Output `{}` must be `pcb_variant` type, not `{}`'.format(name, out.type)) + config_output(out) + out_dir = get_output_dir(out.dir, out, dry=True) + fname = out.get_targets(out_dir)[0] + logger.debug('File from output {} is {}'.format(name, fname)) + if not out._done: + run_output(out) + self.git_hash = out.options.variant.name+'_variant' + return self.cache_file(fname) + def cache_obj(self, name, type): self.git_hash = 'None' - return self.cache_git(name) if type == 'git' else self.cache_file(name), self.git_hash + if type == 'git': + return self.cache_git(name) + if type == 'file': + return self.cache_file(name) + return self.cache_output(name) def create_layers_incl(self, layers): incl_file = None @@ -335,8 +356,10 @@ class DiffOptions(BaseOptions): # List of layers self.incl_file = self.create_layers_incl(self.layers) # Populate the cache - old_hash, gh1 = self.cache_obj(self.old, self.old_type) - new_hash, gh2 = self.cache_obj(self.new, self.new_type) + old_hash = self.cache_obj(self.old, self.old_type) + gh1 = self.git_hash + new_hash = self.cache_obj(self.new, self.new_type) + gh2 = self.git_hash # Compute the diff using the cache cmd = [self.command, '--no_reader', '--new_file_hash', new_hash, '--old_file_hash', old_hash, '--cache_dir', self.cache_dir, '--output_dir', dir_name, '--output_name', file_name, diff --git a/tests/yaml_samples/pcb_variant_1.kibot.yaml b/tests/yaml_samples/pcb_variant_1.kibot.yaml index 7a747291..158a8711 100644 --- a/tests/yaml_samples/pcb_variant_1.kibot.yaml +++ b/tests/yaml_samples/pcb_variant_1.kibot.yaml @@ -15,3 +15,13 @@ outputs: options: variant: default title: 'Hello %V' + + - name: 'diff_pcb' + comment: "PCB difference with variant" + type: diff + layers: ['F.Cu', 'F.Fab'] + options: + old: pcb_default + old_type: output + cache_dir: .cache + add_link_id: true