Skip to content

Refactor setup.py to support editable mode #8379

Closed
@larryliu0820

Description

@larryliu0820

🚀 The feature, motivation and pitch

Blocking #2871

Context:

The current pattern of setup.py in ExecuTorch:

  • Build extensions in CustomBuild class (extending build). Run CMake build commands to build pybind extensions. Triggered from cmdclass["build"]
  • After extensions are built, run InstallerBuildExt class to install the extension artifacts (.so etc). The class takes a list of ext_modules to learn what is the source path (normally .so files in cmake-out/) and what is the destination path in the package. ext_modules list is also controlled by the same CMake flags for custom build. This step is triggered from cmdclass["build_ext"]
  • Lastly, setup.py runsbuild_pyto copy python files to package directories. This step is triggered from cmdclass["build_py"].

This pattern is different from the common pattern, but it works without issue.

Assumption:

We want to support editable mode (pip install -e .). In editable installation we should perform the exact same installation steps as normal mode, respecting the same options as normal mode.

For example, the plain command

pip install -e .

Should install portable_lib extension because by default EXECUTORCH_BUILD_PYBIND=ON

Problem:

The current pattern doesn’t work for editable mode. Here are the reasons:

  1. The build step doesn’t even run when editable mode is on. This is causing build_ext to error out because it’s expecting the .so files to be present in the build directory but they are missing.
  2. We don’t want to diverge the installation behavior between editable mode on and off as much as possible. This means we don’t want to do if editable mode on do A otherwise do B.

Proposal:

Move the python extension installation step (CMake commands) into one of ext_modules.

Alternatives

No response

Additional context

No response

RFC (Optional)

No response

cc @mergennachin @byjlw @SS-JIA @manuelcandales

Metadata

Metadata

Assignees

Labels

module: build/installIssues related to the cmake and buck2 builds, and to installing ExecuTorchmodule: user experienceIssues related to reducing friction for userstriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

Status

Done

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions