[issue45226] Misleading error message when pathlib.Path.symlink_to() fails with permissions error

2021-09-20 Thread Barney Gale


Barney Gale  added the comment:

`os.symlink()` and `pathlib.Path.symlink_to()` have reversed argument orders, 
but in the repro steps you're supplying arguments in the same order.

--
nosy: +barneygale

___
Python tracker 
<https://bugs.python.org/issue45226>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44136] Remove pathlib flavours

2021-06-13 Thread Barney Gale


Barney Gale  added the comment:

Depends: bpo-39899, bpo-43757, bpo-44316, bpo-44403, bpo-44412

--

___
Python tracker 
<https://bugs.python.org/issue44136>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44412] Add os.path.fileuri() function

2021-06-13 Thread Barney Gale


Change by Barney Gale :


--
keywords: +patch
pull_requests: +25296
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/26708

___
Python tracker 
<https://bugs.python.org/issue44412>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44136] Remove pathlib flavours

2021-06-13 Thread Barney Gale


Change by Barney Gale :


--
pull_requests: +25297
pull_request: https://github.com/python/cpython/pull/26708

___
Python tracker 
<https://bugs.python.org/issue44136>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24132] Direct sub-classing of pathlib.Path

2021-06-13 Thread Barney Gale


Change by Barney Gale :


--
pull_requests: +25298
pull_request: https://github.com/python/cpython/pull/26708

___
Python tracker 
<https://bugs.python.org/issue24132>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44412] Add os.path.fileuri() function

2021-06-13 Thread Barney Gale


New submission from Barney Gale :

Proposal:

- Introduce `os.path.fileuri()` function that produces a 'file://' URI
- Adjust `PurePosixPath.to_uri()` to call `posixpath.fileuri()`
- Adjust `PureWindowsPath.to_uri()` to call `ntpath.fileuri()`
- Adjust `nturl2path.pathname2url()` to call `ntpath.fileuri()`

Rationale:

- pathlib is 95% a wrapper around `os` and `os.path`. It implements
  little itself except the OOP interface. `as_uri()` is one of only a
  tiny handful of pathlib features that have no decent antecedents.
- the existence of these OS-specific features complicates pathlib's
  internals, necessitating the existence of OS-specific '_Flavour'
  classes that greatly complicate work on bpo-24132
- this is a useful feature with lots of stackoverflow posts. It seems
  silly to /require/ users to use pathlib for this, as the rest of their
  codebase may work just fine using traditional path manip.

Further discussion on python-ideas: 
https://discuss.python.org/t/pathlib-and-os-path-feature-parity-and-code-de-duplication/9239

Related: bpo-44403, bpo-44136, bpo-24132

--
components: Library (Lib)
messages: 395756
nosy: barneygale
priority: normal
severity: normal
status: open
title: Add os.path.fileuri() function
type: enhancement
versions: Python 3.11

___
Python tracker 
<https://bugs.python.org/issue44412>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42998] pathlib.Path: add `username` argument to `home()`

2021-06-13 Thread Barney Gale


Barney Gale  added the comment:

Per discussion, expanduser('~other') is considered unreliable, and we shouldn't 
add new functions that call through to it. Resolving as 'rejected'.

--
resolution:  -> rejected
stage: patch review -> resolved
status: open -> closed

___
Python tracker 
<https://bugs.python.org/issue42998>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39950] Add pathlib.Path.hardlink_to()

2021-06-13 Thread Barney Gale


Change by Barney Gale :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed
versions: +Python 3.10 -Python 3.9

___
Python tracker 
<https://bugs.python.org/issue39950>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44316] Support preserving path meaning in os.path.normpath() and abspath()

2021-06-12 Thread Barney Gale


Barney Gale  added the comment:

I think I agree

How would you feel about two new arguments? Following `os.curdir` and 
`os.pardir` names:

def normpath(path, *, keep_curdir=False, keep_pardir=False)
...

--

___
Python tracker 
<https://bugs.python.org/issue44316>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27827] pathlib is_reserved fails for some reserved paths on Windows

2021-06-12 Thread Barney Gale


Barney Gale  added the comment:

I've put Eryk's patch up as a PR: https://github.com/python/cpython/pull/26698

--

___
Python tracker 
<https://bugs.python.org/issue27827>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27827] pathlib is_reserved fails for some reserved paths on Windows

2021-06-12 Thread Barney Gale


Change by Barney Gale :


--
nosy: +barneygale
nosy_count: 6.0 -> 7.0
pull_requests: +25283
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/26698

___
Python tracker 
<https://bugs.python.org/issue27827>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44403] Add os.path.isreserved() function

2021-06-12 Thread Barney Gale


New submission from Barney Gale :

Windows reserves certain filenames like 'NUL'. Checking for these names is part 
of a small handful of functionality that is available in pathlib but not in 
os.path.

I propose that we add an os.path.isreserved() function, encorporating Eryk 
Sun's work on bpo-27827. We then adjust pathlib to call the new function.

By doing so, we move one of the few remaining OS-specific implementations in 
pathlib to low-level libraries (posixpath, ntpath) where it arguably belongs.

We also make this functionality available to the segment of people using 
traditional string-based path operations who don't want to dip their toes into 
pathlib just for reserved names.

--
components: Library (Lib)
messages: 395702
nosy: barneygale
priority: normal
severity: normal
status: open
title: Add os.path.isreserved() function
type: enhancement

___
Python tracker 
<https://bugs.python.org/issue44403>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44316] Support preserving path meaning in os.path.normpath() and abspath()

2021-06-12 Thread Barney Gale

Barney Gale  added the comment:

For this bug specifically, the pathlib docs describe the desirable behaviour:



Spurious slashes and single dots are collapsed, but double dots ('..') are not, 
since this would change the meaning of a path in the face of symbolic links:

>>> PurePath('foo//bar')
PurePosixPath('foo/bar')
>>> PurePath('foo/./bar')
PurePosixPath('foo/bar')
>>> PurePath('foo/../bar')
PurePosixPath('foo/../bar')

(a naïve approach would make PurePosixPath('foo/../bar') equivalent to 
PurePosixPath('bar'), which is wrong if foo is a symbolic link to another 
directory)



--

___
Python tracker 
<https://bugs.python.org/issue44316>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44316] Support preserving path meaning in os.path.normpath() and abspath()

2021-06-12 Thread Barney Gale


Barney Gale  added the comment:

Thanks Terry, I've added a topic here: 
https://discuss.python.org/t/pathlib-and-os-path-code-duplication-and-feature-parity/9239

The bit about `normpath()` is towards the middle of the post.

--

___
Python tracker 
<https://bugs.python.org/issue44316>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44316] Support preserving path meaning in os.path.normpath() and abspath()

2021-06-12 Thread Barney Gale


Change by Barney Gale :


--
keywords: +patch
pull_requests: +25279
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/26694

___
Python tracker 
<https://bugs.python.org/issue44316>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29688] Add support for Path.absolute()

