8000 FIX: ensure we import when the user cwd does not exist by tacaswell · Pull Request #19507 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

FIX: ensure we import when the user cwd does not exist #19507

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 2 commits into from
Feb 17, 2021

Conversation

tacaswell
Copy link
Member

PR Summary

This is the only place that we directly access the cwd in the main library.

You can drive your self to this state by in one shell cd'ing to a directory and then from a different shell removing that directory. The first shell will still think it's working directory is the (now non-existent) path and mild chaos ensues.

This has probably been broken forever (at least back to the 2.2.x series), however I do not think that it is worth the trouble to set up this weird state in the tests. If you are in this state IPyhon will not start and PyQt5 will not import.

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).

@tacaswell< 8000 /a> tacaswell added this to the v3.4.1 milestone Feb 12, 2021
@tacaswell
Copy link
Member Author

This was reported to me via private channels as a fatal "application won't start issue".

# as the current working directory do not fail to import.
yield os.path.join(os.getcwd(), 'matplotlibrc')
except FileNotFoundError:
pass
Copy link
Member

Choose a reason for hiding this comment

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

I think I'd feel better if a log message was emitted. People may be wondering why their matplotlibrc file isn't getting picked up.

Copy link
Contributor

Choose a reason for hiding this comment

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

what matplotlibrc? $cwd already doesn't exist, so $cwd/matplotlibrc certainly doesn't either?

Copy link
Contributor
@anntzer anntzer Feb 13, 2021

Choose a reason for hiding this comment

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

Also, it may be easier to just return a relative path here (return "matplotlibrc") and then absolutize it at exit (if os.path.exists(fname) and not os.path.isdir(fname): return os.path.abspath(fname)), which would avoid the exception-checking and also absolutize something set from $MATPLOTLIBRC (well, I'm not sure we ever detailed the semantics of relative-path $MATPLOTLIBRC...)

Copy link
Member

Choose a reason for hiding this comment

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

@anntzer, I am referring to a hypothetical matplotlibrc file that could have been in the cwd(), but is no longer there because the user didn't realize that they are running matplotlib in a directory that has been removed (an extension on the scenario described by @tacaswell). A log message here could provide a useful breadcrumb for a user to come to this realization. The use of relative paths as you'd suggested would actually paper over this problem and make it harder for a user to realize what is going on.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I follow. The same case would apply to a hypothetical matplotlibrc that's in ~/.config/matplotlib/matplotlibrc and that somehow got deleted before you import matplotlib; we don't warn in that case either (i.e. if there's no ~/.config/matplotlib/matplotlibrc, or ~/.config/matplotlib for that matter).

Copy link
Member Author

Choose a reason for hiding this comment

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

If we go this route I don't think we need to abspath it. These paths go to open in very short order we can let it take care of relative paths.

@WeatherGod I'm with @anntzer here, unless we warn when we don't find a local matplotlibrc (but with the folder existing) I don't think we should warn when we do not find a local matplotlibrc (because $cwd does not exist).

timhoffm
timhoffm previously approved these changes Feb 15, 2021
Copy link
Member
@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

Following @anntzer's argument, I agree that a warning is not necessary.

This is the only place that we directly access the cwd in the main
library.
@tacaswell
Copy link
Member Author

Went with the simpler approach (rather than catching FileNotFound from os.getcwd().

Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
@anntzer
Copy link
Contributor
anntzer commented Feb 17, 2021

I'll let @QuLogic decide whether this should be 3.4.0 or 3.4.1.

@QuLogic QuLogic closed this Feb 17, 2021
@QuLogic QuLogic reopened this Feb 17, 2021
@QuLogic QuLogic modified the milestones: v3.4.1, v3.4.0 Feb 17, 2021
@QuLogic QuLogic merged commit 08179da into matplotlib:master Feb 17, 2021
@tacaswell tacaswell deleted the fix_no_cwd branch February 18, 2021 01:32
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.

5 participants
0