-
Notifications
You must be signed in to change notification settings - Fork 253
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
Remove distutils.util usage from packaging.tags #349
Conversation
154a55c
to
b5965a0
Compare
This is in case PEP 632 to deprecate distutils goes through? |
The main reason is because distutils is a poor source to get this information, its internals being undocumented and may break without warning (it already did for some people). See #327 (comment). |
My interest started because distutils has already made a breaking change, and in Python >= 3.8 pip no longer works in the vcvarsall "Developer Prompt for Visual Studio XXX" environment - it tries to install wheels matching the MSVC target architecture, rather than the python.exe into which it's installing things. See https://bugs.python.org/issue38989 for my report of this end-symptom, and pypa/pip#8649 for someone else's. @zooba has indicated, both on python.org and on github that he considers distutils.util.get_host_platform() a private function that should not be used for this purpose. Of course, he's also the author of PEP 632, so it's probably not unrelated to propsing deprecation and removal in general. |
Yeah, the recommendation to not use the function is because it's going to be deprecated soon. Distutils has poor platform detection, so anything else will be an improvement, and honestly I like packaging.tags as a location for it, since then other tools can ask "which platform tag should I build for" (since e.g. manylinux has different kinds of rules from win32). We're progressively moving packaging stuff out of the stdlib anyway, so that it can be divorced from the language version. |
@uranusjr How can we help this along? People keep being bitten by pip looking at the cross-compile target rather than the current platform. |
I've done all I could, someone needs to review and merge the PR. |
packaging/tags.py
Outdated
import sysconfig | ||
import _osx_support | ||
|
||
osname, release, machine = _osx_support.get_platform_osx( |
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.
My only query is whether this should rely on _osx_support
(which I assume is a core CPython module?) or reproduce whatever it's doing.
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.
Correct, it’s a helper module in stdlib. The function is quite complicated and I’d very much keep referencing the stdlib if possible. Not sure who to ask about whether this is a good idea.
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.
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.
Looks like the equivalent public API for this is sysconfig.get_platform()
, so it should be an easy swap. It might even make a suitable fallback for all cases after you've gotten past the initial tests. I suspect you'll still want your own version of it for backporting fixes/changes, but if the stdlib functionality is fine for this bit then you may as well use as much as you can/like.
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.
That said, I only compared to the version of sysconfig in master... it might be that there are already improvements that aren't in 3.9, and so you'll still need the logic you've got here. But the _osx_support
reference can't really be any worse in earlier versions.
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.
git blame
the everything that changed in that function during the recent 5 years are about Windows (ARM support), AIX improvements, and dropping BSD/OS support, so it’s probably safe. I’ll switch that API.
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.
Actually, the same also applies to _aix_support
(prior to 3.9 it’s just {osname}-{release}-{machine}
, and was expanded to support PEP 425), so I replaced that as well.
870e9ee
to
13364f7
Compare
_osx_support.get_platform_osx() only uses three configs: * MACOSX_DEPLOYMENT_TARGET * CFLAGS * _OSX_SUPPORT_INITIAL_CFLAGS All of these should be identical from both sources.
Black-ify, and replace %-formatting with str.format()
1b7e957
to
b7245d6
Compare
b7245d6
to
2f3c6f6
Compare
On further inspection,
In |
If the override isn't applied first, then applying it differently on various platforms seems odd, so I would go with the |
I see nothing in https://bugs.python.org/issue14330 indicating was intentional either. It seems to have been originally intended as an internal flag for cpython's own build system? But now seems to have a bit broader scope (e.g. dh-python's pybuild sets it, and debian documents it as part of cross-building extensions: https://wiki.debian.org/Python/MultiArch, and google found NumPy build scripts for iOS using it). It is potentially a functional difference: sysconfig only honors Which seems unlikely; uname dates all the way back to SVr4 and was standardized by POSIX.1-1988, though BSD didn't get it until 4.4BSD in 1994. The autoconf check and posixmodule.c here do in fact seem to date all the way back to pre-alpha-1.0.0: python/cpython@c39de5f. Back in 1992 it might have made sense to care about 4.3BSD :-) But I don't think there are any early-90s unices still supported by CPython 3.x, so should be moot. The documentation suggests |
Epistemic status: reasonably comfortable with unix history, but no personal knowledge history here, just did doing some software archaeology to see if I could find anything interesting. @doko42 (the original author of |
I’ve filed #396 so we have something to merge if we decide the two implementations are indeed equivalent. |
I haven't fully read up on this PR yet, but I do wonder if it wouldn't be better to move this functionality into the stdlib module sysconfig (with a clear and documented interface). The function is closely related to other functionality in sysconfig (such as BTW. |
Pinging @fangerer for a GraalPython perspective: I don't know if they change os.uname ? |
@ronaldoussoren There is already a
|
The 4th option is to add The |
graalpython appears to identify itself as So it would seem to be another one where the sysconfig and distutils implementation difference would not matter. |
Relying on the os module would break cross-building extensions. I didn't look into cross build recently, so I don't know if it's currently working. The idea is to run the build python (running on your build machine) with the sysconfig module from your host/target machine, assuming that the sysconfig/sysconfig_data modules provide all information for the host/target. That cannot work, if people start relying on the builtin os module. |
@uranusjr had some discussions bout these different sources (before this PR was opened) at https://discuss.python.org/t/pep-425-platform-tag/5157/11 Just to link some more (probably stale) context, which many of the folks commenting have presumably seen, but I just ran across. |
This might be one of those situations where we won't know the ramifications until we ask people widely to test or we do a release and wait to see what the complaints are. |
I'm thinking let's do this but with #396. The behavior change feels like it has a low risk of breakage, with most people affected knowing their nuances better than us -- but I have no data/reasoning behind "why" beyond intuition TBH.
No? This is only used when the user doesn't provide a specific platform that they're generating these tags for. See the stack "down" from https://github.com/uranusjr/packaging/blob/no-distutils/packaging/tags.py#L275. |
Note that the current implementation in the main branch already does not work particularly well in cross-building scenarios, since it relies on |
@pradyunsg your feeling is my feeling as well. No one has any good feeling as to why anything is the way it is, so I say go with the simpler solution. 😄 |
This has been replaced by #396. |
I basically copied
distutils.util.get_host_platform()
, run Black on it, and make the code slightly more modern.There are several possible refactoring available, e.g. move the Windows and Linux logic out of the function to short-circuit some logic, and use function arguments to avoid
os.uname()
being called repeatedly. But each of these adds chance for things to break, and I feel it’s better to first include an implementation that guarentees no backward incompatibility before we try to improve it.Fix #327.