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 — gh-99547: Add isjunction methods for checking if a path is a junction by csm10495 · Pull Request #99548 · python/cpython

Conversation

@csm10495

@csm10495 csm10495 commented Nov 16, 2022

Copy link
Copy Markdown
Contributor

Implementation of gh-99547.

This is my first try at getting something into cpython.. so please go easy on me. Thanks!

Sorry, something went wrong.

Uh oh!

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

All reactions
csm10495 added 5 commits November 11, 2022 15:13
@csm10495
Add an isjunction method to ntpath and posixpath, pass it along as we…
7b1eb2e
…ll in pathlib
@csm10495
Add is_junction test for pathlib
d2a769a
The actual functionality lives in ntpath/posixpath, so just verify the correct function is called and return value is returned
@csm10495
Add a skipIf not win32 for testing ntpath isjunction on non windows p…
5744fc0
…latforms

We can only create junctions on windows, thus only test this on win32
@csm10495
Merge branch 'python:main' into add_isjunction
659af26
@csm10495
Merge branch 'python:main' into add_isjunction
dc9f389
@csm10495
csm10495 requested a review from brettcannon as a code owner November 16, 2022 21:19
@bedevere-bot bedevere-bot mentioned this pull request Nov 16, 2022
isjunction for checking if a given path is a junction #99547
Closed
@bedevere-bot bedevere-bot added the awaiting review label Nov 16, 2022
@bedevere-bot

bedevere-bot commented Nov 16, 2022

Copy link
Copy Markdown

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

All reactions

Sorry, something went wrong.

Uh oh!

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

@ghost

ghost commented Nov 16, 2022 •
edited by ghost
Loading

Uh oh!

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

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

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

@csm10495

This comment was marked as resolved.

Sign in to view
@blurb-it
📜🤖 Added by blurb_it.
e54add0
@brettcannon
brettcannon requested review from a team and removed request for brettcannon November 16, 2022 21:48
@csm10495
Merge branch 'python:main' into add_isjunction
ccaa147
eryksun
eryksun reviewed Nov 17, 2022
View reviewed changes
Comment thread Lib/test/test_ntpath.py Resolved

Uh oh!

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

csm10495 and others added 3 commits November 16, 2022 16:50
@csm10495 @eryksun
Update Lib/test/test_ntpath.py
db3f5b3
Co-authored-by: Eryk Sun <[email protected]>
@csm10495
remove un-needed import
07aaab6
@csm10495
Merge branch 'main' into add_isjunction
12b3bc9
eryksun
eryksun reviewed Nov 17, 2022
View reviewed changes
Comment thread Lib/ntpath.py Resolved

Uh oh!

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

csm10495 and others added 2 commits November 16, 2022 17:32
@csm10495 @eryksun
Update Lib/ntpath.py
bee6b2c
ntpath can be used on POSIX, even though the stat_result won't have st_reparse_tag.

Co-authored-by: Eryk Sun <[email protected]>
@csm10495
fix test... this was a string not an obj
e3fbf24
eryksun
eryksun reviewed Nov 17, 2022
View reviewed changes
Comment thread Lib/posixpath.py Resolved

Uh oh!

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

@csm10495 @eryksun
Update Lib/posixpath.py
262843f
Co-authored-by: Eryk Sun <[email protected]>
eryksun
eryksun reviewed Nov 17, 2022
View reviewed changes
Comment thread Lib/ntpath.py Resolved

Uh oh!

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

csm10495 and others added 2 commits November 16, 2022 17:48
@csm10495 @eryksun
Update Lib/ntpath.py
1a8695f
Co-authored-by: Eryk Sun <[email protected]>
@csm10495
Empty commit to rekick ci
8b32ce5
@zooba

zooba commented Nov 17, 2022

Copy link
Copy Markdown
Member

Code looks good, but we'll also need docs updated (at least the os.path docs and What's New for 3.12)

All reactions

Sorry, something went wrong.

Uh oh!

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

@csm10495

csm10495 commented Nov 17, 2022

Copy link
Copy Markdown
Contributor Author

