MINGW-packages/mingw-w64-python/0095-getpath.py-fix-dirname.patch
2025-06-07 14:11:54 +02:00

56 lines
1.9 KiB
Diff

From 8dd0930f7dd87b02c9616ce85098be33c6e075ce 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 095/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 de7efb6..099cffc 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 6867e98..5687e4f 100644
--- a/Modules/getpath.py
+++ b/Modules/getpath.py
@@ -574,6 +574,9 @@ else:
# 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