From 4745baccc483c413a610004619c354f2ceae5c1a Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Thu, 14 Dec 2023 08:06:31 -0300 Subject: [PATCH] [ERC][KiCad 7][Fixed] Problems when creating a report without ext - Workaround for KiCad 7 explicitly creating a different file Fixes #529 --- CHANGELOG.md | 3 +++ kibot/pre_run_erc.py | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ee6cace..7a779171 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -119,6 +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) ## [1.6.3] - 2023-06-26 diff --git a/kibot/pre_run_erc.py b/kibot/pre_run_erc.py index 032da240..7e8b83b7 100644 --- a/kibot/pre_run_erc.py +++ b/kibot/pre_run_erc.py @@ -11,7 +11,9 @@ Dependencies: version: 2.2.1 """ import os +from shutil import move from sys import exit +from tempfile import NamedTemporaryFile from .macros import macros, pre_class # noqa: F401 from .gs import GS from .optionable import Optionable @@ -52,8 +54,12 @@ class Run_ERC(BasePreFlight): # noqa: F821 # But here we need data from it. output = self.get_targets()[0] os.makedirs(os.path.dirname(output), exist_ok=True) - logger.debug('ERC report: '+output) - cmd = [command, 'run_erc', '-o', output, '-g', str(GS.global_erc_grid)] + # Workaround for KiCad 7 odd behavior: it forces a file extension + # Note: One thing is adding the extension before you enter a name, other is add something you removed on purpose + with NamedTemporaryFile(mode='w', delete=False, suffix='.rpt', prefix='erc_report') as f: + tmp_name = f.name + logger.debug('ERC report: '+tmp_name) + cmd = [command, 'run_erc', '-o', tmp_name, '-g', str(GS.global_erc_grid)] if BasePreFlight.get_option('erc_warnings'): # noqa: F821 cmd.append('-w') if GS.filter_file: @@ -63,6 +69,10 @@ class Run_ERC(BasePreFlight): # noqa: F821 cmd = self.add_extra_options(cmd) logger.info('- Running the ERC') ret = self.exec_with_retry(cmd) + try: + move(tmp_name, output) + except FileNotFoundError: + pass if ret: if ret > 127: ret = -(256-ret)