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
PEP8 compliance in pydot.py #265
Conversation
Hi @hrishikeshrt, thanks for this PR. The timing is great, at the start of a new development cycle. I think we should be able to merge this soon. There is only one thing I really have strong doubts about:
My other remarks are optional. You can decide per item what you want to do with it. They are not blocking merging as far as I am concerned:
Side notes, not requiring change to your proposal:
|
|
Have you considered |
I would also suggest to just use |
@hrishikeshrt Thanks for all the changes. A few more remarks:
Ok, thanks, but now there are still 7 left in
Ok, yes, I see what you mean. Nicely solved.
Hmm. Not really necessary for me actually. Some considerations:
What do you think? If it is all the same to you, maybe better remove them for now.
I see The second issue I see
From line 65:
Hope you can still correct that. For the rest, all your changes to One new remark, something that I did not notice last time, sorry. Optional:
Separate comment on |
Thank you. |
Wow, you're faster than I can turn off my computer. 😄 But you still missed a few blank lines after Do you want to squash your commits yourself or shall I do it on merging? |
I think I've got them all this time 😅 I've also squashed commits (I believe). |
Yes, but now you also removed empty lines below a few Also, you removed empty lines in other parts of the code, while this was supposed to be a final correction. Could you please just revert from the last commit before squash (17f4a35) all changes that went beyond what I requested in my last comment (only remove the blank lines after |
Yes, indeed. |
@ankostis Yes, maybe you are right, but I also still have a few questions/doubts about |
Regarding the longer line-width, there been much debate, sprung from Hettinger's "don't PEP8-me" notorious presentation, and it does make sense in multiple ways, e.g. we don't want a slight change to produce a much bigger git-diff. In general black has been streamlined for git and cooperating developers, mimicking the success of Golang's automated formatting. The whole point is to avoid having lengthy discussions like the one above. |
Done. Also, There were some instances where |
@hrishikeshrt Empty lines below Overall, a lot of inconsistencies removed, completely PEP 8 compliant now and everything looking great again. So, finally merged. Thanks a lot for all your hard work! I will probably need another day to write down my thoughts on |
@ankostis wrote:
@prmtl wrote:
As you may have noticed from my delayed reply, I have been struggling with this for days now already. Especially because the two of you are so positive about it, while I am not overly enthusiastic yet. I can see the promise of automated code formatting, but I do not know if it is going to be so enjoyable to work under it. It takes away part of the art, the fun. There is no leniency at all. If the result is ugly, just suffer it. Computer says no. Another part of our lives controlled by a bot. And not even a very good bot, I feel. I have also been looking at A non-technical problem I have with Then there is @ankostis wrote:
Yeah, ok, well, I watched that Raymond Hettinger talk, but I am not sure if
Yes, it is easy to point out a lengthy discussion about code formatting style, but I think we do not have a lot of them actually. The last PEP8 refresh was in 2016. What is more difficult to point out is the costs of using a code formatter: How do you measure the cost of everyone having to scroll through 170 additional lines of code at the top of Also, how about newcomers? Is this not a slight entry barrier? Predicting a formatting tool is even more difficult than following PEP 8. So we would need to ask new contributors to install that tool (maybe even There is so much more to say, but I will leave it at this now. Hope to hear your thoughts. I am not all negative about it, just struggling with it. Some comparisons:
(I tweaked the settings a bit to make them easier to compare. For details, see the individual commits of each PR.) |
I agree that
And how it works now with PEP8? They need to (should) follow it as to not reject contribution due to formatting or badly formatted code will be introduced into the codebase. Even more: if they fail to stick to formatting rules, it's easier to just run For me it could be any formatter as long as you don't have to think when using it. Sadly with IMHO lets not overthink it (as pydot is rather small codebase) and just integrate |
As explained, the limit is 80 +8(%10), but in that style-manual they also suggest you to make it 90-ish, which btw, the line-length is one of the few configurable parameters of Also you can always mark parts of the code to be excluded from the black, with
Quite the contrary, As long as you have ignored any filename-regexes that must no autoformat, with a section in
all a contributor has to do it to type
Actually it is a good habit to provide an extras extras_require={
"dev": "black==21.5b2; python_version > '3.5'",
... Note that the pinning is good for 2 reasons (1, to be stable, 2. it has no stable release, and causes dependency problem sometimes)
I have contributed to programs that have
Eventually having a test-case that simply runs Look also the github-actions example. The eventual experience as a contributor is rather amusing, you just curse yourself for not having run the test-cases locally prior to push, fix, push-force to re-write commit, and you get accustomed in no time. Thank you for your always dutiful collection of resources, for the list of comparisons. But I'm surprised you didn't already mention the reformatting of string-quotes to In any case, as @ prmtl pointed out, the point is to have an opinionated auto-formatter, whatever that might be. |
@prmtl @ankostis If we were to give
* I guess the exploding of these long lists is what got ** Also the formatting check needs run only once, no need for running it on multiple architectures and Python versions. With regard to With regard to In reply to @ankostis
The link is not working and I am not sure if you understood what I meant, namely that
I think a true implementation of a tolerance of 10% would be if the tool would only seldomly reflow lines to end inside that tolerance zone. Note that this is something else than the tool being "uncompromising" or not. A tool can have sophisticated rules on how to behave in the 10% tolerance zone and still enforce them in an uncompromising way.
Yes, ok, to you it is a gift, because you already know the tool and have it installed. I was thinking more about people sharing one of their first Python bug fixes ever. Anyway, as I stated above, I am ok with it now as long as we do not force contributors to use it before submitting their work.
Yep, that config file will need to be added. Not seeing any files that need to be
Yes, I guess version pinning is good to ensure the same outcome locally as on CI, but does this not lead to conflicts with other packages pinning on different versions? Or are these requirements installed inside the project directory? I do not have much experience with installing through Also, would it not give us the extra work of watching
Thanks, I will check out the documentation. If you still find something later, please share. I can also search a bit more myself. Just a random search on GitHub already yields many results, but it seems like every project has a different approach and many of them are too small to have any example PRs I can look at. Anyway, the CI integration can be done separate from the reformatting and documentation, so I am not too worried about that.
Ok, cool. Thanks for taking away that worry.
Yes, it was one of the main things I did not like, but like I said "there is so much to say". I had been struggling with the whole idea of even handing out control to any formatting tool, and got blocked by the overchoice of tools and settings, all new to me. Time was ticking away, so I decided it was better to give a short response rather than none at all. The double quotes were not on the top of my mind that day. As written above, I do hope that we can start with not reformatting the quotes, but it is not a deal breaker for me.
Ok, your messages are clear and understood. I am starting to get interested in trying it out. Hope you can agree with the proposal at the top of this comment. In reply to @prmtl
Yeah, ok, but the difference is that now the humans can still make an exception. For example, it sometimes happens that some code blocks are similar to each other, many examples of that in Anyway, I have come to accept this as a trade-off and as said above, I am willing to try it out now. I do however hope you can accept my proposal not to use the defaults, especially for line length. Please still let me know what you think of my proposal at the top of this comment. In reply to @hrishikeshrt
No, I think it still adheres to PEP8. Maximum line length is actually configurable and PEP8 allows maximum line lengths up to 99 characters in case the team agrees on it. If I run
For this line: b = node_str[node_port_idx + 1 :] Actually this seems to be a problem with
So, using
I do not know if you have been working on this more? Any thoughts on the whole discussion? I have gotten to know |
I've been passively following the discussion. I can see the appeal in "never having to format the code" ourselves, sure, but I am not entirely in agreement of "write code and forget about formatting". To elaborate, if one writes code in a certain way (which is not horrible, say mostly PEP8 compliant), That said, I think You may create PR yourself. I'll follow the progress and make comments if I have any. (Unfortunately, I cannot commit to the task at the moment). PS: Thank you for your detailed review of the pull request from earlier and overall thorough research. I certainly enjoyed the experience. |
[Black, The Uncompromising Code Formatter][1] promises to save the developers of `pydot` time and mental energy by taking control over code formatting. With this commit, we will start to find out. With `black` installed, you can now run `black .` in the top `pydot` directory and any formatting issues in pydot source files should get corrected automatically: ~/Development/pydot $ black . reformatted dot_parser.py reformatted setup.py reformatted test/pydot_unittest.py reformatted pydot.py All done! 4 files reformatted. Check out the documentation for more on the [Black code style][2] and options for [integrating it with your editor or git pre-commit][3]. This commit contains: - New `pyproject.toml`: Configuration of `black`. - Changed `.py` files: Results of the first run of `black` 21.5b2. Line length is kept at 79 characters for now. This is my personal preference because it allows for reasonable font size when using a phone, side-by-side diffs on a small laptop screen or 3-way diffs on larger screens. For easier review of the formatting changes made by `black`, this commit uses the `--skip-string-normalization` flag to prevent that single quotes are converted to double quotes already. The next commit will drop that flag, so the results of that conversion are shown there. A later commit will take care of the CI integration. Thanks to Kostis Anagnostopoulos for first suggesting `black` and to Sebastian Kalinowski and Hrishikesh Terdalkar for giving their reviews as well. Alternatives that were rejected: - `yapf`: Not clearly better formatting than `black`. More configuration options, but the cost of reaching agreement on all those options might offset the benefits of using a code formatter. - `autopep8`: Focusses mainly on PEP 8 compliance, meaning that a lot of other formatting issues would still need to be decided on manually, reducing the benefits of using a code formatter. As discussed in [pydot#265][265] and [pydot#267][267]. [1]: https://pypi.org/project/black/ [2]: https://black.readthedocs.io/en/latest/the_black_code_style/current_style.html [3]: https://black.readthedocs.io/en/latest/integrations/index.html [265]: pydot#265 [267]: pydot#267
Usage of `extras_require` suggested by Kostis Anagnostopoulos: - pydot#265 (comment)
Continued in #267 with a PR for Black. |
(i know the issue if line-width has been resolved, but found it relevant whatsoever for any future discussion)
|
No description provided.