@zooba is there a wiki or something on which files generate the docs? I had thought maybe it was from the code. Happy to update docs :)

All reactions

Sorry, something went wrong.

Uh oh!

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

@csm10495
update os.path.rst for isjunction
a20ebea
@csm10495 csm10495 reopened this Nov 18, 2022
@csm10495

csm10495 commented Nov 18, 2022

Copy link
Copy Markdown
Contributor Author

Whelp.. doing this on a phone is tough.. reopened

All reactions

Sorry, something went wrong.

Uh oh!

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

@csm10495 @eryksun
Update Doc/library/os.rst
25f48be
Co-authored-by: Eryk Sun <[email protected]>
eryksun
eryksun reviewed Nov 19, 2022
View reviewed changes
Comment thread Lib/test/test_os.py Resolved

Uh oh!

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

csm10495 and others added 2 commits November 18, 2022 16:27
@csm10495 @eryksun
Update Lib/test/test_os.py
2dea623
Co-authored-by: Eryk Sun <[email protected]>
@csm10495
kick ci
5b6ee7d
@barneygale

barneygale commented Nov 20, 2022

Copy link
Copy Markdown
Contributor

shutil.py also checks st_reparse_tag for IO_REPARSE_TAG_MOUNT_POINT. Could it be updated to use the new function, perhaps?

All reactions

Sorry, something went wrong.

Uh oh!

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

@eryksun

eryksun commented Nov 20, 2022

Copy link
Copy Markdown
Contributor

shutil.py also checks st_reparse_tag for IO_REPARSE_TAG_MOUNT_POINT. Could it be updated to use the new function, perhaps?

We could eliminate _rmtree_isdir(). For example:

        try:
            is_dir = (entry.is_dir(follow_symlinks=False) and
                      not entry.is_junction())
        except OSError:
            is_dir = False

This is relatively cheap. On Windows, both tests use the cached stat info from the directory entry. On POSIX, the is_junction() test is always false.

To replace _rmtree_islink(), we could check isjunction() inline. For example:

            if os.path.islink(path) or os.path.isjunction(path):
                # symlinks to directories are forbidden, see bug #1669
                raise OSError("Cannot call rmtree on a symbolic link or junction")

However, this calls lstat() twice, so it might be better to keep _rmtree_islink().

If islink() had a strict option that defaulted to true, then we could call os.path.islink(path, strict=False) to broaden the scope to include junctions, or to include all name-surrogate reparse points. The check for a name-surrogate reparse point is st_reparse_tag & 0x2000_0000.

All reactions

Sorry, something went wrong.

Uh oh!

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

@csm10495

csm10495 commented Nov 20, 2022

Copy link
Copy Markdown
Contributor Author

I'm not a big fan of needing to call stat again if we don't need to.

Part of me thinks that stat objects should have methods similar to pathlib.Path's is_ methods for checking things based on a cached stat. We can kind of cheat to get there with a DirEntry but idk.

I mean I know we have some stat IS_ functions but I guess I like methods on objects better than loose functions.

Regardless: do we feel as though these optimizations should be part of the current issue or should maybe be a post merge task?

I kind of feel as though we're stepping a tiny bit out of the scope of the current task.

barneygale reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@barneygale

barneygale commented Nov 20, 2022

Copy link
Copy Markdown
Contributor

I don't consider the shutil.py thing blocking :)

All reactions

Sorry, something went wrong.

Uh oh!

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

@eryksun

eryksun commented Nov 20, 2022 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Regardless: do we feel as though these optimizations should be part of the current issue or should maybe be a post merge task?

Replacing _rmtree_isdir() would only use the cached stat value of a DirEntry. I think it's worthwhile for this pull request.

I know we have some stat IS_ functions

Junctions don't have a POSIX file type other than as a directory, S_IFDIR. If we add a test function for junctions to the stat module, it can't follow the S_IS* pattern that checks the POSIX file type in st_mode. It still might be worthwhile to implement this.

All reactions

Sorry, something went wrong.

Uh oh!

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

@csm10495

csm10495 commented Nov 20, 2022

