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 — bpo-37609: Update ntpath.splitdrive to use native functionality where possible by zooba · Pull Request #25261 · python/cpython

Conversation

@zooba

@zooba zooba commented Apr 7, 2021 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

https://bugs.python.org/issue37609

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@zooba
bpo-37609: Update ntpath.splitdrive to use native functionality where…
2e54e93
… possible
@zooba zooba added the OS-windows label Apr 7, 2021
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Apr 7, 2021
@bedevere-bot bedevere-bot added the awaiting core review label Apr 7, 2021
@zooba
Add NEWS
5b307a5
eryksun
eryksun reviewed Apr 7, 2021
View reviewed changes
Comment thread Lib/test/test_ntpath.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

eryksun
eryksun reviewed Apr 7, 2021
View reviewed changes
Comment thread Lib/test/test_ntpath.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

eryksun
eryksun reviewed Apr 8, 2021
View reviewed changes
Comment thread Lib/ntpath.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@zooba
Change splitroot to move the trailing slash into the tail
8481e5a
eryksun
eryksun reviewed Apr 9, 2021
View reviewed changes
Comment thread Lib/importlib/_bootstrap_external.py
Comment on lines +119 to 123
path = [p for p in (p1.rstrip(path_separators) for p1 in path) if p]
if not path:
# Avoid losing the root's trailing separator when joining with nothing
return root + path_sep
return root + path_sep.join(path)

@eryksun eryksun Apr 9, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • _path_join('//server/share', 'spam') should return "//server/share/spam", not "//server/sharespam"
  • _path_join("C:/", "spam") should return "C:/spam", not "C:spam"
  • _path_join("C:", "") should return "C:", not "C:\".
  • _path_join("C:", "D:") should return "D:", not "D:\"

I don't like the change to make _path_splitroot() shift the separator into the path. It goes against what I expect given the function name, in terms of separating the root from the rest of the path. The root variable here actually has no root path, which is counterintuitive.

As it stands, the following fixes the above case by shifting the separator back into root. The UNC + relative case has to be handled specially at the end.

    if path and path[0].startswith(path_sep_tuple):
        root += path[0][0]
        path[0] = path[0][1:]
    tail = path_sep.join(c for p in path if (c := p.rstrip(path_separators)))
    # Fix up appending a relative path to a UNC root
    if (tail and root.startswith(path_sep_tuple) and
          not root.endswith(path_sep_tuple) and
          not tail.startswith(path_sep_tuple)):
        root += path_sep
    return root + tail

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
eryksun
eryksun reviewed Apr 9, 2021
View reviewed changes
Comment thread Lib/ntpath.py
Comment on lines +65 to +71
else:
def _splitroot(p):
p = os.fspath(p)
r = _path_splitroot(p)
if isinstance(p, bytes):
return tuple(map(os.fsencode, r))
return r

@eryksun eryksun Apr 9, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe change the name to nt._path_splitdrive, since that makes more sense now that the root is shifted over to the path side. Implement the POSIX fallback as _path_splitdrive, which only returns str, just like the builtin function. Move the above bytes support code into a common implementation of ntpath.splitdrive(), which is likely the only place it will ever be needed. _path_splitdrive() will be used directly when bytes support isn't required.

I'm sure you know the os.fspath() call isn't necessary since it's handled for a path_t argument in C, so why is it called explicitly here?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@zooba zooba Apr 9, 2021

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The isinstance at 69 needs to recognise values for p that have __fspath__ that returns bytes, as well as actual bytes, which is why we fspath once instead of doing it multiple times.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@eryksun eryksun Apr 10, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The isinstance at 69 needs to recognise values for p that have __fspath__ that returns bytes, as well as actual bytes, which is why we fspath once instead of doing it multiple times.

Sigh... sorry about that. :-$

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@zooba

zooba commented Apr 9, 2021

Copy link
Copy Markdown
Member Author

Frankly, I'm out of energy for this patch. Someone else can work on it if they're keen, or maybe I'll get back to it one day.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zooba zooba closed this Apr 9, 2021
@eryksun

eryksun commented Apr 10, 2021

Copy link
Copy Markdown
Contributor

Frankly, I'm out of energy for this patch. Someone else can work on it if they're keen, or maybe I'll get back to it one day.

Thank you for all of your work here. Do you want to repurpose the work for test_ntpath.py in a new issue, to refine exactly what should be be supported by ntpath.join() and ntpath.splitdrive() when used in POSIX? That sets the limits for what a fallback implementation of splitdrive() needs to implement and whatever needs to be adapted in the PathCchSkipRoot result.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@eryksun eryksun mentioned this pull request May 20, 2022
support "UNC" device paths in ntpath.splitdrive #81790
Closed
@zooba
zooba deleted the bpo-37609 branch December 14, 2023 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@eryksun eryksun eryksun left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting core review OS-windows

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@zooba @eryksun @the-knights-who-say-ni @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.