Repository navigation
Refactor optional dependency checking - #11490
Conversation
taldcroft
left a comment
There was a problem hiding this comment.
Nice! Just a couple of comments on the actual code (I didn't review the rest pending one of my comments to use upper case).
910cf6b to
22f5c26
Compare
taldcroft
left a comment
There was a problem hiding this comment.
Looks great, I went through the whole list and didn't see any problems. The only thing left are the docs: https://docs.astropy.org/en/stable/development/testguide.html#tests-requiring-optional-dependencies
|
Great, thanks @taldcroft for having the patience to look through all of the changes! I updated the docs, but currently |
taldcroft
left a comment
There was a problem hiding this comment.
Looks good from my perspective, thanks!!
|
Hm, did RTD fail because I used [ci skip]? Maybe @pllim knows? |
|
RTD failure might be transient... try another push (forced or not) |
|
Just thinking that if we are going to change things around, doing it once only might be better... But agreed that it really is out of scope and we might as well stick with this nice improvement! After all, it is not as if this precludes the scheme I suggested. |
5929e85 to
621b32a
Compare
|
OK, just made a small change based on a suggestion from @mhvk - assuming the relevant tests pass, I think this is ready! |
pllim
left a comment
There was a problem hiding this comment.
This is great! Certainly seems more sane than before.
Just curious: Did you time the astropy import to make sure this does not have bad performance side effects? Sometimes we get complains that importing astropy is too slow as it is.
Some minor comments below.
| import yaml # noqa | ||
| HAS_YAML = True | ||
| except ImportError: | ||
| HAS_YAML = False |
There was a problem hiding this comment.
Hmm... What was the original purpose of this import? Was it to let people use astropy.io.ascii.ui.HAS_YAML?
There was a problem hiding this comment.
It's not documented anywhere that I could find as public API -- possible vestigial?
| from astropy.utils.compat.optional_deps import HAS_SORTEDCONTAINERS | ||
|
|
||
| try: | ||
| if HAS_SORTEDCONTAINERS: |
There was a problem hiding this comment.
Will renaming HAS_SOCO to HAS_SORTEDCONTAINERS break anything downstream? Maybe @taldcroft knows.
There was a problem hiding this comment.
I don't think these things were ever exposed as public API... Also don't see any reference to this in docs. Also don't see any uses of this in other github projects https://github.com/search?p=1&q=HAS_SOCO&type=Code
| test if the dependencies are not present. The following example shows | ||
| how this should be done:: | ||
| For tests that test functions or methods that require optional dependencies | ||
| (e.g. Scipy), pytest should be instructed to skip the test if the dependencies |
There was a problem hiding this comment.
Nitpick.
| (e.g. Scipy), pytest should be instructed to skip the test if the dependencies | |
| (e.g., Scipy), pytest should be instructed to skip the test if the dependencies |
There was a problem hiding this comment.
OK, but I'm skipping CI on this!
| are not present, as the Astropy tests should succeed even if an optional | ||
| dependency is not present. Astropy provides a list of boolean flags that test |
There was a problem hiding this comment.
Capitalized "Astropy" is for the project, not the package.
| are not present, as the Astropy tests should succeed even if an optional | |
| dependency is not present. Astropy provides a list of boolean flags that test | |
| are not present, as the ``astropy`` tests should succeed even if an optional | |
| dependency is not present. ``astropy`` provides a list of boolean flags that test |
There was a problem hiding this comment.
Ah, yes, @lglattly should shake her finger at me :) -- skipping CI for this too...but I'll wait for the last Cron test to finish.
|
Failures in ppc64le and s390x look unrelated. Other tests (except link check) pass. I think it's overkill to run the cron tests again, and I have some doc changes to push from @pllim, so I will |
|
Well, I guess #11091 got merged, so never mind! |
|
Sorry... 😬 |
|
I don't think a rebase warrants more exotic tests, so I removed the |
…_ names separately
matplotlib.pyplot bleach bottleneck bs4 bz2 h5py preserve extreme laziness of imports in connect.py jplephem mpmath, some scipy pandas pkg_resources pytz scipy sortedcontainers yaml fix some accidentally removed imports one more removed import revert cased variable names using actual package names revert error message to standard attribute error oops, typo
621b32a to
5945357
Compare
pllim
left a comment
There was a problem hiding this comment.
I am still curious about the import timing though I don't expect anything shocking, so approving!
|
Wut...? I saw this error in a different PR too. @saimn , do you know what's going on? Maybe we should just merge #10877 and be done with it... |
|
Well, now |
|
That was the changes in the |
This PR centralizes the definition of
HAS_xoptional dependency package import checking, such asHAS_matplotlib. Now that astropy requires Python 3.7+, we can make use of lazy imports as implemented in PEP 0562 and as demonstrated by @pllim in this comment. This implementation is similar to what @pllim suggested, but with some extra flexibility to support flags that check subpackage imports that have different behavior than the top-level package import (e.g.,matplotlib.pyplot). The actual implementation is in the new fileastropy/utils/compat/optional_deps.pyand was added in the first two commits.I decided to go with using the actual package names in the flag names (e.g.,
HAS_matplotlibnotHAS_MATPLOTLIB) because there are cases where the case matters for a package name, likePILorIPython.This fixes #4630, and is relevant for a comment in #11361
cc @nstarman