-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add automatic code formatting for Python code base and also generated standalone code #207
Comments
We thought about it at some point I think. Back at the time I wasn't a huge fan of
I thought about this as well, and I agree that it could be nice in some situations. But it would certainly be a niche-feature that is only relevant to developers, so I wouldn't add a lot of (potentially hard-to-maintain) code for it – I certainly don't want to spend any development/testing time to make this work for different formatters, platforms, etc. 😄 A good middle ground could be something like a build option or preference that simply consists of a command line string that gets called for each file (e.g. something like |
The only reason I suggested And for the
Yep, I agree with you that it shouldn't be creating additional work. It is certainly low priority for brian functionality, which is why none of us has implemented this so far I suppose :P. But it would just make me a bit happier. So I might put in an hour to get something working along the lines you suggested. |
The code style / state in brian2cuda is driving me nuts. I don't know how I survived looking at it for so long... ^^ And changing it as I go was also not the best idea... Now coding style is even inconsistent across the code base. I've always wanted to add some automatic code formatting such that the code just looks good and consistent.
And now that @SudeshnaBora is also working on this code, it becomes even more apparent that people use different coding styles and automatic formatting would just make me happier and everybody's life easier.
I have looked into formatters in the past and mostly gave up when being faced with format style decisions and time-requirements for setting things up. But recently, I came across black and started using it for formatting my own Python code. Simply because it does not require any decision on format, it simply chooses one. It is PEP 8 compatible. I don't have to give it a second thought. Code looks good. And I'm happy with it.
So, I'd like to format all Python code in brian2cuda with
black
and add it as a pre-commit hook, such that it is run automatically at every commit.And while we are at it, I would also love to have an option to automatically format all generated standalone code. When working on a feature, I often first work on the generated code and my eyes are usually bleeding from it. And I never know if I should format the templates such that the templates look good or the generated code looks good (which is basically impossible). This would allow to do the former and still have formatted generated code.
@mstimberg Did you ever consider this? I think inconsistent coding style is also apparent in the brian2 repository. Even though everything should adhere to the basic PEP8 guidelines (that you also have in your developer guide), there are some aspects which are up to the user. E.g. the text width used varies across files and I remember being able to classify a file's author (meaning you or @thesamovar) based on the coding style :D
And for generated code, I'd have to look into it, but adding some brian2
build_option
likeformat_code=True/False
that can be set if desired could be a sweet addition. Might need an optional dependency for formatting, something likeclang-format
(but I haven't looked into that much yet). Generally, would you be interested in having such a thing in brian2?The text was updated successfully, but these errors were encountered: