Skip to content

Issue 3241: CLI tool to explain violations - #3256

Merged
sobolevn merged 55 commits into
wemake-services:masterfrom
Tapeline:issue-3241
Jan 28, 2025
Merged

sobolevn merged 55 commits into
wemake-services:masterfrom
Tapeline:issue-3241

Conversation

@Tapeline

@Tapeline Tapeline commented Jan 5, 2025

Copy link
Copy Markdown
Contributor

I have made things!

Checklist

  • I have double checked that there are no unrelated changes in this pull request (old patches, accidental config files, etc)
  • I have created at least one test case for the changes I have made
  • I have updated the documentation for the changes I have made
  • I have added my changes to the CHANGELOG.md

Related issues

#3241 CLI tool to explain issues

🙏 Please, if you or your company is finding wemake-python-styleguide valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/wemake-python-styleguide. As a thank you, your profile/company logo will be added to our main README which receives hundreds of unique visitors per day.

@sobolevn sobolevn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! There's a lot of work ahead, this is not a full review :)
I will look again tomorrow.

Comment thread docs/pages/usage/cli.rst Outdated
Comment thread wemake_python_styleguide/cli/application.py Outdated
Comment thread wemake_python_styleguide/cli/application.py Outdated
Comment thread wemake_python_styleguide/cli/commands/base.py Outdated
Comment thread wemake_python_styleguide/cli/commands/explain/message_formatter.py Outdated
Comment thread wemake_python_styleguide/cli/commands/explain/message_formatter.py Outdated
Comment thread wemake_python_styleguide/cli/commands/explain/violation_loader.py
Comment thread wemake_python_styleguide/cli/commands/explain/violation_loader.py Outdated
@sobolevn

sobolevn commented Jan 5, 2025

Copy link
Copy Markdown
Member

Please, rebase your PR.

@Tapeline Tapeline changed the title Issue 3241 Issue 3241: CLI tool to explain violations Jan 6, 2025
Tapeline and others added 23 commits January 6, 2025 13:10
Add explain command
# Conflicts:
#	CHANGELOG.md
#	docs/pages/usage/cli.rst
#	wemake_python_styleguide/cli/application.py
#	wemake_python_styleguide/cli/commands/base.py
#	wemake_python_styleguide/cli/commands/explain/command.py
#	wemake_python_styleguide/cli/commands/explain/message_formatter.py
#	wemake_python_styleguide/cli/commands/explain/violation_loader.py
Add explain command (with code review and updated docs)
# Conflicts:
#	CHANGELOG.md
#	docs/pages/usage/cli.rst
#	poetry.lock
#	tests/test_cli/test_explain.py
#	wemake_python_styleguide/cli/application.py
#	wemake_python_styleguide/cli/cli_app.py
#	wemake_python_styleguide/cli/commands/explain/message_formatter.py
#	wemake_python_styleguide/cli/commands/explain/violation_loader.py
#	wemake_python_styleguide/cli/output.py
# Conflicts:
#	tests/test_cli/test_explain.py
@Tapeline
Tapeline requested a review from sobolevn January 24, 2025 13:25
@Tapeline

Copy link
Copy Markdown
Contributor Author

Applied all changes except removing hasattr check (reasoning provided).
Thank you for patiently reviewing my code)

@sobolevn sobolevn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you! Looks like that this is the ~last review round :)

Comment thread wemake_python_styleguide/cli/__init__.py Outdated
Comment thread wemake_python_styleguide/cli/cli_app.py Outdated
Comment thread wemake_python_styleguide/cli/commands/__init__.py Outdated
Comment thread wemake_python_styleguide/cli/commands/explain/__init__.py Outdated
Comment thread wemake_python_styleguide/cli/commands/explain/command.py Outdated
Comment thread wemake_python_styleguide/cli/commands/explain/message_formatter.py Outdated
Comment thread wemake_python_styleguide/cli/commands/explain/violation_loader.py Outdated
Comment thread wemake_python_styleguide/cli/commands/explain/violation_loader.py Outdated
Comment thread wemake_python_styleguide/cli/output.py
Comment thread wemake_python_styleguide/cli/output.py
@Tapeline
Tapeline requested a review from sobolevn January 25, 2025 12:57

@sobolevn sobolevn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I saw some new things to improve 😊

Comment thread tests/test_cli/test_explain.py Outdated
Comment thread tests/test_cli/test_explain.py Outdated
Comment thread tests/test_cli/test_explain.py Outdated
universal_newlines=True,
encoding=encoding,
env=os.environ,
shell=True,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why do we need shell= and env=?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Marking as not really resolved. I think that we might need to use shell=True because wps is not locatable without the PATH, right?

Comment thread tests/test_cli/test_explain.py Outdated
Comment thread tests/test_cli/test_explain.py Outdated
Comment thread tests/test_cli/test_explain.py
Comment thread wemake_python_styleguide/cli/cli_app.py Outdated
Comment thread wemake_python_styleguide/cli/commands/explain/message_formatter.py Outdated

@sobolevn sobolevn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We are almost there! This is going to be an amazing feature, thanks a lot to your for delivering it! 👍

Comment thread tests/test_cli/test_explain.py Outdated
universal_newlines=True,
encoding=encoding,
env=os.environ,
shell=True,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Marking as not really resolved. I think that we might need to use shell=True because wps is not locatable without the PATH, right?

Comment thread tests/test_cli/test_explain_internals.py Outdated
Comment thread tests/test_cli/test_explain_internals.py Outdated
Comment thread wemake_python_styleguide/cli/cli_app.py Outdated
Comment thread wemake_python_styleguide/cli/cli_app.py Outdated
Comment thread wemake_python_styleguide/cli/commands/base.py Outdated
Comment thread wemake_python_styleguide/cli/commands/explain/command.py Outdated
@Tapeline

Copy link
Copy Markdown
Contributor Author

Also thought about a slight improvement: we can add a shorthand for explain subcommand. It may be wps e, for example

@sobolevn

Copy link
Copy Markdown
Member

I don't think that adding some shorthands is actually a good thing :)

Tapeline and others added 3 commits January 27, 2025 01:35
…textwrap library. Add typed arguments for subcommands
# Conflicts:
#	tests/test_cli/test_explain.py
#	tests/test_cli/test_explain_internals.py
#	wemake_python_styleguide/cli/cli_app.py
#	wemake_python_styleguide/cli/commands/explain/message_formatter.py

@sobolevn sobolevn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

Comment thread wemake_python_styleguide/cli/cli_app.py Outdated
Comment thread wemake_python_styleguide/cli/commands/base.py Outdated
Comment thread wemake_python_styleguide/cli/commands/explain/command.py
Comment thread wemake_python_styleguide/cli/commands/explain/command.py
Comment thread wemake_python_styleguide/cli/commands/explain/command.py Outdated
Comment thread wemake_python_styleguide/cli/commands/base.py Outdated
Comment thread wemake_python_styleguide/cli/commands/base.py
Comment thread wemake_python_styleguide/cli/commands/explain/module_loader.py Outdated
# Conflicts:
#	wemake_python_styleguide/cli/application.py
#	wemake_python_styleguide/cli/commands/base.py
#	wemake_python_styleguide/cli/commands/explain/command.py
@Tapeline
Tapeline requested a review from sobolevn January 27, 2025 17:52

@sobolevn sobolevn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you!


def get_violation_submodules() -> Collection[ModuleType]:
"""Get all possible violation submodules."""
return _safely_get_all_submodules(_VIOLATION_MODULE_BASE)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we really need _safely_get_all_submodules? It is used in a single place, but all this function does is calling _safely_get_all_submodules

So, let's just remove _safely_get_all_submodules and move all code to get_violation_submodules

Comment thread wemake_python_styleguide/cli/commands/explain/module_loader.py Outdated
Comment thread wemake_python_styleguide/cli/commands/explain/module_loader.py Outdated
@sobolevn
sobolevn merged commit dffbb62 into wemake-services:master Jan 28, 2025
@sobolevn

Copy link
Copy Markdown
Member

You did a great job here, awesome feature! Thanks a lot for your patience during the review time :)

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.

2 participants