2021-06-12 Thread Barney Gale


Barney Gale  added the comment:

Hi - please could a core dev review PR 26153? It adds documentation and tests 
for Path.absolute(). Thank you!

--

___
Python tracker 
<https://bugs.python.org/issue29688>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44316] Support preserving path meaning in os.path.normpath() and abspath()

2021-06-04 Thread Barney Gale


New submission from Barney Gale :

>>> os.path.normpath('a/./b/../c//.')
'a/c'
>>> pathlib.Path('a/./b/../c//.')
PosixPath('a/b/../c')

pathlib takes care not to change the meaning of the path when normalising. That 
means preserving '..' entries, as these can't be simplified without resolving 
symlinks etc.

normpath(), on the other handle, /always/ eliminates '..' entries, which can 
change the meaning of the path.

We could add a new argument to `normpath()` and `abspath()` that leaves '..' 
entries intact. This was closed as "won't fix" back in bpo-2289, but I think 
it's worth re-considering.

This enhancement would be helpful for my longer-term work to make pathlib an 
OOP wrapper of os + os.path, rather than a parallel implementation.

--
components: Library (Lib)
messages: 395122
nosy: barneygale
priority: normal
severity: normal
status: open
title: Support preserving path meaning in os.path.normpath() and abspath()
type: enhancement

___
Python tracker 
<https://bugs.python.org/issue44316>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29249] Pathlib glob ** bug

2021-06-04 Thread Barney Gale


Change by Barney Gale :


--
nosy: +barneygale

___
Python tracker 
<https://bugs.python.org/issue29249>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44198] Add flags or function in pathlib.Path

2021-05-21 Thread Barney Gale


Barney Gale  added the comment:

My view:

I think the existing solution (that you highlight) is sufficiently idiomatic 
and easy to discover, and doesn't warrant a new argument or function.

However, that may change when `Path` is subclassable, for two reasons:

1. You will be able to subclass `Path` and add your own method, which you may 
find preferable to a helper function.
2. We _may_ add some sort of file type enum that wraps the constants in `stat`. 
In that case it might be natural to add a `file_type` argument to `iterdir()`. 
No promises!

--
nosy: +barneygale

___
Python tracker 
<https://bugs.python.org/issue44198>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43757] pathlib: move 'resolve()' logic out of path flavour

2021-05-20 Thread Barney Gale


Change by Barney Gale :


--
pull_requests: +24875
pull_request: https://github.com/python/cpython/pull/26270

___
Python tracker 
<https://bugs.python.org/issue43757>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38671] pathlib.Path.resolve(strict=False) returns relative path on Windows if the entry does not exist

2021-05-20 Thread Barney Gale


Change by Barney Gale :


--
pull_requests: +24874
pull_request: https://github.com/python/cpython/pull/26270

___
Python tracker 
<https://bugs.python.org/issue38671>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40358] pathlib's relative_to should behave like os.path.relpath

2021-05-16 Thread Barney Gale


Barney Gale  added the comment:

Also requested in #42234.

--
nosy: +barneygale

___
Python tracker 
<https://bugs.python.org/issue40358>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42234] pathlib relative_to behaviour change

2021-05-16 Thread Barney Gale


Barney Gale  added the comment:

In fact, I think this is a duplicate of issue40358, which has an open PR 
against it.

--

___
Python tracker 
<https://bugs.python.org/issue42234>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42234] pathlib relative_to behaviour change

2021-05-16 Thread Barney Gale


Barney Gale  added the comment:

That does sound pretty useful! I'd be happy to review a PR though I'm not a 
core dev.

--
nosy: +barneygale

___
Python tracker 
<https://bugs.python.org/issue42234>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38671] pathlib.Path.resolve(strict=False) returns relative path on Windows if the entry does not exist

2021-05-16 Thread Barney Gale


Change by Barney Gale :


--
nosy: +barneygale
nosy_count: 8.0 -> 9.0
pull_requests: +24802
pull_request: https://github.com/python/cpython/pull/26184

___
Python tracker 
<https://bugs.python.org/issue38671>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39950] Add pathlib.Path.hardlink_to()

2021-05-15 Thread Barney Gale


Change by Barney Gale :


--
pull_requests: +24789
stage: resolved -> patch review
pull_request: https://github.com/python/cpython/pull/26155

___
Python tracker 
<https://bugs.python.org/issue39950>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39950] Add pathlib.Path.hardlink_to()

2021-05-15 Thread Barney Gale


Change by Barney Gale :


--
resolution: fixed -> 
status: closed -> open

___
Python tracker 
<https://bugs.python.org/issue39950>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39924] pathlib handles missing `os.link`, `os.symlink` and `os.readlink` inconsistently

2021-05-15 Thread Barney Gale


Change by Barney Gale :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 
<https://bugs.python.org/issue39924>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39950] Add pathlib.Path.hardlink_to()

2021-05-15 Thread Barney Gale


Change by Barney Gale :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 
<https://bugs.python.org/issue39950>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29688] Add support for Path.absolute()

2021-05-15 Thread Barney Gale


Barney Gale  added the comment:

New PR up here: https://github.com/python/cpython/pull/26153

The correspondence between `pathlib` and `os.path` is as follows:


- `Path.resolve()` is roughly `os.path.realpath()`
- `Path.absolute()` is roughly `os.path.abspath()`

Differences:

- `resolve()` always raises RuntimeError on symlink loops, whereas `realpath()` 
either raises OSError or nothing depending on *strict*.
- `absolute()` doesn't normalize the path, whereas `abspath()` does. 
Normalizing without resolving symlinks can change the meaning of the path, so 
pathlib does the better thing here.

--

___
Python tracker 
<https://bugs.python.org/issue29688>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29688] Add support for Path.absolute()

2021-05-15 Thread Barney Gale


Change by Barney Gale :


--
keywords: +patch
nosy: +barneygale
nosy_count: 8.0 -> 9.0
pull_requests: +24787
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/26153

___
Python tracker 
<https://bugs.python.org/issue29688>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24132] Direct sub-classing of pathlib.Path

2021-05-15 Thread Barney Gale


Change by Barney Gale :


--
pull_requests: +24778
pull_request: https://github.com/python/cpython/pull/26141

___
Python tracker 
<https://bugs.python.org/issue24132>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44136] Remove pathlib flavours

2021-05-15 Thread Barney Gale


Change by Barney Gale :


--
keywords: +patch
pull_requests: +24776
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/26141

___
Python tracker 
<https://bugs.python.org/issue44136>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44136] Remove pathlib flavours

2021-05-14 Thread Barney Gale


New submission from Barney Gale :

Following bpo-39899, bpo-43757 and bpo-43012, `pathlib._Flavour` and its 
subclasses are looking a bit pointless.

The implementations of `is_reserved()` and `make_uri()` (~`as_uri()`) can be 
readily moved to into `PurePosixPath` and `PureWindowsPath`, which removes some 
indirection. This follows the pattern of OS-specific stuff in `PosixPath` and 
`WindowsPath`.

The remaining methods, such as `splitroot()`, can be pulled into `Pure*Path` 
with an underscore prefix.

I'm generally a believer in composition over inheritance, but in this case 
`_Flavour` seems too small and too similar to `PurePath` to separate out into 3 
extra classes.

There should be no impact on public APIs or performance.

--
components: Library (Lib)
messages: 393685
nosy: barneygale
priority: normal
severity: normal
status: open
title: Remove pathlib flavours
type: behavior
versions: Python 3.11

___
Python tracker 
<https://bugs.python.org/issue44136>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43012] Remove pathlib accessors

2021-05-13 Thread Barney Gale


Change by Barney Gale :


--
type:  -> performance
versions: +Python 3.11

___
Python tracker 
<https://bugs.python.org/issue43012>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44119] Use glob.glob() to implement pathlib.Path.glob()

2021-05-13 Thread Barney Gale


Barney Gale  added the comment:

Flawed implementation, timings were bogus. Closing in shame.

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 
<https://bugs.python.org/issue44119>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44119] Use glob.glob() to implement pathlib.Path.glob()

2021-05-12 Thread Barney Gale


New submission from Barney Gale :

I have a scratchy patch that replaces pathlib's globbing implementation with 
glob.glob(), which gained a `root_dir` argument in bpo-38144

Encouraging timings:

$ ./python -m timeit -s "from pathlib import Path; p = Path()" -- 
"list(p.glob('**/*'))"
Unpatched: 43.2 msec per loop
Patched:   4.37 msec per loop

$ ./python -m timeit -s "from pathlib import Path; p = Path('/usr/')" -- 
"list(p.glob('lib*/**/*'))"
Unpatched: 248 msec per loop
Patched:   56.8 msec per loop

$ ./python -m timeit -s "from pathlib import Path; p = Path('/usr/')" -- 
"list(p.glob('lib*/**/'))"
Unpatched: 78.3 msec per loop
Patched:   2.23 msec per loop

Patch to follow.

--
components: Library (Lib)
messages: 393556
nosy: barneygale
priority: normal
severity: normal
status: open
title: Use glob.glob() to implement pathlib.Path.glob()
type: performance
versions: Python 3.11

___
Python tracker 
<https://bugs.python.org/issue44119>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26032] Use scandir() to speed up pathlib globbing

2021-05-12 Thread Barney Gale


Change by Barney Gale :


--
nosy: +barneygale
nosy_count: 8.0 -> 9.0
pull_requests: +24730
pull_request: https://github.com/python/cpython/pull/25701

___
Python tracker 
<https://bugs.python.org/issue26032>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43757] pathlib: move 'resolve()' logic out of path flavour

2021-05-12 Thread Barney Gale


Change by Barney Gale :


--
pull_requests: +24729
pull_request: https://github.com/python/cpython/pull/26090

___
Python tracker 
<https://bugs.python.org/issue43757>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39906] pathlib.Path: add `follow_symlinks` argument to `stat()` and `chmod()`

2021-05-12 Thread Barney Gale


Change by Barney Gale :


--
pull_requests: +24728
pull_request: https://github.com/python/cpython/pull/26089

___
Python tracker 
<https://bugs.python.org/issue39906>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43757] pathlib: move 'resolve()' logic out of path flavour

2021-05-12 Thread Barney Gale


Change by Barney Gale :


--
pull_requests: +24727
pull_request: https://github.com/python/cpython/pull/26088

___
Python tracker 
<https://bugs.python.org/issue43757>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39906] pathlib.Path: add `follow_symlinks` argument to `stat()` and `chmod()`

2021-05-12 Thread Barney Gale


Change by Barney Gale :


--
pull_requests: +24726
pull_request: https://github.com/python/cpython/pull/26087

___
Python tracker 
<https://bugs.python.org/issue39906>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24132] Direct sub-classing of pathlib.Path

2021-05-02 Thread Barney Gale


Barney Gale  added the comment:

Progress report:

I've been working on tidying up the pathlib internals over the 3.9 and 3.10 
releases. We're now in a position where:

- `pathlib._Flavour` is entirely pure, and doesn't make any `os` calls
- `pathlib._Accessor` handles all `os` access.

The internal abstractions are now much tighter, which allows us to begin 
refactoring them with confidence!

The next step is to remove accessors, in bpo-43012.

After that I'll finally be in a position to start working on this bug!

--

___
Python tracker 
<https://bugs.python.org/issue24132>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43012] Remove pathlib accessors

2021-04-28 Thread Barney Gale


Change by Barney Gale :


--
keywords: +patch
pull_requests: +24391
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/25701

___
Python tracker 
<https://bugs.python.org/issue43012>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24132] Direct sub-classing of pathlib.Path

2021-04-28 Thread Barney Gale


Change by Barney Gale :


--
pull_requests: +24392
pull_request: https://github.com/python/cpython/pull/25701

___
Python tracker 
<https://bugs.python.org/issue24132>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42998] pathlib.Path: add `username` argument to `home()`

2021-04-28 Thread Barney Gale


Barney Gale  added the comment:

So far I've been keen to keep the Path and AbstractPath APIs the same, but 
perhaps this case warrants an exception.

What if AbstractPath lacked both home() and expanduser(), and those methods 
only existed on Path? Of all the methods on Path, these two are the *least* 
useful for non-local filesystems.

We can then circle back round to this issue when the fate of expanduser() 
becomes clearer.

Does that sound any good?

--

___
Python tracker 
<https://bugs.python.org/issue42998>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42998] pathlib.Path: add `username` argument to `home()`

2021-04-26 Thread Barney Gale


Barney Gale  added the comment:

Totally valid!

I suppose it hinges on the relatively likelihood/unlikelihood of us being able 
to make `expanduser('~foo')` reliable in future. On this question I'm relieved 
to defer to the experts!

@eryksun: penny for your thoughts?

--

___
Python tracker 
<https://bugs.python.org/issue42998>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42998] pathlib.Path: add `username` argument to `home()`

2021-04-26 Thread Barney Gale


Barney Gale  added the comment:

In the previous comment, I was referring to bpo-39899 when I referred to "my 
patch". Long day! :D

--

___
Python tracker 
<https://bugs.python.org/issue42998>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42998] pathlib.Path: add `username` argument to `home()`

2021-04-26 Thread Barney Gale


Barney Gale  added the comment:

Thanks very much for taking a look. I can understand the view that, given the 
unreliability of `os.path.expanduser('~foo')`, we shouldn't be making that 
functionality *more* available.

My argument for this being a reasonable change is as follows:

Firstly, `os.getcwd()` is a more fundamental operation than 
`os.path.absolute()`. In both pathlib and os.path, the `absolute()` 
implementation is built on the `getcwd()` implementation. The process is: call 
the more fundamental operation, and append whatever else was passed as an 
argument.

