From a02999d50a735a40f8e6275cd14b9632d33e93e4 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Tue, 16 May 2023 13:28:51 -0300 Subject: [PATCH] [Diff][Schematic][Fixed] Project not copied to variant - Any info related to the project wasn't applied. Fixes #438 --- CHANGELOG.md | 2 ++ kibot/gs.py | 14 ++++++++++++++ kibot/kicad/config.py | 4 ++++ kibot/out_any_sch_print.py | 18 +----------------- kibot/out_diff.py | 1 + 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a03821a9..edbd5d27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 SMD components are selected. (See #429) - Diff: - KIBOT_TAG with n > 0 skipped n commits, not n tags (#430) + - Details related to the project not applied during a diff involving a + variant (project not copied) (#438) ## [1.6.2] - 2023-04-24 ### Added diff --git a/kibot/gs.py b/kibot/gs.py index d92d9f3c..6c129431 100644 --- a/kibot/gs.py +++ b/kibot/gs.py @@ -456,6 +456,20 @@ class GS(object): copy2(pro_name, pro_copy) return pro_copy + @staticmethod + def copy_project_sch(sch_dir): + """ Copy the project file to the temporal dir """ + ext = GS.pro_ext + source = GS.pro_file + prj_file = os.path.join(sch_dir, GS.sch_basename+ext) + if source is not None and os.path.isfile(source): + copy2(source, prj_file) + GS.fix_page_layout(prj_file) # Alias for KiConf.fix_page_layout + else: + # Create a dummy project file to avoid warnings + f = open(prj_file, 'wt') + f.close() + @staticmethod def get_pcb_and_pro_names(name): if GS.ki5: diff --git a/kibot/kicad/config.py b/kibot/kicad/config.py index 50613934..e3a4faa3 100644 --- a/kibot/kicad/config.py +++ b/kibot/kicad/config.py @@ -660,3 +660,7 @@ class KiConf(object): if ref_dir is None: ref_dir = os.getcwd() return expanded if expanded.startswith('${') else os.path.normpath(os.path.join(ref_dir, expanded)) + + +# Avoid circular inclusion +GS.fix_page_layout = KiConf.fix_page_layout diff --git a/kibot/out_any_sch_print.py b/kibot/out_any_sch_print.py index 2d869af9..75af3a09 100644 --- a/kibot/out_any_sch_print.py +++ b/kibot/out_any_sch_print.py @@ -5,30 +5,14 @@ # Project: KiBot (formerly KiPlot) import os from tempfile import mkdtemp -from shutil import copy2 from .gs import GS from .out_base import VariantOptions -from .kicad.config import KiConf from .macros import macros, document, output_class # noqa: F401 from . import log logger = log.get_logger() -def copy_project(sch_dir): - """ Copy the project file to the temporal dir """ - ext = GS.pro_ext - source = GS.pro_file - prj_file = os.path.join(sch_dir, GS.sch_basename+ext) - if source is not None and os.path.isfile(source): - copy2(source, prj_file) - KiConf.fix_page_layout(prj_file) - else: - # Create a dummy project file to avoid warnings - f = open(prj_file, 'wt') - f.close() - - class Any_SCH_PrintOptions(VariantOptions): def __init__(self): with document: @@ -62,7 +46,7 @@ class Any_SCH_PrintOptions(VariantOptions): if self._comps or self.title: # Save it to a temporal dir sch_dir = mkdtemp(prefix='tmp-kibot-'+self._expand_ext+'_sch_print-') - copy_project(sch_dir) + GS.copy_project_sch(sch_dir) fname = GS.sch.save_variant(sch_dir) sch_file = os.path.join(sch_dir, fname) self._files_to_remove.append(sch_dir) diff --git a/kibot/out_diff.py b/kibot/out_diff.py index 9289c118..9f60bb46 100644 --- a/kibot/out_diff.py +++ b/kibot/out_diff.py @@ -423,6 +423,7 @@ class DiffOptions(BaseOptions): dir_name = mkdtemp() self.dirs_to_remove.append(dir_name) fname = GS.sch.save_variant(dir_name) + GS.copy_project_sch(dir_name) res = self.cache_file(os.path.join(dir_name, fname)) self.git_hash = 'Current' return res