Skip to content

Commit 5cc90a7

Browse files
committed
Handle sdists that do not have any requirements
grpc-tools (which fails to build a wheel with a message saying to install grpcio-tools) is such a project
1 parent f175ccd commit 5cc90a7

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

metadata_please/sdist.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ def from_zip_sdist(zf: ZipFile) -> bytes:
1212
"""
1313
requires = [f for f in zf.namelist() if f.endswith("/requires.txt")]
1414
requires.sort(key=len)
15+
if not requires:
16+
return b""
17+
1518
data = zf.read(requires[0])
1619
assert data is not None
1720
requires_lines, extras = convert_sdist_requires(data.decode("utf-8"))
@@ -27,6 +30,9 @@ def from_zip_sdist(zf: ZipFile) -> bytes:
2730
def basic_metadata_from_zip_sdist(zf: ZipFile) -> BasicMetadata:
2831
requires = [f for f in zf.namelist() if f.endswith("/requires.txt")]
2932
requires.sort(key=len)
33+
if not requires:
34+
return BasicMetadata((), frozenset())
35+
3036
data = zf.read(requires[0])
3137
assert data is not None
3238
return BasicMetadata.from_sdist_pkg_info_and_requires(b"", data)
@@ -39,6 +45,8 @@ def from_tar_sdist(tf: TarFile) -> bytes:
3945
# XXX Why do ZipFile and TarFile not have a common interface ?!
4046
requires = [f for f in tf.getnames() if f.endswith("/requires.txt")]
4147
requires.sort(key=len)
48+
if not requires:
49+
return b""
4250

4351
fo = tf.extractfile(requires[0])
4452
assert fo is not None
@@ -57,6 +65,8 @@ def basic_metadata_from_tar_sdist(tf: TarFile) -> BasicMetadata:
5765
# XXX Why do ZipFile and TarFile not have a common interface ?!
5866
requires = [f for f in tf.getnames() if f.endswith("/requires.txt")]
5967
requires.sort(key=len)
68+
if not requires:
69+
return BasicMetadata((), frozenset())
6070

6171
fo = tf.extractfile(requires[0])
6272
assert fo is not None

metadata_please/tests/sdist.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ def test_basic_metadata(self) -> None:
4646
)
4747
self.assertEqual({"e"}, bm.provides_extra)
4848

49+
def test_basic_metadata_no_requires_file(self) -> None:
50+
z = MemoryZipFile(
51+
["foo.egg-info/PKG-INFO", "foo/__init__.py"],
52+
read_value=b"\n",
53+
)
54+
bm = basic_metadata_from_zip_sdist(z) # type: ignore
55+
self.assertEqual(
56+
(),
57+
bm.reqs,
58+
)
59+
self.assertEqual(set(), bm.provides_extra)
60+
4961
def test_basic_metadata_absl_py_09(self) -> None:
5062
z = MemoryZipFile(
5163
["foo.egg-info/requires.txt", "foo/__init__.py"],

0 commit comments

Comments
 (0)