Skip to content

Commit fc04436

Browse files
authored
[DevX] Enable editable mode (#7443)
Enable `pip install -e .` with local build flatc and custom ops AOT lib disabled.
1 parent 3aebf2f commit fc04436

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

setup.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,13 @@ def src_path(self, installer: "InstallerBuildExt") -> Path:
216216
file.
217217
"""
218218
# Share the cmake-out location with CustomBuild.
219-
cmake_cache_dir = Path(installer.get_finalized_command("build").cmake_cache_dir)
220-
219+
build_cmd = installer.get_finalized_command("build")
220+
if hasattr(build_cmd, "cmake_cache_dir"):
221+
cmake_cache_dir = Path(build_cmd.cmake_cache_dir)
222+
else:
223+
# If we're in editable mode, use a default or fallback value for cmake_cache_dir
224+
# This could be a hardcoded path, or a path derived from the current working directory
225+
cmake_cache_dir = Path(".")
221226
cfg = get_build_type(installer.debug)
222227

223228
if os.name == "nt":
@@ -232,7 +237,14 @@ def src_path(self, installer: "InstallerBuildExt") -> Path:
232237
srcs = tuple(cmake_cache_dir.glob(self.src))
233238
if len(srcs) != 1:
234239
raise ValueError(
235-
f"Expected exactly one file matching '{self.src}'; found {repr(srcs)}"
240+
f"""Expected exactly one file matching '{self.src}'; found {repr(srcs)}.
241+
242+
If that file is a CMake-built extension module file, and we are installing in editable mode, please disable the corresponding build option since it's not supported yet.
243+
244+
Try:
245+
246+
EXECUTORCH_BUILD_FLATC=OFF EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT=OFF pip install -e .
247+
"""
236248
)
237249
return srcs[0]
238250

@@ -401,7 +413,11 @@ def run(self):
401413
# package, and will look like `pip-out/lib`. It can contain multiple
402414
# python packages, so be sure to copy the files into the `executorch`
403415
# package subdirectory.
404-
dst_root = os.path.join(self.build_lib, self.get_package_dir("executorch"))
416+
if self.editable_mode:
417+
# In editable mode, the package directory is the original source directory
418+
dst_root = self.get_package_dir(".")
419+
else:
420+
dst_root = os.path.join(self.build_lib, self.get_package_dir("executorch"))
405421

406422
# Create the version file.
407423
Version.write_to_python_file(os.path.join(dst_root, "version.py"))

0 commit comments

Comments
 (0)