Skip to content

Ensure that NUMPY_LT_ constants are always defined - #3479

Merged
embray merged 2 commits into
astropy:masterfrom
embray:utils/minversion-2
Feb 11, 2015
Merged

embray merged 2 commits into
astropy:masterfrom
embray:utils/minversion-2

Conversation

@embray

@embray embray commented Feb 10, 2015

Copy link
Copy Markdown
Member

@mdboom -- does this fix #3478 for you?

of the module to check as a string, rather than the module itself.
If the module can't be imported minversion just returns False,
appropriately.  In the process also fixed a bug in resolve_name
so that it could import single modules.

Updated the numpycompat.py module so that the NUMPY_LT_ constants
are always defined, even though they might return False if Numpy
wasn't available upon initial import.  This is fine so long as they
don't need to have any particular value during setup of Astropy
itself.
@embray embray added Affects-dev PRs and issues that do not impact an existing Astropy release Bug utils build labels Feb 10, 2015
@embray

embray commented Feb 10, 2015

Copy link
Copy Markdown
Member Author

Uhh...aside from the test failures, that I didn't see locally for some reason.

@embray

embray commented Feb 10, 2015

Copy link
Copy Markdown
Member Author

Oh I see, they're only on Python 2.

@embray
embray force-pushed the utils/minversion-2 branch from 95f6e78 to ef6446d Compare February 10, 2015 23:44
@embray

embray commented Feb 10, 2015

Copy link
Copy Markdown
Member Author

Oops, last version of this had a totally goofed typo. Pushed an updated version that should work.

@eteq

eteq commented Feb 11, 2015

Copy link
Copy Markdown
Member

@embray - I just tried it now in master vs. this PR, and I can confirm that this fixes #3478 . Or at least, pyasdf refuses to build before this, and succeeds after (if I undo the change @mdboom used to fix it, in pyadsf, that is).

So if appveyor passes (travis already has) I'll merge and backport this.

@astrofrog astrofrog added this to the v1.0.0 milestone Feb 11, 2015
@astrofrog

Copy link
Copy Markdown
Member

👍

@mdboom

mdboom commented Feb 11, 2015

Copy link
Copy Markdown
Contributor

👍

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See my comment in #3478 - I do think you should let the import error be raised. If some package needs it in their setup, then the import error should actually happen. Note that this should never be a problem: before we just imported numpy during setup as well to construct the various NUMPY_LT_... strings.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I disagree--that's not really what the purpose of this function was. If someone needs to actually test that a module can be imported the current solution is to use an explicit import statement.

At some point I think there would still be value in having some sort of optional dependency manager a la #63. The scope of this function is intentionally very limited.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In other words, this should not be a replacement for

try:
    import scipy
    HAS_SCIPY = True
except ImportError:
    HAS_SCIPY = False

it's explicitly limited to just this case of checking for a specific minimum version of a package independent of whether any version of the package is available.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The problem is that with this function, say, NUMPY_LT_1_9 will be True is numpy is not present. It wouldn't seem this function's business to decide what should happen on an import error.

I guess I'm not sure, though, why you do the try/except at all. Is that necessary to resolve a problem? I ask mostly because I cannot see how whatever is resolved could have worked before, where numpy had to be imported just as much. (I do see why you need the string name, as this avoids importing numpy before the test is actually needed, but when the test has to be done, I don't see why you would hide the possible absence of numpy, surely something else will break too).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's just so that I can define these constants regardless of whether Numpy is installed or not. I see what you're saying about NUMPY_LT_1_9 being True being confusing though. I think that's more a problem with the naming of that constant. In any case that only becomes an issue in cases where Numpy is actually not working, and that would be caught in the actual import statements well before the values of those constants matter.

It might be less of an issue if they were named more in accordance with the semantics of minversion. So instead of NUMPY_LT_1_9 have NUMPY_AT_LEAST_1_9 and so on. I just wanted to keep the number of changes at a minimum.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1 to that, we should be using NUMPY_GE_1.9 for example

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There are some cases where even this isn't quite right. For example, say there's a bug in Numpy 1.8.x (all versions) but it's fixed in Numpy 1.9.0.dev1234567. Then what we really want, to check for that bug, is specifically not minversion(numpy, '1.9.0.dev1234567') :( So even still this is just a first approximation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

right, I think we don't want to go overboard with the NUMPY_GT_1_6_BUT_LE_1_8_1_AND_ALSO_I_WANT_RASPBERRY_ICE_CREAM constants. If it's not a common case just using minversion directly makes more sense.

embray added a commit that referenced this pull request Feb 11, 2015
Ensure that NUMPY_LT_ constants are always defined
@embray
embray merged commit 80ab5c9 into astropy:master Feb 11, 2015
@embray
embray deleted the utils/minversion-2 branch February 11, 2015 15:39
embray added a commit that referenced this pull request Feb 11, 2015
Ensure that NUMPY_LT_ constants are always defined
@eteq

eteq commented Feb 11, 2015

Copy link
Copy Markdown
Member

backported to 1.0.x in e332643

@embray embray mentioned this pull request Mar 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Affects-dev PRs and issues that do not impact an existing Astropy release Bug build utils

Projects

None yet

Development

Successfully merging this pull request may close these issues.

#3389 breaks an affiliated package

5 participants