From 66afeb36fcb51854b3c40da11258cfdb167b1c34 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 20 Apr 2024 21:51:04 -0400 Subject: [PATCH] Refactor _resolve_path to be less nested. --- distutils/spawn.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/distutils/spawn.py b/distutils/spawn.py index ce5f78cc..1cf118e2 100644 --- a/distutils/spawn.py +++ b/distutils/spawn.py @@ -124,16 +124,22 @@ def _split_path(path: str | None) -> Iterable[str]: def _resolve_path(path: str | None) -> str | None: - if path is None: - path = os.environ.get('PATH', None) - # bpo-35755: Don't fall through if PATH is the empty string - if path is None: - try: - path = os.confstr("CS_PATH") - except (AttributeError, ValueError): - # os.confstr() or CS_PATH is not available - path = os.defpath - return path + """ + Resolve a path from a specified value, or from environmental state. + """ + if path is not None: + return path + + env = os.environ.get('PATH', None) + # bpo-35755: Don't fall through if PATH is the empty string + if env is not None: + return env + + try: + return os.confstr("CS_PATH") + except (AttributeError, ValueError): + # os.confstr() or CS_PATH is not available + return os.defpath def _search_paths(path):