File: 1060-remove-pkg-resources.patch

package info (click to toggle)
pytorch-cuda 2.6.0%2Bdfsg-7
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid, trixie
  • size: 161,620 kB
  • sloc: python: 1,278,832; cpp: 900,322; ansic: 82,710; asm: 7,754; java: 3,363; sh: 2,811; javascript: 2,443; makefile: 597; ruby: 195; xml: 84; objc: 68
file content (34 lines) | stat: -rw-r--r-- 1,358 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Description: Remove use of deprecated pkg_resources module.
 Replace with importlib.metadata from stdlib
Author: Shengqi Chen <harry-chen@outlook.com>
Bug: https://github.com/pytorch/pytorch/issues/139170
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1083727
Last-Update: 2024-10-29 
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
Index: pytorch/test/run_test.py
===================================================================
--- pytorch.orig/test/run_test.py
+++ pytorch/test/run_test.py
@@ -19,7 +19,7 @@ from datetime import datetime
 from pathlib import Path
 from typing import Any, cast, Dict, List, NamedTuple, Optional, Sequence, Tuple, Union
 
-import pkg_resources
+from importlib.metadata import Distribution, PackageNotFoundError
 
 import torch
 import torch.distributed as dist
@@ -2102,9 +2102,10 @@ def check_pip_packages() -> None:
         "pytest-flakefinder",
         "pytest-xdist",
     ]
-    installed_packages = [i.key for i in pkg_resources.working_set]
     for package in packages:
-        if package not in installed_packages:
+        try:
+            Distribution.from_name(package)
+        except PackageNotFoundError:
             print_to_stderr(
                 f"Missing pip dependency: {package}, please run `pip install -r .ci/docker/requirements-ci.txt`"
             )