Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.12] gh-117114: Add isdevdrive to posixpath (GH-117115) #117249

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions Doc/library/os.path.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.. module:: os.path
:synopsis: Operations on pathnames.

**Source code:** :source:`Lib/posixpath.py` (for POSIX) and
**Source code:** :source:`Lib/genericpath.py`, :source:`Lib/posixpath.py` (for POSIX) and
:source:`Lib/ntpath.py` (for Windows).

.. index:: single: path; operations
Expand Down Expand Up @@ -85,8 +85,6 @@ the :mod:`glob` module.)
if *paths* is empty. Unlike :func:`commonprefix`, this returns a
valid path.

.. availability:: Unix, Windows.

.. versionadded:: 3.5

.. versionchanged:: 3.6
Expand Down Expand Up @@ -317,8 +315,6 @@ the :mod:`glob` module.)
Dev Drives. See `the Windows documentation <https://learn.microsoft.com/windows/dev-drive/>`_
for information on enabling and creating Dev Drives.

.. availability:: Windows.

.. versionadded:: 3.12


Expand Down Expand Up @@ -412,8 +408,6 @@ the :mod:`glob` module.)

*start* defaults to :data:`os.curdir`.

.. availability:: Unix, Windows.

.. versionchanged:: 3.6
Accepts a :term:`path-like object`.

Expand All @@ -424,8 +418,6 @@ the :mod:`glob` module.)
This is determined by the device number and i-node number and raises an
exception if an :func:`os.stat` call on either pathname fails.

.. availability:: Unix, Windows.

.. versionchanged:: 3.2
Added Windows support.

Expand All @@ -440,8 +432,6 @@ the :mod:`glob` module.)

Return ``True`` if the file descriptors *fp1* and *fp2* refer to the same file.

.. availability:: Unix, Windows.

.. versionchanged:: 3.2
Added Windows support.

Expand All @@ -456,8 +446,6 @@ the :mod:`glob` module.)
:func:`os.lstat`, or :func:`os.stat`. This function implements the
underlying comparison used by :func:`samefile` and :func:`sameopenfile`.

.. availability:: Unix, Windows.

.. versionchanged:: 3.4
Added Windows support.

Expand Down
28 changes: 26 additions & 2 deletions Lib/genericpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import stat

__all__ = ['commonprefix', 'exists', 'getatime', 'getctime', 'getmtime',
'getsize', 'isdir', 'isfile', 'islink', 'samefile', 'sameopenfile',
'samestat']
'getsize', 'isdevdrive', 'isdir', 'isfile', 'isjunction', 'islink',
'lexists', 'samefile', 'sameopenfile', 'samestat']


# Does a path exist?
Expand All @@ -22,6 +22,15 @@ def exists(path):
return True


# Being true for dangling symbolic links is also useful.
def lexists(path):
"""Test whether a path exists. Returns True for broken symbolic links"""
try:
os.lstat(path)
except (OSError, ValueError):
return False
return True

# This follows symbolic links, so both islink() and isdir() can be true
# for the same path on systems that support symlinks
def isfile(path):
Expand Down Expand Up @@ -57,6 +66,21 @@ def islink(path):
return stat.S_ISLNK(st.st_mode)


# Is a path a junction?
def isjunction(path):
"""Test whether a path is a junction
Junctions are not supported on the current platform"""
os.fspath(path)
return False


def isdevdrive(path):
"""Determines whether the specified path is on a Windows Dev Drive.
Dev Drives are not supported on the current platform"""
os.fspath(path)
return False


def getsize(filename):
"""Return the size of a file, reported by os.stat()."""
return os.stat(filename).st_size
Expand Down
29 changes: 7 additions & 22 deletions Lib/ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"ismount", "expanduser","expandvars","normpath","abspath",
"curdir","pardir","sep","pathsep","defpath","altsep",
"extsep","devnull","realpath","supports_unicode_filenames","relpath",
"samefile", "sameopenfile", "samestat", "commonpath", "isjunction"]
"samefile", "sameopenfile", "samestat", "commonpath", "isjunction",
"isdevdrive"]

def _get_bothseps(path):
if isinstance(path, bytes):
Expand Down Expand Up @@ -288,21 +289,8 @@ def isjunction(path):
return False
return bool(st.st_reparse_tag == stat.IO_REPARSE_TAG_MOUNT_POINT)
else:
def isjunction(path):
"""Test whether a path is a junction"""
os.fspath(path)
return False


# Being true for dangling symbolic links is also useful.

def lexists(path):
"""Test whether a path exists. Returns True for broken symbolic links"""
try:
st = os.lstat(path)
except (OSError, ValueError):
return False
return True
# Use genericpath.isjunction as imported above
pass

# Is a path a mount point?
# Any drive letter root (eg c:\)
Expand Down Expand Up @@ -883,15 +871,12 @@ def commonpath(paths):

try:
from nt import _path_isdevdrive
except ImportError:
def isdevdrive(path):
"""Determines whether the specified path is on a Windows Dev Drive."""
# Never a Dev Drive
return False
else:
def isdevdrive(path):
"""Determines whether the specified path is on a Windows Dev Drive."""
try:
return _path_isdevdrive(abspath(path))
except OSError:
return False
except ImportError:
# Use genericpath.isdevdrive as imported above
pass
22 changes: 1 addition & 21 deletions Lib/posixpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"samefile","sameopenfile","samestat",
"curdir","pardir","sep","pathsep","defpath","altsep","extsep",
"devnull","realpath","supports_unicode_filenames","relpath",
"commonpath", "isjunction"]
"commonpath", "isjunction","isdevdrive"]


def _get_sep(path):
Expand Down Expand Up @@ -187,26 +187,6 @@ def dirname(p):
return head


# Is a path a junction?

def isjunction(path):
"""Test whether a path is a junction
Junctions are not a part of posix semantics"""
os.fspath(path)
return False


# Being true for dangling symbolic links is also useful.

def lexists(path):
"""Test whether a path exists. Returns True for broken symbolic links"""
try:
os.lstat(path)
except (OSError, ValueError):
return False
return True


# Is a path a mount point?
# (Does this work for all UNIXes? Is it even guaranteed to work by Posix?)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make :func:`os.path.isdevdrive` available on all platforms. For those that do not offer Dev Drives, it will always return ``False``.
Loading