Repository navigation
Fixes to new convolution code - #8035
Conversation
|
Hi there @astrofrog 👋 - thanks for the pull request! I'm just a friendly 🤖 that checks for issues related to the changelog and making sure that this pull request is milestoned and labeled correctly. This is mainly intended for the maintainers, so if you are not a maintainer you can ignore this, and a maintainer will let you know if any action is required on your part 😃. Everything looks good from my point of view! 👍 If there are any issues with this message, please report them here. |
|
From a glance, it seems like there is no "slow Python" fallback if C-extension fails to build? Perhaps a future PR, but is it possible to have that C-extension as optional at all? That is, will some of the convolution functions still run without a C-extension? |
|
@astrofrog Thanks for making the changes.
No, it's always been dependent on the C extension.
Does anything else in Astropy use optional extensions like this? Also, have a missed something, why has this PR (and/or #8032) have anything to do with the extension having build issues? |
|
@jamienoss - the issue wasn't fundamentally related to the convolution changes, it's just that the way the convolution code now looks for the extension means that @bsipocz got a cryptic error about glob rather than simply having an import of the C extension fail. |
|
This is a bit over my head. I don't want to "approve" it because I don't really know what's going on. Can someone else review more usefully? |
| if sys.platform.startswith('win'): | ||
| libConvolve = ctypes.windll.LoadLibrary(lib_path) | ||
| lib_paths = glob.glob(os.path.join(os.path.dirname(__file__), 'lib_convolve*')) | ||
| if len(lib_paths) > 0: |
There was a problem hiding this comment.
lib_paths is a list, isn't if lib_paths preferred?
There was a problem hiding this comment.
Both work and I don't think it matters which one we use here.
4de4f28 to
c61527d
Compare
| libConvolve = ctypes.windll.LoadLibrary(lib_path) | ||
| lib_paths = glob.glob(os.path.join(os.path.dirname(__file__), 'lib_convolve*')) | ||
| if len(lib_paths) > 0: | ||
| if sys.platform.startswith('win'): |
There was a problem hiding this comment.
Think we need something like:
...
#Search for library
lib_paths = glob.glob(os.path.join(root, 'lib_convolve*'))
lib_path =''
for path in lib_paths:
if not path.endswith('.py'):
lib_path = path
break
if not lib_path:
raise Exception("Compiled convolution code is missing, try re-building astropy")
#Load found library
if sys.platform.startswith('win'):
libConvolve = ctypes.windll.LoadLibrary(lib_path)
else:
libConvolve = ctypes.cdll.LoadLibrary(lib_path)
...There was a problem hiding this comment.
I think the exclusion soln. might be better than trying to be explicit for different OS lib suffixes. Neither are pleasant. Any thoughts anyone?
There was a problem hiding this comment.
or
...
lib_paths = glob.glob(os.path.join(root, 'lib_convolve*'))
filtered_lib_paths = [path for path in lib_paths if not path.endswith('.py')]
if not filtered_lib_paths:
raise Exception("Compiled convolution code is missing, try re-building astropy")
# Use the 1st found
lib_path = filtered_lib_paths[0]
#Load found library
if sys.platform.startswith('win'):
libConvolve = ctypes.windll.LoadLibrary(lib_path)
else:
libConvolve = ctypes.cdll.LoadLibrary(lib_path)
...There was a problem hiding this comment.
We can raise on if len(filtered_lib_paths) > 1?
There was a problem hiding this comment.
What about .pyc files? We should make sure we include any kind of similar files. Any other extensions to exclude?
There was a problem hiding this comment.
Not that endswith can semantically handle *.
There was a problem hiding this comment.
pyc
pyo
pyx
pxd
pyd (checking now...) This is the suffix for the windows built library.
There was a problem hiding this comment.
Should it just go straight into the glob, instead?
There was a problem hiding this comment.
Actually, I'm not sure if .pyd would kill the windows usage...?
There was a problem hiding this comment.
Yep, we can't include .pyd in the exclusion list as this is what the the windows build produces.
|
Interesting CircleCI failure -- probably not related? |
|
@pllim it's not related. |
|
|
7062701 to
c61527d
Compare
|
Numpy has a function to load libraries with ctypes, taking care of the cross-platform differences ( |
|
@saimn That sounds awesome! Thanks for the intel. I'll take it for a quick spin on windows tomorrow, but I imagine it works great, probably by design definition. It explicitly solves the lib ext issue that we're having here.
|
| LIBRARY_PATH = os.path.dirname(__file__) | ||
|
|
||
| try: | ||
| lib_convolve = load_library("lib_convolve", LIBRARY_PATH) |
|
This is okay to merge when you think it is ready. Thanks! |
|
@astrofrog I opened #8050, just an FYI incase you felt it necessary to add the test to this PR. |
|
@astrofrog I tested this on windows and it works as it should. Sorry, I wasn't sure what you dev on and it was quick enough for me to test. |
|
I'll merge this for now, I don't have time to figure out a test, but if you do please open a PR! |
|
Thanks again @saimn, nicely saved. |
Fixes to new convolution code
|
@pllim Would you mind quickly adding the |
This fixes #8032
If developers updated to the latest master version of astropy and were in develop mode, and did not rebuild extensions, they would get:
so this PR makes the error message cleaner. For anyone curious, you can reproduce this error with:
Secondly it seems that importing faulthandler doesn't always work (see #8032) - so we should just not import it by default (it's easy for developers to import it in test scripts they are using, or in pytest using pytest-faulthandler).
cc @jamienoss