From 1bfe703b265dd5be731fc7f92213a651d31a40b2 Mon Sep 17 00:00:00 2001 From: Xinxia <985025074@qq.com> Date: Mon, 28 Apr 2025 15:45:57 +0800 Subject: [PATCH 1/4] update shutil.which doc --- Doc/library/shutil.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Doc/library/shutil.rst b/Doc/library/shutil.rst index 2cbf95bcf535e4..aaf0e3371893e3 100644 --- a/Doc/library/shutil.rst +++ b/Doc/library/shutil.rst @@ -445,6 +445,8 @@ Directory and files operations Return the path to an executable which would be run if the given *cmd* was called. If no *cmd* would be called, return ``None``. + If *cmd* contains a directory component, *which* will only check the specified path directly + and will not search the directories listed in *path* or in the system's ``PATH`` environment variable. *mode* is a permission mask passed to :func:`os.access`, by default determining if the file exists and is executable. From 32c1c0b11bd87be88c0cd09d14d7fcd242f5013a Mon Sep 17 00:00:00 2001 From: Xinxia <985025074@qq.com> Date: Mon, 28 Apr 2025 20:05:04 +0800 Subject: [PATCH 2/4] change the location of the note. --- Doc/library/shutil.rst | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Doc/library/shutil.rst b/Doc/library/shutil.rst index aaf0e3371893e3..4eba436ef66e80 100644 --- a/Doc/library/shutil.rst +++ b/Doc/library/shutil.rst @@ -445,8 +445,6 @@ Directory and files operations Return the path to an executable which would be run if the given *cmd* was called. If no *cmd* would be called, return ``None``. - If *cmd* contains a directory component, *which* will only check the specified path directly - and will not search the directories listed in *path* or in the system's ``PATH`` environment variable. *mode* is a permission mask passed to :func:`os.access`, by default determining if the file exists and is executable. @@ -456,6 +454,12 @@ Directory and files operations :envvar:`PATH` environment variable is read from :data:`os.environ`, falling back to :data:`os.defpath` if it is not set. + .. note:: + + If *cmd* contains a directory component, :func:`!which` only checks the + specified path directly and does not search the directories listed in *path* + or in the system's ``PATH`` environment variable. + On Windows, the current directory is prepended to the *path* if *mode* does not include ``os.X_OK``. When the *mode* does include ``os.X_OK``, the Windows API ``NeedCurrentDirectoryForExePathW`` will be consulted to From df20e17c385ef31fa30dd6f20e6ff958cc6dd400 Mon Sep 17 00:00:00 2001 From: Xinxia <985025074@qq.com> Date: Tue, 29 Apr 2025 00:09:04 +0800 Subject: [PATCH 3/4] use envvar for PATH --- Doc/library/shutil.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/shutil.rst b/Doc/library/shutil.rst index 4eba436ef66e80..4ae8651f55a761 100644 --- a/Doc/library/shutil.rst +++ b/Doc/library/shutil.rst @@ -458,7 +458,7 @@ Directory and files operations If *cmd* contains a directory component, :func:`!which` only checks the specified path directly and does not search the directories listed in *path* - or in the system's ``PATH`` environment variable. + or in the system's :envvar:`PATH` environment variable. On Windows, the current directory is prepended to the *path* if *mode* does not include ``os.X_OK``. When the *mode* does include ``os.X_OK``, the From c812c943b0dcfd8ac4f652be9a96568c6923d918 Mon Sep 17 00:00:00 2001 From: Xinxia <985025074@qq.com> Date: Wed, 30 Apr 2025 10:33:16 +0800 Subject: [PATCH 4/4] change path to the next line --- Doc/library/shutil.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/shutil.rst b/Doc/library/shutil.rst index 4ae8651f55a761..7c260aa923a00a 100644 --- a/Doc/library/shutil.rst +++ b/Doc/library/shutil.rst @@ -457,8 +457,8 @@ Directory and files operations .. note:: If *cmd* contains a directory component, :func:`!which` only checks the - specified path directly and does not search the directories listed in *path* - or in the system's :envvar:`PATH` environment variable. + specified path directly and does not search the directories listed in + *path* or in the system's :envvar:`PATH` environment variable. On Windows, the current directory is prepended to the *path* if *mode* does not include ``os.X_OK``. When the *mode* does include ``os.X_OK``, the