56 lines
1.9 KiB
Diff
56 lines
1.9 KiB
Diff
From 42b0d0dc1ba018965faa3a91935a8561dadd4e0f Mon Sep 17 00:00:00 2001
|
|
From: Naveen M K <naveen521kk@gmail.com>
|
|
Date: Sun, 25 Jun 2023 19:39:30 +0530
|
|
Subject: [PATCH 136/N] getpath.py: fix `dirname`
|
|
|
|
also, fix finding prefix when in a venv
|
|
---
|
|
Modules/getpath.c | 12 ++++++++++++
|
|
Modules/getpath.py | 3 +++
|
|
2 files changed, 15 insertions(+)
|
|
|
|
diff --git a/Modules/getpath.c b/Modules/getpath.c
|
|
index f7cef43..da87df3 100644
|
|
--- a/Modules/getpath.c
|
|
+++ b/Modules/getpath.c
|
|
@@ -89,6 +89,12 @@ getpath_basename(PyObject *Py_UNUSED(self), PyObject *args)
|
|
}
|
|
Py_ssize_t end = PyUnicode_GET_LENGTH(path);
|
|
Py_ssize_t pos = PyUnicode_FindChar(path, SEP, 0, end, -1);
|
|
+#ifdef ALTSEP
|
|
+ if (pos < 0) {
|
|
+ // try using altsep
|
|
+ pos = PyUnicode_FindChar(path, ALTSEP, 0, end, -1);
|
|
+ }
|
|
+#endif
|
|
if (pos < 0) {
|
|
return Py_NewRef(path);
|
|
}
|
|
@@ -105,6 +111,12 @@ getpath_dirname(PyObject *Py_UNUSED(self), PyObject *args)
|
|
}
|
|
Py_ssize_t end = PyUnicode_GET_LENGTH(path);
|
|
Py_ssize_t pos = PyUnicode_FindChar(path, SEP, 0, end, -1);
|
|
+#ifdef ALTSEP
|
|
+ if (pos < 0) {
|
|
+ // try using altsep
|
|
+ pos = PyUnicode_FindChar(path, ALTSEP, 0, end, -1);
|
|
+ }
|
|
+#endif
|
|
if (pos < 0) {
|
|
return PyUnicode_FromStringAndSize(NULL, 0);
|
|
}
|
|
diff --git a/Modules/getpath.py b/Modules/getpath.py
|
|
index 83db516..fe23ba2 100644
|
|
--- a/Modules/getpath.py
|
|
+++ b/Modules/getpath.py
|
|
@@ -574,6 +574,9 @@ def search_up(prefix, *landmarks, test=isfile):
|
|
# First try to detect prefix by looking alongside our runtime library, if known
|
|
if library and not prefix:
|
|
library_dir = dirname(library)
|
|
+ if os_name == 'nt' and is_mingw:
|
|
+ # QUIRK: On Windows, mingw Python DLLs are in the bin directory
|
|
+ library_dir = joinpath(library_dir, '..')
|
|
if ZIP_LANDMARK:
|
|
if os_name == 'nt':
|
|
# QUIRK: Windows does not search up for ZIP file
|