Commit graph

134 commits

Author SHA1 Message Date
Wei-Hsiang (Matt) Wang
d47d7e1124
[3.12] gh-123517: Remove unnecessary :meth: parentheses (gh-123518) (GH-123576) 2024-09-02 16:02:39 +02:00
Miss Islington (bot)
f5009b69e0
[3.12] GH-120794: Use example paths with multiple parts in pathlib docs (GH-122887) (#122896)
GH-120794: Use example paths with multiple parts in pathlib docs (GH-122887)

In the documentation of `PosixPath` and `WindowsPath`, and their `Pure*`
equivalents, use example paths with multiple non-anchor parts.

(cherry picked from commit 363374cf69)

Co-authored-by: Barney Gale <barney.gale@gmail.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
2024-08-10 22:31:59 +01:00
Barney Gale
8205c16c7c
[3.12] GH-121462: pathlib docs: improve table of corresponding os/os.path functions (GH-121465) (#122360)
Re-order table of corresponding functions with the following priorities:

1. Pure functionality is at the top
2. `os.path` functions are shown before `os` functions
3. Similar functionality is kept together
4. Functionality follows docs order where possible

Add a few missed correspondences:

- `os.path.isjunction` and `Path.is_junction`
- `os.path.ismount` and `Path.is_mount`
- `os.lstat()` and `Path.lstat()`
- `os.lchmod()` and `Path.lchmod()`

Also add footnotes describing a few differences.

(cherry picked from commit cbac8a3888)
2024-07-27 17:13:20 +00:00
Russell Keith-Magee
71970d602f
[3.12] Docs: spelling and grammar fixes (GH-122084) (#122107)
(cherry picked from commit bc264eac3a)

Co-authored-by: Ville Skyttä <ville.skytta@iki.fi>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-07-21 18:39:48 -07:00
Miss Islington (bot)
d4747727af
[3.12] GH-119054: Add alt text to pathlib inheritance diagram (GH-121158) (#121169)
GH-119054: Add alt text to pathlib inheritance diagram (GH-121158)
(cherry picked from commit 6b280a8498)

Co-authored-by: Barney Gale <barney.gale@gmail.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2024-06-29 17:53:27 +00:00
Barney Gale
d6eff187b5
[3.12] GH-119054: Fix pathlib docs subtitle word order (#121167)
When backporting GH-120505 to 3.12, I accidentally transposed
"Permissions and ownership" into "Ownership and permissions".
Swap it back for consistency with 3.13 and main.
2024-06-29 18:50:01 +01:00
Barney Gale
22dfecf1f5
[3.12] GH-119054: Add "Expanding and resolving paths" section to pathlib docs. (GH-120970) (#121156)
Add dedicated subsection for `home()`, `expanduser()`, `cwd()`,
`absolute()`, `resolve()` and `readlink()`. The position of this section
keeps all the `Path` constructors (`Path()`, `Path.from_uri()`,
`Path.home()` and `Path.cwd()`) near the top. Within the section, closely
related methods are kept adjacent. Specifically:

- `home()` and `expanduser()` (the former calls the latter)
- `cwd()` and `absolute()` (the former calls the latter)
- `absolute()` and `resolve()` (both make paths absolute)
- `resolve()` and `readlink()` (both read symlink targets)
- Ditto `cwd()` and `absolute()`
- Ditto `absolute()` and `resolve()`

The "Other methods" section is removed.

(cherry picked from commit d6d8707ff2)
2024-06-29 16:38:39 +01:00
Barney Gale
52bc99743c
[3.12] GH-119054: Add "Permissions and ownership" section to pathlib docs. (GH-120505) (#120968)
Add dedicated subsection for `pathlib.owner()`, `group()`, `chmod()` and
`lchmod()`.

(cherry picked from commit e4a97a7fb1)
2024-06-24 20:32:24 +01:00
Miss Islington (bot)
c9fc099c59
[3.12] GH-119054: Add "Renaming and deleting" section to pathlib docs. (GH-120465) (#120473)
GH-119054: Add "Renaming and deleting" section to pathlib docs. (GH-120465)

Add dedicated subsection for `pathlib.Path.rename()`, `replace()`,
`unlink()` and `rmdir()`.
(cherry picked from commit d88a1f2e15)

Co-authored-by: Barney Gale <barney.gale@gmail.com>
2024-06-13 20:31:52 +00:00
Barney Gale
eff055340f
[3.12] GH-119054: Add "Creating files and directories" section to pathlib docs. (GH-120186) (#120464)
Add dedicated subsection for `pathlib.Path.touch()`, `mkdir()`,
`symlink_to()` and `hardlink_to()`. Also note that `open()`, `write_text()`
and `write_bytes()` are often used to create files.

(cherry picked from commit c2d810b6d4)
2024-06-13 19:21:27 +01:00
Barney Gale
59224b8fdc
[3.12] GH-119054: Add "Reading directories" section to pathlib docs (GH-119956) (#120184)
Add a dedicated subsection for `Path.iterdir()`-related methods,
specifically `iterdir()`, `glob()`, `rglob()` and `walk()`.

(cherry picked from commit 14e1506a6d)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-06-07 01:24:44 +01:00
Barney Gale
059be67b51
[3.12] GH-119054: Add "Reading and writing files" section to pathlib docs (GH-119524) (#119955)
Add a dedicated subsection for `open()`, `read_text()`, `read_bytes()`,
`write_text()` and `write_bytes()`.

(cherry picked from commit bd6d4ed645)
2024-06-02 21:14:29 +01:00
Barney Gale
85020647c2
[3.12] GH-119054: Add "Querying file type and status" section to pathlib docs (GH-119055) (#119952)
Add a dedicated subsection for `Path.stat()`-related methods, specifically
`stat()`, `lstat()`, `exists()`, `is_*()`, and `samefile()`.

(cherry picked from commit 81d6336230)
2024-06-02 20:38:00 +01:00
Barney Gale
a0786bcb74
[3.12] GH-118701: Note that recursive wildcards aren't supported in PurePath.match() (#118713) 2024-05-11 19:10:51 +01:00
Serhiy Storchaka
530c3bb271
[3.12] Format None, True, False and NotImplemented as literals (GH-118758) (GH-118794)
(cherry picked from commit 05c2fe1acd)
2024-05-08 19:55:13 +00:00
Miss Islington (bot)
b83b3cb9da
[3.12] docs: module page titles should not start with a link to themselves (GH-117099) (#118791)
docs: module page titles should not start with a link to themselves (GH-117099)
(cherry picked from commit bcb435ee8f)

Co-authored-by: Ned Batchelder <ned@nedbatchelder.com>
2024-05-08 19:42:01 +00:00
Miss Islington (bot)
ccd8d77112
[3.12] GH-105900: Fix pathlib.Path.symlink_to(target_is_directory=...) docs (GH-114035) (#114464)
Clarify that *target_is_directory* only matters if the target doesn't
exist.
(cherry picked from commit b822b85ac1)

Co-authored-by: Barney Gale <barney.gale@gmail.com>
2024-01-23 05:36:16 +00:00
Miss Islington (bot)
9c2db5725e
[3.12] GH-82695: Clarify pathlib.Path.mkdir() documentation (GH-114032) (#114462)
Remove a double negative in the documentation of `mkdir()`'s *exist_ok*
parameter.

(cherry picked from commit 32c227470a)

Co-authored-by: Barney Gale <barney.gale@gmail.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
2024-01-23 02:37:35 +00:00
Miss Islington (bot)
a199ab3f33
[3.12] GH-99334: Explain that PurePath.is_relative_to() is purely lexical. (GH-114031) (#114460)
(cherry picked from commit 3a61d24062)
2024-01-23 01:12:59 +00:00
Barney Gale
0ee681a665
[3.12] GH-78988: Document pathlib.Path.glob() exception propagation. (GH-114036) (#114154)
We propagate the `OSError` from the `is_dir()` call on the top-level
directory, and suppress all others.

(cherry picked from commit 7092b3f131)
2024-01-16 22:39:09 +00:00
Miss Islington (bot)
259a4af3d2
[3.12] gh-112758: Updated pathlib documentation for PurePath.match (GH-112814) (#112882)
gh-112758: Updated pathlib documentation for PurePath.match (GH-112814)
(cherry picked from commit ed8720ace4)

Co-authored-by: Taylor Packard <3.t.packard@gmail.com>
2023-12-08 18:26:46 +00:00
Barney Gale
ef58c0428d
[3.12] GH-104375: Use versionchanged to describe new arguments in pathlib docs (GH-104376, GH-106058)
(cherry picked from commit 4a6c84fc1e)
2023-06-24 16:25:47 +01:00
Barney Gale
e7cb216339
[3.12] GH-105113: Improve performance of pathlib.PurePath.match() (GH-105114)
We now compile a `re.Pattern` object for the entire pattern. This is made
more difficult by `fnmatch` not treating directory separators as special
when evaluating wildcards (`*`, `?`, etc), and so we arrange the path parts
onto separate *lines* in a string, and ensure we don't set `re.DOTALL`.

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-05-31 21:37:37 +01:00
thirumurugan
dcdc90d384
GH-104484: Add case_sensitive argument to pathlib.PurePath.match() (GH-104565)
Co-authored-by: Barney Gale <barney.gale@gmail.com>
2023-05-18 18:59:31 +01:00
Hugo van Kemenade
13ac1766bc
gh-103960: Dark mode: invert image brightness (#103983) 2023-05-10 16:46:37 +03:00
Barney Gale
d00d942149
GH-100479: Add pathlib.PurePath.with_segments() (GH-103975)
Add `pathlib.PurePath.with_segments()`, which creates a path object from arguments. This method is called whenever a derivative path is created, such as from `pathlib.PurePath.parent`. Subclasses may override this method to share information between path objects.

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-05-05 19:04:53 +00:00
Barney Gale
8100be5535
GH-81079: Add case_sensitive argument to pathlib.Path.glob() (GH-102710)
This argument allows case-sensitive matching to be enabled on Windows, and
case-insensitive matching to be enabled on Posix.

Co-authored-by: Steve Dower <steve.dower@microsoft.com>
2023-05-04 16:44:36 +00:00
andrei kulakov
af886ffa06
GH-89769: pathlib.Path.glob(): do not follow symlinks when checking for precise match (GH-29655)
Co-authored-by: Barney Gale <barney.gale@gmail.com>
2023-05-03 04:50:10 +01:00
Barney Gale
6716254e71
GH-101362: Optimise PurePath(PurePath(...)) (GH-101667)
The previous `_parse_args()` method pulled the `_parts` out of any supplied `PurePath` objects; these were subsequently joined in `_from_parts()` using `os.path.join()`. This is actually a slower form of joining than calling `fspath()` on the path object, because it doesn't take advantage of the fact that the contents of `_parts` is normalized!

This reduces the time taken to run `PurePath("foo", "bar")` by ~20%, and the time taken to run `PurePath(p, "cheese")`, where `p = PurePath("/foo", "bar", "baz")`, by ~40%.

Automerge-Triggered-By: GH:AlexWaygood
2023-03-05 15:50:21 -08:00
Furkan Onder
3690688149
GH-101898: Fix missing term references for hashable definition (#101899)
Fix missing term references for hashable definition
2023-02-14 14:20:11 +04:00
Barney Gale
01093b8203
gh-86610: Use attribute directive in docs for pathlib.PurePath (#101114) 2023-01-20 23:13:58 +01:00
Jürgen Gmach
61f338a005
GH-101112: Specify type of pattern for Path.rglob (#101132)
The documentation for `rglob` did not mention what `pattern` actually
is.

Mentioning and linking to `fnmatch` makes this explicit, as the
documentation for `fnmatch` both shows the syntax and some explanation.
2023-01-20 23:11:31 +01:00
Shantanu
2f2fa03ff3
gh-87691: clarify use of anchor in pathlib docs (#100782)
This is feedback from https://github.com/python/cpython/pull/100737#discussion_r1062968696

This matches the wording from the `os.path.join` docs better:
https://docs.python.org/3/library/os.path.html#os.path.join

In particular, the previous use of "anchor" was incorrect given the
pathlib definition of "anchor".

Co-authored-by: Barney Gale <barney.gale@gmail.com>
2023-01-05 17:49:33 -08:00
Shantanu
1ae619c911
gh-87691: add an absolute path pathlib example in / operator docs (GH-100737)
The behaviour is fully explained a couple paragraphs above, but it may be useful to have a brief example to cover the behaviour.

Automerge-Triggered-By: GH:hauntsaninja
2023-01-05 14:55:35 -08:00
Barney Gale
5a991da329
gh-78707: deprecate passing >1 argument to PurePath.[is_]relative_to() (GH-94469)
This brings `relative_to()` and `is_relative_to()` more in line with other pathlib methods like `rename()` and `symlink_to()`.

Resolves #78707.
2022-12-16 16:14:27 -08:00
Charles Machalow
1b2de89bce
gh-99547: Add isjunction methods for checking if a path is a junction (GH-99548) 2022-11-22 17:19:34 +00:00
Mateusz
0023f51deb
gh-98240: Updated Path.rename docs, when it is atomic (GH-98245) 2022-10-28 16:31:37 -07:00
domragusa
e089f23bbb
gh-84538: add strict argument to pathlib.PurePath.relative_to (GH-19813)
By default, :meth:`pathlib.PurePath.relative_to` doesn't deal with paths that are not a direct prefix of the other, raising an exception in that instance. This change adds a *walk_up* parameter that can be set to allow for using ``..`` to calculate the relative path.

example:
```
>>> p = PurePosixPath('/etc/passwd')
>>> p.relative_to('/etc')
PurePosixPath('passwd')
>>> p.relative_to('/usr')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pathlib.py", line 940, in relative_to
    raise ValueError(error_message.format(str(self), str(formatted)))
ValueError: '/etc/passwd' does not start with '/usr'
>>> p.relative_to('/usr', strict=False)
PurePosixPath('../etc/passwd')
```


https://bugs.python.org/issue40358

Automerge-Triggered-By: GH:brettcannon
2022-10-28 16:20:14 -07:00
Julien Palard
2eb503e4dd
Doc: Found some remaining default roles. (GH-98392) 2022-10-18 15:46:18 +02:00
Ansab Gillani
b462f143ff
Fix documentation typo for pathlib.Path.walk (GH-96301) 2022-08-26 14:21:40 -07:00
Barney Gale
29650fea96
gh-86943: implement pathlib.WindowsPath.is_mount() (GH-31458)
Have `pathlib.WindowsPath.is_mount()` call `ntpath.ismount()`. Previously it raised `NotImplementedError` unconditionally.


https://bugs.python.org/issue42777
2022-08-05 15:37:44 -07:00
Stanislav Zmiev
c1e929858a
gh-90385: Add pathlib.Path.walk() method (GH-92517)
Automerge-Triggered-By: GH:brettcannon
2022-07-22 16:55:46 -07:00
Ned Batchelder
6e2fbdab92
docs: use 'recursively' in the description of rglob, and mention globs in the os equivalences (GH-94954)
The r in `rglob` stands for "recursively", so use the word in the description. Also, glob and rglob can usefully be mentioned as the pathlib equivalent of os.walk.

Automerge-Triggered-By: GH:brettcannon
2022-07-20 14:47:43 -07:00
Chris Adams
3789c63577
Add additional pointers to pathlib's mapping to os.path functions (#94828)
* Add additional pointers to pathlib's mapping to os.path functions

os.path.splitext has a somewhat quirky signature since it mixes the path and filename components but I wanted the documentation to mention `PurePath.stem` as the natural counterpart to `PurePath.suffix` for the common use of `os.path.splitext` to turn "file.py" into "file" and "py".

Technically this could have some discussion of how to handle the parent directory hierarchy but that seems a bit out of keeping with the spirit of this table so I omitted mentioning `PurePath.parents` here.

* Update Doc/library/pathlib.rst

Co-authored-by: Ezio Melotti <ezio.melotti@gmail.com>

Co-authored-by: Ezio Melotti <ezio.melotti@gmail.com>
2022-07-16 00:09:27 +02:00
Oleg Iarygin
f62ff97f31
gh-93851: Fix all broken links in Doc/ (GH-93853) 2022-06-21 20:55:18 +02:00
Oleg Iarygin
78f1a43694
gh-91317: Document that Path does not collapse initial // (GH-32193)
Documentation for `pathlib` says:

> 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:

However, it omits that initial double slashes also aren't collapsed.

Later, in documentation of `PurePath.drive`, `PurePath.root`, and `PurePath.name` it mentions UNC but:

- this abbreviation says nothing to a person who is unaware about existence of UNC (Wikipedia doesn't help either by [giving a disambiguation page](https://en.wikipedia.org/wiki/UNC))
- it shows up only if a person needs to use a specific property or decides to fully learn what the module provides.

For context, see the BPO entry.
2022-06-10 15:52:36 -07:00
jacksonriley
8ef7929baf
Fix PurePath.relative_to links in the pathlib documentation. (GH-93268)
These are currently broken as they refer to :meth:`Path.relative_to` rather than :meth:`PurePath.relative_to`, and `relative_to` is a method on `PurePath`.
2022-06-07 11:54:16 -07:00
Brett Cannon
d59b2d0441
Fix a directive in the pathlib docs (GH-93030) 2022-05-20 15:52:38 -07:00
Stanley
f51ed04c66
gh-72073: Add Windows case in pathlib.rename (GH-93002)
#72073

https://docs.python.org/3.12/library/pathlib.html#pathlib.Path.rename
2022-05-20 15:25:39 -07:00
Serhiy Storchaka
b1c4368824
Revert "gh-92550 - Fix regression in pathlib.Path.rglob() (GH-92583)" (GH-92598)
This reverts commit dcdf250d2d.
2022-05-11 07:14:25 +03:00