Skip to content

[build] modernize build-backend: setuptools.build_meta:__legacy__ -> setuptools.build_meta#155998

Closed
XuehaiPan wants to merge 45 commits intogh/XuehaiPan/279/basefrom
gh/XuehaiPan/279/head
Closed

[build] modernize build-backend: setuptools.build_meta:__legacy__ -> setuptools.build_meta#155998
XuehaiPan wants to merge 45 commits intogh/XuehaiPan/279/basefrom
gh/XuehaiPan/279/head

Conversation

@XuehaiPan
Copy link
Collaborator

@XuehaiPan XuehaiPan commented Jun 14, 2025

Stack from ghstack (oldest at bottom):

Change build-system.build-backend: setuptools.build_meta:__legacy__ -> setuptools.build_meta. Also, move static package info from setup.py to pyproject.toml.

Now the repo can be installed from source via pip command instead of python setup.py develop:

python -m pip install --verbose --editable .

python -m pip install --verbose --no-build-isolation --editable .

In addition, the SDist is also buildable:

python -m build --sdist
python -m install dist/torch-*.tar.gz  # build from source using SDist

Note that we should build the SDist with a fresh git clone if we will upload the output to PyPI. Because all files under third_party will be included in the SDist. The SDist file will be huge if the git submodules are initialized.

cc @seemethere @malfet @osalpekar @atalman

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Jun 14, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/155998

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit fc23e9c with merge base a6fab82 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@XuehaiPan XuehaiPan added module: binaries Anything related to official binaries that we release to users module: build Build system issues ciflow/binaries Trigger all binary build and upload jobs on the PR ciflow/trunk Trigger trunk jobs on your pull request release notes: releng release notes category release notes: build release notes category ciflow/binaries_wheel Trigger binary build and upload jobs for wheel on the PR ciflow/binaries_libtorch Trigger binary build and upload jobs for libtorch on the PR topic: build topic: binaries labels Jun 14, 2025
@XuehaiPan XuehaiPan self-assigned this Jun 14, 2025
MANIFEST.in Outdated
include WORKSPACE
include requirements.txt
include version.txt
include .gitmodules
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Buillding from sdist works with only .gitmodules?

Copy link
Collaborator Author

@XuehaiPan XuehaiPan Jun 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess .gitmodules is not required because we will need to build under a git clone anyway.

One solution is to ship .gitmodules in the SDist and initialize an empty git folder to allow submodule cloning:

# in setup.py
if not os.path.exists(os.path.join(cwd, '.git')):
    subprocesses.check_call(['git', 'init'], cwd=cwd)
    subprocesses.check_call(['git', 'add', '.'], cwd=cwd)
    subprocesses.check_call(['git', 'commit', '-m', 'init for building from sdist'], cwd=cwd)
subprocesses.check_call(['git', 'submodule', 'update', '--init', '--recursive'], cwd=cwd)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sdist should include all submodules. It looks to me like this is already included (since third_party is explicitly included) in gh-152098. .gitmodules should then not be required.

Comment on lines +21 to +23
graft torchgen
# FIXME: torch-xla codegen build failure if include this file in wheel
exclude torchgen/BUILD.bazel
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

