Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: Fix a MacOS build failure #17906

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

Merged
merged 1 commit into from
Dec 12, 2020
Merged

BUG: Fix a MacOS build failure #17906

merged 1 commit into from
Dec 12, 2020

Conversation

fxcoudert
Copy link
Contributor

numpy fails to build on macOS Big Sur, on a Python 3.9.0 that was configured with MACOSX_DEPLOYMENT_TARGET=11:

    File "/private/var/folders/kf/25msxpx52j98k6qm2pgq11rh0000gn/T/pip-req-build-zkhrmwam/numpy/distutils/fcompiler/gnu.py", line 346, in get_flags_linker_so
      flags = GnuFCompiler.get_flags_linker_so(self)
    File "/private/var/folders/kf/25msxpx52j98k6qm2pgq11rh0000gn/T/pip-req-build-zkhrmwam/numpy/distutils/fcompiler/gnu.py", line 136, in get_flags_linker_so
      os.environ['MACOSX_DEPLOYMENT_TARGET'] = target
    File "/usr/local/Cellar/[email protected]/3.9.0_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/os.py", line 684, in __setitem__
      value = self.encodevalue(value)
    File "/usr/local/Cellar/[email protected]/3.9.0_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/os.py", line 756, in encode
      raise TypeError("str expected, not %s" % type(value).__name__)
  TypeError: str expected, not int

On such a system, sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') will return 11 as an int, not as a str. And setting an environment variable to an int is not allowed, and fails as seen above.

@eric-wieser
Copy link
Member

eric-wieser commented Dec 3, 2020

On such a system, sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') will return 11 as an int, not as a str.

Is it supposed to do this? This seems like an accidental breaking change in python that may need addressing upstream.

@fxcoudert
Copy link
Contributor Author

See python/cpython#23556 and https://bugs.python.org/issue42504
The intent of sysconfig.get_config_var() is pretty clear: see the code for parse_config_h at https://github.com/python/cpython/blob/master/Lib/sysconfig.py#L461

@charris charris changed the title Update gnu.py MAINT: Update gnu.py Dec 4, 2020
@luketaverne
Copy link

Just wanted to +1 this, as I've just run into this myself.

@mattip
Copy link
Member

mattip commented Dec 9, 2020

Although as you point out the intent may have been clear when reading the code, it was not clear to CPython devs (hence the need for a fix in other places in the code) nor to anyone else using sysconfig (like us), nor is it documented behaviour. This seems like one bad API choice following another.

@fxcoudert
Copy link
Contributor Author

nor is it documented behaviour

From the documentation you link:

>>> import sysconfig
>>> sysconfig.get_config_var('Py_ENABLE_SHARED')
0

It is clear that int-type values are returned as int.

@luketaverne
Copy link

I quickly tried it out on a 10.14.6 (Mojave) MBP and got the following results:

>>> sysconfig.get_config_var('Py_ENABLE_SHARED')
0
>>> sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
'10.14'

So at some point it did return a string. I get 11 as an int on Big Sur.

@fxcoudert
Copy link
Contributor Author

So at some point it did return a string.

It returns an int when the value is exactly representable as an int, and a string otherwise.

@mattip
Copy link
Member

mattip commented Dec 9, 2020

@fxcoudert I would not call that documented behaviour. The documentation should clearly state that the function will try to return an int and if it fails, a str.

@luketaverne 10.14 cannot be converted to an int, so the value is returned as a str. But your comment points out how confusing this behaviour is.

@BvB93 BvB93 changed the title MAINT: Update gnu.py BUG: Fix a MacOS build failure Dec 12, 2020
Copy link
Member

@rgommers rgommers left a comment

Choose a reason for hiding this comment

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

The discussion is interesting but shouldn't affect the proposed change in this PR, the one liner fix is correct and unbreaks the build for some macOS 11 users, so let's get this in. Thanks @fxcoudert, all.

@rgommers rgommers merged commit 7796131 into numpy:master Dec 12, 2020
@rgommers rgommers added the 09 - Backport-Candidate PRs tagged should be backported label Dec 12, 2020
@rgommers rgommers added this to the 1.21.0 release milestone Dec 12, 2020
@fxcoudert fxcoudert deleted the patch-1 branch December 12, 2020 20:20
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Dec 18, 2020
@charris charris removed this from the 1.21.0 release milestone Dec 18, 2020
@fxcoudert
Copy link
Contributor Author

@rgommers I see this didn't make it into the 1.19.5 version (Homebrew/homebrew-core#68346), shouldn't this simple patch be backported?

@rgommers rgommers added the 09 - Backport-Candidate PRs tagged should be backported label Jan 6, 2021
@rgommers
Copy link
Member

rgommers commented Jan 6, 2021

Argh yes, that is an oversight. I should have put on a label, then @charris would have seen it when deciding what to backport for 1.19.5. Done now; luckily 1.20.0 is also imminent, so the damage is very limited. I checked the fix is in the 1.20.x branch.

@charris
Copy link
Member

charris commented Jan 6, 2021

I should have put on a label

The milestone needed to be 1.19.5.

NumPy 1.20.0 is waiting for pyarrow to release. If they don't get a move on I'll release anyway.

@charris
Copy link
Member

charris commented Jan 6, 2021

I'm not planning on another 1.19 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants