Open rewolff opened 1 year ago
I don't know if anybody at Raspberry Pi has time to implement something like this, but we welcome Pull Requests. From a quick web-search, it looks like https://jinja.palletsprojects.com/en/3.1.x/ is the most popular / common Python templating module?
The round tuits seem to be in short supply here.
That jinja seems to be "doing most the work" if we'd adopt that.
Some of the files are generated directly from the Python code (i.e. F-strings in the code itself). I suppose some of that data could be moved to templates, however, a lot of the code is manually generated by Python and what the user requested as parameters, rather than templated, so I wonder how that might work. I think templates might work for project files, less likely to work for program files. If I have time I will have a think if that gives us any real benefit.
The way I understand Jinja is that it will be easy to create a template and then say: here call that python function.
In an incremental way of implementing this, at first the template for main.c will just be "trigger python function output main.c "
But I currently see say defines for SPI at the top and an "initialize spi" in main(). Over time that'd be replaced by python function if (spi enabled) output defines and if (spi_enabled) output initcode.
Quite possibly possible, but I do not know Jinja at all. Sounds like a big change and I would need to learn some Jinja so not likely to be done in the near future due to workload.
yeah! Same here. just some notes for whomever will pick this up in the future.
There's also a careful balancing-act to be done between adding advanced features (like user-supplied templates), and keeping the project-generator simple enough that it can still be used by novice users :balance_scale: :slightly_smiling_face:
Oh, the default should surely be "as it is now". At most there will be an extra "select template" pulldown menu (that starts out on "default"). Maybe even hidden until "provoked".
As I understand things, the project generator currently holds a bunch of files that get "dumped" into the project directory with a few changes.
I would like to suggest that this is changed to: A template is copied from the templates directory with a few changes.
e.g. put PPG_PROJECTNAME there where the project name needs to be inserted.
Then you could provide a few different project templates (but you don't have to), but I could build my own template that has stuff that I always use myself. (I could copy over the last project that uses "my template" but I've decided against that: too difficult to remove the specific stuff for that project. )
Anyway, should this be possible, keep in mind that I'd want to add my own templates to the list of possible templates, and it would be neatest if you'd search through both a system templates and user-templates directory....