Skip to content

Refactor watermark #65

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

Merged
merged 14 commits into from
Nov 19, 2020
Merged

Refactor watermark #65

merged 14 commits into from
Nov 19, 2020

Conversation

GreatBahram
Copy link
Contributor

@GreatBahram GreatBahram commented Oct 26, 2020

Hi there, @rasbt

I refactored the watermark module:

  • Firstly, I changed all information-gathering functions to return a dictionary as their output. Now I believe, it is much easier for newcomers to focus on only what they want to solve, without messing other parts.
  • Secondly, I combined all these outputs according to user inputs inside the watermark method as it was.
  • Finally, I wrote a simple method to produce a formatted string, _generate_formatted_text, which is fine in my opinion, even if someone wants to elaborate it to produce much fancy string it is easier than before.

PS: I added a .pep8speaks file to increase the line length to 88. I hope you find this pull request useful.
Thanks


Screenshot from 2020-10-26 16-10-27

* sort imported modules
* use dedent to indent multi-line string
* get information from each function separately
* Combine different information in one function instead of all over the object
* Sort imports and other part
.pep8speaks.yml Outdated
@@ -0,0 +1,2 @@
pycodestyle:
max-line-length: 88 # To be compatible with black
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious: why particularly 88, and what's black?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, generally the community answer to make the PEP8 code style was to use a lint tool like flake8 or pycodestyle and etc. These tools only report the problem, do not fix them. On the other hand, black is an auto-code-formatter (as they say).

You just run it and it automatically fixes the problem. There are also some Jupyter extensions, such as this one, that run black inside Jupyter notebook.

And by the way, black uses 88, by default, characters per line.

You can read more about it on their documentation site. It's a great tool and I hope you’ll check it out!

Copy link
Contributor

@jamesmyatt jamesmyatt Oct 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pep8speaks
Copy link

pep8speaks commented Oct 26, 2020

Hello @GreatBahram! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-11-19 16:01:15 UTC

@rasbt
Copy link
Owner

rasbt commented Oct 26, 2020

Nice work, I agree that the restructuring (and use of lists) will make everything a bit more manageable.

@jamesmyatt
Copy link
Contributor

If the official code style is now "black", can you update the Readme to include this? e.g. there's a developer guidelines section now.

@rasbt
Copy link
Owner

rasbt commented Oct 29, 2020

Thanks for the clarification @GreatBahram . The tool (black) looks really nice. I would prefer to stick with the PEP8 80-char though.

Personally, I also have a slight preference for the "# Aligned with opening delimiter" style in PEP8. I.e., I find

Screen Shot 2020-10-29 at 10 29 47 AM

more readable than

Screen Shot 2020-10-29 at 10 29 54 AM

Both are good styles, and I also sometimes use the latter, but in this case, I really think the upper one is a tad more readable.

No worries, I can make these little changes (just personal preferences) to this otherwise awesome PR.

@rasbt
Copy link
Owner

rasbt commented Nov 19, 2020

Just going through code again, I really like this refactoring. Also, thanks for improving the output style (capitalization etc.)! Awesome PR!

@rasbt rasbt merged commit 3a6797e into rasbt:master Nov 19, 2020
@GreatBahram
Copy link
Contributor Author

Thank you so much for your compliment!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants