[Python-ideas] Re: Add mechanism to check if a path is a junction (for Windows)
On Tue, 8 Nov 2022 at 23:34, Steven D'Aprano wrote: > > Most Python coders are using Windows. Surely it is time to do better > for them than "just roll your own"? While I frequently advocate on the side of "not every 3-line function needs to be in the stdlib", there are a lot of convenience functions for Unix in the stdlib (reflecting the fact that Python was initially developed on Unix) and having them for Windows as well seems only fair. Given the existence of pathlib.Path.is_fifo(), I think it's reasonable to include is_junction() too. (There's no isfifo() in os.path, though, so the argument for os.path.isjunction() is correspondingly weaker). Paul ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/AY6PMBU7DWFO3CB3WXOGF5Y7XEVKQXNU/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Add mechanism to check if a path is a junction (for Windows)
On Tue, Nov 08, 2022 at 09:55:04PM +, Barry wrote: > But anyone that is suitably motivated can implement this. This is true for every function in a Turing Complete language. Perhaps we should start using iota or jot? :-) https://en.wikipedia.org/wiki/Iota_and_Jot A "suitably motivated" person could implement ismount, islink, the entire os and Pathlib modules, and more. But they probably won't do as good a job of it as what we have. On systems that support junction points, they are as much a fundamental file system object as symlinks, directories and mount points. Non-experts will probably have to google for hints how to implement this, and the internet is full of bad advice. On Stackoverflow, I find this question: https://stackoverflow.com/questions/17174703/symlinks-on-windows which starts off by giving the false information (or at least obsolete) that Windows doesn't support symlinks only shortcuts (NTFS has supported symlinks since at least Windows Vista, in 2006), and then later gives a solution for detecting junction points which requires ctypes. Most Python coders are using Windows. Surely it is time to do better for them than "just roll your own"? -- Steve ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/VLUZSVAS6TJVRTQNRGHZJ7AQIVFEMGIS/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Add mechanism to check if a path is a junction (for Windows)
On 8 Nov 2022, at 17:56, Charles Machalow wrote:I would argue that just because it was easy for one to implement doesn't mean it's easy for others. That is true of so many things in life!I would have had no idea how to implement this without extra Googling and confusion.Having the abstraction makes it easier for others.But anyone that is suitably motivated can implement this.Barry- Charlie Scott Machalow On Tue, Nov 8, 2022 at 1:12 AM Eryk Sunwrote:On 11/8/22, Charles Machalow wrote: > > Funny enough in PowerShell, for prints an "l" for both symlinks and > junctions.. so it kind of thinks of it as a link of some sort too I guess. As does Python already in many cases. For example, os.lstat() doesn't traverse a mount point (junction). On Windows, symlinks and mount points are in a general category of name-surrogate reparse points. os.lstat() doesn't traverse them. If Python supported copying a mount point via os.symlink(os.readlink(src), dst), I'd be reluctantly in favor of just letting ntpath.islink() return true for a mount point, as a practical measure for seamless cross-platform implementations of functions like rmtree() and copytree(). In terms of POSIX that's nonsense, but not really on Windows. > Is it that much of a waste to just return False on posix? I mean it's a > couple lines and just maintains api.. and in theory can be more clear to > some. I'm just thinking this through in terms of conceptual cost and usefulness in the standard library relative to how easy it is to implement one's own isjunction() or is_name_surrogate() test. Of course, a lot of the os.path tests have simple implementations, such as exists(), isdir() and isfile(). They're in the standard library because they're commonly needed. The question is whether isjunction() is needed enough generally to justify adding it. ___Python-ideas mailing list -- python-ideas@python.orgTo unsubscribe send an email to python-ideas-le...@python.orghttps://mail.python.org/mailman3/lists/python-ideas.python.org/Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/MOY5NNFQK5PMD5GQBADZE3COVT7ONA62/Code of Conduct: http://python.org/psf/codeofconduct/___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/WKA3ZPPLHTY3K3CCADUYC3KZI76NYTTA/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Add mechanism to check if a path is a junction (for Windows)
I would argue that just because it was easy for one to implement doesn't mean it's easy for others. I would have had no idea how to implement this without extra Googling and confusion. Having the abstraction makes it easier for others. - Charlie Scott Machalow On Tue, Nov 8, 2022 at 1:12 AM Eryk Sun wrote: > On 11/8/22, Charles Machalow wrote: > > > > Funny enough in PowerShell, for prints an "l" for both symlinks and > > junctions.. so it kind of thinks of it as a link of some sort too I > guess. > > As does Python already in many cases. For example, os.lstat() doesn't > traverse a mount point (junction). On Windows, symlinks and mount > points are in a general category of name-surrogate reparse points. > os.lstat() doesn't traverse them. > > If Python supported copying a mount point via > os.symlink(os.readlink(src), dst), I'd be reluctantly in favor of just > letting ntpath.islink() return true for a mount point, as a practical > measure for seamless cross-platform implementations of functions like > rmtree() and copytree(). In terms of POSIX that's nonsense, but not > really on Windows. > > > Is it that much of a waste to just return False on posix? I mean it's a > > couple lines and just maintains api.. and in theory can be more clear to > > some. > > I'm just thinking this through in terms of conceptual cost and > usefulness in the standard library relative to how easy it is to > implement one's own isjunction() or is_name_surrogate() test. Of > course, a lot of the os.path tests have simple implementations, such > as exists(), isdir() and isfile(). They're in the standard library > because they're commonly needed. The question is whether isjunction() > is needed enough generally to justify adding it. > ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/MOY5NNFQK5PMD5GQBADZE3COVT7ONA62/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Add mechanism to check if a path is a junction (for Windows)
On 11/8/22, Charles Machalow wrote: > > Funny enough in PowerShell, for prints an "l" for both symlinks and > junctions.. so it kind of thinks of it as a link of some sort too I guess. As does Python already in many cases. For example, os.lstat() doesn't traverse a mount point (junction). On Windows, symlinks and mount points are in a general category of name-surrogate reparse points. os.lstat() doesn't traverse them. If Python supported copying a mount point via os.symlink(os.readlink(src), dst), I'd be reluctantly in favor of just letting ntpath.islink() return true for a mount point, as a practical measure for seamless cross-platform implementations of functions like rmtree() and copytree(). In terms of POSIX that's nonsense, but not really on Windows. > Is it that much of a waste to just return False on posix? I mean it's a > couple lines and just maintains api.. and in theory can be more clear to > some. I'm just thinking this through in terms of conceptual cost and usefulness in the standard library relative to how easy it is to implement one's own isjunction() or is_name_surrogate() test. Of course, a lot of the os.path tests have simple implementations, such as exists(), isdir() and isfile(). They're in the standard library because they're commonly needed. The question is whether isjunction() is needed enough generally to justify adding it. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/G4YQTXFPDN5YQLNYUUKCP2NV4DLGWSTN/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Add mechanism to check if a path is a junction (for Windows)
On Mon, Nov 07, 2022 at 07:31:36PM -, Charles Machalow wrote: > I propose adding a mechanism to both pathlib.Path and os.path to check > if a given path is a junction or not. Currently is_symlink/islink > return False for junctions. +1 on a function is_junction. I am neutral on the question of whether that function should: 1. only exist on Windows, 2. or exist on other platforms but always return False. Prior art suggests the second is probably better: when Python doesn't support symbolic links, `os.islink` exists but always returns False. https://docs.python.org/3/library/os.path.html#os.path.islink I am also neutral on whether ismount() on Windows should always return True for junctions, as well as mount points. I leave that to Windows experts to decide. -1 on adding a flag parameter to existing functions. -- Steve ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/M36XXF4QZ6VJJSTEDPOTAGEODC35NVLM/ Code of Conduct: http://python.org/psf/codeofconduct/