Skip to content

Commit 3d373b6

Browse files
committed
Update Codegen.cmake for improved Python package path handling
- Modified the method of retrieving the Python site-packages path to use `importlib.util.find_spec` for better compatibility. - fix #6689
1 parent 39e5b91 commit 3d373b6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

build/Codegen.cmake

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,19 @@ function(generate_bindings_for_kernels)
7979
execute_process(
8080
COMMAND
8181
"${PYTHON_EXECUTABLE}" -c
82-
"from distutils.sysconfig import get_python_lib;print(get_python_lib())"
82+
"from importlib.util import find_spec;print(find_spec('torchgen').submodule_search_locations[0])"
8383
OUTPUT_VARIABLE site-packages-out
8484
ERROR_VARIABLE site-packages-out-error
8585
RESULT_VARIABLE site-packages-result
8686
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
8787
OUTPUT_STRIP_TRAILING_WHITESPACE
8888
)
89-
file(GLOB_RECURSE _torchgen_srcs "${site-packages-out}/torchgen/*.py")
89+
file(GLOB_RECURSE _torchgen_srcs "${site-packages-out}/*.py")
9090
set(_gen_command
9191
"${PYTHON_EXECUTABLE}" -m torchgen.gen_executorch
9292
--source-path=${EXECUTORCH_ROOT}/codegen --install-dir=${_out_dir}
93-
--tags-path=${site-packages-out}/torchgen/packaged/ATen/native/tags.yaml
94-
--aten-yaml-path=${site-packages-out}/torchgen/packaged/ATen/native/native_functions.yaml
93+
--tags-path=${site-packages-out}/packaged/ATen/native/tags.yaml
94+
--aten-yaml-path=${site-packages-out}/packaged/ATen/native/native_functions.yaml
9595
--op-selection-yaml-path=${_oplist_yaml}
9696
)
9797

0 commit comments

Comments
 (0)