Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Make ExecutableUnavailableError #14776

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 4 commits into from
Jul 22, 2019
Merged

Conversation

alexrudy
Copy link
Contributor

PR Summary

When checking for executables which are optional dependencies, this makes matplotlib more forgiving of badly-behaved executables. Motivated by #14756, but should be generally helpful.

The new exception (ExecutableUnavailableError) inherits from FileNotFoundError to ensure that we don't break anyones existing code which uses except FileNotFoundError: to catch this kind of exception.

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@@ -283,6 +283,12 @@ def wrapper():
_ExecInfo = namedtuple("_ExecInfo", "executable version")


class ExecutableUnavailableError(FileNotFoundError):
Copy link
Member

Choose a reason for hiding this comment

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

Should this maybe be called ExecutableNotFoundError in analogy to FileNotFoundError?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess I went with Unavailable b/c the motivating case was when an executable convert is found, but convert --version returns nonsense.

@timhoffm timhoffm modified the milestones: v3.1.2, v3.2.0 Jul 14, 2019
Copy link
Contributor

@anntzer anntzer left a comment

Choose a reason for hiding this comment

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

_get_executable_info is private, so ExecutableNotFoundError should be private too (ie _ExecutableNotFoundError)

@timhoffm
Copy link
Member

@anntzer Not sure about this. I don't think we wrap all usages in a try-catch block. Therefore the ExecutableNotFoundError can rise to the user. In this case it should not be private.

@anntzer anntzer dismissed their stale review July 15, 2019 09:18

fair point by @timhoffm

@jklymak
Copy link
Member

jklymak commented Jul 15, 2019

LGTM. Not going to merge yet, in case anyone else wants to weigh in on the benefits of this. I wasn't really aware that we could define our own errors like this, so am not sure if this is usual in packages...

@timhoffm
Copy link
Member

@jklymak Refining excpetions by subclassing is a valid practice. See e.g. https://github.com/pandas-dev/pandas/blob/v0.24.2/pandas/errors/__init__.py#L96-L100 and surrounding code.

While I don't think one should do it for every exception, it's good if one can make it more specific (and maybe just want to catch that specific one). IMHO that's the case here.

class ExecutableNotFoundError(FileNotFoundError):
"""Error raised when an executable that Matplotlib optionally
depends on can't be found."""
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need the "pass" here.

Also the docstring would typically be formatted

"""
Error raised...
"""

(basically either it fits in one line and we write

"""A one line docstring."""

or it doesn't and we write

"""
A multiline
docstring.
"""

or even

"""
One line, but just too long to have opening and closing quotes on the same line.
"""

Copy link
Contributor

@anntzer anntzer left a comment

Choose a reason for hiding this comment

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

just tiny formatting stuff

@anntzer anntzer merged commit 64ba969 into matplotlib:master Jul 22, 2019
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