Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 45 commits into from

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]
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 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
@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.

MANIFEST.in Outdated
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.

@@ -38,9 +16,56 @@ requires = [
"typing-extensions>=4.10.0",
"requests",
]
# 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.

@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.

@pytorchmergebot pytorchmergebot added Reverted ci-no-td Do not run TD on this PR labels Jul 3, 2025
[ghstack-poisoned]
XuehaiPan added a commit to XuehaiPan/pytorch that referenced this pull request Jul 3, 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: f0c9fda
Pull-Request: pytorch#155998
XuehaiPan added a commit to XuehaiPan/pytorch that referenced this pull request Jul 4, 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: f0c9fda
Pull-Request: pytorch#155998
[ghstack-poisoned]
XuehaiPan added a commit to XuehaiPan/pytorch that referenced this pull request Jul 4, 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: 9a2a960
Pull-Request: pytorch#155998
[ghstack-poisoned]
XuehaiPan added a commit to XuehaiPan/pytorch that referenced this pull request Jul 4, 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: 58b5296
Pull-Request: pytorch#155998
XuehaiPan added a commit to XuehaiPan/pytorch that referenced this pull request Jul 4, 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: 58b5296
Pull-Request: pytorch#155998
[ghstack-poisoned]
XuehaiPan added a commit to XuehaiPan/pytorch that referenced this pull request Jul 4, 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: 3f1f3b1
Pull-Request: pytorch#155998
[ghstack-poisoned]
XuehaiPan added a commit to XuehaiPan/pytorch that referenced this pull request Jul 4, 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: 2e61e35
Pull-Request: pytorch#155998
@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

@github-actions github-actions bot deleted the gh/XuehaiPan/279/head branch August 4, 2025 02:21
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