Closed rtibbles closed 11 months ago
Just one comment about the changes to
pre-commit
- I'm sure it isn't but it looks like pre-commit could end up circular ifpre-commit
now runsmake build
which calls thegenerate_from_specs
which then callspre-commit
again on a particular set of files that it has changed.
I saw this too. Dropping in my thoughts
To respond to both of you - yes, I had deliberately scoped the pre-commit invocation from within the generation script to only the generated files, so as to avoid the recursion.
I originally did not do it this way, and instead thought that just by putting the generation hook first, that would somehow be OK, but pre-commit doesn't rescan for newly changed files during the pre-commit process, so even as the first hook, the new files did not get picked up by subsequent hook executions and so were not reformatted.
Then if you go to recommit those newly generated files to let them get reformatted, the original change that triggered the new hook in the first place retriggers the new hook and I ended up in a loop of trying to commit and failing because the files were getting formatted and unformatted in quick succession.
This didn't suffer from any of those problems, and because the outputted files always conform precisely to the requirements of pre-commit because they are all run through it in the generation script, there are never any issues with the subsequent hook invocations too.
I do think it would be better to have make build
be a manual process, outside of pre-commit
. We would always have the PR check to ensure files are regenerated, since pre-commit
could be missing or skipped. So it feels we're doubling up the automation and breaking a boundary which perhaps exists for a good reason-- you should be able to see the full diff of what you're committing.
you should be able to see the full diff of what you're committing.
That's still the case - nothing is committed outside of user control here, it just ensures that when you commit changes that should result in changes in generated files, those changes are generated and now are available to be committed.
We also don't currently have a check to make sure generated files are regenerated when needed - the only check is to make sure that no finalized specs are modified. So this adds this missing check.
Oh I see. It does still fail the first commit. I thought that wouldn't be the case. Sorry for the confusion.
I still dislike this change though. First, I tried it and the double output will surely confuse someone. Secondly, within pre-commit, I think applying code formatting is acceptable because the code shouldn't functionally change. With the scripts/generate_from_specs.py
, it's generating actual code which will be imported broadly into Kolibri's and browsers through the published packages. So having that happen automatically in pre-commit, where it's too easy to just accept the auto changes from it, makes me uneasy about the placement of this automation within pre-commit specifically.
OK - to avoid stalling this unnecessarily, I've backed out the change to pre-commit but left everything else the same.
We can revisit how to add an automated check that files have been rebuilt in the future.
N.B. This will not stop all Kolibris from importing them, as very old Kolibris rely on the content kind, and to avoid a kind proliferation, I have kept the kind here as HTML5. However, that is only on versions older than 0.11.x, of which there are very few.