Skip to content

Commit c378a24

Browse files
naveen521kklazka
authored andcommitted
getpath.py: fix dirname
also, fix finding prefix when in a venv
1 parent d27d14e commit c378a24

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Modules/getpath.c

+12
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ getpath_basename(PyObject *Py_UNUSED(self), PyObject *args)
8989
}
9090
Py_ssize_t end = PyUnicode_GET_LENGTH(path);
9191
Py_ssize_t pos = PyUnicode_FindChar(path, SEP, 0, end, -1);
92+
#ifdef ALTSEP
93+
if (pos < 0) {
94+
// try using altsep
95+
pos = PyUnicode_FindChar(path, ALTSEP, 0, end, -1);
96+
}
97+
#endif
9298
if (pos < 0) {
9399
return Py_NewRef(path);
94100
}
@@ -105,6 +111,12 @@ getpath_dirname(PyObject *Py_UNUSED(self), PyObject *args)
105111
}
106112
Py_ssize_t end = PyUnicode_GET_LENGTH(path);
107113
Py_ssize_t pos = PyUnicode_FindChar(path, SEP, 0, end, -1);
114+
#ifdef ALTSEP
115+
if (pos < 0) {
116+
// try using altsep
117+
pos = PyUnicode_FindChar(path, ALTSEP, 0, end, -1);
118+
}
119+
#endif
108120
if (pos < 0) {
109121
return PyUnicode_FromStringAndSize(NULL, 0);
110122
}

Modules/getpath.py

+3
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,9 @@ def search_up(prefix, *landmarks, test=isfile):
574574
# First try to detect prefix by looking alongside our runtime library, if known
575575
if library and not prefix:
576576
library_dir = dirname(library)
577+
if os_name == 'nt' and is_mingw:
578+
# QUIRK: On Windows, mingw Python DLLs are in the bin directory
579+
library_dir = joinpath(library_dir, '..')
577580
if ZIP_LANDMARK:
578581
if os_name == 'nt':
579582
# QUIRK: Windows does not search up for ZIP file

0 commit comments

Comments
 (0)