Skip to content

Commit 1946c3d

Browse files
AkiSakuraikirklandsign
authored andcommitted
Update Codegen.cmake for improved Python package path handling (#6730)
- Modified the method of retrieving the Python site-packages path to use `importlib.util.find_spec` for better compatibility. - fix #6689
1 parent 0225671 commit 1946c3d

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

tools/cmake/Codegen.cmake

+7-7
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,19 @@ function(generate_bindings_for_kernels)
8383
execute_process(
8484
COMMAND
8585
"${PYTHON_EXECUTABLE}" -c
86-
"from distutils.sysconfig import get_python_lib;print(get_python_lib())"
87-
OUTPUT_VARIABLE site-packages-out
88-
ERROR_VARIABLE site-packages-out-error
89-
RESULT_VARIABLE site-packages-result
86+
"import torchgen;import os; print(os.path.dirname(torchgen.__file__))"
87+
OUTPUT_VARIABLE torchgen-out
88+
ERROR_VARIABLE torchgen-out-error
89+
RESULT_VARIABLE torchgen-result
9090
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
9191
OUTPUT_STRIP_TRAILING_WHITESPACE
9292
)
93-
file(GLOB_RECURSE _torchgen_srcs "${site-packages-out}/torchgen/*.py")
93+
file(GLOB_RECURSE _torchgen_srcs "${torchgen-out}/*.py")
9494
set(_gen_command
9595
"${PYTHON_EXECUTABLE}" -m torchgen.gen_executorch
9696
--source-path=${EXECUTORCH_ROOT}/codegen --install-dir=${_out_dir}
97-
--tags-path=${site-packages-out}/torchgen/packaged/ATen/native/tags.yaml
98-
--aten-yaml-path=${site-packages-out}/torchgen/packaged/ATen/native/native_functions.yaml
97+
--tags-path=${torchgen-out}/packaged/ATen/native/tags.yaml
98+
--aten-yaml-path=${torchgen-out}/packaged/ATen/native/native_functions.yaml
9999
--op-selection-yaml-path=${_oplist_yaml}
100100
)
101101
if(GEN_ADD_EXCEPTION_BOUNDARY)

0 commit comments

Comments
 (0)