Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
21c0ba9
gh-101000: Add os.path.splitroot()
barneygale Jan 12, 2023
836b85d
Use splitroot() from pathlib
barneygale Jan 12, 2023
bc2d1f9
Use splitroot() from posixpath
barneygale Jan 12, 2023
ecdc40d
Use splitroot() from ntpath
barneygale Jan 12, 2023
6592b27
Optimizations
barneygale Jan 12, 2023
78f4227
Correct and expand examples in splitroot() docstring
barneygale Jan 13, 2023
9726ca4
Update Lib/ntpath.py
barneygale Jan 13, 2023
7a6613c
Use splitroot() from pathlib.PurePath.with_name()
barneygale Jan 14, 2023
26a8dba
Reduce ntpath.normpath() diff noise
barneygale Jan 15, 2023
0c237d4
Simplify ntpath.commonpath() now that 'isabs' is unused.
barneygale Jan 15, 2023
11ed3eb
Reduce posixpath.normpath() diff noise
barneygale Jan 15, 2023
2c9eed8
Improve documentation
barneygale Jan 15, 2023
8299e96
Add whatsnew entry.
barneygale Jan 15, 2023
27ffe37
Simplify ntpath.splitroot() slightly
barneygale Jan 15, 2023
9beff2a
Apply suggestions from code review
barneygale Jan 16, 2023
bacdee1
Update Doc/library/os.path.rst
barneygale Jan 16, 2023
4ebe545
Note that drive may be empty on Windows
barneygale Jan 16, 2023
2927afe
Re-order drive example
barneygale Jan 16, 2023
b0aa73e
Update Doc/library/os.path.rst
barneygale Jan 16, 2023
19777d6
Adjust docstring examples
barneygale Jan 18, 2023
32e212e
Apply suggestions from code review
barneygale Jan 19, 2023
37cded3
Update Doc/library/os.path.rst
barneygale Jan 19, 2023
5a8dfce
Change example username in docs to 'Sam'
barneygale Jan 19, 2023
0e75a55
Adjust first paragraph to use prose
barneygale Jan 19, 2023
3663237
Update Doc/library/os.path.rst
barneygale Jan 22, 2023
053729d
Add tests for bytes (POSIX only) and path-like objects (both platforms)
barneygale Jan 22, 2023
694f093
Add tests for mixed path separators (Windows only)
barneygale Jan 22, 2023
e99e3cd
Remove errant newline.
barneygale Jan 22, 2023
f618a00
Move most test cases from `test_splitdrive` to `test_splitroot`
barneygale Jan 22, 2023
1c522c9
Mention pathlib performance improvement in news entry.
barneygale Jan 22, 2023
df17269
Merge branch 'main' into gh-101000-splitroot
AlexWaygood Jan 22, 2023
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
Prev Previous commit
Next Next commit
Improve documentation
  • Loading branch information
barneygale committed Jan 15, 2023
commit 2c9eed88823e840d8b39a34b26ae0e63f0a9fe38
26 changes: 19 additions & 7 deletions Doc/library/os.path.rst
Original file line number Diff line number Diff line change
Expand Up @@ -492,16 +492,28 @@ the :mod:`glob` module.)

Split the pathname *path* into a triad ``(drive, root, tail)`` where:

1. *drive* is an optional mount point, exactly like :func:`splitdrive`;
2. *root* is an optional sequence of separators following the drive; and
1. *drive* is a mount point or the empty string;
2. *root* is a sequence of separators following the drive or the empty string; and
3. *tail* is anything after the root.

On Posix, *drive* is always empty. The *root* may be empty (relative path),
a single forward slash (absolute path), or two forward slashes
(implementation-defined per the POSIX standard).
On POSIX systems, *drive* is always empty. The *root* may be empty (if *path* is
relative), a single forward slash (if *path* is absolute), or two forward slashes
(implementation-defined per `IEEE Std 1003.1 2013 Edition; 4.13 Pathname Resolution
<https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13>`_.)
For example::

On Windows, *drive* may be a UNC sharepoint or a traditional DOS drive. The
*root* may be empty, a forward slash, or a backward slash.
>>> splitroot('/etc/hosts')
('', '/', 'etc/hosts')

On Windows, *drive* may be a UNC sharepoint or a traditional drive-letter drive. The
*root* may be empty, a forward slash, or a backward slash. For example::

>>> splitroot('//server/share/')
('//server/share', '/', '')
>>> splitroot('C:/Users/Barney')
('C:', '/', 'Users/Barney')
>>> splitroot('Windows/notepad')
('', '', 'Windows/notepad')

In all cases, ``drive + root + tail`` will be the same as *path*.

Expand Down