3
3
import sys
4
4
import tempfile
5
5
from contextlib import contextmanager
6
+ from itertools import chain
6
7
from os .path import abspath
7
8
from os .path import join as pjoin
8
9
from subprocess import STDOUT , check_call , check_output
@@ -380,6 +381,15 @@ def build_sdist(
380
381
},
381
382
)
382
383
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
+
383
393
def _call_hook (self , hook_name : str , kwargs : Mapping [str , Any ]) -> Any :
384
394
extra_environ = {"_PYPROJECT_HOOKS_BUILD_BACKEND" : self .build_backend }
385
395
@@ -394,8 +404,9 @@ def _call_hook(self, hook_name: str, kwargs: Mapping[str, Any]) -> Any:
394
404
# Run the hook in a subprocess
395
405
with _in_proc_script_path () as script :
396
406
python = self .python_executable
407
+ opts = self ._get_warnopts ()
397
408
self ._subprocess_runner (
398
- [python , abspath (str (script )), hook_name , td ],
409
+ [python , * opts , abspath (str (script )), hook_name , td ],
399
410
cwd = self .source_dir ,
400
411
extra_environ = extra_environ ,
401
412
)
0 commit comments