csdms / babelizer

Transform BMI-wrapped models into Python packages
https://babelizer.readthedocs.io
MIT License
4 stars 3 forks source link

Remove black and isort dependencies #92

Closed mcflugen closed 6 months ago

mcflugen commented 6 months ago

My goal with this pull request is to remove the black and isort dependencies of the babelizer. Although they serve an important purpose in that they produce reproducible builds and remove lint that might be generated by the jinja templates (e.g. trailing whitespace), they add a couple extra dependencies. Instead of using black and isort, I thought it would be better if we ensure the babelizer generates well formatted code all by itself.

To this end, I attempted to modify the jinja templates but that quickly resulted in complex and difficult to read template files (I don't think I ever got them to work just right, anyway). Instead, I've added a new module, _render_files.py that renders some of the project's files with Python and then the template files just include the generated file contents. The Python code is much easier to read and to maintain than the equivalent jinja code.

To ensure that the resulting files are formatted correctly (at least for black and isort) I've added tests that run black and isort over the generated projects, returning an error if anything needs modifying.

mcflugen commented 6 months ago

@mdpiper What do you think of these changes? I like removing dependencies but does this make things easier or more difficult to follow? I felt that some of our jinja templates were becoming overly complicated.

mdpiper commented 6 months ago

@mcflugen I think it's a good idea! As much as I enjoy templating, the files were getting thick with jinja code, making them hard to read.

mcflugen commented 6 months ago

@mdpiper I've added a few more sub-commands to babelize that, like babelize sample-config, generate individual files rather than an entire project. I don't think they contribute much to the babelizer but they were easy to add and are things we may want to use as standalone commands.

I can imagine using these commands not so much with the babelizer but when creating new projects (or, in the case of babelize sample-meson-build, when converting setuptools projects to meson projects).

mdpiper commented 6 months ago

@mcflugen I think these are great!

I think it would be neat to use this technique to make the bind-c layer for a Fortran component.