From a58cc5a13c99251956b073a50e03aec41a3a2e3f Mon Sep 17 00:00:00 2001 From: Tom Aarsen Date: Thu, 15 Sep 2022 10:57:49 +0200 Subject: Prevent OSError when env variables contain long value --- bitsandbytes/cuda_setup/paths.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/bitsandbytes/cuda_setup/paths.py b/bitsandbytes/cuda_setup/paths.py index 6f6425f..231b053 100644 --- a/bitsandbytes/cuda_setup/paths.py +++ b/bitsandbytes/cuda_setup/paths.py @@ -1,3 +1,4 @@ +import errno from pathlib import Path from typing import Set, Union from warnings import warn @@ -12,17 +13,22 @@ def extract_candidate_paths(paths_list_candidate: str) -> Set[Path]: def remove_non_existent_dirs(candidate_paths: Set[Path]) -> Set[Path]: - non_existent_directories: Set[Path] = { - path for path in candidate_paths if not path.exists() - } - + existent_directories: Set[Path] = set() + for path in candidate_paths: + try: + if path.exists(): + existent_directories.add(path) + except errno.ENAMETOOLONG: + pass + + non_existent_directories: Set[Path] = candidate_paths - existent_directories if non_existent_directories: warn( "WARNING: The following directories listed in your path were found to " f"be non-existent: {non_existent_directories}" ) - return candidate_paths - non_existent_directories + return existent_directories def get_cuda_runtime_lib_paths(candidate_paths: Set[Path]) -> Set[Path]: -- cgit v1.2.3 From 7d771d1d6d4c3df83c1b82d4d5df2b4dc95c1759 Mon Sep 17 00:00:00 2001 From: Tom Aarsen Date: Thu, 15 Sep 2022 11:13:12 +0200 Subject: Catch OSError with specific error number --- bitsandbytes/cuda_setup/paths.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bitsandbytes/cuda_setup/paths.py b/bitsandbytes/cuda_setup/paths.py index 231b053..ba3f97f 100644 --- a/bitsandbytes/cuda_setup/paths.py +++ b/bitsandbytes/cuda_setup/paths.py @@ -18,8 +18,9 @@ def remove_non_existent_dirs(candidate_paths: Set[Path]) -> Set[Path]: try: if path.exists(): existent_directories.add(path) - except errno.ENAMETOOLONG: - pass + except OSError as exc: + if exc.errno != errno.ENAMETOOLONG: + raise exc non_existent_directories: Set[Path] = candidate_paths - existent_directories if non_existent_directories: -- cgit v1.2.3