8000 [BE]: Add PEP621 project section to pyproject.toml (#153055) · pytorch/pytorch@032ef48 · GitHub
[go: up one dir, main page]

Skip to content

Commit 032ef48

Browse files
Skylion007pytorchmergebot
authored andcommitted
[BE]: Add PEP621 project section to pyproject.toml (#153055)
Follow up to @ezyang's PR #153020 , but better uses PEP621 to reduce redundant fields and pass through metadata better to uv, setuptools, poetry and other tooling. * Enables modern tooling like uv sync and better support for tools like poetry. * Also allows us to set project wide settings that are respected by linters and IDE (in this example we are able centralize the minimum supported python version). * Currently most of the values are dynamically fetched from setuptools, eventually we can migrate all the statically defined values to pyproject.toml and they will be autopopulated in the setuptool arguments. * This controls what additional metadata shows up on PyPi . Special URL Names are listed here for rendering on pypi: https://packaging.python.org/en/latest/specifications/well-known-project-urls/#well-known-labels These also clearly shows us what fields will need to be migrated to pyproject.toml over time from setup.py per #152276. Static fields be fairly easy to migrate, the dynamically built ones like requirements are a bit more challenging. Without this, `uv sync` complains: ``` error: No `project` table found in: `pytorch/pyproject.toml` ``` Pull Request resolved: #153055 Approved by: https://github.com/ezyang
1 parent ceb009b commit 032ef48

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

pyproject.toml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
[project]
2+
name = "torch"
3+
requires-python = ">=3.9"
4+
license = {text = "BSD-3-Clause"}
5+
dynamic = [
6+
"authors",
7+
"classifiers",
8+
"entry-points",
9+
"dependencies",
10+
"description",
11+
"keywords",
12+
"optional-dependencies",
13+
"readme",
14+
"scripts",
15+
"version",
16+
]
17+
18+
[project.urls]
19+
Homepage = "https://pytorch.org/"
20+
Documentation = "https://pytorch.org/docs/"
21+
Source = "https://github.com/pytorch/pytorch"
22+
Forum = "https://discuss.pytorch.org/"
23+
24+
125
[build-system]
226
requires = [
327
# After 75.8.2 dropped dep disttools API. Please fix
@@ -18,8 +42,6 @@ build-backend = "setuptools.build_meta:__legacy__"
1842

1943
[tool.black]
2044
line-length = 88
21-
target-version = ["py38"]
22-
2345

2446
[tool.isort]
2547
src_paths = ["caffe2", "torch", "torchgen", "functorch", "test"]
@@ -42,7 +64,6 @@ standard_library = ["typing_extensions"]
4264

4365

4466
[tool.ruff]
45-
target-version = "py39"
4667
line-length = 88
4768
src = ["caffe2", "torch", "torchgen", "functorch", "test"]
4869

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,8 @@ def main():
12961296
install_requires=install_requires,
12971297
extras_require=extras_require,
12981298
package_data=package_data,
1299+
# TODO fix later Manifest.IN file was previously ignored
1300+
include_package_data=False, # defaults to True with pyproject.toml file
12991301
url="https://pytorch.org/",
13001302
download_url="https://github.com/pytorch/pytorch/tags",
13011303
author="PyTorch Team",

test/test_testing.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,6 +2352,11 @@ def test_circular_dependencies(self) -> None:
23522352
"torch.onnx._internal", # depends on onnx-script
23532353
"torch._inductor.runtime.triton_helpers", # depends on triton
23542354
"torch._inductor.codegen.cuda", # depends on cutlass
2355+
"torch.distributed.benchmarks", # depends on RPC and DDP Optim
2356+
"torch.distributed.examples", # requires CUDA and torchvision
2357+
"torch.distributed.tensor.examples", # example scripts
2358+
"torch.csrc", # files here are devtools, not part of torch
2359+
"torch.include", # torch include files after install
23552360
]
23562361
if IS_WINDOWS or IS_MACOS or IS_JETSON:
23572362
# Distributed should be importable on Windows(except nn.api.), but not on Mac

torch/distributed/examples/memory_tracker_example.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# mypy: allow-untyped-defs
2-
import torchvision
3-
42
import torch
53
from torch.distributed._tools import MemoryTracker
64

@@ -30,4 +28,9 @@ def run_one_model(net: torch.nn.Module, input: torch.Tensor):
3028
mem_tracker.show_traces()
3129

3230

33-
run_one_model(torchvision.models.resnet34(), torch.rand(32, 3, 224, 224, device="cuda"))
31+
if __name__ == "__main__":
32+
import torchvision
33+
34+
run_one_model(
35+
torchvision.models.resnet34(), torch.rand(32, 3, 224, 224, device="cuda")
36+
)

0 commit comments

Comments
 (0)
0