Skip to content

Commit 50bc6ba

Browse files
committed
update files
1 parent b8eda18 commit 50bc6ba

File tree

3 files changed

+21
-26
lines changed

3 files changed

+21
-26
lines changed

.github/workflows/build_python_3.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,4 @@ jobs:
125125
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
126126
with:
127127
name: wheels-${{ env.ARTIFACT_NAME }}
128-
path: ./wheelhouse/*.whl
128+
path: ./wheelhouse/*.whl

scripts/validate_wheel.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@
2222
def compute_hash(data):
2323
"""Compute the urlsafe base64 encoded SHA256 hash of data."""
2424
hash_digest = hashlib.sha256(data).digest()
25-
return base64.urlsafe_b64encode(hash_digest).rstrip(b'=').decode('ascii')
25+
return base64.urlsafe_b64encode(hash_digest).rstrip(b"=").decode("ascii")
2626

2727

2828
def validate_wheel(wheel_path):
2929
"""Validate that wheel contents match its RECORD file."""
3030
errors = []
3131

32-
with zipfile.ZipFile(wheel_path, 'r') as wheel:
32+
with zipfile.ZipFile(wheel_path, "r") as wheel:
3333
# Find the RECORD file
3434
record_path = None
3535
for name in wheel.namelist():
36-
if name.endswith('.dist-info/RECORD'):
36+
if name.endswith(".dist-info/RECORD"):
3737
record_path = name
3838
break
3939

@@ -42,7 +42,7 @@ def validate_wheel(wheel_path):
4242
return errors
4343

4444
# Parse the RECORD file
45-
record_content = wheel.read(record_path).decode('utf-8')
45+
record_content = wheel.read(record_path).decode("utf-8")
4646
record_entries = {}
4747

4848
reader = csv.reader(io.StringIO(record_content))
@@ -51,16 +51,13 @@ def validate_wheel(wheel_path):
5151
continue
5252

5353
file_path, hash_str, size_str = row[0], row[1], row[2]
54-
record_entries[file_path] = {
55-
'hash': hash_str,
56-
'size': int(size_str) if size_str else None
57-
}
54+
record_entries[file_path] = {"hash": hash_str, "size": int(size_str) if size_str else None}
5855

5956
# Get all files in the wheel (excluding directories)
6057
wheel_files = set()
6158
for name in wheel.namelist():
6259
# Skip directories (they end with /)
63-
if not name.endswith('/'):
60+
if not name.endswith("/"):
6461
wheel_files.add(name)
6562

6663
record_files = set(record_entries.keys())
@@ -87,25 +84,23 @@ def validate_wheel(wheel_path):
8784
file_data = wheel.read(file_path)
8885

8986
# Check size
90-
if record_entry['size'] is not None:
87+
if record_entry["size"] is not None:
9188
actual_size = len(file_data)
92-
if actual_size != record_entry['size']:
89+
if actual_size != record_entry["size"]:
9390
errors.append(
94-
f"Size mismatch for {file_path}: "
95-
f"RECORD says {record_entry['size']}, actual is {actual_size}"
91+
f"Size mismatch for {file_path}: RECORD says {record_entry['size']}, actual is {actual_size}"
9692
)
9793

9894
# Check hash
99-
if record_entry['hash']:
95+
if record_entry["hash"]:
10096
# Parse the hash format (algorithm=base64hash)
101-
if '=' in record_entry['hash']:
102-
algo, expected_hash = record_entry['hash'].split('=', 1)
103-
if algo == 'sha256':
97+
if "=" in record_entry["hash"]:
98+
algo, expected_hash = record_entry["hash"].split("=", 1)
99+
if algo == "sha256":
104100
actual_hash = compute_hash(file_data)
105101
if actual_hash != expected_hash:
106102
errors.append(
107-
f"Hash mismatch for {file_path}: "
108-
f"RECORD says {expected_hash}, actual is {actual_hash}"
103+
f"Hash mismatch for {file_path}: RECORD says {expected_hash}, actual is {actual_hash}"
109104
)
110105
else:
111106
errors.append(f"Unknown hash algorithm {algo} for {file_path} (expected sha256)")
@@ -143,4 +138,4 @@ def main():
143138

144139

145140
if __name__ == "__main__":
146-
sys.exit(main())
141+
sys.exit(main())

scripts/zip_filter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def update_record(record_content, patterns):
2222

2323
# Rebuild the RECORD content
2424
output = io.StringIO()
25-
writer = csv.writer(output, lineterminator='\n')
25+
writer = csv.writer(output, lineterminator="\n")
2626
for record in records:
2727
writer.writerow(record)
2828

@@ -36,8 +36,8 @@ def remove_from_zip(zip_filename, patterns):
3636
# First pass: read RECORD file if it exists
3737
with zipfile.ZipFile(zip_filename, "r") as source_zip:
3838
for file in source_zip.infolist():
39-
if file.filename.endswith('.dist-info/RECORD'):
40-
record_content = source_zip.read(file.filename).decode('utf-8')
39+
if file.filename.endswith(".dist-info/RECORD"):
40+
record_content = source_zip.read(file.filename).decode("utf-8")
4141
break
4242

4343
# Second pass: create new zip without removed files and with updated RECORD
@@ -48,7 +48,7 @@ def remove_from_zip(zip_filename, patterns):
4848
for file in source_zip.infolist():
4949
if any(fnmatch.fnmatch(file.filename, pattern) for pattern in patterns):
5050
continue
51-
elif file.filename.endswith('.dist-info/RECORD') and record_content:
51+
elif file.filename.endswith(".dist-info/RECORD") and record_content:
5252
# Update the RECORD file
5353
updated_record = update_record(record_content, patterns)
5454
temp_zip.writestr(file, updated_record)
@@ -66,4 +66,4 @@ def parse_args():
6666

6767
if __name__ == "__main__":
6868
args = parse_args()
69-
remove_from_zip(args.zipfile, args.patterns)
69+
remove_from_zip(args.zipfile, args.patterns)

0 commit comments

Comments
 (0)