[Global options] Now the global `dir` option also applies to the preflights

- Can be disabled using `use_dir_for_preflights`.

Closes #292
This commit is contained in:
Salvador E. Tropea 2022-09-15 09:33:57 -03:00
parent 74d8b57830
commit 488f2dcbc2
12 changed files with 43 additions and 14 deletions

View File

@ -45,6 +45,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Diff: when comparing a file now the links says Current/FILE instead of None
- Now the global `dir` option also applies to the preflights, can be disabled
using `use_dir_for_preflights`. (#292)
## [1.3.0] - 2022-09-08

View File

@ -665,7 +665,8 @@ global:
Is also used for the PCB/SCH date formatting when `time_reformat` is enabled (default behavior).
Uses the `strftime` format.
- `date_time_format`: [string='%Y-%m-%d_%H-%M-%S'] Format used for the PCB and schematic date when using the file timestamp. Uses the `strftime` format.
- `dir`: [string=''] Default pattern for the output directories.
- `dir`: [string=''] Default pattern for the output directories. It also applies to the preflights, unless
`use_dir_for_preflights` is disabled.
- `disable_3d_alias_as_env`: [boolean=false] Disable the use of environment and text variables as 3D models aliases.
- `drc_exclusions_workaround`: [boolean=false] KiCad 6 introduced DRC exclusions. They are stored in the project but ignored by the Python API.
This is reported as bug number 11562 (https://gitlab.com/kicad/code/kicad/-/issues/11562).
@ -744,6 +745,7 @@ global:
- `time_reformat`: [boolean=true] Tries to reformat the PCB/SCH date using the `date_format`.
This assumes you let KiCad fill this value and hence the time is in ISO format (YY-MM-DD).
- `units`: [string=''] [millimeters,inches,mils] Default units. Affects `position` and `bom` outputs. Also KiCad 6 dimensions.
- `use_dir_for_preflights`: [boolean=true] Use the global `dir` as subdir for the preflights.
- `variant`: [string=''] Default variant to apply to all outputs.

View File

@ -143,7 +143,8 @@ class Globals(FiltersOptions):
self.date_time_format = '%Y-%m-%d_%H-%M-%S'
""" Format used for the PCB and schematic date when using the file timestamp. Uses the `strftime` format """
self.dir = ''
""" Default pattern for the output directories """
""" Default pattern for the output directories. It also applies to the preflights, unless
`use_dir_for_preflights` is disabled """
self.disable_3d_alias_as_env = False
""" Disable the use of environment and text variables as 3D models aliases """
self.drc_exclusions_workaround = False
@ -224,6 +225,8 @@ class Globals(FiltersOptions):
This assumes you let KiCad fill this value and hence the time is in ISO format (YY-MM-DD) """
self.units = ''
""" [millimeters,inches,mils] Default units. Affects `position` and `bom` outputs. Also KiCad 6 dimensions """
self.use_dir_for_preflights = True
""" Use the global `dir` as subdir for the preflights """
self.variant = ''
""" Default variant to apply to all outputs """
self.out_dir = ''

View File

@ -136,6 +136,7 @@ class GS(object):
global_time_format = None
global_time_reformat = None
global_units = None
global_use_dir_for_preflights = None
global_variant = None
@staticmethod

View File

@ -96,7 +96,8 @@ class Filters(BasePreFlight): # noqa: F821
def apply(self):
# Create the filters file
if self._value:
o_dir = get_output_dir('', self)
our_dir = GS.global_dir if GS.global_use_dir_for_preflights else ''
o_dir = get_output_dir(our_dir, self)
GS.filter_file = os.path.join(o_dir, 'kibot_errors.filter')
with open(GS.filter_file, 'w') as f:
f.write(self._value)

View File

@ -40,11 +40,16 @@ class Run_DRC(BasePreFlight): # noqa: F821
load_board()
out_pattern = GS.global_output if GS.global_output is not None else GS.def_global_output
name = Optionable.expand_filename_pcb(self, out_pattern)
return [os.path.abspath(os.path.join(self.expand_dirname(GS.out_dir), name))]
out_dir = self.expand_dirname(GS.out_dir)
logger.error(GS.global_dir)
if GS.global_dir and GS.global_use_dir_for_preflights:
out_dir = os.path.join(out_dir, self.expand_dirname(GS.global_dir))
return [os.path.abspath(os.path.join(out_dir, name))]
def run(self):
command = self.ensure_tool('KiAuto')
output = self.get_targets()[0]
os.makedirs(os.path.dirname(output), exist_ok=True)
logger.debug('DRC report: '+output)
cmd = [command, 'run_drc', '-o', output]
if GS.filter_file:

View File

@ -41,13 +41,18 @@ class Run_ERC(BasePreFlight): # noqa: F821
load_sch()
out_pattern = GS.global_output if GS.global_output is not None else GS.def_global_output
name = Optionable.expand_filename_sch(self, out_pattern)
return [os.path.abspath(os.path.join(self.expand_dirname(GS.out_dir), name))]
out_dir = self.expand_dirname(GS.out_dir)
logger.error(GS.global_dir)
if GS.global_dir and GS.global_use_dir_for_preflights:
out_dir = os.path.join(out_dir, self.expand_dirname(GS.global_dir))
return [os.path.abspath(os.path.join(out_dir, name))]
def run(self):
command = self.ensure_tool('KiAuto')
# The schematic is loaded only before executing an output related to it.
# 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]
if BasePreFlight.get_option('erc_warnings'): # noqa: F821

View File

@ -72,10 +72,10 @@ def test_erc_warning_1(test_dir):
def test_erc_warning_2(test_dir):
""" Using an SCH with ERC warnings as errors """
prj = 'warning-project'
ctx = context.TestContextSCH(test_dir, 'erc_warning/'+prj, 'erc_no_w', '')
ctx = context.TestContextSCH(test_dir, 'erc_warning/'+prj, 'erc_no_w', 'def_dir')
ctx.run(ERC_ERROR)
# Check all outputs are there
ctx.expect_out_file(prj+'-erc.txt')
ctx.expect_out_file(prj+'-erc.txt', sub=True)
ctx.search_err(r"ERROR:1 ERC errors detected")
ctx.clean_up()
@ -92,11 +92,11 @@ def test_drc_1(test_dir):
def test_drc_filter_1(test_dir):
""" Test using internal filters """
prj = 'fail-project'
ctx = context.TestContext(test_dir, prj, 'drc_filter', '')
ctx = context.TestContext(test_dir, prj, 'drc_filter', 'def_dir')
ctx.run(extra_debug=True)
# Check all outputs are there
ctx.expect_out_file(prj+'-drc.txt')
ctx.expect_out_file('kibot_errors.filter')
ctx.expect_out_file(prj+'-drc.txt', sub=True)
ctx.expect_out_file('kibot_errors.filter', sub=True)
ctx.clean_up(keep_project=True)

View File

@ -193,8 +193,8 @@ class TestContext(object):
if os.path.isfile(fp_cache):
os.remove(fp_cache)
def get_out_path(self, filename):
return os.path.join(self.output_dir, filename)
def get_out_path(self, filename, sub=False):
return os.path.join(self.output_dir, filename) if not sub else os.path.join(self.output_dir, self.sub_dir, filename)
def get_gerber_job_filename(self):
return os.path.join(self.sub_dir, self.board_name+'-job.gbrjob')
@ -256,8 +256,8 @@ class TestContext(object):
def get_npth_pdf_drl_filename(self):
return os.path.join(self.sub_dir, self.board_name+'-NPTH-drl_map.pdf')
def expect_out_file(self, filename):
file = self.get_out_path(filename)
def expect_out_file(self, filename, sub=False):
file = self.get_out_path(filename, sub)
assert os.path.isfile(file), file
assert os.path.getsize(file) > 0
logging.debug(filename+' OK')

View File

@ -2,5 +2,9 @@
kibot:
version: 1
global:
dir: 'def_dir'
use_dir_for_preflights: false
preflight:
run_drc: true

View File

@ -2,6 +2,9 @@
kibot:
version: 1
global:
dir: 'def_dir'
preflight:
run_drc: true
filters:

View File

@ -2,6 +2,9 @@
kibot:
version: 1
global:
dir: 'def_dir'
preflight:
run_erc: true
erc_warnings: true