Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions src/fromager/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
BUILD_SDIST_REQ_FILE_NAME = "build-sdist-requirements.txt"
INSTALL_REQ_FILE_NAME = "requirements.txt"

# marker for Fromager's stub PKG-INFO
STUB_PKG_INFO_SUMMARY = "Fromage stub PKG-INFO"


def get_build_system_dependencies(
*,
Expand Down Expand Up @@ -314,14 +317,28 @@ def default_get_install_dependencies_of_sdist(
config_settings=config_settings,
validate=True,
)
validate_dist_name_version(
req=req,
version=version,
what="sdist metadata",
# Metadata name is a non-normalized string
dist_name=canonicalize_name(metadata.name),
dist_version=metadata.version,
)
if metadata.summary is None or STUB_PKG_INFO_SUMMARY not in metadata.summary:
# Do not attempt to validate stub metadata. Version may be incorrect.
# Treat other validation errors as non-fatal errors.
try:
validate_dist_name_version(
req=req,
version=version,
what="sdist metadata",
# Metadata name is a non-normalized string
dist_name=canonicalize_name(metadata.name),
dist_version=metadata.version,
)
except Exception as e:
logger.error(
"metadata for %s==%s in %r failed to validate: %s",
req.name,
version,
sdist_root_dir,
e,
)
else:
logger.debug("Fromager stub metadata detected, not validating name and version")
if not metadata.requires_dist:
return set()
return set(metadata.requires_dist)
Expand Down
3 changes: 2 additions & 1 deletion src/fromager/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ def pep517_build_sdist(
Metadata-Version: 1.0
Name: {name}
Version: {version}
Summary: Fromage stub PKG-INFO
Summary: {summary}
"""


Expand Down Expand Up @@ -726,6 +726,7 @@ def ensure_pkg_info(
PKG_INFO_CONTENT.format(
name=req.name,
version=str(version),
summary=dependencies.STUB_PKG_INFO_SUMMARY,
)
)
had_pkg_info = False
Expand Down
29 changes: 29 additions & 0 deletions tests/test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ def test_default_get_install_dependencies_of_sdist(
m_pep517_metadata_of_sdist: Mock,
tmp_context: context.WorkContext,
tmp_path: pathlib.Path,
caplog: pytest.LogCaptureFixture,
) -> None:
req = Requirement("huggingface-hub")
version = Version("1.2.3")
Expand Down Expand Up @@ -245,6 +246,34 @@ def test_default_get_install_dependencies_of_sdist(
)
assert requirements == {Requirement("filelock"), Requirement("requests")}

# bad metadata (version mismatch) is treated as non-fatal error
metadata_txt = textwrap.dedent(
"""\
Metadata-Version: 2.3
Name: HuggingFace_Hub
Version: 1.2a0
Requires-Dist: filelock
Requires-Dist: requests
"""
)
metadata = Metadata.from_email(metadata_txt)
m_pep517_metadata_of_sdist.return_value = metadata
requirements = dependencies.default_get_install_dependencies_of_sdist(
ctx=tmp_context,
req=req,
version=version,
sdist_root_dir=tmp_path,
build_env=Mock(),
extra_environ={},
build_dir=tmp_path,
config_settings={},
)
assert requirements == {Requirement("filelock"), Requirement("requests")}
assert (
"sdist metadata '1.2a0' does not match public version '1.2.3'"
in caplog.messages[-1]
)


@pytest.mark.parametrize(
"req_str,version_str,dist_name_str,dist_version_str,exc",
Expand Down
Loading