Gentoo Archives: gentoo-commits

From: Benda XU <heroxbd@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/sci:master commit in: sci-libs/pytorch/, sci-libs/pytorch/files/
Date: Sun, 26 Dec 2021 13:38:24
Message-Id: 1640525812.74376475a3dbb8124f5fedea9af4ba69a2a4b82f.heroxbd@gentoo
1 commit: 74376475a3dbb8124f5fedea9af4ba69a2a4b82f
2 Author: YiyangWu <xgreenlandforwyy <AT> gmail <DOT> com>
3 AuthorDate: Sat Dec 25 16:46:19 2021 +0000
4 Commit: Benda XU <heroxbd <AT> gentoo <DOT> org>
5 CommitDate: Sun Dec 26 13:36:52 2021 +0000
6 URL: https://gitweb.gentoo.org/proj/sci.git/commit/?id=74376475
7
8 sci-libs/pytorch: fix python build with >=setuptools-59.6
9
10 Reference: https://github.com/pytorch/pytorch/commit/07767569c964552702bf374da753212eb9cde327
11 Reference: https://github.com/gentoo/sci/pull/1123#issuecomment-999597677
12 Package-Manager: Portage-3.0.22, Repoman-3.0.3
13 Closes: https://github.com/gentoo/sci/pull/1130
14 Signed-off-by: Yiyang Wu <xgreenlandforwyy <AT> gmail.com>
15 Signed-off-by: Benda Xu <heroxbd <AT> gentoo.org>
16
17 .../files/pytorch-1.10.0-fix-distutils.patch | 93 ++++++++++++++++++++++
18 sci-libs/pytorch/pytorch-1.10.1.ebuild | 1 +
19 2 files changed, 94 insertions(+)
20
21 diff --git a/sci-libs/pytorch/files/pytorch-1.10.0-fix-distutils.patch b/sci-libs/pytorch/files/pytorch-1.10.0-fix-distutils.patch
22 new file mode 100644
23 index 000000000..334bcda6f
24 --- /dev/null
25 +++ b/sci-libs/pytorch/files/pytorch-1.10.0-fix-distutils.patch
26 @@ -0,0 +1,93 @@
27 +This fix distutils-r1_src_install failure with setuptools-59
28 +
29 +From 9af2edb158b3603c44eff6e12896f1d215e8b898 Mon Sep 17 00:00:00 2001
30 +From: Nikita Shulga <nshulga@××.com>
31 +Date: Tue, 14 Dec 2021 07:15:34 -0800
32 +Subject: [PATCH] Properly import LooseVersion
33 +
34 +This fixes regression introduced by https://github.com/pytorch/pytorch/pull/57040
35 +
36 +Somehow importing `distutils` from `setuptool` caused import of
37 +`distutils.versions`, which is not a documented dependency and got
38 +change with the release of
39 +[setuptools-59.6.0](https://github.com/pypa/setuptools/tree/v59.6.0)
40 +We should not rely on that, as
41 +`import distutils` never re-imports `distutils.version`, which one can
42 +see by observing
43 +https://github.com/python/cpython/blob/3.9/Lib/distutils/__init__.py
44 +or by running:
45 +```
46 +% python3 -c "import distutils;print(distutils.__version__, dir(distutils))"
47 +3.7.5 ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'sys']
48 +% python3 -c "from setuptools import distutils;print(distutils.__version__, dir(distutils))"
49 +3.7.5 ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'archive_util', 'ccompiler', 'cmd', 'config', 'core', 'debug', 'dep_util', 'dir_util', 'dist', 'errors', 'extension', 'fancy_getopt', 'file_util', 'filelist', 'log', 'spawn', 'sys', 'sysconfig', 'util', 'version']
50 +```
51 +---
52 + test/run_test.py | 4 ++--
53 + tools/setup_helpers/cmake.py | 8 ++++----
54 + torch/testing/_internal/common_methods_invocations.py | 8 ++++----
55 + 3 files changed, 10 insertions(+), 10 deletions(-)
56 +
57 +diff --git a/tools/setup_helpers/cmake.py b/tools/setup_helpers/cmake.py
58 +index 01e87b4bca879..686b5c4a34f4c 100644
59 +--- a/tools/setup_helpers/cmake.py
60 ++++ b/tools/setup_helpers/cmake.py
61 +@@ -8,7 +8,7 @@
62 + from subprocess import check_call, check_output, CalledProcessError
63 + import sys
64 + import sysconfig
65 +-from setuptools import distutils # type: ignore[import]
66 ++from distutils.version import LooseVersion
67 + from typing import IO, Any, Dict, List, Optional, Union, cast
68 +
69 + from . import which
70 +@@ -120,10 +120,10 @@ def _get_cmake_command() -> str:
71 + return cmake_command
72 + cmake3 = which('cmake3')
73 + cmake = which('cmake')
74 +- if cmake3 is not None and CMake._get_version(cmake3) >= distutils.version.LooseVersion("3.10.0"):
75 ++ if cmake3 is not None and CMake._get_version(cmake3) >= LooseVersion("3.10.0"):
76 + cmake_command = 'cmake3'
77 + return cmake_command
78 +- elif cmake is not None and CMake._get_version(cmake) >= distutils.version.LooseVersion("3.10.0"):
79 ++ elif cmake is not None and CMake._get_version(cmake) >= LooseVersion("3.10.0"):
80 + return cmake_command
81 + else:
82 + raise RuntimeError('no cmake or cmake3 with version >= 3.10.0 found')
83 +@@ -134,7 +134,7 @@ def _get_version(cmd: str) -> Any:
84 +
85 + for line in check_output([cmd, '--version']).decode('utf-8').split('\n'):
86 + if 'version' in line:
87 +- return distutils.version.LooseVersion(line.strip().split(' ')[2])
88 ++ return LooseVersion(line.strip().split(' ')[2])
89 + raise RuntimeError('no version found')
90 +
91 + def run(self, args: List[str], env: Dict[str, str]) -> None:
92 +diff --git a/torch/testing/_internal/common_methods_invocations.py b/torch/testing/_internal/common_methods_invocations.py
93 +index b66e6470b590c..6ec77c2b0ce2e 100644
94 +--- a/torch/testing/_internal/common_methods_invocations.py
95 ++++ b/torch/testing/_internal/common_methods_invocations.py
96 +@@ -40,7 +40,7 @@
97 + freeze_rng_state)
98 + import torch.testing._internal.opinfo_helper as opinfo_helper
99 +
100 +-from setuptools import distutils
101 ++from distutils.version import LooseVersion
102 +
103 + has_scipy_fft = False
104 + if TEST_SCIPY:
105 +@@ -14008,11 +14008,11 @@ def ref_pairwise_distance(input1, input2):
106 + skips=(
107 + # Reference: https://github.com/pytorch/pytorch/pull/49155#issuecomment-742664611
108 + DecorateInfo(unittest.skip("Skipped!"), 'TestUnaryUfuncs', 'test_reference_numerics_extremal',
109 +- active_if=TEST_SCIPY and distutils.version.LooseVersion(scipy.__version__) < "1.4.0"),
110 ++ active_if=TEST_SCIPY and LooseVersion(scipy.__version__) < "1.4.0"),
111 + DecorateInfo(unittest.skip("Skipped!"), 'TestUnaryUfuncs', 'test_reference_numerics_hard',
112 +- active_if=TEST_SCIPY and distutils.version.LooseVersion(scipy.__version__) < "1.4.0"),
113 ++ active_if=TEST_SCIPY and LooseVersion(scipy.__version__) < "1.4.0"),
114 + DecorateInfo(unittest.skip("Skipped!"), 'TestUnaryUfuncs', 'test_reference_numerics_normal',
115 +- active_if=TEST_SCIPY and distutils.version.LooseVersion(scipy.__version__) < "1.4.0"),
116 ++ active_if=TEST_SCIPY and LooseVersion(scipy.__version__) < "1.4.0"),
117 + )),
118 + UnaryUfuncInfo('lgamma',
119 + ref=reference_lgamma if TEST_SCIPY else _NOTHING,
120
121 diff --git a/sci-libs/pytorch/pytorch-1.10.1.ebuild b/sci-libs/pytorch/pytorch-1.10.1.ebuild
122 index e3b49e630..2a11e6240 100644
123 --- a/sci-libs/pytorch/pytorch-1.10.1.ebuild
124 +++ b/sci-libs/pytorch/pytorch-1.10.1.ebuild
125 @@ -117,6 +117,7 @@ PATCHES=(
126 "${FILESDIR}"/${PN}-1.7.1-no-rpath.patch
127 "${FILESDIR}"/${PN}-1.7.1-torch_shm_manager.patch
128 "${FILESDIR}"/${PN}-1.10.0-nonull.patch
129 + "${FILESDIR}"/${PN}-1.10.0-fix-distutils.patch
130 )
131
132 distutils_enable_tests pytest