finufft icon indicating copy to clipboard operation
finufft copied to clipboard

First attempt at cross-python wheel

Open janden opened this issue 1 year ago • 13 comments

Following https://github.com/joerick/python-ctypes-package-sample/blob/main/setup.py.

janden avatar Dec 19 '23 21:12 janden

@blackwer Still getting different wheels on this one for the same platform. Let me know if you have any ideas.

janden avatar Dec 19 '23 22:12 janden

@blackwer Still getting different wheels on this one for the same platform. Let me know if you have any ideas.

just a typo, cmd_class should be cmdclass

lu1and10 avatar Dec 19 '23 23:12 lu1and10

feel free to grab the CI changes from https://github.com/flatironinstitute/finufft/pull/394/files -- they get rid of the other pythons etc.

blackwer avatar Dec 19 '23 23:12 blackwer

just a typo, cmd_class should be cmdclass

That's embarrassing. Thanks for catching.

janden avatar Dec 21 '23 22:12 janden

just a typo, cmd_class should be cmdclass

That's embarrassing. Thanks for catching.

I always make typos, Robert fixed it. Now failing on win, I find https://github.com/mxschmitt/action-tmate useful to debug ci. If the ci fails you can ssh onto the runner and debug by adding following lines to ci yml.

    - name: Setup tmate session
      if: ${{ failure() }}
      uses: mxschmitt/action-tmate@v3

lu1and10 avatar Dec 21 '23 22:12 lu1and10

I suspect the windows failure is from the CTypesExtension and build_ext changes. These override get_export_symbols to make it so that PyInit_ModuleName is no longer a required export symbol.

This would allow Windows to link the extension without the stub for that function, but it also prevents the module from being imported with importlib which seems to be used to find the path to the shared library.

These aren't really needed for the cross-py wheels, only the bdist_wheel_abi_none function is

WardBrian avatar Dec 22 '23 02:12 WardBrian

I suspect the windows failure is from the CTypesExtension and build_ext changes. These override get_export_symbols to make it so that PyInit_ModuleName is no longer a required export symbol.

This would allow Windows to link the extension without the stub for that function, but it also prevents the module from being imported with importlib which seems to be used to find the path to the shared library.

These aren't really needed for the cross-py wheels, only the bdist_wheel_abi_none function is

The importlib can not recognize .so on windows, I tried .pyd for windows, it seems to work.

    def get_ext_filename(self, ext_name):
        if self._ctypes:
            if platform.system() != "Windows":
                return ext_name + ".so"
            else:
                return ext_name + ".pyd"
        return super().get_ext_filename(ext_name)

lu1and10 avatar Dec 22 '23 04:12 lu1and10

That would work, but I think you can still just remove the CtypesExtension class and extra logic, it is not really buying you anything here. The intention of the class is to unify the file extension and remove the need to make the library importable, but if you're still going to make it importable and customize the file extension back to being platform specific it's not necessary to have

WardBrian avatar Dec 22 '23 13:12 WardBrian

That would work, but I think you can still just remove the CtypesExtension class and extra logic, it is not really buying you anything here. The intention of the class is to unify the file extension and remove the need to make the library importable, but if you're still going to make it importable and customize the file extension back to being platform specific it's not necessary to have

Yes, it wouldn't be platform portable. Maybe I miss something, adding the ctypesextension makes just one wheel and one extension binary for all python3.8...3.12 on windows, without the get_ext_filename, it generates finufftc.cp3*-win_amd64.pyd for each python version, with the logic we get one finufftc.pyd and only one wheel for all versions. I guess this PR intends to make python version portable wheel/extension on each platform...

lu1and10 avatar Dec 22 '23 14:12 lu1and10

The wheels being generic for any Python version is provided by bdist_wheel_abi_none, not the CtypesExtension

WardBrian avatar Dec 22 '23 14:12 WardBrian

The wheels being generic for any Python version is provided by bdist_wheel_abi_none, not the CtypesExtension

Yes, the wheel name is by bdist_wheel_abi_none, so we get finufft-2.2.0b0-py3-none-win_amd64.whl, inside the wheel there is a binary extension file finufftc.pyd if with the overided get_ext_filename. Without the overided get_ext_filename, using python 3.9, we get same wheel name finufft-2.2.0b0-py3-none-win_amd64.whl, but the inside binary extension name is finufftc.cp39-win_amd64.pyd, python3.10 can install the wheel, probably will search for finufftc.cp310-win_amd64.pyd and won't recognize finufftc.cp39-win_amd64.pyd, I remember encountered such issue before, may be I'm wrong....

lu1and10 avatar Dec 22 '23 15:12 lu1and10

Ah, I understand. You could of course avoid having to import the library at all and locate it without importlib, but at that point you might as well avoid using Extension for any part of the build (which I think is something @blackwer wants anyway?)

WardBrian avatar Dec 22 '23 20:12 WardBrian

Ah, I understand. You could of course avoid having to import the library at all and locate it without importlib, but at that point you might as well avoid using Extension for any part of the build (which I think is something @blackwer wants anyway?)

Yes, that’s Robert PR #394, shipping the finufft c++ lib as package data so no module extension built, no ctypeextension class needed. If we use PR #394, I guess this PR may not be merged.

lu1and10 avatar Dec 22 '23 21:12 lu1and10

Superseded by #429.

janden avatar Jul 12 '24 11:07 janden