-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use setuptools instead of distutils #100
Conversation
setup.py
Outdated
from numpy.distutils.system_info import default_include_dirs, default_lib_dirs | ||
|
||
from distutils.sysconfig import get_config_vars | ||
|
||
default_include_dirs = [] | ||
default_lib_dirs = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@deinst presumably something better needs to go here but I'm not sure what. I think that you said you worked out some code for this...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ive spent a bit of time rummaging about in the numpy.distutils code to see what it does to fill the default_*_dirs variables. The above works for me, but that is because I keep my flint in a non standard place and need to supply the directory to setup.py.
On the unix/osx side, this is easy, just make a list of the usual suspects, and filter out the ones that don't exist. On the windows side things are more complicated and I'm working on figuring out what is needed.
I believe you still need get config_vars
for the python dirs, but you can get it from sysconfig
instead of distutils.sysconfig
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you still need get
config_vars
for the python dirs, but you can get it fromsysconfig
instead ofdistutils.sysconfig
In the version of setup.py on master this is only used to set the OPT
environment variable:
Lines 38 to 39 in 2fd4fd6
(opt,) = get_config_vars('OPT') | |
os.environ['OPT'] = " ".join(flag for flag in opt.split() if flag != '-Wstrict-prototypes') |
What uses that environment variable?
The value I have locally on Linux is:
In [4]: from distutils.sysconfig import get_config_vars
In [5]: get_config_vars('OPT')
Out[5]: ['-DNDEBUG -g -fwrapv -O3 -Wall']
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand it OPT
supplies default options to gcc. All setup.py does is removes -Wstrict-prototypes
from it. Considering the number of compiler warnings already generated, it seems that filtering out -Wstrict_prototypes
is probably not particularly helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With Python 3.12 I have:
In [2]: from sysconfig import get_config_vars
In [3]: get_config_vars('OPT')
Out[3]: ['-DNDEBUG -g -O3 -Wall']
Either way there does not seem to be any -Wstrict-prototypes
.
Probably that can be removed but I'll leave it there for now while getting the main problems fixed.
I think I might have get the setup.py working for all Python version or OS combinations. Fingers crossed that the Windows build is about to succeed in CI...
The only thing currently missing is default_include_dirs
and default_lib_dirs
but I'm not sure why we should need to get those anyway. I would have thought that it was setuptools job to handle the default dirs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If setuptools can get the directories correctly that is great. If not, I think I have gotten the requisite code from numpy.distutils.system_info to generate the default paths. I have only a foggy notion of exactly what the windows code is doing as things like vcpkg
are inovations that postdate my working on code for windows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I have gotten the requisite code from numpy.distutils.system_info to generate the default paths.
I think let's get this PR in for now because it at least means we have CI built wheels for 3.12 and that building a development checkout for 3.12 now works.
We can follow up with another PR for generating the paths. I don't know whether there is actually a reason for doing something other than just trusting setuptools to do it for us though.
Longer term if we can move to meson and meson-python then they should take care of default paths and library discovery etc so in principle it should not be a concern for us.
Everything here seems to be working here except Windows. One of the things that I worried about with using setuptools is that its support for mingw is supposedly not as good as numpy.distutils and mingw is used for building the Windows wheels. The build failure on Windows is:
Those exact errors are reported as a general Cython+mingw issue here: The comments here indicate that mingw support in setuptools has improved: cython/cython#4470 (comment). Apparently though it is still necessary to apply a patch to CPython's header files for Python < 3.12. We don't see this working for 3.12 working here because it fails building the 3.9 wheel before attempting the 3.12 wheel. I'm going to push a commit that only builds 3.12 wheels to see if at least that works. |
It does work so what works is:
What does not work is:
To build with setuptools we would apparently need to apply this patch to CPython: diff --git a/PC/pyconfig.h b/PC/pyconfig.h
index 1a33d4c5a1e4f..1d8408b363a66 100644
--- a/PC/pyconfig.h
+++ b/PC/pyconfig.h
@@ -209,6 +209,16 @@ typedef int pid_t;
#endif /* _MSC_VER */
+/* ------------------------------------------------------------------------*/
+/* mingw and mingw-w64 define __MINGW32__ */
+#ifdef __MINGW32__
+
+#ifdef _WIN64
+#define MS_WIN64
+#endif
+
+#endif /* __MINGW32__*/
+
/* ------------------------------------------------------------------------*/
/* egcs/gnu-win32 defines __GNUC__ and _WIN32 */
#if defined(__GNUC__) && defined(_WIN32) I am more tempted though just to add some Python-version logic to setup.py. We have a setup that has been working for Python < 3.12 and I think I have just found a setup that works for Python 3.12 at least for development builds and for building wheels in CI. Not having the default paths added in setup.py is a problem but at least being able to build at all on Python 3.12 is an improvement. This check passes in CI so it at least seems to pick up Flint in python-flint/bin/pip_install_ubuntu.sh Lines 24 to 56 in 2fd4fd6
|
So it is working for all Python versions and for Windows as well as OSX and Linux. Note that the |
I think this has to be merged before Cirrus CI will start generating 3.12 wheels for OSX ARM64. I think everything else is working here now so I'll merge and then see what CI does on the merge build. |
Partial (short term) fix for gh-52
Uses setuptools instead of distutils.