Skip to content

Commit

Permalink
[Global options] Now the global dir option also applies to the pref…
Browse files Browse the repository at this point in the history
…lights

- Can be disabled using `use_dir_for_preflights`.

Closes #292
  • Loading branch information
set-soft committed Sep 15, 2022
1 parent 74d8b57 commit 488f2dc
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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.


Expand Down
5 changes: 4 additions & 1 deletion kibot/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ def __init__(self):
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
Expand Down Expand Up @@ -224,6 +225,8 @@ def __init__(self):
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 = ''
Expand Down
1 change: 1 addition & 0 deletions kibot/gs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion kibot/pre_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def get_doc(cls):
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)
7 changes: 6 additions & 1 deletion kibot/pre_run_drc.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,16 @@ def get_targets(self):
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:
Expand Down
7 changes: 6 additions & 1 deletion kibot/pre_run_erc.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,18 @@ def get_targets(self):
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
Expand Down
10 changes: 5 additions & 5 deletions tests/test_plot/test_preflight.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)


Expand Down
8 changes: 4 additions & 4 deletions tests/utils/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ def clean_up(self, keep_project=False):
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')
Expand Down Expand Up @@ -256,8 +256,8 @@ def get_npth_gbr_drl_filename(self):
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')
Expand Down
4 changes: 4 additions & 0 deletions tests/yaml_samples/drc.kibot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
kibot:
version: 1

global:
dir: 'def_dir'
use_dir_for_preflights: false

preflight:
run_drc: true
3 changes: 3 additions & 0 deletions tests/yaml_samples/drc_filter.kibot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
kibot:
version: 1

global:
dir: 'def_dir'

preflight:
run_drc: true
filters:
Expand Down
3 changes: 3 additions & 0 deletions tests/yaml_samples/erc_no_w.kibot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
kibot:
version: 1

global:
dir: 'def_dir'

preflight:
run_erc: true
erc_warnings: true
Expand Down

0 comments on commit 488f2dc

Please sign in to comment.