Skip to content
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

Refactor watermark #65

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

GreatBahram added 4 commits Oct 25, 2020
* 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
@@ -0,0 +1,2 @@
pycodestyle:
max-line-length: 88 # To be compatible with black

This comment has been minimized.

@rasbt

rasbt Oct 26, 2020
Owner

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

This comment has been minimized.

@GreatBahram

GreatBahram Oct 27, 2020
Author Contributor

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!

@pep8speaks
Copy link

@pep8speaks 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 rasbt commented Oct 26, 2020

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

jamesmyatt added a commit to jamesmyatt/watermark that referenced this pull request Oct 29, 2020
@jamesmyatt
Copy link
Contributor

@jamesmyatt jamesmyatt commented Oct 29, 2020

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 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.

docs/watermark.ipynb Outdated Show resolved Hide resolved
watermark/watermark.py Outdated Show resolved Hide resolved
GreatBahram and others added 2 commits Nov 2, 2020
@rasbt
Copy link
Owner

@rasbt 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 approved these changes Nov 19, 2020
@rasbt rasbt merged commit 3a6797e into rasbt:master Nov 19, 2020
1 check passed
1 check passed
Travis CI - Pull Request Build Passed
Details
@GreatBahram
Copy link
Contributor Author

@GreatBahram GreatBahram commented Nov 19, 2020

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
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants