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

Only import matplotlib when needed #48

Merged
merged 1 commit into from Dec 14, 2016
Merged

Only import matplotlib when needed #48

merged 1 commit into from Dec 14, 2016

Conversation

r-owen
Copy link
Contributor

@r-owen r-owen commented Dec 14, 2016

Some tests and one bit of library code were importing matplotlib
even if plotting was not requested. This could cause needless failures
(not to mention unwanted rebuilds of the font cache).
I standardized on only importing when plotting is specifically requested,
and the library code prints an error message and continues
(whereas the unit tests fail, a safe thing to do because they
do not normally plot anyway).

Copy link
Member

@timj timj left a comment

Choose a reason for hiding this comment

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

Comprehensive cleanup. Thank you. Have any of the tests been tried with plotting enabled to make sure they still work?

@r-owen
Copy link
Contributor Author

r-owen commented Dec 14, 2016

I have not yet tried the tests with plotting enabled but will do so before merging.

@r-owen
Copy link
Contributor Author

r-owen commented Dec 14, 2016

Good suggestion to test the plotting. Setting the back end to Agg in testFitTanSipWcsTask.py was useful because the plots are saved as pngs so I restored it. I found an error in testLoadAstrometryNetObjects.py's plotStars method and fixed that. )Of course all this plotting code is subject to bit rot since it is rarely used.)

Some tests and one bit of library code were importing matplotlib
even if plotting was not requested. This could cause needless failures
(not to mention unwanted rebuilds of the font cache).

I standardized the following:
- Only import matplotlib when plotting is specifically requested.
- Library code logs a warning and continues if importing matplotlib
  fails. One bit of code did that already, but printed a message
  to stderr instead of logging the message.
- Unit tests raise an exception if importing matplotlib fails.
  This is reasonable because you have to modify a test to make it plot.
- `import matplotlib.pyplot as plt`, as per our coding standards.
@r-owen
Copy link
Contributor Author

r-owen commented Dec 14, 2016

I also did what I could to test the plotting changes in the library code. Two of the three files apparently aren't being run by unit tests.

@ktlim ktlim deleted the tickets/DM-8656 branch August 25, 2018 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants