Add ability to add custom code in documents #1259
Draft
+98
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
This PR adds a document setting "Custom Code".
As for the motivation, see #1258.
tl;dr: I as a Document Maintainer want to be able to define a function once in the document and use it in multiple formulas.
Proposed solution
I added a new string in the document settings. This string is inserted into the python module that is built per document.
I also added two hooks to ensure that the code is used:
load_table
: When the tables are read for the first time, the module is already built, but the code was not available. Once the document settings are loaded, the code is rebuilt.BulkUpdateRecord
: When the document settings are updated, the whole document is invalidated to use the new code. This could be optimized, but that optimization is not easy.While creating the change, I used a dev container. Feel free to keep or remove that.
Related issues
#1258
and "How do I add more python packages?"
This PR should also allow putting imports into the custom code.
Has this been tested?
I did some manual testing (which I guess should be automated):
Each time checking that the cells contain the expected value in the end.
I did not consider:
Screenshots / Screencasts