classification
Title: Add `has_flag` method to `distutils.CCompiler`
Type: enhancement Stage: resolved
Components: Distutils Versions: Python 3.6
process
Status: closed Resolution: out of date
Dependencies: 25544 Superseder:
Assigned To: dstufft Nosy List: James.Tatum, SilentGhost, berker.peksag, dstufft, eric.araujo, ned.deily, steve.dower, sylvain.corlay
Priority: normal Keywords: patch

Created on 2016-04-03 00:31 by sylvain.corlay, last changed 2021-02-03 18:21 by steve.dower. This issue is now closed.

Files
File name Uploaded Description Edit
has_flag.diff sylvain.corlay, 2016-04-03 01:30 review
has_flag.diff sylvain.corlay, 2016-04-04 04:29 review
has_flag.diff sylvain.corlay, 2016-04-04 19:10 review
Messages (18)
msg262805 - (view) Author: Sylvain Corlay (sylvain.corlay) * Date: 2016-04-03 00:31
I would be very useful to have a `has_flag` method in `distutils.CCompiler` similar to `has_function`, allowing to check if the compiler supports certain flags.

Cmake has a `CHECK_CXX_COMPILER_FLAG` macro for that purpose, which checks if a simple C++ file compiles with the said flag.
msg262808 - (view) Author: Sylvain Corlay (sylvain.corlay) * Date: 2016-04-03 01:30
I attached a patch for ccompiler.py adding the new `has_flag` method.
msg262821 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2016-04-03 10:19
I've left a comment on Rietveld
msg262843 - (view) Author: Sylvain Corlay (sylvain.corlay) * Date: 2016-04-04 04:29
New version of the patch using the context manager.
msg262851 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2016-04-04 10:01
I understand that you're copying approach of has_function, but shouldn't you remove this temporary file at the end of the function? Perhaps using tempfile.NamedTemporaryFile would be a better solution (both in has_flag and has_function). Also import can be moved to the top level, since it's used in more than one method.
msg262853 - (view) Author: Sylvain Corlay (sylvain.corlay) * Date: 2016-04-04 16:35
@minrk submitted http://bugs.python.org/file40933/0001-cleanup-temporary-files-in-ccompiler.has_function.patch
doing what you describe for `has_function`. 

I don't know much about the process to contribute to cpython. I would be glad to open a "PR" incorporating Min's commits too.
msg262855 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2016-04-04 17:00
I guess it would make sense to depend on issue25544 and implement the has_flag with minrk's patch in mind. I guess his patch didn't get a second look because it didn't apply cleanly.

In any case, for implementing has_flag using current best practice is what I'd recommend.
msg262863 - (view) Author: Sylvain Corlay (sylvain.corlay) * Date: 2016-04-04 19:10
A new version of the patch using `NamedTemporaryFile` instead a the regular fdopen.
msg262927 - (view) Author: Sylvain Corlay (sylvain.corlay) * Date: 2016-04-06 00:52
Are you fine with the new state of the patch?
msg262942 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2016-04-06 11:15
I'm largely fine with it, bar the in-function import. It would also be good if you could verify that no other temporary files are left after the function is run.

As I said earlier, issue 25544 should have priority and it should get a refreshed patch soon.

Donald, I'm assigning issue to you since you're maintaining this module.
msg263932 - (view) Author: Sylvain Corlay (sylvain.corlay) * Date: 2016-04-21 19:17
Hey, any blocker to getting this in?
msg265183 - (view) Author: James Tatum (James.Tatum) * Date: 2016-05-09 04:21
FYI, NamedTemporaryFile doesn't work well with Windows. There are a handful of issues about it.
msg273062 - (view) Author: Sylvain Corlay (sylvain.corlay) * Date: 2016-08-18 19:34
Any chance to get this in for 3.6?
msg273152 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2016-08-19 18:45
Sylvain, have you brought this feature request up on the Distutils mailing list?  The PyPA there is responsible for packaging features.  One big issue with adding new features to Distutils is the backwards-compatibility tradeoff: many third-party package authors want to support their distributions on multiple Python versions which is one of the reasons why we are generally very cautious about changing or even adding APIs to Distutils at this point in its life.

https://mail.python.org/mailman/listinfo/distutils-sig
msg273157 - (view) Author: Sylvain Corlay (sylvain.corlay) * Date: 2016-08-19 19:59
Thanks Ned. I posted a couple of messages on distutils-sig and got little attention.

I think that this feature is very important for detecting whether a compiler supports a certain flag like `-std=c++11` and provide a meaningful error when needed.

CMake has the same feature, implemented in a similar fashion (CHECK_CXX_COMPILER_FLAG).
msg273162 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2016-08-19 22:42
"I posted a couple of messages on distutils-sig and got little attention."

OK, for future reference, the start of the discussion was here:

https://mail.python.org/pipermail/distutils-sig/2016-May/029010.html

It looks like the first item, the one relative to this issue, got lost in the discussion of the second item.  I'm attempting to (re-)start the discussion there (my post may be awaiting moderation).
msg273181 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2016-08-20 01:45
https://mail.python.org/pipermail/distutils-sig/2016-August/029469.html
msg386366 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2021-02-03 18:21
Distutils is now deprecated (see PEP 632) and all tagged issues are being closed. From now until removal, only release blocking issues will be considered for distutils.

If this issue does not relate to distutils, please remove the component and reopen it. If you believe it still requires a fix, most likely the issue should be re-reported at https://github.com/pypa/setuptools
History
Date User Action Args
2021-02-03 18:21:48steve.dowersetstatus: open -> closed

nosy: + steve.dower
messages: + msg386366

resolution: out of date
stage: patch review -> resolved
2016-08-20 01:45:18ned.deilysetmessages: + msg273181
2016-08-19 22:42:26ned.deilysetmessages: + msg273162
2016-08-19 19:59:24sylvain.corlaysetmessages: + msg273157
2016-08-19 18:45:13ned.deilysetnosy: + ned.deily
messages: + msg273152
2016-08-19 08:44:00berker.peksagsetnosy: + berker.peksag
stage: commit review -> patch review

versions: - Python 2.7
2016-08-18 19:34:40sylvain.corlaysetmessages: + msg273062
2016-05-09 04:21:38James.Tatumsetnosy: + James.Tatum
messages: + msg265183
2016-04-21 19:17:04sylvain.corlaysetmessages: + msg263932
2016-04-06 11:17:04SilentGhostsetstatus: pending -> open
2016-04-06 11:15:28SilentGhostsetstatus: open -> pending
assignee: dstufft
messages: + msg262942

stage: patch review -> commit review
2016-04-06 00:52:16sylvain.corlaysetmessages: + msg262927
2016-04-04 19:10:10sylvain.corlaysetfiles: + has_flag.diff

messages: + msg262863
2016-04-04 17:00:56SilentGhostsetdependencies: + cleanup temporary files in distutils.has_function
messages: + msg262855
2016-04-04 16:35:30sylvain.corlaysetmessages: + msg262853
2016-04-04 10:01:25SilentGhostsetmessages: + msg262851
2016-04-04 04:29:58sylvain.corlaysetfiles: + has_flag.diff

messages: + msg262843
2016-04-03 10:19:55SilentGhostsetnosy: + SilentGhost
messages: + msg262821
2016-04-03 06:11:01SilentGhostsetstage: patch review
versions: - Python 3.2, Python 3.3, Python 3.4, Python 3.5
2016-04-03 01:30:09sylvain.corlaysetfiles: + has_flag.diff
keywords: + patch
messages: + msg262808
2016-04-03 00:31:21sylvain.corlaycreate