Skip to content

Support updating text variables in .kicad_pcb file explicitly#861

Merged
set-soft merged 1 commit into
INTI-CMNB:devfrom
matthijskooijman:update-text-variables-cache
Sep 8, 2025
Merged

Support updating text variables in .kicad_pcb file explicitly#861
set-soft merged 1 commit into
INTI-CMNB:devfrom
matthijskooijman:update-text-variables-cache

Conversation

@matthijskooijman

Copy link
Copy Markdown

Normally, the text variables in the .kicad_pcb file are cleared when requested, or when changing them with the set_text_variables preflight. This causes KiCad to load the variables from the project file when opening the PCB, but this does not work when the .kicad_pcb file is used in isolation (e.g. when submitting to a PCB manufacturer).

This commit adds support for invalidate_pcb_text_cache=update, which causes kibot to explicitly write the (updated / current) variables to the .kicad_pcb file, making it self-contained.

This fixes #860

@matthijskooijman
matthijskooijman force-pushed the update-text-variables-cache branch from f7f1bd3 to 3188455 Compare September 4, 2025 13:54
@matthijskooijman

Copy link
Copy Markdown
Author

(force pushed to fix typo)

I've submitted this as a draft, since I am not entirely convinced that my approach of adding a new 'update' value to the existing invalidate_pcb_text_cache config directive is the best approach, for two reasons: 1) the config is about invalidating cache, not updating it, which might be a bit weird and 2) this now only works when requesting update explicitely, so there is no way to express "update them only when changed by set_text_variables", like the current auto value does (which is changed to yes by set_text_variables.

I'm not sure what the best approach would be, maybe also add an auto_update value (that can be changed to update by set_text_variables), or deprecate invalidate_pcb_text_cache and add a new value like update_pcb_text_cache=no/clear/update/auto_clear/auto_update, or maybe split into two config directives? Or maybe just make this the default and only behavior? Let me know your thoughts.

Even with the above caveats, I wanted to submit this PR to demonstrate that the approach itself works as expected (tested locally by copying the updated files into a kibot docker container).

@set-soft

set-soft commented Sep 5, 2025

Copy link
Copy Markdown
Member

What about a new, and independent, global option update_pcb_text_cache with no|yes as options.
And handle it separately.
It could even have an auto option that becomes yes when using set_text_variables.
So we get all the combinations without changing the current options, just adding more.

@matthijskooijman
matthijskooijman force-pushed the update-text-variables-cache branch from 3188455 to 0e516f9 Compare September 7, 2025 16:32
@matthijskooijman

Copy link
Copy Markdown
Author

That sounds like a good approach, I've just implemented this, including the 'auto' option. I'm marking this PR as non-draft, AFAICS it would be ready to review and merge.

There is one (existing) caveat that I ran into: There is a restore_project option that is intended to undo any changes to the project file, in particular made by the set_text_variables preflight. However, that does not undo the changes to the PCB file, as made by invalidate_pcb_text_cache (and now also update_pcb_text_cache. This is not a big deal for me, as I am mostly using kibot in CI, so lingering changes are not problematic, but maybe this is something to fix separately.

@matthijskooijman
matthijskooijman marked this pull request as ready for review September 7, 2025 16:37
@set-soft

set-soft commented Sep 8, 2025

Copy link
Copy Markdown
Member

There is one (existing) caveat that I ran into: There is a restore_project option that is intended to undo any changes to the project file, in particular made by the set_text_variables preflight. However, that does not undo the changes to the PCB file, as made by invalidate_pcb_text_cache (and now also update_pcb_text_cache. This is not a big deal for me, as I am mostly using kibot in CI, so lingering changes are not problematic, but maybe this is something to fix separately.

I think people that wants to avoid changes should disable the invalidate_pcb_text_cache and update_pcb_text_cache. The restore_project applies to the kicad_pro file.

@set-soft

set-soft commented Sep 8, 2025

Copy link
Copy Markdown
Member

Can you rebase this PR to the dev branch?
I can merge it as-is, but it won't be attributed to you.

Also: you don't need to include changes to docs/source/configuration/sup_globals.rst they are automatically generated.

@matthijskooijman
matthijskooijman force-pushed the update-text-variables-cache branch from 0e516f9 to 8e51de2 Compare September 8, 2025 12:34
@matthijskooijman
matthijskooijman changed the base branch from master to dev September 8, 2025 12:34
Normally, the text variables in the .kicad_pcb file are cleared when
requested, or when changing them with the set_text_variables preflight.
This causes KiCad to load the variables from the project file when
opening the PCB, but this does not work when the .kicad_pcb file is used
in isolation (e.g. when submitting to a PCB manufacturer).

This commit adds support for a new update_pcb_text_cache option, which
causes kibot to explicitly write the (updated / current) variables to
the .kicad_pcb file, making it self-contained.

This fixes INTI-CMNB#860
@matthijskooijman
matthijskooijman force-pushed the update-text-variables-cache branch from 8e51de2 to 508d773 Compare September 8, 2025 12:35
@set-soft set-soft self-assigned this Sep 8, 2025
@set-soft set-soft added the enhancement New feature or request label Sep 8, 2025
@matthijskooijman

Copy link
Copy Markdown
Author

Can you rebase this PR to the dev branch?

Done, though I did not do any additional testing with the rebased version (no time right now).

Also: you don't need to include changes to docs/source/configuration/sup_globals.rst they are automatically generated.

Ah, I dropped those changes.

When are they autogenerated? When building the docs with the Makefile, it seems? If so, why is the file present in git at all? Might be cleaner to not have it than carry an outdated version around?

@set-soft
set-soft merged commit 36f8312 into INTI-CMNB:dev Sep 8, 2025
20 checks passed
@set-soft

set-soft commented Sep 9, 2025

Copy link
Copy Markdown
Member

When are they autogenerated? When building the docs with the Makefile, it seems?

Yes, make doc

If so, why is the file present in git at all?

Mainly because you need a working KiBot to generate them, which isn't always true. The requirements to generate the HTML files are relaxed in this way

Might be cleaner to not have it than carry an outdated version around?

They are synced very often, the doc target generates a lot of stuff.

matthijskooijman added a commit to matthijskooijman/PCB-workflows that referenced this pull request Sep 11, 2025
This makes sure the exported PCB file is self-contained and can be
submitted to a PCB manufacturer directly, without needing the project
file.

This requires support in kibot, as introduced by
INTI-CMNB/KiBot#861
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Copy text variables from project file to pcb file

2 participants