GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add os.path.splitroot() function · Issue #101000 · python/cpython

Add os.path.splitroot() function #101000

New issue
Copy link
New issue
Copy link
Closed
Closed
Add os.path.splitroot() function#101000
Copy link
Labels
3.12only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-pathlibtype-featureA feature request or enhancementA feature request or enhancement

Description

@barneygale
barneygale
opened on Jan 12, 2023
Issue body actions

Feature or enhancement

Add a function that splits a path into a (drive, root, tail) triad:

  1. The drive part has the same meaning as in splitdrive()
  2. The root part is one of: the empty string, a forward slash, a backward slash (Windows only), or two forward slashes (POSIX only)
  3. The tail part is everything following the root.

Similarly to splitdrive(), a splitroot() function would ensure that drive + root + tail is the same as the input path.

Pitch

The extra level of detail reflects an extra step in the Windows 'current path' hierarchy -- Windows has both a 'current drive', and a 'current directory' for one or more drives, which results in several kinds of non-absolute paths, e.g. 'foo/bar', '/foo/bar', 'X:foo/bar'

This three-part model is used successfully by pathlib, which exposes root as an attribute, and combines drive + root as an attribute called anchor. The anchor has useful properties, e.g. comparing two paths anchors can tell us whether a relative_to() operation is possible.

Pathlib has its own implementation of splitroot(), but its performance is hamstrung by its need for OS-agnosticism. By moving the implementation into ntpath and posixpath we can take advantage of OS-specific rules to improve pathlib performance.

Previous discussion

  • https://discuss.python.org/t/add-os-path-splitroot/22243
  • https://github.com/python/cpython/pull/31691/files#r944987609
  • https://github.com/python/cpython/pull/100351/files/5b67a7489e5518975d0c11033cd35bf60fad0ddf#r1065219273

Linked PRs

  • gh-101000: Add os.path.splitroot() #101002

Activity

  1. barneygale
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Jan 12, 2023
  2. barneygale
    added a commit that references this issue on Jan 12, 2023

    pythongh-101000: Add os.path.splitroot()

    21c0ba9
  3. eryksun
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    3.12only security fixesonly security fixes
    topic-pathlib
    on Jan 13, 2023
  4. AlexWaygood
    added 2 commits that reference this issue on Jan 22, 2023

    Merge branch 'main' into pythongh-101000-splitroot

    df17269

    gh-101000: Add os.path.splitroot() (#101002)

    e5b08dd
  5. AlexWaygood commented on Jan 27, 2023

    @AlexWaygood
    AlexWaygood
    on Jan 27, 2023
    Member
    More actions

    Added in #101002. Thanks @barneygale 🎉🥳

  6. AlexWaygood
    closed this as completedon Jan 27, 2023
  7. barneygale commented on Jan 27, 2023

    @barneygale
    barneygale
    on Jan 27, 2023
    ContributorAuthor
    More actions

    Thank you very much Alex! \o/

    Reacted by Alex Waygood and JimmyyHilmmyyyy
  8. mdboom
    added a commit that references this issue on Jan 31, 2023

    pythongh-101000: Add os.path.splitroot() (python#101002)

    a20b37a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-pathlibtype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.