py2docfx 0.1.11.dev1824276__py3-none-any.whl → 0.1.11.dev1827111__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. py2docfx/convert_prepare/environment.py +1 -1
  2. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/_collections.py +0 -145
  3. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/bcppcompiler.py +1 -2
  4. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/ccompiler.py +7 -11
  5. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/command/bdist.py +4 -3
  6. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/command/build_ext.py +1 -4
  7. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/command/check.py +3 -4
  8. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/command/install_data.py +39 -29
  9. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/command/install_lib.py +1 -3
  10. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/command/sdist.py +4 -4
  11. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/compat/py38.py +1 -0
  12. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/cygwinccompiler.py +21 -42
  13. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/dist.py +3 -12
  14. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/extension.py +9 -4
  15. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/msvc9compiler.py +1 -3
  16. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/msvccompiler.py +1 -3
  17. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/spawn.py +0 -1
  18. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/sysconfig.py +44 -25
  19. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/tests/test_archive_util.py +1 -1
  20. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/tests/test_build.py +1 -2
  21. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/tests/test_build_ext.py +1 -1
  22. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/tests/test_cygwinccompiler.py +0 -42
  23. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/tests/test_dist.py +1 -1
  24. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/tests/test_extension.py +4 -1
  25. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/tests/test_install_data.py +17 -9
  26. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/tests/test_mingwccompiler.py +5 -4
  27. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/tests/test_spawn.py +1 -1
  28. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/tests/test_sysconfig.py +6 -3
  29. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/tests/test_unixccompiler.py +35 -1
  30. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/tests/test_util.py +4 -24
  31. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/unixccompiler.py +19 -20
  32. py2docfx/venv/0/Lib/site-packages/setuptools/_distutils/util.py +20 -26
  33. py2docfx/venv/0/Lib/site-packages/wheel/__init__.py +3 -0
  34. py2docfx/venv/0/Lib/site-packages/wheel/__main__.py +23 -0
  35. py2docfx/venv/0/Lib/site-packages/wheel/_bdist_wheel.py +604 -0
  36. py2docfx/venv/0/Lib/site-packages/wheel/_setuptools_logging.py +26 -0
  37. py2docfx/venv/0/Lib/site-packages/wheel/bdist_wheel.py +11 -0
  38. py2docfx/venv/0/Lib/site-packages/wheel/cli/__init__.py +155 -0
  39. py2docfx/venv/0/Lib/site-packages/wheel/cli/convert.py +273 -0
  40. py2docfx/venv/0/Lib/site-packages/wheel/cli/pack.py +85 -0
  41. py2docfx/venv/0/Lib/site-packages/wheel/cli/tags.py +139 -0
  42. py2docfx/venv/0/Lib/site-packages/wheel/cli/unpack.py +30 -0
  43. py2docfx/venv/0/Lib/site-packages/wheel/macosx_libfile.py +482 -0
  44. py2docfx/venv/0/Lib/site-packages/wheel/metadata.py +183 -0
  45. py2docfx/venv/0/Lib/site-packages/wheel/util.py +26 -0
  46. py2docfx/venv/0/Lib/site-packages/wheel/vendored/__init__.py +0 -0
  47. py2docfx/venv/0/Lib/site-packages/wheel/vendored/packaging/__init__.py +0 -0
  48. py2docfx/venv/0/Lib/site-packages/wheel/vendored/packaging/_elffile.py +108 -0
  49. py2docfx/venv/0/Lib/site-packages/wheel/vendored/packaging/_manylinux.py +260 -0
  50. py2docfx/venv/0/Lib/site-packages/wheel/vendored/packaging/_musllinux.py +83 -0
  51. py2docfx/venv/0/Lib/site-packages/wheel/vendored/packaging/_parser.py +356 -0
  52. py2docfx/venv/0/Lib/site-packages/wheel/vendored/packaging/_structures.py +61 -0
  53. py2docfx/venv/0/Lib/site-packages/wheel/vendored/packaging/_tokenizer.py +192 -0
  54. py2docfx/venv/0/Lib/site-packages/wheel/vendored/packaging/markers.py +253 -0
  55. py2docfx/venv/0/Lib/site-packages/wheel/vendored/packaging/requirements.py +90 -0
  56. py2docfx/venv/0/Lib/site-packages/wheel/vendored/packaging/specifiers.py +1011 -0
  57. py2docfx/venv/0/Lib/site-packages/wheel/vendored/packaging/tags.py +571 -0
  58. py2docfx/venv/0/Lib/site-packages/wheel/vendored/packaging/utils.py +172 -0
  59. py2docfx/venv/0/Lib/site-packages/wheel/vendored/packaging/version.py +561 -0
  60. py2docfx/venv/0/Lib/site-packages/wheel/wheelfile.py +227 -0
  61. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/_collections.py +0 -145
  62. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/bcppcompiler.py +1 -2
  63. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/ccompiler.py +7 -11
  64. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/command/bdist.py +4 -3
  65. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/command/build_ext.py +1 -4
  66. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/command/check.py +3 -4
  67. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/command/install_data.py +39 -29
  68. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/command/install_lib.py +1 -3
  69. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/command/sdist.py +4 -4
  70. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/compat/py38.py +1 -0
  71. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/cygwinccompiler.py +21 -42
  72. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/dist.py +3 -12
  73. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/extension.py +9 -4
  74. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/msvc9compiler.py +1 -3
  75. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/msvccompiler.py +1 -3
  76. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/spawn.py +0 -1
  77. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/sysconfig.py +44 -25
  78. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/tests/test_archive_util.py +1 -1
  79. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/tests/test_build.py +1 -2
  80. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/tests/test_build_ext.py +1 -1
  81. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/tests/test_cygwinccompiler.py +0 -42
  82. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/tests/test_dist.py +1 -1
  83. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/tests/test_extension.py +4 -1
  84. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/tests/test_install_data.py +17 -9
  85. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/tests/test_mingwccompiler.py +5 -4
  86. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/tests/test_spawn.py +1 -1
  87. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/tests/test_sysconfig.py +6 -3
  88. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/tests/test_unixccompiler.py +35 -1
  89. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/tests/test_util.py +4 -24
  90. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/unixccompiler.py +19 -20
  91. py2docfx/venv/template/Lib/site-packages/setuptools/_distutils/util.py +20 -26
  92. py2docfx/venv/template/Lib/site-packages/wheel/__init__.py +3 -0
  93. py2docfx/venv/template/Lib/site-packages/wheel/__main__.py +23 -0
  94. py2docfx/venv/template/Lib/site-packages/wheel/_bdist_wheel.py +604 -0
  95. py2docfx/venv/template/Lib/site-packages/wheel/_setuptools_logging.py +26 -0
  96. py2docfx/venv/template/Lib/site-packages/wheel/bdist_wheel.py +11 -0
  97. py2docfx/venv/template/Lib/site-packages/wheel/cli/__init__.py +155 -0
  98. py2docfx/venv/template/Lib/site-packages/wheel/cli/convert.py +273 -0
  99. py2docfx/venv/template/Lib/site-packages/wheel/cli/pack.py +85 -0
  100. py2docfx/venv/template/Lib/site-packages/wheel/cli/tags.py +139 -0
  101. py2docfx/venv/template/Lib/site-packages/wheel/cli/unpack.py +30 -0
  102. py2docfx/venv/template/Lib/site-packages/wheel/macosx_libfile.py +482 -0
  103. py2docfx/venv/template/Lib/site-packages/wheel/metadata.py +183 -0
  104. py2docfx/venv/template/Lib/site-packages/wheel/util.py +26 -0
  105. py2docfx/venv/template/Lib/site-packages/wheel/vendored/__init__.py +0 -0
  106. py2docfx/venv/template/Lib/site-packages/wheel/vendored/packaging/__init__.py +0 -0
  107. py2docfx/venv/template/Lib/site-packages/wheel/vendored/packaging/_elffile.py +108 -0
  108. py2docfx/venv/template/Lib/site-packages/wheel/vendored/packaging/_manylinux.py +260 -0
  109. py2docfx/venv/template/Lib/site-packages/wheel/vendored/packaging/_musllinux.py +83 -0
  110. py2docfx/venv/template/Lib/site-packages/wheel/vendored/packaging/_parser.py +356 -0
  111. py2docfx/venv/template/Lib/site-packages/wheel/vendored/packaging/_structures.py +61 -0
  112. py2docfx/venv/template/Lib/site-packages/wheel/vendored/packaging/_tokenizer.py +192 -0
  113. py2docfx/venv/template/Lib/site-packages/wheel/vendored/packaging/markers.py +253 -0
  114. py2docfx/venv/template/Lib/site-packages/wheel/vendored/packaging/requirements.py +90 -0
  115. py2docfx/venv/template/Lib/site-packages/wheel/vendored/packaging/specifiers.py +1011 -0
  116. py2docfx/venv/template/Lib/site-packages/wheel/vendored/packaging/tags.py +571 -0
  117. py2docfx/venv/template/Lib/site-packages/wheel/vendored/packaging/utils.py +172 -0
  118. py2docfx/venv/template/Lib/site-packages/wheel/vendored/packaging/version.py +561 -0
  119. py2docfx/venv/template/Lib/site-packages/wheel/wheelfile.py +227 -0
  120. {py2docfx-0.1.11.dev1824276.dist-info → py2docfx-0.1.11.dev1827111.dist-info}/METADATA +1 -1
  121. {py2docfx-0.1.11.dev1824276.dist-info → py2docfx-0.1.11.dev1827111.dist-info}/RECORD +123 -67
  122. {py2docfx-0.1.11.dev1824276.dist-info → py2docfx-0.1.11.dev1827111.dist-info}/WHEEL +0 -0
  123. {py2docfx-0.1.11.dev1824276.dist-info → py2docfx-0.1.11.dev1827111.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,482 @@
1
+ """
2
+ This module contains function to analyse dynamic library
3
+ headers to extract system information
4
+
5
+ Currently only for MacOSX
6
+
7
+ Library file on macosx system starts with Mach-O or Fat field.
8
+ This can be distinguish by first 32 bites and it is called magic number.
9
+ Proper value of magic number is with suffix _MAGIC. Suffix _CIGAM means
10
+ reversed bytes order.
11
+ Both fields can occur in two types: 32 and 64 bytes.
12
+
13
+ FAT field inform that this library contains few version of library
14
+ (typically for different types version). It contains
15
+ information where Mach-O headers starts.
16
+
17
+ Each section started with Mach-O header contains one library
18
+ (So if file starts with this field it contains only one version).
19
+
20
+ After filed Mach-O there are section fields.
21
+ Each of them starts with two fields:
22
+ cmd - magic number for this command
23
+ cmdsize - total size occupied by this section information.
24
+
25
+ In this case only sections LC_VERSION_MIN_MACOSX (for macosx 10.13 and earlier)
26
+ and LC_BUILD_VERSION (for macosx 10.14 and newer) are interesting,
27
+ because them contains information about minimal system version.
28
+
29
+ Important remarks:
30
+ - For fat files this implementation looks for maximum number version.
31
+ It not check if it is 32 or 64 and do not compare it with currently built package.
32
+ So it is possible to false report higher version that needed.
33
+ - All structures signatures are taken form macosx header files.
34
+ - I think that binary format will be more stable than `otool` output.
35
+ and if apple introduce some changes both implementation will need to be updated.
36
+ - The system compile will set the deployment target no lower than
37
+ 11.0 for arm64 builds. For "Universal 2" builds use the x86_64 deployment
38
+ target when the arm64 target is 11.0.
39
+ """
40
+
41
+ from __future__ import annotations
42
+
43
+ import ctypes
44
+ import os
45
+ import sys
46
+ from io import BufferedIOBase
47
+ from typing import TYPE_CHECKING
48
+
49
+ if TYPE_CHECKING:
50
+ from typing import Union
51
+
52
+ StrPath = Union[str, os.PathLike[str]]
53
+
54
+ """here the needed const and struct from mach-o header files"""
55
+
56
+ FAT_MAGIC = 0xCAFEBABE
57
+ FAT_CIGAM = 0xBEBAFECA
58
+ FAT_MAGIC_64 = 0xCAFEBABF
59
+ FAT_CIGAM_64 = 0xBFBAFECA
60
+ MH_MAGIC = 0xFEEDFACE
61
+ MH_CIGAM = 0xCEFAEDFE
62
+ MH_MAGIC_64 = 0xFEEDFACF
63
+ MH_CIGAM_64 = 0xCFFAEDFE
64
+
65
+ LC_VERSION_MIN_MACOSX = 0x24
66
+ LC_BUILD_VERSION = 0x32
67
+
68
+ CPU_TYPE_ARM64 = 0x0100000C
69
+
70
+ mach_header_fields = [
71
+ ("magic", ctypes.c_uint32),
72
+ ("cputype", ctypes.c_int),
73
+ ("cpusubtype", ctypes.c_int),
74
+ ("filetype", ctypes.c_uint32),
75
+ ("ncmds", ctypes.c_uint32),
76
+ ("sizeofcmds", ctypes.c_uint32),
77
+ ("flags", ctypes.c_uint32),
78
+ ]
79
+ """
80
+ struct mach_header {
81
+ uint32_t magic; /* mach magic number identifier */
82
+ cpu_type_t cputype; /* cpu specifier */
83
+ cpu_subtype_t cpusubtype; /* machine specifier */
84
+ uint32_t filetype; /* type of file */
85
+ uint32_t ncmds; /* number of load commands */
86
+ uint32_t sizeofcmds; /* the size of all the load commands */
87
+ uint32_t flags; /* flags */
88
+ };
89
+ typedef integer_t cpu_type_t;
90
+ typedef integer_t cpu_subtype_t;
91
+ """
92
+
93
+ mach_header_fields_64 = mach_header_fields + [("reserved", ctypes.c_uint32)]
94
+ """
95
+ struct mach_header_64 {
96
+ uint32_t magic; /* mach magic number identifier */
97
+ cpu_type_t cputype; /* cpu specifier */
98
+ cpu_subtype_t cpusubtype; /* machine specifier */
99
+ uint32_t filetype; /* type of file */
100
+ uint32_t ncmds; /* number of load commands */
101
+ uint32_t sizeofcmds; /* the size of all the load commands */
102
+ uint32_t flags; /* flags */
103
+ uint32_t reserved; /* reserved */
104
+ };
105
+ """
106
+
107
+ fat_header_fields = [("magic", ctypes.c_uint32), ("nfat_arch", ctypes.c_uint32)]
108
+ """
109
+ struct fat_header {
110
+ uint32_t magic; /* FAT_MAGIC or FAT_MAGIC_64 */
111
+ uint32_t nfat_arch; /* number of structs that follow */
112
+ };
113
+ """
114
+
115
+ fat_arch_fields = [
116
+ ("cputype", ctypes.c_int),
117
+ ("cpusubtype", ctypes.c_int),
118
+ ("offset", ctypes.c_uint32),
119
+ ("size", ctypes.c_uint32),
120
+ ("align", ctypes.c_uint32),
121
+ ]
122
+ """
123
+ struct fat_arch {
124
+ cpu_type_t cputype; /* cpu specifier (int) */
125
+ cpu_subtype_t cpusubtype; /* machine specifier (int) */
126
+ uint32_t offset; /* file offset to this object file */
127
+ uint32_t size; /* size of this object file */
128
+ uint32_t align; /* alignment as a power of 2 */
129
+ };
130
+ """
131
+
132
+ fat_arch_64_fields = [
133
+ ("cputype", ctypes.c_int),
134
+ ("cpusubtype", ctypes.c_int),
135
+ ("offset", ctypes.c_uint64),
136
+ ("size", ctypes.c_uint64),
137
+ ("align", ctypes.c_uint32),
138
+ ("reserved", ctypes.c_uint32),
139
+ ]
140
+ """
141
+ struct fat_arch_64 {
142
+ cpu_type_t cputype; /* cpu specifier (int) */
143
+ cpu_subtype_t cpusubtype; /* machine specifier (int) */
144
+ uint64_t offset; /* file offset to this object file */
145
+ uint64_t size; /* size of this object file */
146
+ uint32_t align; /* alignment as a power of 2 */
147
+ uint32_t reserved; /* reserved */
148
+ };
149
+ """
150
+
151
+ segment_base_fields = [("cmd", ctypes.c_uint32), ("cmdsize", ctypes.c_uint32)]
152
+ """base for reading segment info"""
153
+
154
+ segment_command_fields = [
155
+ ("cmd", ctypes.c_uint32),
156
+ ("cmdsize", ctypes.c_uint32),
157
+ ("segname", ctypes.c_char * 16),
158
+ ("vmaddr", ctypes.c_uint32),
159
+ ("vmsize", ctypes.c_uint32),
160
+ ("fileoff", ctypes.c_uint32),
161
+ ("filesize", ctypes.c_uint32),
162
+ ("maxprot", ctypes.c_int),
163
+ ("initprot", ctypes.c_int),
164
+ ("nsects", ctypes.c_uint32),
165
+ ("flags", ctypes.c_uint32),
166
+ ]
167
+ """
168
+ struct segment_command { /* for 32-bit architectures */
169
+ uint32_t cmd; /* LC_SEGMENT */
170
+ uint32_t cmdsize; /* includes sizeof section structs */
171
+ char segname[16]; /* segment name */
172
+ uint32_t vmaddr; /* memory address of this segment */
173
+ uint32_t vmsize; /* memory size of this segment */
174
+ uint32_t fileoff; /* file offset of this segment */
175
+ uint32_t filesize; /* amount to map from the file */
176
+ vm_prot_t maxprot; /* maximum VM protection */
177
+ vm_prot_t initprot; /* initial VM protection */
178
+ uint32_t nsects; /* number of sections in segment */
179
+ uint32_t flags; /* flags */
180
+ };
181
+ typedef int vm_prot_t;
182
+ """
183
+
184
+ segment_command_fields_64 = [
185
+ ("cmd", ctypes.c_uint32),
186
+ ("cmdsize", ctypes.c_uint32),
187
+ ("segname", ctypes.c_char * 16),
188
+ ("vmaddr", ctypes.c_uint64),
189
+ ("vmsize", ctypes.c_uint64),
190
+ ("fileoff", ctypes.c_uint64),
191
+ ("filesize", ctypes.c_uint64),
192
+ ("maxprot", ctypes.c_int),
193
+ ("initprot", ctypes.c_int),
194
+ ("nsects", ctypes.c_uint32),
195
+ ("flags", ctypes.c_uint32),
196
+ ]
197
+ """
198
+ struct segment_command_64 { /* for 64-bit architectures */
199
+ uint32_t cmd; /* LC_SEGMENT_64 */
200
+ uint32_t cmdsize; /* includes sizeof section_64 structs */
201
+ char segname[16]; /* segment name */
202
+ uint64_t vmaddr; /* memory address of this segment */
203
+ uint64_t vmsize; /* memory size of this segment */
204
+ uint64_t fileoff; /* file offset of this segment */
205
+ uint64_t filesize; /* amount to map from the file */
206
+ vm_prot_t maxprot; /* maximum VM protection */
207
+ vm_prot_t initprot; /* initial VM protection */
208
+ uint32_t nsects; /* number of sections in segment */
209
+ uint32_t flags; /* flags */
210
+ };
211
+ """
212
+
213
+ version_min_command_fields = segment_base_fields + [
214
+ ("version", ctypes.c_uint32),
215
+ ("sdk", ctypes.c_uint32),
216
+ ]
217
+ """
218
+ struct version_min_command {
219
+ uint32_t cmd; /* LC_VERSION_MIN_MACOSX or
220
+ LC_VERSION_MIN_IPHONEOS or
221
+ LC_VERSION_MIN_WATCHOS or
222
+ LC_VERSION_MIN_TVOS */
223
+ uint32_t cmdsize; /* sizeof(struct min_version_command) */
224
+ uint32_t version; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */
225
+ uint32_t sdk; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */
226
+ };
227
+ """
228
+
229
+ build_version_command_fields = segment_base_fields + [
230
+ ("platform", ctypes.c_uint32),
231
+ ("minos", ctypes.c_uint32),
232
+ ("sdk", ctypes.c_uint32),
233
+ ("ntools", ctypes.c_uint32),
234
+ ]
235
+ """
236
+ struct build_version_command {
237
+ uint32_t cmd; /* LC_BUILD_VERSION */
238
+ uint32_t cmdsize; /* sizeof(struct build_version_command) plus */
239
+ /* ntools * sizeof(struct build_tool_version) */
240
+ uint32_t platform; /* platform */
241
+ uint32_t minos; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */
242
+ uint32_t sdk; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */
243
+ uint32_t ntools; /* number of tool entries following this */
244
+ };
245
+ """
246
+
247
+
248
+ def swap32(x: int) -> int:
249
+ return (
250
+ ((x << 24) & 0xFF000000)
251
+ | ((x << 8) & 0x00FF0000)
252
+ | ((x >> 8) & 0x0000FF00)
253
+ | ((x >> 24) & 0x000000FF)
254
+ )
255
+
256
+
257
+ def get_base_class_and_magic_number(
258
+ lib_file: BufferedIOBase,
259
+ seek: int | None = None,
260
+ ) -> tuple[type[ctypes.Structure], int]:
261
+ if seek is None:
262
+ seek = lib_file.tell()
263
+ else:
264
+ lib_file.seek(seek)
265
+ magic_number = ctypes.c_uint32.from_buffer_copy(
266
+ lib_file.read(ctypes.sizeof(ctypes.c_uint32))
267
+ ).value
268
+
269
+ # Handle wrong byte order
270
+ if magic_number in [FAT_CIGAM, FAT_CIGAM_64, MH_CIGAM, MH_CIGAM_64]:
271
+ if sys.byteorder == "little":
272
+ BaseClass = ctypes.BigEndianStructure
273
+ else:
274
+ BaseClass = ctypes.LittleEndianStructure
275
+
276
+ magic_number = swap32(magic_number)
277
+ else:
278
+ BaseClass = ctypes.Structure
279
+
280
+ lib_file.seek(seek)
281
+ return BaseClass, magic_number
282
+
283
+
284
+ def read_data(struct_class: type[ctypes.Structure], lib_file: BufferedIOBase):
285
+ return struct_class.from_buffer_copy(lib_file.read(ctypes.sizeof(struct_class)))
286
+
287
+
288
+ def extract_macosx_min_system_version(path_to_lib: str):
289
+ with open(path_to_lib, "rb") as lib_file:
290
+ BaseClass, magic_number = get_base_class_and_magic_number(lib_file, 0)
291
+ if magic_number not in [FAT_MAGIC, FAT_MAGIC_64, MH_MAGIC, MH_MAGIC_64]:
292
+ return
293
+
294
+ if magic_number in [FAT_MAGIC, FAT_CIGAM_64]:
295
+
296
+ class FatHeader(BaseClass):
297
+ _fields_ = fat_header_fields
298
+
299
+ fat_header = read_data(FatHeader, lib_file)
300
+ if magic_number == FAT_MAGIC:
301
+
302
+ class FatArch(BaseClass):
303
+ _fields_ = fat_arch_fields
304
+
305
+ else:
306
+
307
+ class FatArch(BaseClass):
308
+ _fields_ = fat_arch_64_fields
309
+
310
+ fat_arch_list = [
311
+ read_data(FatArch, lib_file) for _ in range(fat_header.nfat_arch)
312
+ ]
313
+
314
+ versions_list: list[tuple[int, int, int]] = []
315
+ for el in fat_arch_list:
316
+ try:
317
+ version = read_mach_header(lib_file, el.offset)
318
+ if version is not None:
319
+ if el.cputype == CPU_TYPE_ARM64 and len(fat_arch_list) != 1:
320
+ # Xcode will not set the deployment target below 11.0.0
321
+ # for the arm64 architecture. Ignore the arm64 deployment
322
+ # in fat binaries when the target is 11.0.0, that way
323
+ # the other architectures can select a lower deployment
324
+ # target.
325
+ # This is safe because there is no arm64 variant for
326
+ # macOS 10.15 or earlier.
327
+ if version == (11, 0, 0):
328
+ continue
329
+ versions_list.append(version)
330
+ except ValueError:
331
+ pass
332
+
333
+ if len(versions_list) > 0:
334
+ return max(versions_list)
335
+ else:
336
+ return None
337
+
338
+ else:
339
+ try:
340
+ return read_mach_header(lib_file, 0)
341
+ except ValueError:
342
+ """when some error during read library files"""
343
+ return None
344
+
345
+
346
+ def read_mach_header(
347
+ lib_file: BufferedIOBase,
348
+ seek: int | None = None,
349
+ ) -> tuple[int, int, int] | None:
350
+ """
351
+ This function parses a Mach-O header and extracts
352
+ information about the minimal macOS version.
353
+
354
+ :param lib_file: reference to opened library file with pointer
355
+ """
356
+ base_class, magic_number = get_base_class_and_magic_number(lib_file, seek)
357
+ arch = "32" if magic_number == MH_MAGIC else "64"
358
+
359
+ class SegmentBase(base_class):
360
+ _fields_ = segment_base_fields
361
+
362
+ if arch == "32":
363
+
364
+ class MachHeader(base_class):
365
+ _fields_ = mach_header_fields
366
+
367
+ else:
368
+
369
+ class MachHeader(base_class):
370
+ _fields_ = mach_header_fields_64
371
+
372
+ mach_header = read_data(MachHeader, lib_file)
373
+ for _i in range(mach_header.ncmds):
374
+ pos = lib_file.tell()
375
+ segment_base = read_data(SegmentBase, lib_file)
376
+ lib_file.seek(pos)
377
+ if segment_base.cmd == LC_VERSION_MIN_MACOSX:
378
+
379
+ class VersionMinCommand(base_class):
380
+ _fields_ = version_min_command_fields
381
+
382
+ version_info = read_data(VersionMinCommand, lib_file)
383
+ return parse_version(version_info.version)
384
+ elif segment_base.cmd == LC_BUILD_VERSION:
385
+
386
+ class VersionBuild(base_class):
387
+ _fields_ = build_version_command_fields
388
+
389
+ version_info = read_data(VersionBuild, lib_file)
390
+ return parse_version(version_info.minos)
391
+ else:
392
+ lib_file.seek(pos + segment_base.cmdsize)
393
+ continue
394
+
395
+
396
+ def parse_version(version: int) -> tuple[int, int, int]:
397
+ x = (version & 0xFFFF0000) >> 16
398
+ y = (version & 0x0000FF00) >> 8
399
+ z = version & 0x000000FF
400
+ return x, y, z
401
+
402
+
403
+ def calculate_macosx_platform_tag(archive_root: StrPath, platform_tag: str) -> str:
404
+ """
405
+ Calculate proper macosx platform tag basing on files which are included to wheel
406
+
407
+ Example platform tag `macosx-10.14-x86_64`
408
+ """
409
+ prefix, base_version, suffix = platform_tag.split("-")
410
+ base_version = tuple(int(x) for x in base_version.split("."))
411
+ base_version = base_version[:2]
412
+ if base_version[0] > 10:
413
+ base_version = (base_version[0], 0)
414
+ assert len(base_version) == 2
415
+ if "MACOSX_DEPLOYMENT_TARGET" in os.environ:
416
+ deploy_target = tuple(
417
+ int(x) for x in os.environ["MACOSX_DEPLOYMENT_TARGET"].split(".")
418
+ )
419
+ deploy_target = deploy_target[:2]
420
+ if deploy_target[0] > 10:
421
+ deploy_target = (deploy_target[0], 0)
422
+ if deploy_target < base_version:
423
+ sys.stderr.write(
424
+ "[WARNING] MACOSX_DEPLOYMENT_TARGET is set to a lower value ({}) than "
425
+ "the version on which the Python interpreter was compiled ({}), and "
426
+ "will be ignored.\n".format(
427
+ ".".join(str(x) for x in deploy_target),
428
+ ".".join(str(x) for x in base_version),
429
+ )
430
+ )
431
+ else:
432
+ base_version = deploy_target
433
+
434
+ assert len(base_version) == 2
435
+ start_version = base_version
436
+ versions_dict: dict[str, tuple[int, int]] = {}
437
+ for dirpath, _dirnames, filenames in os.walk(archive_root):
438
+ for filename in filenames:
439
+ if filename.endswith(".dylib") or filename.endswith(".so"):
440
+ lib_path = os.path.join(dirpath, filename)
441
+ min_ver = extract_macosx_min_system_version(lib_path)
442
+ if min_ver is not None:
443
+ min_ver = min_ver[0:2]
444
+ if min_ver[0] > 10:
445
+ min_ver = (min_ver[0], 0)
446
+ versions_dict[lib_path] = min_ver
447
+
448
+ if len(versions_dict) > 0:
449
+ base_version = max(base_version, max(versions_dict.values()))
450
+
451
+ # macosx platform tag do not support minor bugfix release
452
+ fin_base_version = "_".join([str(x) for x in base_version])
453
+ if start_version < base_version:
454
+ problematic_files = [k for k, v in versions_dict.items() if v > start_version]
455
+ problematic_files = "\n".join(problematic_files)
456
+ if len(problematic_files) == 1:
457
+ files_form = "this file"
458
+ else:
459
+ files_form = "these files"
460
+ error_message = (
461
+ "[WARNING] This wheel needs a higher macOS version than {} "
462
+ "To silence this warning, set MACOSX_DEPLOYMENT_TARGET to at least "
463
+ + fin_base_version
464
+ + " or recreate "
465
+ + files_form
466
+ + " with lower "
467
+ "MACOSX_DEPLOYMENT_TARGET: \n" + problematic_files
468
+ )
469
+
470
+ if "MACOSX_DEPLOYMENT_TARGET" in os.environ:
471
+ error_message = error_message.format(
472
+ "is set in MACOSX_DEPLOYMENT_TARGET variable."
473
+ )
474
+ else:
475
+ error_message = error_message.format(
476
+ "the version your Python interpreter is compiled against."
477
+ )
478
+
479
+ sys.stderr.write(error_message)
480
+
481
+ platform_tag = prefix + "_" + fin_base_version + "_" + suffix
482
+ return platform_tag
@@ -0,0 +1,183 @@
1
+ """
2
+ Tools for converting old- to new-style metadata.
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ import functools
8
+ import itertools
9
+ import os.path
10
+ import re
11
+ import textwrap
12
+ from email.message import Message
13
+ from email.parser import Parser
14
+ from typing import Generator, Iterable, Iterator, Literal
15
+
16
+ from .vendored.packaging.requirements import Requirement
17
+
18
+
19
+ def _nonblank(str: str) -> bool | Literal[""]:
20
+ return str and not str.startswith("#")
21
+
22
+
23
+ @functools.singledispatch
24
+ def yield_lines(iterable: Iterable[str]) -> Iterator[str]:
25
+ r"""
26
+ Yield valid lines of a string or iterable.
27
+ >>> list(yield_lines(''))
28
+ []
29
+ >>> list(yield_lines(['foo', 'bar']))
30
+ ['foo', 'bar']
31
+ >>> list(yield_lines('foo\nbar'))
32
+ ['foo', 'bar']
33
+ >>> list(yield_lines('\nfoo\n#bar\nbaz #comment'))
34
+ ['foo', 'baz #comment']
35
+ >>> list(yield_lines(['foo\nbar', 'baz', 'bing\n\n\n']))
36
+ ['foo', 'bar', 'baz', 'bing']
37
+ """
38
+ return itertools.chain.from_iterable(map(yield_lines, iterable))
39
+
40
+
41
+ @yield_lines.register(str)
42
+ def _(text: str) -> Iterator[str]:
43
+ return filter(_nonblank, map(str.strip, text.splitlines()))
44
+
45
+
46
+ def split_sections(
47
+ s: str | Iterator[str],
48
+ ) -> Generator[tuple[str | None, list[str]], None, None]:
49
+ """Split a string or iterable thereof into (section, content) pairs
50
+ Each ``section`` is a stripped version of the section header ("[section]")
51
+ and each ``content`` is a list of stripped lines excluding blank lines and
52
+ comment-only lines. If there are any such lines before the first section
53
+ header, they're returned in a first ``section`` of ``None``.
54
+ """
55
+ section = None
56
+ content: list[str] = []
57
+ for line in yield_lines(s):
58
+ if line.startswith("["):
59
+ if line.endswith("]"):
60
+ if section or content:
61
+ yield section, content
62
+ section = line[1:-1].strip()
63
+ content = []
64
+ else:
65
+ raise ValueError("Invalid section heading", line)
66
+ else:
67
+ content.append(line)
68
+
69
+ # wrap up last segment
70
+ yield section, content
71
+
72
+
73
+ def safe_extra(extra: str) -> str:
74
+ """Convert an arbitrary string to a standard 'extra' name
75
+ Any runs of non-alphanumeric characters are replaced with a single '_',
76
+ and the result is always lowercased.
77
+ """
78
+ return re.sub("[^A-Za-z0-9.-]+", "_", extra).lower()
79
+
80
+
81
+ def safe_name(name: str) -> str:
82
+ """Convert an arbitrary string to a standard distribution name
83
+ Any runs of non-alphanumeric/. characters are replaced with a single '-'.
84
+ """
85
+ return re.sub("[^A-Za-z0-9.]+", "-", name)
86
+
87
+
88
+ def requires_to_requires_dist(requirement: Requirement) -> str:
89
+ """Return the version specifier for a requirement in PEP 345/566 fashion."""
90
+ if requirement.url:
91
+ return " @ " + requirement.url
92
+
93
+ requires_dist: list[str] = []
94
+ for spec in requirement.specifier:
95
+ requires_dist.append(spec.operator + spec.version)
96
+
97
+ if requires_dist:
98
+ return " " + ",".join(sorted(requires_dist))
99
+ else:
100
+ return ""
101
+
102
+
103
+ def convert_requirements(requirements: list[str]) -> Iterator[str]:
104
+ """Yield Requires-Dist: strings for parsed requirements strings."""
105
+ for req in requirements:
106
+ parsed_requirement = Requirement(req)
107
+ spec = requires_to_requires_dist(parsed_requirement)
108
+ extras = ",".join(sorted(safe_extra(e) for e in parsed_requirement.extras))
109
+ if extras:
110
+ extras = f"[{extras}]"
111
+
112
+ yield safe_name(parsed_requirement.name) + extras + spec
113
+
114
+
115
+ def generate_requirements(
116
+ extras_require: dict[str | None, list[str]],
117
+ ) -> Iterator[tuple[str, str]]:
118
+ """
119
+ Convert requirements from a setup()-style dictionary to
120
+ ('Requires-Dist', 'requirement') and ('Provides-Extra', 'extra') tuples.
121
+
122
+ extras_require is a dictionary of {extra: [requirements]} as passed to setup(),
123
+ using the empty extra {'': [requirements]} to hold install_requires.
124
+ """
125
+ for extra, depends in extras_require.items():
126
+ condition = ""
127
+ extra = extra or ""
128
+ if ":" in extra: # setuptools extra:condition syntax
129
+ extra, condition = extra.split(":", 1)
130
+
131
+ extra = safe_extra(extra)
132
+ if extra:
133
+ yield "Provides-Extra", extra
134
+ if condition:
135
+ condition = "(" + condition + ") and "
136
+ condition += f"extra == '{extra}'"
137
+
138
+ if condition:
139
+ condition = " ; " + condition
140
+
141
+ for new_req in convert_requirements(depends):
142
+ canonical_req = str(Requirement(new_req + condition))
143
+ yield "Requires-Dist", canonical_req
144
+
145
+
146
+ def pkginfo_to_metadata(egg_info_path: str, pkginfo_path: str) -> Message:
147
+ """
148
+ Convert .egg-info directory with PKG-INFO to the Metadata 2.1 format
149
+ """
150
+ with open(pkginfo_path, encoding="utf-8") as headers:
151
+ pkg_info = Parser().parse(headers)
152
+
153
+ pkg_info.replace_header("Metadata-Version", "2.1")
154
+ # Those will be regenerated from `requires.txt`.
155
+ del pkg_info["Provides-Extra"]
156
+ del pkg_info["Requires-Dist"]
157
+ requires_path = os.path.join(egg_info_path, "requires.txt")
158
+ if os.path.exists(requires_path):
159
+ with open(requires_path, encoding="utf-8") as requires_file:
160
+ requires = requires_file.read()
161
+
162
+ parsed_requirements = sorted(split_sections(requires), key=lambda x: x[0] or "")
163
+ for extra, reqs in parsed_requirements:
164
+ for key, value in generate_requirements({extra: reqs}):
165
+ if (key, value) not in pkg_info.items():
166
+ pkg_info[key] = value
167
+
168
+ description = pkg_info["Description"]
169
+ if description:
170
+ description_lines = pkg_info["Description"].splitlines()
171
+ dedented_description = "\n".join(
172
+ # if the first line of long_description is blank,
173
+ # the first line here will be indented.
174
+ (
175
+ description_lines[0].lstrip(),
176
+ textwrap.dedent("\n".join(description_lines[1:])),
177
+ "\n",
178
+ )
179
+ )
180
+ pkg_info.set_payload(dedented_description)
181
+ del pkg_info["Description"]
182
+
183
+ return pkg_info
@@ -0,0 +1,26 @@
1
+ from __future__ import annotations
2
+
3
+ import base64
4
+ import logging
5
+
6
+ log = logging.getLogger("wheel")
7
+
8
+ # ensure Python logging is configured
9
+ try:
10
+ __import__("setuptools.logging")
11
+ except ImportError:
12
+ # setuptools < ??
13
+ from . import _setuptools_logging
14
+
15
+ _setuptools_logging.configure()
16
+
17
+
18
+ def urlsafe_b64encode(data: bytes) -> bytes:
19
+ """urlsafe_b64encode without padding"""
20
+ return base64.urlsafe_b64encode(data).rstrip(b"=")
21
+
22
+
23
+ def urlsafe_b64decode(data: bytes) -> bytes:
24
+ """urlsafe_b64decode without padding"""
25
+ pad = b"=" * (4 - (len(data) & 3))
26
+ return base64.urlsafe_b64decode(data + pad)