[ERC][KiCad 7][Fixed] Problems when creating a report without ext

- Workaround for KiCad 7 explicitly creating a different file

Fixes #529
This commit is contained in:
Salvador E. Tropea 2023-12-14 08:06:31 -03:00
parent 89365a8d5d
commit 4745baccc4
2 changed files with 15 additions and 2 deletions

View File

@ -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 temporal, generating problems with the plot outputs, like pcb_print
- Project options not preserved, i.e. set_text_variables failing - Project options not preserved, i.e. set_text_variables failing
- Bottom QRs should be mirrored in the Y axis - 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 ## [1.6.3] - 2023-06-26

View File

@ -11,7 +11,9 @@ Dependencies:
version: 2.2.1 version: 2.2.1
""" """
import os import os
from shutil import move
from sys import exit from sys import exit
from tempfile import NamedTemporaryFile
from .macros import macros, pre_class # noqa: F401 from .macros import macros, pre_class # noqa: F401
from .gs import GS from .gs import GS
from .optionable import Optionable from .optionable import Optionable
@ -52,8 +54,12 @@ class Run_ERC(BasePreFlight): # noqa: F821
# But here we need data from it. # But here we need data from it.
output = self.get_targets()[0] output = self.get_targets()[0]
os.makedirs(os.path.dirname(output), exist_ok=True) os.makedirs(os.path.dirname(output), exist_ok=True)
logger.debug('ERC report: '+output) # Workaround for KiCad 7 odd behavior: it forces a file extension
cmd = [command, 'run_erc', '-o', output, '-g', str(GS.global_erc_grid)] # 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 if BasePreFlight.get_option('erc_warnings'): # noqa: F821
cmd.append('-w') cmd.append('-w')
if GS.filter_file: if GS.filter_file:
@ -63,6 +69,10 @@ class Run_ERC(BasePreFlight): # noqa: F821
cmd = self.add_extra_options(cmd) cmd = self.add_extra_options(cmd)
logger.info('- Running the ERC') logger.info('- Running the ERC')
ret = self.exec_with_retry(cmd) ret = self.exec_with_retry(cmd)
try:
move(tmp_name, output)
except FileNotFoundError:
pass
if ret: if ret:
if ret > 127: if ret > 127:
ret = -(256-ret) ret = -(256-ret)