Analagously, `gethomedir()` is a more fundamental operation than 
`expanduser()`. In the same way, `expanduser()` can call a more fundamental 
operation and then append the path passed in.

Secondly, for a `pathlib.AbstractPath` implementation, it's a much cleaner API 
to have `getcwd()` and `gethomedir()` as abstract methods with identical 
signatures, and `absolute()` and `expanduser()` with default implementations.

Thirdly, if there's are issues with the implementation for retrieving other 
user's home directories, those should be treated as individual issues with 
their own bugs, and we should add suitable warnings in the docs in the short 
term. My patch should make these cases *easier* to solve as we no longer have 
two competing implementations of the same thing.

Finally, I don't think anyone is going to see `home('barney')` in the docs and 
decided to retrieve a user's home directory on a whim. If someone *does* need 
to retrieve another user's home directory, they're going to use `Path('~' + 
user).expanduser()` if `Path.home(user)` isn't available.

My argument mostly comes from the similarities I perceive between 
getcwd/absolute and gethomedir/expanduser. We don't expect users to 
`os.path.absolute('.')` to get the current working directory, after all! But 
perhaps I've overestimated the similarities here. Any thoughts?

Thanks again for taking a look.

--

___
Python tracker 
<https://bugs.python.org/issue42998>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43936] os.path.realpath() normalizes paths before resolving links on Windows

2021-04-24 Thread Barney Gale


New submission from Barney Gale :

Capturing a write-up by eryksun on GitHub into a new bug.

Link: https://github.com/python/cpython/pull/25264#pullrequestreview-631787754

> `nt._getfinalpathname()` opens a handle to a file/directory with 
> `CreateFileW()` and calls `GetFinalPathNameByHandleW()`. The latter makes a 
> few system calls to get the final opened path in the filesystem (e.g. 
> "\Windows\explorer.exe") and the canonical DOS name of the volume device on 
> which the filesystem is mounted (e.g. "\Device\HarddiskVolume2" -> "\\?\C:") 
> in order to return a canonical DOS path (e.g. "\\?\C:\Windows\explorer.exe").
> 
> Opening a handle with `CreateFileW()` entails first getting a fully-qualified 
> and normalized NT path, which, among other things, entails resolving ".." 
> components naively in the path string. This does not take reparse points such 
> as symlinks and mountpoints into account. The only time Windows parses ".." 
> components in an opened path the way POSIX does is in the kernel when they're 
> in the target path of a relative symlink.
> 
> `nt.readlink()` opens a handle to the file with the flag 
> `FILE_FLAG_OPEN_REPARSE_POINT`. If the final path component is a reparse 
> point, it opens it instead of traversing it. Then the reparse point is read 
> with the filesystem control request, `FSCTL_GET_REPARSE_POINT`. System 
> symlinks and mountpoints (`IO_REPARSE_TAG_SYMLINK` and 
> `IO_REPARSE_TAG_MOUNT_POINT`) are the only supported name-surrogate 
> reparse-point types, though `os.stat()` and `os.lstat()` handle all 
> name-surrogate types as 'links'. Moreover, only symlinks get the `S_IFLNK` 
> mode flag in a stat result, because they're the only ones we can create with 
> `os.symlink()` to satisfy the usage `if os.path.islink(src): 
> os.symlink(os.readlink(src), dst)`.
>
> > What would it take to do a POSIX-style "normalize as we resolve",
> > and would we want to? I guess we'd need to call nt._getfinalpathname()
> > on each path component in turn (C:, C:\Users, C:\Users\Barney etc),
> > which from my pretty basic Windows knowledge might be rather slow if
> > that involves file handles.
> 
> You asked, so I decided to write up an outline of what implementing a 
> POSIX-style `realpath()` might look like in Windows. At its core, it's 
> similar to POSIX: lstat(), and, for a symlink, readlink() and recur. The 
> equivalent calls in Windows are the following:
> 
> * `CreateFileW()` (open a handle)
> 
> * `GetFileInformationByHandleEx()`: `FileAttributeTagInfo`
> 
> * `DeviceIoControl()`: `FSCTL_GET_REPARSE_POINT`
> 
> 
> A symlink has the reparse tag `IO_REPARSE_TAG_SYMLINK`.
> 
> Filesystem mountpoints (aka junctions, which are like Unix bind mountpoints) 
> must be retained in the resolved path in order to correctly resolve relative 
> symlinks such as "\spam" (relative to the resolved device) and "..\..\spam". 
> Anyway, this is consistent with the UNC case, since mountpoints on a remote 
> server can never be resolved (i.e. a final UNC path never resolves 
> mountpoints).
> 
> Here are some of the notable differences compared to POSIX:
> 
> * If the source path is not a "\\?\" verbatim path, `GetFullPathNameW()` 
> must be called initially.  However, ".." components in the target path of a 
> relative symlink must be resolved the POSIX way, else symlinks in the target 
> path may be removed incorrectly before their target is resolved (e.g. 
> "foo\symlink\..\bar" incorrectly resolved as "foo\bar"). The opened path is 
> initially normalized as follows:
>   
>   * replace forward slashes with backslashes
>   * collapse repeated backslashes (except the UNC root must have exactly 
> two backslashes)
>   * resolve a relative path (e.g. "spam"), drive-relative path (e.g. 
> "Z:spam"), or rooted path (e.g. "\spam") as a fully-qualified path (e.g. 
> "Z:\eggs\spam")
>   * resolve "." and ".." components in the opened path (naive to symlinks)
>   * strip trailing spaces and dots from the final component (e.g. 
> "C:\spam. . ." -> "C:\spam")
>   * resolve reserved device names in the final component of a non-UNC 
> path (e.g. "C:\nul" -> "\\.\nul")
> 
> * Substitute drives (e.g. created by "subst.exe", or `DefineDosDeviceW`) 
> and mapped drives (e.g. created by "net.exe", or `WNetAddConnection2W`) must 
> be resolved, respectively via `QueryDosDeviceW()` and 
> `WNetGetUniversalNameW()`. Like all DOS 'devices', these drives are 
>

