Skip to content

Commit

Permalink
getpath.py: fix dirname
Browse files Browse the repository at this point in the history
also, fix finding prefix when in a venv
  • Loading branch information
naveen521kk committed Jun 25, 2023
1 parent ea0a016 commit e8f495e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Modules/getpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
3 changes: 3 additions & 0 deletions Modules/getpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e8f495e

Please sign in to comment.