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

pyreverse: better error messages for unsupported file formats #5951

Merged

Conversation

DudeNr33
Copy link
Collaborator

  • Add yourself to CONTRIBUTORS.txt if you are a new contributor.
  • Add a ChangeLog entry describing what your PR does.
  • If it's a new feature, or an important bug fix, add a What's New entry in
    doc/whatsnew/<current release.rst>.
  • Write a good description on what the PR does.

Type of Changes

Type
🐛 Bug fix
✨ New feature
🔨 Refactoring
📜 Docs

Description

When supplying any format not directly known to pyreverse, we will try to convert it using Graphviz (if available).
Until now we just called the dot command and presented any error messages from it directly to the user, which can be confusing if it complains about unsupported file formats.

This PR aims to make the error messages clearer and to fail fast if we can already tell that the format is not supported by Graphviz.

Closes #5950

@@ -152,7 +152,6 @@ def generate(self, outputfile: str) -> None:
with open(dot_sourcepath, "w", encoding="utf8") as outfile:
outfile.writelines(self.lines)
if target not in graphviz_extensions:
check_graphviz_availability()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We already check that in the Run class. No need to do it twice.

help=(
f"create a *.<format> output file if format is available. Available formats are: {', '.join(DIRECTLY_SUPPORTED_FORMATS)}. "
f"Any other format will be tried to create by means of the 'dot' command line tool, which requires a graphviz installation."
),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We did not state the directly supported output formats in the help output previously, I think this also makes it a bit clearer what is going on under the hood.

@@ -292,7 +293,34 @@ def check_graphviz_availability():
if shutil.which("dot") is None:
print(
"The requested output format is currently not available.\n"
"Please install 'Graphviz' to have other output formats "
"than 'dot' or 'vcg'."
"Please install 'Graphviz' to have image output formats."
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The message was outdated as we now support other output formats as well. Reiterating the directly supported output formats here is not necessary I think, so I kept it more general.

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"Please install 'Graphviz' to have image output formats."
"'Graphviz' need to be installed for your chosen output format."

"Pyreverse will continue, but subsequent error messages "
"regarding the output format may come from Graphviz directly."
)
return
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

mypy forced me to include this. 😉
Relying on the textual output of the dot command to determine the supported output formats is probably not the best solution, but I'd argue the tradeoff for more user friendly error messages and ability to fail fast is worth it.
But if you have concerns or feedback please feel free to address it.

@DudeNr33 DudeNr33 marked this pull request as ready for review March 22, 2022 09:41
@Pierre-Sassoulas Pierre-Sassoulas added the pyreverse Related to pyreverse component label Mar 22, 2022
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

Look pretty good already. I think we can include in 2.13 :)

@@ -292,7 +293,34 @@ def check_graphviz_availability():
if shutil.which("dot") is None:
print(
"The requested output format is currently not available.\n"
"Please install 'Graphviz' to have other output formats "
"than 'dot' or 'vcg'."
"Please install 'Graphviz' to have image output formats."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"Please install 'Graphviz' to have image output formats."
"'Graphviz' need to be installed for your chosen output format."

Comment on lines 64 to 68
with pytest.raises(SystemExit):
# we have to catch the SystemExit so the test execution does not stop
main.Run(["-o", "png", TEST_DATA_DIR])
# Check that the right info message is shown to the user
assert (
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
with pytest.raises(SystemExit):
# we have to catch the SystemExit so the test execution does not stop
main.Run(["-o", "png", TEST_DATA_DIR])
# Check that the right info message is shown to the user
assert (
with pytest.raises(SystemExit) as exc_info:
# we have to catch the SystemExit so the test execution does not stop
main.Run(["-o", "png", TEST_DATA_DIR])
# Check that the right info message is shown to the user
assert exc_info.value.code == 2 # (?)
assert (

I'll let you decide if it's worth it, there's 3 similar assert that could be done if you want to assert that the error code is correct.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I included the check.

@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.13.0 milestone Mar 22, 2022
@DudeNr33 DudeNr33 merged commit 9c90db1 into pylint-dev:main Mar 22, 2022
@DudeNr33 DudeNr33 deleted the fix-5950-pyreverse-supported-formats branch March 22, 2022 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation 📗 pyreverse Related to pyreverse component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DOC: pyreverse supported format not recognized missing puml, plantuml, mmd, etc
2 participants