From 488f2dcbc27d1d457c29a98a552256a55fc10ff0 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Thu, 15 Sep 2022 09:33:57 -0300 Subject: [PATCH] [Global options] Now the global `dir` option also applies to the preflights - Can be disabled using `use_dir_for_preflights`. Closes #292 --- CHANGELOG.md | 2 ++ README.md | 4 +++- kibot/globals.py | 5 ++++- kibot/gs.py | 1 + kibot/pre_filters.py | 3 ++- kibot/pre_run_drc.py | 7 ++++++- kibot/pre_run_erc.py | 7 ++++++- tests/test_plot/test_preflight.py | 10 +++++----- tests/utils/context.py | 8 ++++---- tests/yaml_samples/drc.kibot.yaml | 4 ++++ tests/yaml_samples/drc_filter.kibot.yaml | 3 +++ tests/yaml_samples/erc_no_w.kibot.yaml | 3 +++ 12 files changed, 43 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8720f65..cfb8015a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 673dbc36..18c993ad 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/kibot/globals.py b/kibot/globals.py index 2575aafa..244eff5b 100644 --- a/kibot/globals.py +++ b/kibot/globals.py @@ -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 = '' diff --git a/kibot/gs.py b/kibot/gs.py index 8df0a646..78be71e6 100644 --- a/kibot/gs.py +++ b/kibot/gs.py @@ -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 diff --git a/kibot/pre_filters.py b/kibot/pre_filters.py index b250d25f..2f9bf0c9 100644 --- a/kibot/pre_filters.py +++ b/kibot/pre_filters.py @@ -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) diff --git a/kibot/pre_run_drc.py b/kibot/pre_run_drc.py index 8c5e6b28..d7a8b1d9 100644 --- a/kibot/pre_run_drc.py +++ b/kibot/pre_run_drc.py @@ -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: diff --git a/kibot/pre_run_erc.py b/kibot/pre_run_erc.py index 5eecc032..a7c24ec4 100644 --- a/kibot/pre_run_erc.py +++ b/kibot/pre_run_erc.py @@ -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 diff --git a/tests/test_plot/test_preflight.py b/tests/test_plot/test_preflight.py index 2a45e46f..edb6ebc9 100644 --- a/tests/test_plot/test_preflight.py +++ b/tests/test_plot/test_preflight.py @@ -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) diff --git a/tests/utils/context.py b/tests/utils/context.py index 56674ce9..d09071db 100644 --- a/tests/utils/context.py +++ b/tests/utils/context.py @@ -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') diff --git a/tests/yaml_samples/drc.kibot.yaml b/tests/yaml_samples/drc.kibot.yaml index b834f17c..72fe7c4e 100644 --- a/tests/yaml_samples/drc.kibot.yaml +++ b/tests/yaml_samples/drc.kibot.yaml @@ -2,5 +2,9 @@ kibot: version: 1 +global: + dir: 'def_dir' + use_dir_for_preflights: false + preflight: run_drc: true diff --git a/tests/yaml_samples/drc_filter.kibot.yaml b/tests/yaml_samples/drc_filter.kibot.yaml index 15db1080..5ff1021a 100644 --- a/tests/yaml_samples/drc_filter.kibot.yaml +++ b/tests/yaml_samples/drc_filter.kibot.yaml @@ -2,6 +2,9 @@ kibot: version: 1 +global: + dir: 'def_dir' + preflight: run_drc: true filters: diff --git a/tests/yaml_samples/erc_no_w.kibot.yaml b/tests/yaml_samples/erc_no_w.kibot.yaml index a134f54b..3dd15bcb 100644 --- a/tests/yaml_samples/erc_no_w.kibot.yaml +++ b/tests/yaml_samples/erc_no_w.kibot.yaml @@ -2,6 +2,9 @@ kibot: version: 1 +global: + dir: 'def_dir' + preflight: run_erc: true erc_warnings: true