forked from johnbeard/kiplot
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Added][Ouput] Jobset, to run KiCad Jobsets
- Loading branch information
Showing
12 changed files
with
490 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
.. _JobSetOptions: | ||
|
||
|
||
JobSetOptions parameters | ||
~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
- **download** :index:`: <pair: output - jobset - options; download>` [:ref:`boolean <boolean>`] (default: ``true``) Downloads missing 3D models from KiCad git. | ||
Only applies to models in KISYS3DMOD and KICAD6_3DMODEL_DIR. |br| | ||
They are downloaded to a temporal directory and discarded. |br| | ||
If you want to cache the downloaded files specify a directory using the | ||
KIBOT_3D_MODELS environment variable. | ||
- **jobset** :index:`: <pair: output - jobset - options; jobset>` [:ref:`string <string>`] (default: ``''``) Name of the KiCad jobset file you want to use. Should have `kicad_jobset` extension. | ||
Leave empty to look for a jobset with the same name as the project. | ||
- **no_virtual** :index:`: <pair: output - jobset - options; no_virtual>` [:ref:`boolean <boolean>`] (default: ``false``) Used to exclude 3D models for components with 'virtual' attribute. | ||
- **run_output** :index:`: <pair: output - jobset - options; run_output>` [:ref:`string <string>`] (default: ``''``) Output to be generated. When empty KiCad runs all possible outputs. | ||
Here the name can be obtained from the .kicad_jobset file, in JSON format. |br| | ||
The `outputs` section contains all the defined outputs. Each output has an `id` use it here. | ||
- ``dnf_filter`` :index:`: <pair: output - jobset - options; dnf_filter>` [:ref:`string <string>` | :ref:`list(string) <list(string)>`] (default: ``'_null'``) Name of the filter to mark components as not fitted. | ||
Is a short-cut to use for simple cases where a variant is an overkill. |br| | ||
Can be used to fine-tune a variant for a particular output that needs extra filtering done before the | ||
variant. | ||
|
||
- ``download_lcsc`` :index:`: <pair: output - jobset - options; download_lcsc>` [:ref:`boolean <boolean>`] (default: ``true``) In addition to try to download the 3D models from KiCad git also try to get | ||
them from LCSC database. In order to work you'll need to provide the LCSC | ||
part number. The field containing the LCSC part number is defined by the | ||
`field_lcsc_part` global variable. | ||
- ``exclude_filter`` :index:`: <pair: output - jobset - options; exclude_filter>` [:ref:`string <string>` | :ref:`list(string) <list(string)>`] (default: ``'_null'``) Name of the filter to exclude components from processing. | ||
Is a short-cut to use for simple cases where a variant is an overkill. |br| | ||
Can be used to fine-tune a variant for a particular output that needs extra filtering done before the | ||
variant. | ||
|
||
- ``kicad_3d_url`` :index:`: <pair: output - jobset - options; kicad_3d_url>` [:ref:`string <string>`] (default: ``'https://gitlab.com/kicad/libraries/kicad-packages3D/-/raw/master/'``) Base URL for the KiCad 3D models. | ||
- ``kicad_3d_url_suffix`` :index:`: <pair: output - jobset - options; kicad_3d_url_suffix>` [:ref:`string <string>`] (default: ``''``) Text added to the end of the download URL. | ||
Can be used to pass variables to the GET request, i.e. ?VAR1=VAL1&VAR2=VAL2. | ||
- ``pre_transform`` :index:`: <pair: output - jobset - options; pre_transform>` [:ref:`string <string>` | :ref:`list(string) <list(string)>`] (default: ``'_null'``) Name of the filter to transform fields before applying other filters. | ||
Is a short-cut to use for simple cases where a variant is an overkill. |br| | ||
Can be used to fine-tune a variant for a particular output that needs extra filtering done before the | ||
variant. | ||
|
||
- ``stop_on_error`` :index:`: <pair: output - jobset - options; stop_on_error>` [:ref:`boolean <boolean>`] (default: ``true``) Stop generation when an error is detected. | ||
- ``variant`` :index:`: <pair: output - jobset - options; variant>` [:ref:`string <string>`] (default: ``''``) Board variant to apply. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
.. Automatically generated by KiBot, please don't edit this file | ||
.. index:: | ||
pair: KiCad Jobset (batch execution); jobset | ||
|
||
KiCad Jobset (batch execution) | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Generates outputs defined in a KiCad jobset file (.kicad_jobset). | ||
The outputs will be generated using the `dir` directory as base. |br| | ||
This is provided just for convenience | ||
|
||
Type: ``jobset`` | ||
|
||
|
||
Parameters: | ||
|
||
- **comment** :index:`: <pair: output - jobset; comment>` [:ref:`string <string>`] (default: ``''``) A comment for documentation purposes. It helps to identify the output. | ||
- **dir** :index:`: <pair: output - jobset; dir>` [:ref:`string <string>`] (default: ``'./'``) Output directory for the generated files. | ||
If it starts with `+` the rest is concatenated to the default dir. | ||
- **name** :index:`: <pair: output - jobset; name>` [:ref:`string <string>`] (default: ``''``) Used to identify this particular output definition. | ||
Avoid using `_` as first character. These names are reserved for KiBot. | ||
- **options** :index:`: <pair: output - jobset; options>` [:ref:`JobSetOptions parameters <JobSetOptions>`] [:ref:`dict <dict>`] (default: empty dict, default values used) Options for the `jobset` output. | ||
- **type** :index:`: <pair: output - jobset; type>` 'jobset' | ||
- ``category`` :index:`: <pair: output - jobset; category>` [:ref:`string <string>` | :ref:`list(string) <list(string)>`] (default: ``''``) [:ref:`comma separated <comma_sep>`] The category for this output. If not specified an internally defined | ||
category is used. |br| | ||
Categories looks like file system paths, i.e. **PCB/fabrication/gerber**. |br| | ||
Using '.' or './' as a category puts the file at the root. |br| | ||
The categories are currently used for `navigate_results` and `navigate_results_rb`. | ||
|
||
- ``disable_run_by_default`` :index:`: <pair: output - jobset; disable_run_by_default>` [:ref:`string <string>` | :ref:`boolean <boolean>`] (default: ``''``) Use it to disable the `run_by_default` status of other output. | ||
Useful when this output extends another and you don't want to generate the original. |br| | ||
Use the boolean true value to disable the output you are extending. | ||
- ``extends`` :index:`: <pair: output - jobset; extends>` [:ref:`string <string>`] (default: ``''``) Copy the `options` section from the indicated output. | ||
Used to inherit options from another output of the same type. | ||
- ``groups`` :index:`: <pair: output - jobset; groups>` [:ref:`string <string>` | :ref:`list(string) <list(string)>`] (default: ``''``) One or more groups to add this output. In order to catch typos | ||
we recommend to add outputs only to existing groups. You can create an empty group if | ||
needed. | ||
|
||
- ``output_id`` :index:`: <pair: output - jobset; output_id>` [:ref:`string <string>`] (default: ``''``) Text to use for the %I expansion content. To differentiate variations of this output. | ||
- ``priority`` :index:`: <pair: output - jobset; priority>` [:ref:`number <number>`] (default: ``50``) (range: 0 to 100) Priority for this output. High priority outputs are created first. | ||
Internally we use 10 for low priority, 90 for high priority and 50 for most outputs. | ||
- ``run_by_default`` :index:`: <pair: output - jobset; run_by_default>` [:ref:`boolean <boolean>`] (default: ``true``) When enabled this output will be created when no specific outputs are requested. | ||
|
||
.. toctree:: | ||
:caption: Used dicts | ||
|
||
JobSetOptions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (c) 2025 Salvador E. Tropea | ||
# Copyright (c) 2025 Instituto Nacional de Tecnología Industrial | ||
# License: AGPL-3.0 | ||
# Project: KiBot (formerly KiPlot) | ||
import os | ||
import re | ||
from .misc import MISSING_FILES, MISSING_TOOL | ||
from .kiplot import run_command | ||
from .gs import GS | ||
from .out_base_3d import Base3DOptions, Base3D | ||
from .macros import macros, document, output_class # noqa: F401 | ||
from . import log | ||
|
||
logger = log.get_logger() | ||
|
||
|
||
class JobSetOptions(Base3DOptions): | ||
def __init__(self): | ||
with document: | ||
self.jobset = '' | ||
""" *Name of the KiCad jobset file you want to use. Should have `kicad_jobset` extension. | ||
Leave empty to look for a jobset with the same name as the project """ | ||
self.run_output = '' | ||
""" *Output to be generated. When empty KiCad runs all possible outputs. | ||
Here the name can be obtained from the .kicad_jobset file, in JSON format. | ||
The `outputs` section contains all the defined outputs. Each output has an `id` use it here """ | ||
self.stop_on_error = True | ||
""" Stop generation when an error is detected """ | ||
super().__init__() | ||
|
||
def run(self, output): | ||
if not GS.ki9: | ||
GS.exit_with_error("`jobset` needs KiCad 9+", MISSING_TOOL) | ||
if not GS.pro_file: | ||
GS.exit_with_error("Missing project file, must be available in order to run a jobset", MISSING_FILES) | ||
jobset_file = self.jobset if self.jobset else GS.pro_file.replace('.kicad_pro', '.kicad_jobset') | ||
if not os.path.isfile(jobset_file): | ||
GS.exit_with_error(f"Missing jobset file `{jobset_file}`", MISSING_FILES) | ||
super().run(output) | ||
# Base command with overwrite | ||
cmd = ['kicad-cli', 'jobset', 'run', '--file', os.path.abspath(jobset_file)] | ||
if self.run_output: | ||
cmd.extend(['--output', self.run_output]) | ||
if self.stop_on_error: | ||
cmd.append('--stop-on-error') | ||
# The board | ||
board_name = self.filter_components(also_sch=True) | ||
cmd.append(board_name.replace('.kicad_pcb', '.kicad_pro')) | ||
res = run_command(cmd, change_to=output) | ||
for j in re.findall(r'\| Running job \d+, (.*)', res): | ||
logger.info(' - '+j) | ||
self.remove_temporals() | ||
|
||
|
||
@output_class | ||
class JobSet(Base3D): | ||
""" KiCad Jobset (batch execution) | ||
Generates outputs defined in a KiCad jobset file (.kicad_jobset). | ||
The outputs will be generated using the `dir` directory as base. | ||
This is provided just for convenience """ | ||
def __init__(self): | ||
super().__init__() | ||
with document: | ||
self.options = JobSetOptions | ||
""" *[dict={}] Options for the `jobset` output """ | ||
# We need a full project | ||
self._both_related = True | ||
|
||
@staticmethod | ||
def get_conf_examples(name, layers): | ||
if not GS.ki9: | ||
return None | ||
jobfile = GS.pro_file.replace('.kicad_pro', '.kicad_jobset') | ||
if not os.path.isfile(jobfile): | ||
return None | ||
gb = {} | ||
gb['name'] = 'basic_'+name | ||
gb['comment'] = 'Run KiCad jobset' | ||
gb['type'] = name | ||
gb['dir'] = 'Jobset' | ||
gb['options'] = {'jobset': jobfile} | ||
return [gb] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.