Speed up wcsaxes import by avoiding unnecessary pytest import#10302
Speed up wcsaxes import by avoiding unnecessary pytest import#10302lpsinger wants to merge 1 commit intoastropy:mainfrom
Conversation
mhvk
left a comment
There was a problem hiding this comment.
Yes, this simply seems wrong. I'm confident enough to approve, but it would be good for @astrofrog to review, since he added it here.
|
@lpsinger - if you did notice other cases, and have time, definitely tell where or open other PRs. |
|
Unfortunately, the conftest.py doesn't work. I'm trying a few different strategies here. |
|
Might it work in |
|
Hmm, I think I'm starting to see the problem (never think @astrofrog did strange looking things for no reason..). But perhaps one can avoid loading Aside: |
|
p.s. I cancelled travis to save some cycles, since you wrote things didn't work. |
d0df5e6 to
4868eda
Compare
|
Hello @lpsinger 👋! It looks like you've made some changes in your pull request, so I've checked the code again for style. There are no PEP8 style issues with this pull request - thanks! 🎉 Comment last updated at 2020-05-04 21:18:18 UTC |
In `astropy.visualization.wcsaxes`, do not import pytest unless we are actually running the tests. Pytest is a fairly heavyweight import, so it should not be imported unless it's actually needed.
4868eda to
43fea65
Compare
|
|
||
| if tests.RUNNING: | ||
| import pytest | ||
| pytest.importorskip("matplotlib") |
There was a problem hiding this comment.
Wait a minute. Why is this even here? It should have been in the individual test modules under tests. Looks like we inherited this from the package we absorbed in #5496. @astrofrog , do you remember why this is at subpackage init level and not the tests?
There was a problem hiding this comment.
I suspect that this is because wcsaxes is unique in Astropy in that it subclasses many different Matplotlib subclasses, and so the conditional imports of the kind in astropy.visualization.mpl_normalize were not appropriate:
try:
import matplotlib # pylint: disable=W0611
from matplotlib.colors import Normalize
from matplotlib import pyplot as plt
except ImportError:
class Normalize:
def __init__(self, *args, **kwargs):
raise ImportError('matplotlib is required in order to use this '
'class.')There was a problem hiding this comment.
I suppose it was a convenient way to make sure mpl is needed for the whole module and skip it at collection time at the earliest and quickest way possible. Fully agreed that it should not be used like this.
pllim
left a comment
There was a problem hiding this comment.
I have a feeling that this is not the correct solution. See my comment above. Thanks for bringing this to our attention!
|
@lpsinger - that feels too hacky, modifying some almost global state. I also worry that things like Also, which other modules have things like this? Maybe some of those can more easily be changed? Because you are definitely right that we should not be importing |
Happily, this is the only such module in Astropy itself. |
|
I feel like the more correct solution would be something like #10260 but it is a lot more work and is borderline controversial to some people. I mean, if we make |
|
Agree with the sentiment, though there are lots of modules here which use it, and having the whole module indented becomes a bit much! But perhaps there are cleverer solutions? |
|
Well, in the PR for |
|
Hi humans 👋 - this pull request hasn't had any new commits for approximately 5 months. I plan to close this in a month if the pull request doesn't have any new commits by then. In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock. If you believe I commented on this pull request incorrectly, please report this here. |
|
I see that this has been re-milestoned several times. Would you like me to rebase it? |
|
@lpsinger , thanks for pinging us. Personally, I am not convinced that this is the correct solution. It is weird that the |
|
I wonder if we could use Line 145 in ba283e7 |
|
FWIW, I tried putting the |
Just tried that. Didn't work. |
|
What about moving |
That would not work. The import errors occur during collection, not while running the tests. |
Ah, right, that rings a faraway bell now. Sigh... How does |
|
Hi humans 👋 - this pull request hasn't had any new commits for approximately 1 year, 4 months. I plan to close this in 30 days if the pull request doesn't have any new commits by then. In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary. If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock. If you believe I commented on this pull request incorrectly, please report this here. |
|
I'm going to close this pull request as per my previous message. If you think what is being added/fixed here is still important, please remember to open an issue to keep track of it. Thanks! If this is the first time I am commenting on this issue, or if you believe I closed this issue incorrectly, please report this here. |
In
astropy.visualization.wcsaxes, do not import pytest unless we are actually running the tests. Pytest is a fairly heavyweight import, so it should not be imported unless it's actually needed.