@@ -140,9 +140,11 @@ def default_get_build_backend_dependencies(
140140 Defaults to result of hook call
141141 :meth:`~pyproject_hooks.BuildBackendHookCaller.get_requires_for_build_wheel`
142142 """
143- pyproject_toml = get_pyproject_contents (build_dir )
144143 hook_caller = get_build_backend_hook_caller (
145- build_dir , pyproject_toml , override_environ = extra_environ
144+ ctx = ctx ,
145+ req = req ,
146+ build_dir = build_dir ,
147+ override_environ = extra_environ ,
146148 )
147149 return hook_caller .get_requires_for_build_wheel ()
148150
@@ -197,9 +199,11 @@ def default_get_build_sdist_dependencies(
197199 Defaults to result of hook call
198200 :meth:`~pyproject_hooks.BuildBackendHookCaller.get_requires_for_build_wheel`
199201 """
200- pyproject_toml = get_pyproject_contents (build_dir )
201202 hook_caller = get_build_backend_hook_caller (
202- build_dir , pyproject_toml , override_environ = extra_environ
203+ ctx = ctx ,
204+ req = req ,
205+ build_dir = build_dir ,
206+ override_environ = extra_environ ,
203207 )
204208 return hook_caller .get_requires_for_build_wheel ()
205209
@@ -220,13 +224,12 @@ def get_install_dependencies_of_sdist(
220224 logger .info (
221225 f"{ req .name } : getting install requirements for { req } from sdist in { build_dir } "
222226 )
223- pyproject_toml = get_pyproject_contents (build_dir )
224227 extra_environ = pbi .get_extra_environ ()
225228 hook_caller = get_build_backend_hook_caller (
226- build_dir ,
227- pyproject_toml ,
229+ ctx = ctx ,
230+ req = req ,
231+ build_dir = build_dir ,
228232 override_environ = extra_environ ,
229- network_isolation = ctx .network_isolation ,
230233 build_env = build_env ,
231234 )
232235 with tempfile .TemporaryDirectory () as tmp_dir :
@@ -296,39 +299,44 @@ def get_build_backend(pyproject_toml: dict[str, typing.Any]) -> dict[str, typing
296299
297300
298301def get_build_backend_hook_caller (
299- sdist_root_dir : pathlib .Path ,
300- pyproject_toml : dict [str , typing .Any ],
301- override_environ : dict [str , typing .Any ],
302302 * ,
303- network_isolation : bool = False ,
303+ ctx : context .WorkContext ,
304+ req : Requirement ,
305+ build_dir : pathlib .Path ,
306+ override_environ : dict [str , typing .Any ],
304307 build_env : build_environment .BuildEnvironment | None = None ,
305308) -> pyproject_hooks .BuildBackendHookCaller :
306- backend = get_build_backend ( pyproject_toml )
309+ """Create pyproject_hooks build backend caller"""
307310
308311 def _run_hook_with_extra_environ (
309312 cmd : typing .Sequence [str ],
310313 cwd : str | None = None ,
311314 extra_environ : typing .Mapping [str , str ] | None = None ,
312315 ) -> None :
313316 """The BuildBackendHookCaller is going to pass extra_environ
314- and our build system may want to set some values, too. Merge
315- the 2 sets of values before calling the actual runner function.
317+ and our build system may want to set some values, too. The hook
318+ also needs env vars from the build environment's virtualenv. Merge
319+ the 3 sets of values before calling the actual runner function.
316320 """
317- full_environ : dict [str , typing .Any ] = {}
318- if extra_environ is not None :
319- full_environ .update (extra_environ )
320- full_environ .update (override_environ )
321+ if typing .TYPE_CHECKING :
322+ assert build_env is not None
323+ extra_environ = dict (extra_environ ) if extra_environ else {}
324+ extra_environ .update (override_environ )
325+ if build_env is not None :
326+ extra_environ .update (build_env .get_venv_environ (template_env = extra_environ ))
321327 external_commands .run (
322328 cmd ,
323329 cwd = cwd ,
324- extra_environ = full_environ ,
325- network_isolation = network_isolation ,
330+ extra_environ = extra_environ ,
331+ network_isolation = ctx . network_isolation ,
326332 )
327333
334+ pyproject_toml = get_pyproject_contents (build_dir )
335+ backend = get_build_backend (pyproject_toml )
328336 python_executable = str (build_env .python ) if build_env is not None else None
329337
330338 return pyproject_hooks .BuildBackendHookCaller (
331- source_dir = str (sdist_root_dir ),
339+ source_dir = str (build_dir ),
332340 build_backend = backend ["build-backend" ],
333341 backend_path = backend ["backend-path" ],
334342 runner = _run_hook_with_extra_environ ,
0 commit comments