33import sys
44import tempfile
55from contextlib import contextmanager
6+ from itertools import chain
67from os .path import abspath
78from os .path import join as pjoin
89from subprocess import STDOUT , check_call , check_output
@@ -380,6 +381,15 @@ def build_sdist(
380381 },
381382 )
382383
384+ def _get_warnopts (self ) -> Iterator [str ]:
385+ """
386+ Reconstruct Python's warn options that are active for the current process,
387+ so that it can be forwarded to a subprocess.
388+ """
389+ # `sys.warnoptions` is documented/mentioned in
390+ # https://docs.python.org/3.13/library/warnings.html#describing-warning-filters
391+ return chain .from_iterable (("-W" , opt ) for opt in sys .warnoptions )
392+
383393 def _call_hook (self , hook_name : str , kwargs : Mapping [str , Any ]) -> Any :
384394 extra_environ = {"_PYPROJECT_HOOKS_BUILD_BACKEND" : self .build_backend }
385395
@@ -394,8 +404,9 @@ def _call_hook(self, hook_name: str, kwargs: Mapping[str, Any]) -> Any:
394404 # Run the hook in a subprocess
395405 with _in_proc_script_path () as script :
396406 python = self .python_executable
407+ opts = self ._get_warnopts ()
397408 self ._subprocess_runner (
398- [python , abspath (str (script )), hook_name , td ],
409+ [python , * opts , abspath (str (script )), hook_name , td ],
399410 cwd = self .source_dir ,
400411 extra_environ = extra_environ ,
401412 )
0 commit comments