Copy link
Copy Markdown
Contributor Author

It's just continually adding things on to the same PR is kind of discouraging for me as a new contributor.

I'd greatly prefer having all asks at once (so they can be attacked at once) as opposed to small ones continually given over and over.

barneygale reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

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

@eryksun

eryksun commented Nov 20, 2022

Copy link
Copy Markdown
Contributor

It's just continually adding things on to the same PR is kind of discouraging for me as a new contributor.

Okay. I'm sorry if you feel discouraged. This pull request is outstanding for a new contributor.

All reactions

Sorry, something went wrong.

Uh oh!

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

@eryksun

eryksun commented Nov 21, 2022

Copy link
Copy Markdown
Contributor

@zooba, since your last review there was a minor change to the documentation, and a test was fixed. If that's all okay with you, then this is ready to be merged as soon as Charles says so.

All reactions

Sorry, something went wrong.

Uh oh!

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

@csm10495
Remove _rmtree_is_dir() since we can now just check if the entry is a…
dfeb40b
… dir and not a junction across the board
@csm10495

csm10495 commented Nov 22, 2022

Copy link
Copy Markdown
Contributor Author

Ok i removed _rmtree_is_dir() and replaced its usage with is_dir/is_junction checks. Unit tests pass. If its ok, i'm good with a merge at this point.

All reactions

Sorry, something went wrong.

Uh oh!

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

eryksun
eryksun reviewed Nov 22, 2022
View reviewed changes
Comment thread Lib/shutil.py Resolved

Uh oh!

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

csm10495 and others added 2 commits November 21, 2022 19:48
@csm10495 @eryksun
Update Lib/shutil.py
8a90cba
Co-authored-by: Eryk Sun <[email protected]>
@csm10495
update from suggestion
296992b
@csm10495

csm10495 commented Nov 22, 2022

Copy link
Copy Markdown
Contributor Author

I wonder if one day is_dir should be updated to return False on OSError internally.. regardless I've updated the implementation to handle that case here. I'll leave that to a separate thread.

Updated. If it all passes, i'm still good for merge here.

All reactions

Sorry, something went wrong.

Uh oh!

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

@eryksun

eryksun commented Nov 22, 2022

Copy link
Copy Markdown
Contributor

I wonder if one day is_dir should be updated to return False on OSError internally..

The rationale is in PEP 471, notes on exception handling.

csm10495 reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

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

eryksun
eryksun reviewed Nov 22, 2022
View reviewed changes
Comment thread Lib/shutil.py Resolved

Uh oh!

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

@csm10495 @eryksun
Update Lib/shutil.py
f3372db
Co-authored-by: Eryk Sun <[email protected]>
@zooba
zooba merged commit 1b2de89 into python:main Nov 22, 2022
@bedevere-bot bedevere-bot removed the awaiting merge label Nov 22, 2022
@zooba

zooba commented Nov 22, 2022

Copy link
Copy Markdown
Member

Thanks! Great job, and congratulations on your first contribution!

barneygale reacted with thumbs up emoji hugovk reacted with hooray emoji csm10495 reacted with heart emoji hugovk reacted with rocket emoji
All reactions
  • 👍 1 reaction
  • 🎉 1 reaction
  • ❤️ 1 reaction
  • 🚀 1 reaction

Sorry, something went wrong.

Uh oh!

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

@browniebroke browniebroke mentioned this pull request Dec 21, 2022
Add Python 3.12 to the test suite pytest-dev/pyfakefs#764
Merged
5 of 6 tasks
@sobolevn sobolevn mentioned this pull request Aug 31, 2023
gh-108717: Speedup os.DirEntry.is_junction function #108718
Merged
This was referenced Aug 5, 2026
Task 24: add local Showdown oracle chrismaghuhn/BattleBelief#35
Merged
[RESULT] P01-A: deliver WP6.6 Discovery admission ZK-Theory/TDL#244
Closed
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
@zooba zooba zooba approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

None yet

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.

5 participants

@csm10495 @bedevere-bot @zooba @eryksun @barneygale
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.