Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/fromager/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def default_get_build_sdist_dependencies(
"""Get build sdist dependencies

Defaults to result of hook call
:meth:`~pyproject_hooks.BuildBackendHookCaller.get_requires_for_build_wheel`
:meth:`~pyproject_hooks.BuildBackendHookCaller.get_requires_for_build_sdist`
"""
logger.info(f"looking for build sdist dependencies in {build_dir}")
pbi = ctx.package_build_info(req)
Expand All @@ -247,7 +247,7 @@ def default_get_build_sdist_dependencies(
override_environ=extra_environ,
build_env=build_env,
)
return hook_caller.get_requires_for_build_wheel(
return hook_caller.get_requires_for_build_sdist(
config_settings=pbi.config_settings,
)

Expand Down
56 changes: 56 additions & 0 deletions tests/test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import os
import pathlib
import shutil
import sys
import textwrap
import typing
import zipfile
from unittest.mock import Mock, patch

import hatchling.build
import pyproject_hooks
import pytest
from packaging.metadata import Metadata
from packaging.requirements import Requirement
Expand Down Expand Up @@ -294,6 +296,60 @@ def test_get_build_sdist_dependencies(
assert names == set()


@pytest.mark.parametrize(
"backend_source,expected",
[
(
"def get_requires_for_build_wheel(config_settings=None):\n"
" return ['wheel-only>=1']\n"
"def get_requires_for_build_sdist(config_settings=None):\n"
" return ['sdist-only>=2']\n",
["sdist-only>=2"],
),
(
"def get_requires_for_build_wheel(config_settings=None):\n"
" return ['wheel-only>=1']\n",
[],
),
(
"def get_requires_for_build_wheel(config_settings=None):\n"
" raise RuntimeError('wheel hook must not run')\n"
"def get_requires_for_build_sdist(config_settings=None):\n"
" return ['sdist-only>=2']\n",
["sdist-only>=2"],
),
],
ids=["distinct-requirements", "optional-sdist-hook", "wheel-hook-fails"],
)
def test_default_get_build_sdist_dependencies_uses_sdist_hook(
backend_source: str,
expected: list[str],
tmp_context: context.WorkContext,
tmp_path: pathlib.Path,
) -> None:
"""Discover sdist requirements independently of the wheel hook."""
tmp_path.joinpath("backend.py").write_text(backend_source)
hook_caller = pyproject_hooks.BuildBackendHookCaller(
source_dir=str(tmp_path),
build_backend="backend",
backend_path=["."],
python_executable=sys.executable,
)
with patch(
"fromager.dependencies.get_build_backend_hook_caller",
return_value=hook_caller,
):
results = dependencies.default_get_build_sdist_dependencies(
ctx=tmp_context,
req=Requirement("example"),
sdist_root_dir=tmp_path,
build_dir=tmp_path,
extra_environ={},
build_env=Mock(spec=build_environment.BuildEnvironment),
)
assert list(results) == expected


def test_get_build_sdist_dependencies_cached(
tmp_context: context.WorkContext, tmp_path: pathlib.Path
) -> None:
Expand Down
Loading