[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2021-04-08 Thread Barney Gale


Barney Gale  added the comment:

Good spot Eryk - I've put in another PR to address it.

--

___
Python tracker 
<https://bugs.python.org/issue39899>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42998] pathlib.Path: add `username` argument to `home()`

2021-04-08 Thread Barney Gale


Barney Gale  added the comment:

Thanks for the feedback.

1. We can check the return value, like we do in `Path.expanduser()`
2. Seems like expected behaviour?
3. Worth fixing in `ntpath.expanduser()` I think. See Eryk Sun's comment here: 
https://bugs.python.org/issue39899#msg390507

--

___
Python tracker 
<https://bugs.python.org/issue42998>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2021-04-08 Thread Barney Gale


Change by Barney Gale :


--
pull_requests: +24014
stage: resolved -> patch review
pull_request: https://github.com/python/cpython/pull/25277

___
Python tracker 
<https://bugs.python.org/issue39899>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue930024] os.path.realpath can't handle symlink loops

2021-04-07 Thread Barney Gale


Change by Barney Gale :


--
nosy: +barneygale
nosy_count: 3.0 -> 4.0
pull_requests: +24006
pull_request: https://github.com/python/cpython/pull/25264

___
Python tracker 
<https://bugs.python.org/issue930024>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42998] pathlib.Path: add `username` argument to `home()`

2021-04-07 Thread Barney Gale


Change by Barney Gale :


--
keywords: +patch
pull_requests: +24004
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/25271

___
Python tracker 
<https://bugs.python.org/issue42998>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24132] Direct sub-classing of pathlib.Path

2021-04-07 Thread Barney Gale


Change by Barney Gale :


--
pull_requests: +24005
pull_request: https://github.com/python/cpython/pull/25271

___
Python tracker 
<https://bugs.python.org/issue24132>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27002] Support different modes in posixpath.realpath()

2021-04-07 Thread Barney Gale


Barney Gale  added the comment:

Just stumbled upon this issue after submitting a PR: 
https://github.com/python/cpython/pull/25264

In my PR, `strict=False` is like `--canonicalize-missing`, and `strict=True` is 
like `--canonicalize-existing`.

Looks like our patches are along similar lines. I've missed a trick by not 
calling `stat()` to trigger the ELOOP error.

--
nosy: +barneygale

___
Python tracker 
<https://bugs.python.org/issue27002>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43757] pathlib: move 'resolve()' logic out of path flavour

2021-04-07 Thread Barney Gale


Change by Barney Gale :


--
keywords: +patch
pull_requests: +24000
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/25264

___
Python tracker 
<https://bugs.python.org/issue43757>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2021-04-07 Thread Barney Gale


Barney Gale  added the comment:

Apologies, I think I started writing a comment before your reply was posted, 
which undid your changes.

--
resolution: not a bug -> 
status: closed -> open
versions: +Python 3.10 -Python 3.9

___
Python tracker 
<https://bugs.python.org/issue39899>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2021-04-07 Thread Barney Gale


Barney Gale  added the comment:

Thanks for taking a look, Steve.

A couple things maybe worth noting:

Firstly, `os.path.expanduser()` is already documented to return the path 
unchanged if the home directory can't be resolved:

> If the expansion fails or if the path does not begin with a tilde, the path 
> is returned unchanged.

Secondly, `ntpath.expanduser()` already returns the path unchanged if neither 
USERPROFILE nor HOMEPATH are in the environment.

An alternative would be to leave `ntpath.expanduser()` method alone, and forgo 
the slightly-improved error checking in `WindowsPath.expanduser()` in the name 
of conformity. Or perhaps we could add a `stict` parameter to `expanduser()`?

I can understand why this could be seen as change for change's sake. In fact 
this code removal greatly aids my work towards addressing bpo-24132.

Thanks again

--
resolution:  -> not a bug
stage: patch review -> resolved
status: open -> closed
versions: +Python 3.9 -Python 3.10

___
Python tracker 
<https://bugs.python.org/issue39899>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43757] pathlib: move 'resolve()' logic out of path flavour

2021-04-06 Thread Barney Gale


New submission from Barney Gale :

Under-the-hood functionality in pathlib is divided between:

- The 'flavour', which implements path syntax (separators, casefolding, etc)
- The 'accessor', which accesses the local (file)system.

The '_WindowsFlavour/_PosixFlavour.resolve()' function is misplaced, as it 
requires OS calls such as `os.getcwd()`, `os.readlink()`, and 
`nt._getfinalpathname()`. While the implementation *does* differ across Windows 
and POSIX, it's still properly part of the accessor interface, and not the 
flavour interface.

In preparation for addressing bpo-24132 I'd like to get these interfaces really 
tidy. Once bpo-39899 is fixed, this will be the last remaining flavour method 
that does accessor-y things.

--
components: Library (Lib)
messages: 390397
nosy: barneygale
priority: normal
severity: normal
status: open
title: pathlib: move 'resolve()' logic out of path flavour
type: enhancement
versions: Python 3.10

___
Python tracker 
<https://bugs.python.org/issue43757>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40107] pathlib: make `_Accessor.open()` return a file object and not a file descriptor

2021-04-06 Thread Barney Gale


Change by Barney Gale :


--
keywords: +patch
pull_requests: +23978
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/25240

___
Python tracker 
<https://bugs.python.org/issue40107>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24132] Direct sub-classing of pathlib.Path

2021-04-06 Thread Barney Gale


Change by Barney Gale :


--
pull_requests: +23979
stage: needs patch -> patch review
pull_request: https://github.com/python/cpython/pull/25240

___
Python tracker 
<https://bugs.python.org/issue24132>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43012] Remove pathlib accessors

2021-01-23 Thread Barney Gale

New submission from Barney Gale :

Per Pitrou:

> The original intent for the “accessor” thing was to have a variant that did 
> all accesses under a filesystem tree in a race condition-free way using 
> openat and friends. It turned out to be much too hairy to actually implement, 
> so was entirely abandoned, but the accessor abstraction was left there.

https://discuss.python.org/t/make-pathlib-extensible/3428/2

Accessors are:

- Lacking any internal purpose - '_NormalAccessor' is the only implementation
- Lacking any firm conceptual difference to `Path` objects themselves (inc. 
subclasses)
- Non-public, i.e. underscore prefixed - '_Accessor' and '_NormalAccessor' 
- Unofficially used to implement customized `Path` objects, but once once 
bpo-24132 lands there will be a supported route for that.

When bpo-24132 lands, I think we're free to remove accessors and simplify some 
code

--
components: Library (Lib)
messages: 385556
nosy: barneygale
priority: normal
severity: normal
status: open
title: Remove pathlib accessors

___
Python tracker 
<https://bugs.python.org/issue43012>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42999] `pathlib.Path.link_to()` documentation is misleading

2021-01-21 Thread Barney Gale


Change by Barney Gale :


--
pull_requests: +23117
pull_request: https://github.com/python/cpython/pull/24294

___
Python tracker 
<https://bugs.python.org/issue42999>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42999] `pathlib.Path.link_to()` documentation is misleading

2021-01-21 Thread Barney Gale


Change by Barney Gale :


--
keywords: +patch
pull_requests: +23116
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/18909

___
Python tracker 
<https://bugs.python.org/issue42999>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39950] Add pathlib.Path.hardlink_to()

2021-01-21 Thread Barney Gale


Barney Gale  added the comment:

I've logged bpo-42999 to cover fixing the existing `link_to()` docs issues. PR 
incoming...

--

___
Python tracker 
<https://bugs.python.org/issue39950>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42999] `pathlib.Path.link_to()` documentation is misleading

2021-01-21 Thread Barney Gale


New submission from Barney Gale :

Compare the documentation of `symlink_to()` and `link_to()`:

.. method:: Path.symlink_to(target, target_is_directory=False)
Make this path a symbolic link to *target*.

.. method:: Path.link_to(target)
Create a hard link pointing to a path named *target*.

In fact, `link_to()` does something like:

Make *target* a hard link to this path.

Which is unexpected given the naming and inconsistency with `symlink_to()`, but 
it's the way the current implementation works, and so the documentation should 
reflect that.

Adding a replacement `hardlink_to()` function is covered here in bpo-39950.

--
assignee: docs@python
components: Documentation
messages: 385474
nosy: barneygale, docs@python
priority: normal
severity: normal
status: open
title: `pathlib.Path.link_to()` documentation is misleading
type: behavior

___
Python tracker 
<https://bugs.python.org/issue42999>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42998] pathlib.Path: add `username` argument to `home()`

2021-01-21 Thread Barney Gale


Barney Gale  added the comment:

I should add that this is part of a plan to spin out some `Path` methods into a 
new `UserPath` class. Notably, in this case, `UserPath.expanduser()` will call 
`self.home()` under-the-hood. This is done to reduce the surface area of 
abstract methods that subclasses of `UserPath` need implement. More discussion 
here: https://discuss.python.org/t/make-pathlib-extensible/3428

--

___
Python tracker 
<https://bugs.python.org/issue42998>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42998] pathlib.Path: add `username` argument to `home()`

2021-01-21 Thread Barney Gale


New submission from Barney Gale :

The `pathlib.Path.home()` function looks like:

@classmethod
def home(cls):
"""Return a new path pointing to the user's home directory (as
returned by os.path.expanduser('~')).
"""
return cls(cls()._flavour.gethomedir(None))

If we add a `username=None` parameter and pass this to `gethomedir()` we can 
easily add a lookup of another user's home directory, so:

import pathlib
username = 'phil'
pathlib.Path.home(username) == pathlib.Path('~' + username).expanduser()

--
components: Library (Lib)
messages: 385472
nosy: barneygale
priority: normal
severity: normal
status: open
title: pathlib.Path: add `username` argument to `home()`
type: enhancement

___
Python tracker 
<https://bugs.python.org/issue42998>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39950] Add pathlib.Path.hardlink_to()

2021-01-21 Thread Barney Gale


Barney Gale  added the comment:

Makes sense to me. Should I leave the documentation for `link_to` completely 
alone? With the addition of a similar function, I wonder if that may in itself 
cause confusion.

--

___
Python tracker 
<https://bugs.python.org/issue39950>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40038] pathlib: remove partial support for preserving accessor when modifying a path

2020-04-03 Thread Barney Gale


Change by Barney Gale :


--
keywords: +patch
pull_requests: +18706
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/19342

___
Python tracker 
<https://bugs.python.org/issue40038>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39924] pathlib handles missing `os.link`, `os.symlink` and `os.readlink` inconsistently

2020-03-29 Thread Barney Gale


Change by Barney Gale :


--
pull_requests: +18582
pull_request: https://github.com/python/cpython/pull/19220

___
Python tracker 
<https://bugs.python.org/issue39924>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40107] pathlib: make `_Accessor.open()` return a file object and not a file descriptor

2020-03-29 Thread Barney Gale


New submission from Barney Gale :

This is one of a series of bug reports / PRs that lay the groundwork for making 
pathlib extensible. See here for detail: 
https://discuss.python.org/t/make-pathlib-extensible/3428

Currently `_Accessor.open()` is expected to function like `os.open()` and 
return a file descriptor. I'd suggest this interface is too low-level if our 
eventual aim is to allow users to implement their own accessor.

It would be better is `_Accessor.open()` is expected to function like 
`io.open()` and return a file object. That way, accessors don't need to deal 
with file descriptors at all, which is important if they're working with remote 
filesystems.

I'm planning to wait for bpo-39895 / gh-18838 to land before starting work on 
this.

--
components: Library (Lib)
messages: 365283
nosy: barneygale
priority: normal
severity: normal
status: open
title: pathlib: make `_Accessor.open()` return a file object and not a file 
descriptor
type: enhancement
versions: Python 3.9

___
Python tracker 
<https://bugs.python.org/issue40107>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24132] Direct sub-classing of pathlib.Path

2020-03-29 Thread Barney Gale


Barney Gale  added the comment:

I'm taking another look at making `pathlib` extensible. There's some discussion 
here: https://discuss.python.org/t/make-pathlib-extensible/3428

List or preparatory bugfixes and tidy-ups: 
https://docs.google.com/spreadsheets/d/1TicFDMudKKA6CZcrscg1Xq9kt5Q8To8y0hADGw9u11I/edit#gid=0

--
nosy: +barneygale

___
Python tracker 
<https://bugs.python.org/issue24132>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39950] Add pathlib.Path.hardlink_to()

2020-03-29 Thread Barney Gale


Barney Gale  added the comment:

A question:

For my patch, I need to include a Python version where `Path.link_to()` will 
become unavailable. I'm not entirely sure how this should be determined. Some 
factors in play:

- `link_to()` was added in Python 3.8
- On github, I found these three repos which use `link_to()`:
  - https://github.com/akubera/pion-analysis
  - https://github.com/DailyDreaming/load-project
  - https://github.com/eight04/vpip

Can anyone suggest in which version of Python this function should be removed? 
Thanks.

--

___
Python tracker 
<https://bugs.python.org/issue39950>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40038] pathlib: remove partial support for preserving accessor when modifying a path

2020-03-21 Thread Barney Gale


New submission from Barney Gale :

`pathlib.Path._init()` accepts a 'template' argument that pathlib uses - in 
some cases - to preserve the current accessor object when creating modified 
path objects. This works for `resolve()`, `absolute()` and `readlink()`, *but 
no other cases*!

As customizing the accessor is not something we support (yet! see 
https://discuss.python.org/t/make-pathlib-extensible/3428), and the majority of 
path methods do not call `_init()` with a 'template' argument (and so do not 
preserve the accessor), I suggest this internal functionality be removed. 
Together with bpo-39682 / gh-18846, I believe this would allow us to remove 
`Path._init()` entirely, which would be a small performance win and a 
simplification of the code.

Demo:

```
import pathlib


class CustomAccessor(pathlib._NormalAccessor):
pass


def print_accessor(path):
if isinstance(path._accessor, CustomAccessor):
print("%r: custom" % path)
else:
print("%r: normal" % path)


print("Here's a path with a custom accessor:")
p = pathlib.Path("/tmp")
p._accessor = CustomAccessor()
print_accessor(p)

print("Our accessor type is retained in resolve(), absolute() and readlink():")
print_accessor(p.absolute())
print_accessor(p.resolve())
#print_accessor(p.readlink())

print("But not in any other path-creating methods!")
print_accessor(p.with_name("foo"))
print_accessor(p.with_suffix(".foo"))
print_accessor(p.relative_to("/"))
print_accessor(p / "foo")
print_accessor(p.joinpath("foo"))
print_accessor(p.parent)
print_accessor(p.parents[0])
print_accessor(list(p.iterdir())[0])
print_accessor(list(p.glob("*"))[0])
print_accessor(list(p.rglob("*"))[0])
#print_accessor(p.expanduser())
```

--
components: Library (Lib)
messages: 364783
nosy: barneygale
priority: normal
severity: normal
status: open
title: pathlib: remove partial support for preserving accessor when modifying a 
path
type: performance
versions: Python 3.9

___
Python tracker 
<https://bugs.python.org/issue40038>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39950] Add pathlib.Path.hardlink_to()

2020-03-12 Thread Barney Gale


Change by Barney Gale :


--
keywords: +patch
pull_requests: +18321
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/18909

___
Python tracker 
<https://bugs.python.org/issue39950>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39950] Add pathlib.Path.hardlink_to()

2020-03-12 Thread Barney Gale


New submission from Barney Gale :

Per bpo-39291, the argument order for `pathlib.Path.link_to()` is inconsistent 
with `symlink_to()` and its own documentation.

This ticket covers adding a new `hardlink_to()` method with the correct 
argument order, and deprecating `link_to()`.

Discussion on python-dev: 
https://mail.python.org/archives/list/python-...@python.org/thread/7QPLYW36ZK6QTW4SV4FI6C343KYWCPAT/

--
components: Library (Lib)
messages: 364060
nosy: barneygale
priority: normal
severity: normal
status: open
title: Add pathlib.Path.hardlink_to()
type: enhancement
versions: Python 3.9

___
Python tracker 
<https://bugs.python.org/issue39950>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39291] "pathlib.Path.link_to()" and "pathlib.Path.symlink_to()" have reversed usage

2020-03-12 Thread Barney Gale


Barney Gale  added the comment:

Per discussion on the mailing list, I'd like to request that this bug be 
re-opened.

https://mail.python.org/archives/list/python-...@python.org/thread/7QPLYW36ZK6QTW4SV4FI6C343KYWCPAT/

--
nosy: +barneygale

___
Python tracker 
<https://bugs.python.org/issue39291>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39924] pathlib handles missing `os.link`, `os.symlink` and `os.readlink` inconsistently

2020-03-12 Thread Barney Gale


Barney Gale  added the comment:

Good points! Do you know of an example of a community library that uses 
`_Accessor.link`? Thanks

--

___
Python tracker 
<https://bugs.python.org/issue39924>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39925] `pathlib.Path.link_to()` has the wrong argument order

2020-03-10 Thread Barney Gale


Change by Barney Gale :


--
keywords: +patch
pull_requests: +18264
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/18909

___
Python tracker 
<https://bugs.python.org/issue39925>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39925] `pathlib.Path.link_to()` has the wrong argument order

2020-03-10 Thread Barney Gale


Barney Gale  added the comment:

I'm not sure how it can be fixed on the documentation side - it's difficult to 
explain that `a.link_to(b)` creates a link from B to A, and not vice-versa.

We could introduce a new method that does the right thing? `Path.hardlink_to()`?

--

___
Python tracker 
<https://bugs.python.org/issue39925>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39925] `pathlib.Path.link_to()` has the wrong argument order

2020-03-10 Thread Barney Gale


New submission from Barney Gale :

`mylink.symlink_to(target)` and `mylink.link_to(target)` should both create a 
link (soft or hard) at *mylink* that points to *target*. But `link_to()` does 
the opposite - it creates *target* and points it towards *mylink*.


Correct behaviour from `symlink_to()`:

barney@acorn ~/projects/cpython $ touch /tmp/target
barney@acorn ~/projects/cpython $ ./python 
Python 3.9.0a3+ (heads/bpo-39659-pathlib-getcwd-dirty:a4ba8a3, Feb 19 2020, 
02:22:39) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pathlib
>>> p = pathlib.Path('/tmp/link')
>>> p.symlink_to('/tmp/target')
>>> exit()
barney@acorn ~/projects/cpython $ ls -l /tmp/link /tmp/target
lrwxrwxrwx 1 barney barney 11 Mar 10 21:20 /tmp/link -> /tmp/target
-rw-rw-r-- 1 barney barney  0 Mar 10 21:20 /tmp/target


Incorrect behaviour from `link_to()`:

barney@acorn ~/projects/cpython $ rm /tmp/link 
barney@acorn ~/projects/cpython $ ./python 
Python 3.9.0a3+ (heads/bpo-39659-pathlib-getcwd-dirty:a4ba8a3, Feb 19 2020, 
02:22:39) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pathlib
>>> p = pathlib.Path('/tmp/link')
>>> p.link_to('/tmp/target')
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/barney/projects/cpython/Lib/pathlib.py", line 1370, in link_to
self._accessor.link_to(self, target)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/link' -> 
'/tmp/target'
>>> # but...
>>> p = pathlib.Path('/tmp/target')
>>> p.link_to('/tmp/link')
>>> exit()
barney@acorn ~/projects/cpython $ ls -l /tmp/link /tmp/target
-rw-rw-r-- 2 barney barney 0 Mar 10 21:20 /tmp/link
-rw-rw-r-- 2 barney barney 0 Mar 10 21:20 /tmp/target

--
components: Library (Lib)
messages: 363850
nosy: barneygale
priority: normal
severity: normal
status: open
title: `pathlib.Path.link_to()` has the wrong argument order
type: behavior
versions: Python 3.9

___
Python tracker 
<https://bugs.python.org/issue39925>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39924] pathlib handles missing `os.link`, `os.symlink` and `os.readlink` inconsistently

2020-03-10 Thread Barney Gale


New submission from Barney Gale :

Small bug report encompassing some related issues in `pathlib._NormalAccessor`:

- `link_to()` should be named `link()` for consistency with other methods
- `symlink()` doesn't need to guard against `os.symlink()` not accepting 
`target_is_directory` on non-Windows platforms; this has been fixed since 3.3
- `readlink()` doesn't raise `NotImplementedError` when `os.readlink()` is 
unavailable

Only the last of these has a user impact, and only on exotic systems.

--
components: Library (Lib)
messages: 363845
nosy: barneygale
priority: normal
severity: normal
status: open
title: pathlib handles missing `os.link`, `os.symlink` and `os.readlink` 
inconsistently
type: behavior
versions: Python 3.9

___
Python tracker 
<https://bugs.python.org/issue39924>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39900] `pathlib.Path.__bytes__()` calls `os.fsencode()` without using accessor

2020-03-10 Thread Barney Gale


Barney Gale  added the comment:

Closing after @pitrou clarified the meaning of __fspath__() here: 
https://discuss.python.org/t/make-pathlib-extensible/3428/12?u=barneygale

--
resolution:  -> not a bug
stage: patch review -> resolved
status: open -> closed

___
Python tracker 
<https://bugs.python.org/issue39900>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39907] `pathlib.Path.iterdir()` wastes memory by using `os.listdir()` rather than `os.scandir()`

2020-03-09 Thread Barney Gale

Barney Gale  added the comment:

Thanks Rémi and Serhiy! Closing this ticket as the patch doesn't provide any 
sort of improvement.

--

___
Python tracker 
<https://bugs.python.org/issue39907>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39907] `pathlib.Path.iterdir()` wastes memory by using `os.listdir()` rather than `os.scandir()`

2020-03-09 Thread Barney Gale


Change by Barney Gale :


--
resolution:  -> not a bug
stage: patch review -> resolved
status: open -> closed

___
Python tracker 
<https://bugs.python.org/issue39907>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39907] `pathlib.Path.iterdir()` wastes memory by using `os.listdir()` rather than `os.scandir()`

2020-03-09 Thread Barney Gale


Barney Gale  added the comment:

Less reliable how? Doesn't appear any slower:

barney.gale@heilbron:~$ python3 -m timeit -s "import os; 
os.listdir('/usr/local')"
1 loops, best of 3: 0.0108 usec per loop
barney.gale@heilbron:~$ python3 -m timeit -s "import os; 
list(os.scandir('/usr/local'))"
1 loops, best of 3: 0.00919 usec per loop

--

___
Python tracker 
<https://bugs.python.org/issue39907>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39907] `pathlib.Path.iterdir()` wastes memory by using `os.listdir()` rather than `os.scandir()`

2020-03-09 Thread Barney Gale


Barney Gale  added the comment:

Ah, right you are! The globbing helpers call `list(os.scandir(...))` - perhaps 
we should do the same here?

--

___
Python tracker 
<https://bugs.python.org/issue39907>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39907] `pathlib.Path.iterdir()` wastes memory by using `os.listdir()` rather than `os.scandir()`

2020-03-08 Thread Barney Gale


Change by Barney Gale :


--
keywords: +patch
pull_requests: +18223
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/18865

___
Python tracker 
<https://bugs.python.org/issue39907>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39907] `pathlib.Path.iterdir()` wastes memory by using `os.listdir()` rather than `os.scandir()`

2020-03-08 Thread Barney Gale


New submission from Barney Gale :

`pathlib.Path.iterdir()` uses `os.listdir()` rather than `os.scandir()`. I 
think this has a small performance cost, per PEP 471:

> It returns a generator instead of a list, so that scandir acts as a true 
> iterator instead of returning the full list immediately.

As `scandir()` is already available from `_NormalAccessor` it's a simple patch 
to use `scandir()` instead.

--
components: Library (Lib)
messages: 363689
nosy: barneygale
priority: normal
severity: normal
status: open
title: `pathlib.Path.iterdir()` wastes memory by using `os.listdir()` rather 
than `os.scandir()`
type: resource usage
versions: Python 3.9

___
Python tracker 
<https://bugs.python.org/issue39907>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39906] pathlib.Path: add `follow_symlinks` argument to `stat()` and `chmod()`

2020-03-08 Thread Barney Gale


Change by Barney Gale :


--
keywords: +patch
pull_requests: +18221
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/18864

___
Python tracker 
<https://bugs.python.org/issue39906>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7479] os.lchmod is not present

2020-03-08 Thread Barney Gale


Change by Barney Gale :


--
nosy: +barneygale
nosy_count: 5.0 -> 6.0
pull_requests: +18222
pull_request: https://github.com/python/cpython/pull/18864

___
Python tracker 
<https://bugs.python.org/issue7479>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39906] pathlib.Path: add `follow_symlinks` argument to `stat()` and `chmod()`

2020-03-08 Thread Barney Gale


New submission from Barney Gale :

As of Python 3.3, `os.lstat()` and `os.lchmod()` are available as 
`os.stat(follow_symlinks=False)` and `os.chmod(follow_symlinks=False)`, but an 
equivalent change didn't make it into pathlib. I propose we add the  
`follow_symlinks` argument to `Path.stat()` and `Path.chmod()` for consistency 
with `os` and because the new notation is arguable clearer for people who don't 
know many system calls off by heart :)

--
components: Library (Lib)
messages: 363681
nosy: barneygale
priority: normal
severity: normal
status: open
title: pathlib.Path: add `follow_symlinks` argument to `stat()` and `chmod()`
type: enhancement
versions: Python 3.9

___
Python tracker 
<https://bugs.python.org/issue39906>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2020-03-08 Thread Barney Gale


Barney Gale  added the comment:

The only design flaw mentioned in that thread is that `os.path.expanduser()` 
returns the input unchanged if expansion fails, which is not very pythonic. 
However, such a problem doesn't necessitate a rewrite of 
`os.path.expanduser()`. Checking `result[:1]` is enough.

I think there's also a difference in the Windows heuristic in that pathlib 
checks whether `basename(%HOMEPATH%) == %USERNAME%` whereas `ntpath.expanduser` 
doesn't. But if that's really an issue it should probably be fixed in `ntpath` 
IMO, rather than having divergent implementations.

--

___
Python tracker 
<https://bugs.python.org/issue39899>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39682] pathlib.Path objects can be used as context managers

2020-03-08 Thread Barney Gale


Change by Barney Gale :


--
keywords: +patch
pull_requests: +18203
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/18846

___
Python tracker 
<https://bugs.python.org/issue39682>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39899] `pathlib.Path.expanduser()` does not call `os.path.expanduser()`

2020-03-08 Thread Barney Gale


Barney Gale  added the comment:

I see no reason for the duplication, and I can point to one concrete bug 
affecting your re-implementation of `expanduser` that doesn't affect the 
original, i.e. that a `KeyError` is raised on Windows when `"USERNAME"` is not 
present in `os.environ`, whereas all similar cases raise `RuntimeError`. These 
sorts of issues sneak in when you duplicate code - better to stick with the 
battle-hardened version rather than an inherently risky rewrite.

--

___
Python tracker 
<https://bugs.python.org/issue39899>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39901] `pathlib.Path.owner()` and `group()` use `pwd` and `grp` modules directly

2020-03-08 Thread Barney Gale


Change by Barney Gale :


--
keywords: +patch
pull_requests: +18201
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/18844

___
Python tracker 
<https://bugs.python.org/issue39901>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39901] `pathlib.Path.owner()` and `group()` use `pwd` and `grp` modules directly

2020-03-08 Thread Barney Gale


New submission from Barney Gale :

The implementations of `Path.owner()` and `Path.group()` directly import and 
use the `pwd` and `grp` modules. Given these modules provide information about 
the *local* system, I believe these implementations should instead live in 
`pathlib._NormalAccessor` for consistency with other methods that do "impure" 
things.

--
components: Library (Lib)
messages: 363643
nosy: barneygale
priority: normal
severity: normal
status: open
title: `pathlib.Path.owner()` and `group()` use `pwd` and `grp` modules directly
versions: Python 3.9

___
Python tracker 
<https://bugs.python.org/issue39901>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   >