From e871efe4bd3f674046df1f7a5b84c6082ff0d628 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Fri, 9 Sep 2022 13:09:56 -0300 Subject: [PATCH] [Diff] Option to use variant's file_id for the link - Also changed None by Current/FILE --- CHANGELOG.md | 3 +++ README.md | 2 ++ docs/samples/generic_plot.kibot.yaml | 3 +++ kibot/out_diff.py | 21 +++++++++++++-------- tests/yaml_samples/sch_variant_1.kibot.yaml | 3 ++- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16b46ca8..9d9741a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Problems to compress netlists. (#287) +### Changed +- Diff: when comparing a file now the links says Current/FILE instead of None + ## [1.3.0] - 2022-09-08 ### Added diff --git a/README.md b/README.md index 5dd6b10a..9bf3c5ab 100644 --- a/README.md +++ b/README.md @@ -1538,6 +1538,8 @@ Notes: - `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. + - `use_file_id`: [boolean=false] When creating the link name of an output file related to a variant use the variant + `file_id` instead of its name. - `category`: [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. - `disable_run_by_default`: [string|boolean] Use it to disable the `run_by_default` status of other output. diff --git a/docs/samples/generic_plot.kibot.yaml b/docs/samples/generic_plot.kibot.yaml index c3b658b8..d3c31545 100644 --- a/docs/samples/generic_plot.kibot.yaml +++ b/docs/samples/generic_plot.kibot.yaml @@ -463,6 +463,9 @@ outputs: # [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 threshold: 0 + # [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 layers: all # Datasheets downloader: - name: 'download_datasheets_example' diff --git a/kibot/out_diff.py b/kibot/out_diff.py index 29eeb9dc..e716094a 100644 --- a/kibot/out_diff.py +++ b/kibot/out_diff.py @@ -89,6 +89,9 @@ class DiffOptions(BaseOptions): to do a checkout, even after stashing, this option can workaround the problem. Note that using it you could potentially lose modified files. For more information read https://stackoverflow.com/questions/1248029/git-pull-error-entry-foo-not-uptodate-cannot-merge """ + self.use_file_id = False + """ When creating the link name of an output file related to a variant use the variant + `file_id` instead of its name """ super().__init__() self._expand_id = 'diff' self._expand_ext = 'pdf' @@ -161,6 +164,7 @@ class DiffOptions(BaseOptions): return hash def cache_file(self, name=None): + self.git_hash = 'Current' if not name else 'FILE' return self.cache_pcb(name) if self.pcb else self.cache_sch(name) def run_git(self, cmd, cwd=None, just_raise=False): @@ -329,11 +333,11 @@ class DiffOptions(BaseOptions): 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) + res = self.cache_file(fname) + self.git_hash = out.options.variant.file_id if self.use_file_id else out.options.variant.name+'_variant' + return res def cache_obj(self, name, type): - self.git_hash = 'None' if type == 'git': return self.cache_git(name) if type == 'file': @@ -352,7 +356,7 @@ class DiffOptions(BaseOptions): f.write(str(la.id)+'\n') return incl_file - def do_compare(self, old, old_type, new, new_type, name): + def do_compare(self, old, old_type, new, new_type, name, name_ori): dir_name = os.path.dirname(name) file_name = os.path.basename(name) # Populate the cache @@ -373,7 +377,7 @@ class DiffOptions(BaseOptions): cmd.insert(1, '-'+'v'*GS.debug_level) run_command(cmd) if self.add_link_id: - name_comps = os.path.splitext(name) + name_comps = os.path.splitext(name_ori) target = name_comps[0]+'_'+gh1+'-'+gh2+name_comps[1] if self.copy_instead_of_link: copy2(name, target) @@ -402,6 +406,7 @@ class DiffOptions(BaseOptions): GS.check_sch() self.file_exist = GS.sch_file self.incl_file = None + name_ori = name try: # List of layers self.incl_file = self.create_layers_incl(self.layers) @@ -413,7 +418,7 @@ class DiffOptions(BaseOptions): logger.info(' - {} vs {}'.format(pair[0], pair[1])) self._expand_id = '{}_variants_{}_VS_{}'.format(base_id, pair[0], pair[1]) name = self._parent.expand_filename(self._parent.output_dir, self.output) - self.do_compare(pair[0], 'output', pair[1], 'output', name) + self.do_compare(pair[0], 'output', pair[1], 'output', name, name_ori) self._expand_id = base_id elif self.new_type == 'multivar' and self.old_type == 'multivar': # Special case, we generate various files @@ -423,10 +428,10 @@ class DiffOptions(BaseOptions): logger.info(' - {} vs {}'.format(ref_name, new_variant)) self._expand_id = '{}_variant_{}'.format(base_id, new_variant) name = self._parent.expand_filename(self._parent.output_dir, self.output) - self.do_compare(self.old, 'file', new_variant, 'output', name) + self.do_compare(self.old, 'file', new_variant, 'output', name, name_ori) self._expand_id = base_id else: - self.do_compare(self.old, self.old_type, self.new, self.new_type, name) + self.do_compare(self.old, self.old_type, self.new, self.new_type, name, name_ori) finally: # Clean-up if remove_cache: diff --git a/tests/yaml_samples/sch_variant_1.kibot.yaml b/tests/yaml_samples/sch_variant_1.kibot.yaml index 36775f35..904147af 100644 --- a/tests/yaml_samples/sch_variant_1.kibot.yaml +++ b/tests/yaml_samples/sch_variant_1.kibot.yaml @@ -60,4 +60,5 @@ outputs: new: [sch_default, sch_production, sch_test] new_type: multivar cache_dir: .cache - # add_link_id: true + # use_file_id: true + add_link_id: true