@@ -694,32 +694,54 @@ endif
694694# building, but we can't add it to the sources of that extension (this C file
695695# doesn't compile, it's only included in another r file. Hence use the slightly
696696# hacky --ignore argument to the next custom_target().
697+ codegen_files = [
698+ ' code_generators/__init__.py' ,
699+ ' code_generators/genapi.py' ,
700+ ' code_generators/generate_numpy_api.py' ,
701+ ' code_generators/generate_ufunc_api.py' ,
702+ ' code_generators/generate_umath_doc.py' ,
703+ ' code_generators/generate_umath.py' ,
704+ ' code_generators/numpy_api.py' ,
705+ ' code_generators/ufunc_docstrings.py' ,
706+ ]
707+ codegen_env = {
708+ # Explicitly set PYTHONPATH to avoid depending on the current working directory
709+ # at build time, and on unsafe paths that may be prepended to sys.path and can be
710+ # disabled by PYTHONSAFEPATH. See:
711+ # [1] https://github.com/numpy/numpy/issues/24907
712+ # [2] https://docs.python.org/3/library/sys.html#sys.path
713+ ' PYTHONPATH' : meson .current_source_dir(),
714+ }
715+
697716src_umath_api_c = custom_target (' __umath_generated' ,
698717 output : ' __umath_generated.c' ,
699- input : ' code_generators/generate_umath.py' ,
700- command : [py, ' @INPUT@' , ' -o' , ' @OUTPUT@' ],
718+ depend_files : codegen_files,
719+ command : [py, ' -m' , ' code_generators.generate_umath' , ' -o' , ' @OUTPUT@' ],
720+ env : codegen_env,
701721)
702722
703723src_umath_doc_h = custom_target (' _umath_doc_generated' ,
704724 output : ' _umath_doc_generated.h' ,
705- input : [ ' code_generators/generate_umath_doc.py ' ,
706- ' code_generators/ufunc_docstrings.py ' ],
707- command : [py, ' @INPUT0@ ' , ' -o ' , ' @OUTPUT@ ' ] ,
725+ depend_files : codegen_files ,
726+ command : [py, ' -m ' , ' code_generators.generate_umath_doc ' , ' -o ' , ' @OUTPUT@ ' ],
727+ env : codegen_env ,
708728)
709729
710730src_numpy_api = custom_target (' __multiarray_api' ,
711731 output : [' __multiarray_api.c' , ' __multiarray_api.h' ],
712- input : ' code_generators/generate_numpy_api.py' ,
713- command : [py, ' @INPUT@' , ' -o' , ' @OUTDIR@' , ' --ignore' , src_umath_api_c],
732+ depend_files : codegen_files,
733+ command : [py, ' -m' , ' code_generators.generate_numpy_api' , ' -o' , ' @OUTDIR@' , ' --ignore' , src_umath_api_c],
734+ env : codegen_env,
714735 install : true , # NOTE: setup.py build installs all, but just need .h?
715736 install_dir : np_dir / ' _core/include/numpy' ,
716737 install_tag : ' devel'
717738)
718739
719740src_ufunc_api = custom_target (' __ufunc_api' ,
720741 output : [' __ufunc_api.c' , ' __ufunc_api.h' ],
721- input : ' code_generators/generate_ufunc_api.py' ,
722- command : [py, ' @INPUT@' , ' -o' , ' @OUTDIR@' ],
742+ depend_files : codegen_files,
743+ command : [py, ' -m' , ' code_generators.generate_ufunc_api' , ' -o' , ' @OUTDIR@' ],
744+ env : codegen_env,
723745 install : true , # NOTE: setup.py build installs all, but just need .h?
724746 install_dir : np_dir / ' _core/include/numpy' ,
725747 install_tag : ' devel'
0 commit comments