New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rework Files to support generated files #3451
Merged
Conversation
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
oprypin
force-pushed
the
genfile
branch
3 times, most recently
from
December 15, 2023 22:11
15e06eb
to
03f7e9e
Compare
The previous attempt always computed these on the fly #3017 but now they will be cached after first access, so the performance penalty is avoided. The fields can still be overwritten manually. And one can ask the fields to be recomputed by using the `del` operation.
Co-authored-by: Tim Vink <vinktim@gmail.com>
Add a new field `content_bytes`/`content_string` to read the content regardless of whether it's backed by the new style or still by `abs_src_path` (which is now not always present)
-it populates `generated_by` automatically as well, based on the currently running plugin event.
This means plugins don't have to carefully find the sort order to put files in.
Ready for review |
The Before: with open(os.path.join(temp_dir, 'new_file.md'), 'w', encoding='utf-8') as f:
f.write("content")
f = File('new_file.md', temp_dir, config.site_dir, config.use_directory_urls)
f.generated_by = 'my-plugin'
files.append(f) After, option 1: with open(any_tmp_path, 'w', encoding='utf-8') as f:
f.write("content")
f = File.generated(config, 'new_file.md', abs_src_path=any_tmp_path)
files.append(f) After, option 2: f = File.generated(config, 'new_file.md', content="content")
files.append(f) |
Awesome, that looks like a huge quality of life improvement for plugin authors 👏 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
generated_by
attribute toFile
class #3344