Skip to content

Commit c64f173

Browse files
committed
[GR-52784] Patch wheel to avoid 2GB bytes size limit
PullRequest: graalpython/3259
2 parents ec19f54 + c59ae36 commit c64f173

File tree

7 files changed

+294
-288
lines changed

7 files changed

+294
-288
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[[rules]]
22
version = '== 6.0.0'
33
patch = 'flake8-6.0.0.patch'
4+
subdir = 'src'

graalpython/lib-graalpython/patches/tensorflow/tensorflow-2.14.0.patch

Lines changed: 93 additions & 140 deletions
Large diffs are not rendered by default.

graalpython/lib-graalpython/patches/tensorflow/tensorflow-2.15.0.patch

Lines changed: 94 additions & 143 deletions
Large diffs are not rendered by default.

graalpython/lib-graalpython/patches/torch/torch-2.2.1.patch

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,18 @@ index 68fd53d0..2871915e 100644
317317
auto *tb = reinterpret_cast<PyTracebackObject *>(m_trace.ptr());
318318

319319
// Get the deepest trace possible.
320+
diff --git a/tools/generate_torch_version.py b/tools/generate_torch_version.py
321+
index 93689693..81e360dc 100644
322+
--- a/tools/generate_torch_version.py
323+
+++ b/tools/generate_torch_version.py
324+
@@ -40,6 +40,7 @@ def get_tag(pytorch_root: Union[str, Path]) -> str:
325+
326+
327+
def get_torch_version(sha: Optional[str] = None) -> str:
328+
+ return '2.2.1'
329+
pytorch_root = Path(__file__).parent.parent
330+
version = open(pytorch_root / "version.txt").read().strip()
331+
320332
diff --git a/torch/_dynamo/types.py b/torch/_dynamo/types.py
321333
index 0c1deddd..f60e9d72 100644
322334
--- a/torch/_dynamo/types.py

graalpython/lib-graalpython/patches/wheel/metadata.toml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
[[rules]]
22
# Always pin a specific version. Our virtualenv seeder pins setuptools and pip to the bundled
33
# ones, so it makes sense to always pin wheel too to avoid it getting out of sync with setuptools.
4-
version = '== 0.41.2'
5-
# Backport pypa/packaging PR for fixing graalpy architecture. Not strictly necessary for building wheels
6-
patch = 'wheel-0.41.2.patch'
4+
version = '== 0.43.0'
5+
# Add a workaround for building wheels with files larger than 2GB
6+
patch = 'wheel-0.43.patch'
77
subdir = 'src'
88

9+
# Catch all rule for newer versions
910
[[rules]]
10-
version = '>= 0.41.2'
11-
patch = 'wheel-0.41.2.patch'
11+
version = '>= 0.43.0'
12+
patch = 'wheel-0.43.patch'
1213
subdir = 'src'
1314
install-priority = 0
1415

16+
[[rules]]
17+
version = '== 0.41.2'
18+
patch = 'wheel-0.41.2.patch'
19+
subdir = 'src'
20+
1521
[[rules]]
1622
version = '>= 0.40, < 0.41.2'
1723
patch = 'wheel-0.40.patch'
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
diff --git a/wheel/wheelfile.py b/wheel/wheelfile.py
2+
index 6440e90..7ef7528 100644
3+
--- a/wheel/wheelfile.py
4+
+++ b/wheel/wheelfile.py
5+
@@ -144,7 +144,9 @@ class WheelFile(ZipFile):
6+
def write(self, filename, arcname=None, compress_type=None):
7+
with open(filename, "rb") as f:
8+
st = os.fstat(f.fileno())
9+
- data = f.read()
10+
+ data = []
11+
+ while chunk := f.read(4194304):
12+
+ data.append(chunk)
13+
14+
zinfo = ZipInfo(
15+
arcname or filename, date_time=get_zipinfo_datetime(st.st_mtime)
16+
@@ -164,7 +166,10 @@ class WheelFile(ZipFile):
17+
if isinstance(data, str):
18+
data = data.encode("utf-8")
19+
20+
- ZipFile.writestr(self, zinfo_or_arcname, data, compress_type)
21+
+ # GraalPy change
22+
+ if not isinstance(data, list):
23+
+ data = [data]
24+
+ self.writestr_list(zinfo_or_arcname, data, compress_type)
25+
fname = (
26+
zinfo_or_arcname.filename
27+
if isinstance(zinfo_or_arcname, ZipInfo)
28+
@@ -172,12 +177,52 @@ class WheelFile(ZipFile):
29+
)
30+
log.info(f"adding '{fname}'")
31+
if fname != self.record_path:
32+
- hash_ = self._default_algorithm(data)
33+
+ hash_ = self._default_algorithm()
34+
+ for chunk in data:
35+
+ hash_.update(chunk)
36+
self._file_hashes[fname] = (
37+
hash_.name,
38+
urlsafe_b64encode(hash_.digest()).decode("ascii"),
39+
)
40+
- self._file_sizes[fname] = len(data)
41+
+ self._file_sizes[fname] = sum(map(len, data))
42+
+
43+
+ # GraalPy change: version that accepts data as a list of bytes chunks, to
44+
+ # avoid running into the 2GB limit for bytes object size
45+
+ def writestr_list(self, zinfo_or_arcname, data,
46+
+ compress_type=None, compresslevel=None):
47+
+ if not isinstance(zinfo_or_arcname, ZipInfo):
48+
+ zinfo = ZipInfo(filename=zinfo_or_arcname,
49+
+ date_time=time.localtime(time.time())[:6])
50+
+ zinfo.compress_type = self.compression
51+
+ zinfo._compresslevel = self.compresslevel
52+
+ if zinfo.filename[-1] == '/':
53+
+ zinfo.external_attr = 0o40775 << 16 # drwxrwxr-x
54+
+ zinfo.external_attr |= 0x10 # MS-DOS directory flag
55+
+ else:
56+
+ zinfo.external_attr = 0o600 << 16 # ?rw-------
57+
+ else:
58+
+ zinfo = zinfo_or_arcname
59+
+
60+
+ if not self.fp:
61+
+ raise ValueError(
62+
+ "Attempt to write to ZIP archive that was already closed")
63+
+ if self._writing:
64+
+ raise ValueError(
65+
+ "Can't write to ZIP archive while an open writing handle exists."
66+
+ )
67+
+
68+
+ if compress_type is not None:
69+
+ zinfo.compress_type = compress_type
70+
+
71+
+ if compresslevel is not None:
72+
+ zinfo._compresslevel = compresslevel
73+
+
74+
+ zinfo.file_size = sum(map(len, data)) # Uncompressed size
75+
+ with self._lock:
76+
+ with self.open(zinfo, mode='w') as dest:
77+
+ for chunk in data:
78+
+ dest.write(chunk)
79+
+
80+
81+
def close(self):
82+
# Write RECORD

mx.graalpython/mx_graalpython.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,6 +2106,7 @@ def _python_checkpatchfiles():
21062106
# Empty license field. It's MIT
21072107
'urllib3-2.patch',
21082108
# Empty license field. It's MIT
2109+
'wheel-0.43.patch',
21092110
'wheel-0.41.2.patch',
21102111
'wheel-0.40.patch',
21112112
'wheel-0.38.patch',

0 commit comments

Comments
 (0)