Skip to content

Commit d8690f3

Browse files
author
Jonathon Belotti
committed
WHEEL files can container empty lines, so handle that. the .data dir is optional in WHEELs so handle that
1 parent 8caa860 commit d8690f3

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/wheel.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pkg_resources
55
import glob
66

7-
from typing import Dict
7+
from typing import Dict, Optional
88

99

1010
class Wheel(object):
@@ -43,7 +43,7 @@ def unzip(self, directory):
4343
whl.extractall(directory)
4444

4545

46-
def get_dist_info(extracted_whl_directory):
46+
def get_dist_info(extracted_whl_directory) -> str:
4747
dist_info_dirs = glob.glob(os.path.join(extracted_whl_directory, "*.dist-info"))
4848
if not dist_info_dirs:
4949
raise ValueError(f"No *.dist-info directory found. {extracted_whl_directory} is not a valid Wheel.")
@@ -54,11 +54,11 @@ def get_dist_info(extracted_whl_directory):
5454
return dist_info
5555

5656

57-
def get_dot_data_directory(extracted_whl_directory):
57+
def get_dot_data_directory(extracted_whl_directory) -> Optional[str]:
5858
# See: https://www.python.org/dev/peps/pep-0491/#the-data-directory
5959
dot_data_dirs = glob.glob(os.path.join(extracted_whl_directory, "*.data"))
6060
if not dot_data_dirs:
61-
raise ValueError(f"No *.data directory found. {extracted_whl_directory} is not a valid Wheel.")
61+
return None
6262
elif len(dot_data_dirs) > 1:
6363
raise ValueError(f"Found more than 1 *.data directory. {extracted_whl_directory} is not a valid Wheel.")
6464
else:
@@ -71,6 +71,8 @@ def parse_WHEEL_file(whl_file_path: str) -> Dict[str, str]:
7171
with open(whl_file_path, "r") as f:
7272
for line in f:
7373
cleaned = line.strip()
74+
if not cleaned:
75+
continue
7476
try:
7577
key, value = cleaned.split(":", maxsplit=1)
7678
contents[key] = value.strip()

0 commit comments

Comments
 (0)