torch_xla/csrc/BUILD genrule command (from target //torch_xla/csrc:gen_lazy_tensor) cannot import torchgen if this file is present in site-packages/torchgen/BUILD.bazel. cc @qihqi

The following fix will not resolve the import issue.

CI failure before pytorch/xla#9310: https://hud.pytorch.org/pr/pytorch/pytorch/153538#43672158222
CI failure after pytorch/xla#9310: https://hud.pytorch.org/pr/pytorch/pytorch/153538#44066727613

XuehaiPan added a commit to XuehaiPan/pytorch that referenced this pull request Jun 14, 2025
…> `setuptools.build_meta`

Change `build-system.build-backend`: `setuptools.build_meta:__legacy__` -> `setuptools.build_meta`. Also, move static package info from `setup.py` to `pyproject.toml`.

Now the repo can be installed from source via `pip` command instead of `python setup.py develop`:

```bash
python -m pip install --verbose --editable .

python -m pip install --verbose --no-build-isolation --editable .
```

In addition, the SDist is also buildable:

```bash
python -m build --sdist
python -m install dist/torch-*.tar.gz  # build from source using SDist
```


ghstack-source-id: 6dbd393
Pull-Request: pytorch#155998
@Skylion007
Copy link
Collaborator

Skylion007 commented Jun 14, 2025

@XuehaiPan We are sure this doesn't break s3cache, right (with the temporary build dir)?

@Skylion007
Copy link
Collaborator

uv also support --no-build-isolation flag in pyproject.toml (unlike pip). Maybe we should add an entry for it.

]
# Use legacy backend to import local packages in setup.py
build-backend = "setuptools.build_meta:__legacy__"
build-backend = "setuptools.build_meta"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ultimately, this still builds under build isolation which is a big gotcha for the CI. Can we migrate to legacy scikit-build? That at least does a lot of stuff to effectively disable build isolation by default.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand this comment. It doesn't seem like a good idea to migrate to another legacy tool. Build isolation can be confusing for users when they're not that experienced, but for better or worse it is how Python packaging works. I don't see a reason to try hard to subvert that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scikit-build-core works too, but I'm not sure how stable the setup tools shim is for it.

BUILD_LIBTORCH_WHL = os.getenv("BUILD_LIBTORCH_WHL", "0") == "1"
BUILD_PYTHON_ONLY = os.getenv("BUILD_PYTHON_ONLY", "0") == "1"

# Also update `project.requires-python` in pyproject.toml when changing this
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if we could detect build isolation and raise a warning

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's possible, nor is it desirable - it's perfectly valid for example for a packager to build with python -m build --wheel.

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@Skylion007
Copy link
Collaborator

@rgommers Main reason to subvert build isolation is the multi-hour build times of pytorch when building from src.

@rgommers
Copy link
Collaborator

rgommers commented Jul 2, 2025

@rgommers Main reason to subvert build isolation is the multi-hour build times of pytorch when building from src.

I'm not sure I understand what you mean. Yes building PyTorch is quite slow, but whether or not one uses build isolation or not has no impact on build time.

[ghstack-poisoned]
@XuehaiPan
Copy link
Collaborator Author

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot
Copy link
Collaborator

Merge failed

Reason: 1 mandatory check(s) failed. The first few are:

Dig deeper by viewing the failures on hud

Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

@XuehaiPan
Copy link
Collaborator Author

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot
Copy link
Collaborator

The merge job was canceled or timed out. This most often happen if two merge requests were issued for the same PR, or if merge job was waiting for more than 6 hours for tests to finish. In later case, please do not hesitate to reissue the merge command
For more information see pytorch-bot wiki.

@XuehaiPan
Copy link
Collaborator Author

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@malfet
Copy link
Contributor

malfet commented Jul 3, 2025

@pytorchbot revert -m "Broke inductor_cpp, wrapper see https://hud.pytorch.org/hud/pytorch/pytorch/e472daa80963aae389089f9dc324b04261e2a5ef/1?per_page=50&name_filter=inductor_cpp_" -c nosignal

@pytorchmergebot
Copy link
Collaborator

@pytorchbot successfully started a revert job. Check the current status here.
Questions? Feedback? Please reach out to the PyTorch DevX Team

@pytorchmergebot
Copy link
Collaborator

@XuehaiPan your PR has been successfully reverted.

[ghstack-poisoned]
XuehaiPan added 4 commits July 4, 2025 15:39
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@XuehaiPan
Copy link
Collaborator Author

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-no-td Do not run TD on this PR ciflow/binaries_libtorch Trigger binary build and upload jobs for libtorch on the PR ciflow/binaries_wheel Trigger binary build and upload jobs for wheel on the PR ciflow/binaries Trigger all binary build and upload jobs on the PR ciflow/inductor ciflow/trunk Trigger trunk jobs on your pull request Merged module: binaries Anything related to official binaries that we release to users module: build Build system issues open source release notes: build release notes category release notes: releng release notes category Reverted topic: binaries topic: build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

setup.py develop command is disappearing soon from setuptools

9 participants