-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Absorb macos_libfile
from pypa/wheel
#4965
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
base: main
Are you sure you want to change the base?
Conversation
The internal pep425tags module has been removed in favor of the "packaging" library.
Fixes pypa/wheel#385. Co-authored-by: FX Coudert <[email protected]>
…atform tag for fat binaries (pypa/wheel#390) The system compiler in Xcode 12 will not set the deployment target for arm64 below 11.0.0 (which is the first version of macOS supporting arm64). To allow building wheels that target an earlier version of macOS (by way of the x86_64 part of fat binaries) ignore the deployment target in the arm64 part of fat binaries when that's 11.0.0.
Added pyupgrade and flake8-bugbear to pre-commit configuration. Converted all code to py37+ syntax. Reformatted the pre-commit configuration file.
Distutils has been deprecated and will be removed in Python 3.12. This changeset replaces distutils logging with similar logging functionality from setuptools (when ready), and if not available, provides a replacement of its own. Co-authored-by: Jason R. Coombs <[email protected]>
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/pycqa/isort: 5.11.4 → 5.12.0](PyCQA/isort@5.11.4...5.12.0) - [github.com/psf/black: 22.12.0 → 23.1.0](psf/black@22.12.0...23.1.0) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- use `struct.calcsize("P") == 4` rather than `sys.maxsize == 2147483647` - extend the 32bit check to `linux-aarch64` => `linux-armv7l`
Function `get_base_class_and_magic_number()` already tests the value of `seek`, followed by a `seek()` call if needed. No need to duplicate the code in calling function `read_mach_header()`.
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/pre-commit/pre-commit-hooks: v4.6.0 → v5.0.0](pre-commit/pre-commit-hooks@v4.6.0...v5.0.0) - [github.com/astral-sh/ruff-pre-commit: v0.5.0 → v0.6.9](astral-sh/ruff-pre-commit@v0.5.0...v0.6.9) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Type checkers don't seem very happy about the new file. I am tempted to ignore it for now... Update: "ignore" annotations and adjustments for type checkers in 48c2889 |
c8625ec
to
48c2889
Compare
I have noticed that simply importing the file from This is something undesired, as it is important to browse the file history when investigating the code base. Therefore I re-made the PR using the code available before rm -rf /tmp/replace.txt /tmp/export-macos_libfile
cat <<EOF > /tmp/replace.txt
regex:#(\d+)==>pypa/wheel#\1
EOF
git clone --no-tags --revision 374c4026acc114a95c77f0529891613973be78c0 https://github.com/pypa/wheel.git /tmp/export-macos_libfile
cd /tmp/export-macos_libfile
git filter-repo --replace-message /tmp/replace.txt --path wheel/macosx_libfile.py --path src/wheel/macosx_libfile.py --path-rename 'src/wheel/macosx_libfile.py':'setuptools/command/_macosx_libfile.py'
git checkout -b main
cd ~/workspace/setuptools
git checkout absorb-macos_libfile
git reset --hard upstream/main
git remote remove import-macos_libfile
git checkout -b absorb-macos_libfile
git remote add import-macos_libfile /tmp/export-macos_libfile
git fetch import-macos_libfile
git merge --allow-unrelated-histories import-macos_libfile/main
git cherry-pick 1ca55e4 c8625ec |
Note about licensing: So as far as I understand it should be OK. I will add a licensing comment to the top of the file just in case: 6f2f7e5 |
1d86604
to
db201aa
Compare
Tests on PyPy and 3.14 seem to already be broken in |
@dholth, @agronholm, do we have your permission to "transfer" the file from the wheel to the setuptools repo? Is the copyright information I added at the beginning of the file enough for this purpose? Setuptools also has MIT license so the overall license text at the root of the repo is the same. |
I think what's needed is to retain some information on who committed the original code (@Czaki), as they are the actual copyright holder of at least the majority of the module code. |
I tried to keep the git history in this PR, so the information of the commits should be fairly similar to the same information that is currently available on @Czaki, if you prefer I can modify the file in the following way: - # This file was originally contributed to the pypa/wheel project under
- # the following license and copyright notice:
+ # This file was originally contributed by Grzegorz Bokota
+ # to pypa/wheel under the following license and copyright notice:
#
# MIT License
#
# Copyright (c) 2012 Daniel Holth <[email protected]> and contributors Do you have any thoughts? |
It will be nice to be mentioned. |
d76f385
to
a6dee59
Compare
It looks like you'll also need to adopt the test module to make |
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.
Kudos and nice work retaining the commit history.
Concerning type-checking issues. I don't wanna cause a change after approval, so just something to consider if it comes up again. (I haven't looked at the actual type issue either) |
This is the procedure used to import the file history: ``` rm -rf /tmp/replace.txt /tmp/wheel_files.txt /tmp/export-macos_libfile cat <<EOF > /tmp/replace.txt regex:#(\d+)==>pypa/wheel#\1 EOF cat <<EOF > /tmp/wheel_files.txt wheel/macosx_libfile.py wheel/macosx_libfile.py==>setuptools/command/_macosx_libfile.py src/wheel/macosx_libfile.py src/wheel/macosx_libfile.py==>setuptools/command/_macosx_libfile.py tests/test_macosx_libfile.py tests/test_macosx_libfile.py==>setuptools/tests/macosx_libfile/test_macosx_libfile.py tests/testdata/macosx_minimal_system_version/ tests/testdata/macosx_minimal_system_version/==>setuptools/tests/macosx_libfile/testdata/macosx_minimal_system_version/ EOF git clone --no-tags --revision 374c4026acc114a95c77f0529891613973be78c0 https://github.com/pypa/wheel.git /tmp/export-macos_libfile cd /tmp/export-macos_libfile git filter-repo --paths-from-file /tmp/wheel_files.txt --replace-message /tmp/replace.txt git checkout -b main cd ~/workspace/setuptools git checkout -b absorb-macos_libfile git remote add import-macos_libfile /tmp/export-macos_libfile git fetch import-macos_libfile git merge --allow-unrelated-histories import-macos_libfile/main ```
a6dee59
to
35a75e8
Compare
Good point! I forgot the test files. I have re-done the This is the list of commands I usedrm -rf /tmp/replace.txt /tmp/wheel_files.txt /tmp/export-macos_libfile
cat <<EOF > /tmp/replace.txt
regex:#(\d+)==>pypa/wheel#\1
EOF
cat <<EOF > /tmp/wheel_files.txt
wheel/macosx_libfile.py
wheel/macosx_libfile.py==>setuptools/command/_macosx_libfile.py
src/wheel/macosx_libfile.py
src/wheel/macosx_libfile.py==>setuptools/command/_macosx_libfile.py
tests/test_macosx_libfile.py
tests/test_macosx_libfile.py==>setuptools/tests/macosx_libfile/test_macosx_libfile.py
tests/testdata/macosx_minimal_system_version/
tests/testdata/macosx_minimal_system_version/==>setuptools/tests/macosx_libfile/testdata/macosx_minimal_system_version/
EOF
git clone --no-tags --revision 374c4026acc114a95c77f0529891613973be78c0 https://github.com/pypa/wheel.git /tmp/export-macos_libfile
cd /tmp/export-macos_libfile
git filter-repo --paths-from-file /tmp/wheel_files.txt --replace-message /tmp/replace.txt
git checkout -b main
cd ~/workspace/setuptools
git checkout absorb-macos_libfile
git reset --hard upstream/main
git remote remove import-macos_libfile
git checkout -b absorb-macos_libfile
git remote add import-macos_libfile /tmp/export-macos_libfile
git fetch import-macos_libfile
git merge --allow-unrelated-histories import-macos_libfile/main
git cherry-pick 'fcbc3cb69^..a6dee5922' @jaraco, the tests in the |
a4ff14f
to
c4caf27
Compare
Hi @Avasam, I think the typing problems (at least with mypy) are most related to the fact that the module dynamically define classes for interoperating with Hopefully we would like to not need much further modifications, but we can never know, in the end of the day we will have to maintain the file and apply bugfixes etc. |
Thanks for flagging that. I'm a little uneasy including those, especially because they present a growing maintenance burden - how are those files generated; how can they be refreshed? I'm not opposed to including them as-is, but it might be a good opportunity to at least document (perhaps just in this PR) what it takes to build them and maybe open a TODO to build them on demand. |
That is a very good point. I don't think this procedure is documented in I am not sure (and also not an macOS daily user), but if I had to guess:
Maybe we can put something together. This is a very first naïve attempt: cd <...>/testdata/macosx_minimal_system_version
# -o, -mmacosx-version-min, -arch
targets=(
"test_lib_10_6_fat.dylib 10.6.0 x86_64 i386"
"test_lib_10_10_fat.dylib 10.10.0 x86_64 i386"
"test_lib_10_14_fat.dylib 10.14.0 x86_64 i386"
"test_lib_10_6.dylib 10.6.0 x86_64"
"test_lib_10_10.dylib 10.10.0 x86_64"
"test_lib_10_14.dylib 10.14.0 x86_64"
"test_lib_10_6_386.dylib 10.6.0 i386"
"test_lib_10_10_386.dylib 10.10.0 i386"
"test_lib_10_14_386.dylib 10.14.0 i386"
"test_lib_multiple_fat.dylib 10.14.0 x86_64 arm64"
"test_lib_10_10_10.dylib 10.10.10 x86_64"
"test_lib_11.dylib 11.0.0 x86_64"
"test_lib_10_9_universal2.dylib 10.9.0 x86_64 arm64"
)
for target in "${targets[@]}"; do
output=$(echo $target | cut -d ' ' -f 1)
version=$(echo $target | cut -d ' ' -f 2)
archs=$(echo $target | cut -d ' ' -f 3-)
arch_flags=$(printf " -arch %s" $archs)
echo "clang -dynamiclib $arch_flags -mmacos-version-min=$version -o $output test_lib.c"
done This would result in something like: clang -dynamiclib -arch x86_64 -arch i386 -mmacos-version-min=10.6.0 -o test_lib_10_6_fat.dylib test_lib.c
clang -dynamiclib -arch x86_64 -arch i386 -mmacos-version-min=10.10.0 -o test_lib_10_10_fat.dylib test_lib.c
clang -dynamiclib -arch x86_64 -arch i386 -mmacos-version-min=10.14.0 -o test_lib_10_14_fat.dylib test_lib.c
clang -dynamiclib -arch x86_64 -mmacos-version-min=10.6.0 -o test_lib_10_6.dylib test_lib.c
clang -dynamiclib -arch x86_64 -mmacos-version-min=10.10.0 -o test_lib_10_10.dylib test_lib.c
clang -dynamiclib -arch x86_64 -mmacos-version-min=10.14.0 -o test_lib_10_14.dylib test_lib.c
clang -dynamiclib -arch i386 -mmacos-version-min=10.6.0 -o test_lib_10_6_386.dylib test_lib.c
clang -dynamiclib -arch i386 -mmacos-version-min=10.10.0 -o test_lib_10_10_386.dylib test_lib.c
clang -dynamiclib -arch i386 -mmacos-version-min=10.14.0 -o test_lib_10_14_386.dylib test_lib.c
clang -dynamiclib -arch x86_64 -arch arm64 -mmacos-version-min=10.14.0 -o test_lib_multiple_fat.dylib test_lib.c
clang -dynamiclib -arch x86_64 -mmacos-version-min=10.10.10 -o test_lib_10_10_10.dylib test_lib.c
clang -dynamiclib -arch x86_64 -mmacos-version-min=11.0.0 -o test_lib_11.dylib test_lib.c
clang -dynamiclib -arch x86_64 -arch arm64 -mmacos-version-min=10.9.0 -o test_lib_10_9_universal2.dylib test_lib.c I don't know if that is correct, or would produce the intended results. Also it probably depends on the installed versions of the build tools. @Czaki, it has been a long time you contributed these files, but do you remember what was the procedure that was used for compiling? As Jason pointed out, it would be good if we can document it. |
This one that I added was compiled using
Apple had changed the header format, and last time when I tested it, setting low deployment target do not change the header format to the old one (based on my memories). So generation data during test may not provide files with old header format so not test all code path. |
IIRC the reason there are wheel files in the test data is to prevent false negatives if a bug was introduced in |
Thanks @agronholm. Yes I agree that we can construct |
Thank you @Czaki. Was the procedure you used just setting
If that is the case, this mean that we cannot regenerate these binary files dynamically, @jaraco and we would need to accept them as "magic files" in the PR. Footnotes
|
If I correctly remember, I compile separate files and the combine them using
I will try to find time and check these files. Maybe at least part of them could be generated dynamically. |
Summary of changes
This implements the approach discussed in https://discuss.python.org/t/extraction-of-deprecated-wheel-macosx-libfile-into-its-own-package/87509/9
An attempt to keep the file's git history was made by following the procedure1:
UPDATE: I have redone this using
--revision 374c4026acc114a95c77f0529891613973be78c0
forgit clone
instead of simply getting the file from themain
branch to improve the ability of navigating the commit history viagit blame
.UPDATE: To include the test files this procedure was revisited in #4965 (comment).
My own authored commits are:
Closes #4935
Pull Request Checklist
newsfragments/
.(See documentation for details)
Footnotes
Git history may be important in the future when trying to understand why some particular approach was implemented. ↩