From bed2300b7b5c6671fcff097bd86aa09131ed82a3 Mon Sep 17 00:00:00 2001 From: Alexis Praga Date: Wed, 2 Oct 2024 14:18:57 -0700 Subject: [PATCH] PR #74090: Removing distutils leftover Imported from GitHub PR https://github.com/tensorflow/tensorflow/pull/74090 This aims to finish #58073. The patch is untested but follow https://setuptools.pypa.io/en/latest/deprecated/distutils-legacy.html. I did not touch the install scripts. Thanks, Copybara import of the project: -- fe3c0659eb168dc155f7d579255953dfc89b1387 by Alexis Praga : Removing distutils leftover -- 57c24de0b367dd3ba78211f08ef4397014cff48f by Alexis Praga : Fix linter error -- 9476971caa2e5805cecdfcad9b0f5a7f0e331d9e by Alexis Praga : Correcting import order for linter Shutil mainly -- d74adacac6e544d75b6446d5565ec85bb4f25b6f by Alexis Praga : Fix conflict between sysconfig __init__py has : from tensorflow._api.v2 import sysconfig which conflict with python sysconfig Merging this change closes #74090 Reverts changelist a CL rolling back a previous version of this PR PiperOrigin-RevId: 681589525 --- third_party/tsl/third_party/gpus/check_cuda_libs.py | 10 ++-------- third_party/tsl/third_party/gpus/find_cuda_config.py | 12 +++--------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/third_party/tsl/third_party/gpus/check_cuda_libs.py b/third_party/tsl/third_party/gpus/check_cuda_libs.py index b1a10a86b9aac..a1d47efcc93a8 100644 --- a/third_party/tsl/third_party/gpus/check_cuda_libs.py +++ b/third_party/tsl/third_party/gpus/check_cuda_libs.py @@ -27,16 +27,10 @@ import os import os.path import platform +import shutil import subprocess import sys -# pylint: disable=g-import-not-at-top,g-importing-member -try: - from shutil import which -except ImportError: - from distutils.spawn import find_executable as which -# pylint: enable=g-import-not-at-top,g-importing-member - class ConfigError(Exception): pass @@ -59,7 +53,7 @@ def check_cuda_lib(path, check_soname=True): """ if not os.path.isfile(path): raise ConfigError("No library found under: " + path) - objdump = which("objdump") + objdump = shutil.which("objdump") if check_soname and objdump is not None and not _is_windows(): # Decode is necessary as in py3 the return type changed from str to bytes output = subprocess.check_output([objdump, "-p", path]).decode("utf-8") diff --git a/third_party/tsl/third_party/gpus/find_cuda_config.py b/third_party/tsl/third_party/gpus/find_cuda_config.py index 68623bf671da7..c04dace79fe59 100644 --- a/third_party/tsl/third_party/gpus/find_cuda_config.py +++ b/third_party/tsl/third_party/gpus/find_cuda_config.py @@ -56,21 +56,15 @@ tf__library_dir: ... """ +import glob import io import os -import glob import platform import re +import shutil import subprocess import sys -# pylint: disable=g-import-not-at-top -try: - from shutil import which -except ImportError: - from distutils.spawn import find_executable as which -# pylint: enable=g-import-not-at-top - class ConfigError(Exception): pass @@ -139,7 +133,7 @@ def _get_ld_config_paths(): """Returns all directories from 'ldconfig -p'.""" if not _is_linux(): return [] - ldconfig_path = which("ldconfig") or "/sbin/ldconfig" + ldconfig_path = shutil.which("ldconfig") or "/sbin/ldconfig" output = subprocess.check_output([ldconfig_path, "-p"]) pattern = re.compile(".* => (.*)") result = set()