pyselfupdate 0.6.0__tar.gz → 0.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyselfupdate-0.6.0 → pyselfupdate-0.8.0}/PKG-INFO +48 -21
- {pyselfupdate-0.6.0 → pyselfupdate-0.8.0}/README.md +47 -20
- {pyselfupdate-0.6.0 → pyselfupdate-0.8.0}/src/pyselfupdate/__init__.py +2 -0
- {pyselfupdate-0.6.0 → pyselfupdate-0.8.0}/src/pyselfupdate/config.py +3 -0
- {pyselfupdate-0.6.0 → pyselfupdate-0.8.0}/src/pyselfupdate/errors.py +9 -0
- {pyselfupdate-0.6.0 → pyselfupdate-0.8.0}/src/pyselfupdate/github.py +4 -7
- {pyselfupdate-0.6.0 → pyselfupdate-0.8.0}/src/pyselfupdate/install.py +72 -14
- {pyselfupdate-0.6.0 → pyselfupdate-0.8.0}/src/pyselfupdate/typercmd.py +9 -2
- {pyselfupdate-0.6.0 → pyselfupdate-0.8.0}/src/pyselfupdate/updater.py +57 -13
- {pyselfupdate-0.6.0 → pyselfupdate-0.8.0}/.gitignore +0 -0
- {pyselfupdate-0.6.0 → pyselfupdate-0.8.0}/LICENSE +0 -0
- {pyselfupdate-0.6.0 → pyselfupdate-0.8.0}/pyproject.toml +0 -0
- {pyselfupdate-0.6.0 → pyselfupdate-0.8.0}/src/pyselfupdate/notifier.py +0 -0
- {pyselfupdate-0.6.0 → pyselfupdate-0.8.0}/src/pyselfupdate/py.typed +0 -0
- {pyselfupdate-0.6.0 → pyselfupdate-0.8.0}/src/pyselfupdate/source.py +0 -0
- {pyselfupdate-0.6.0 → pyselfupdate-0.8.0}/src/pyselfupdate/state.py +0 -0
- {pyselfupdate-0.6.0 → pyselfupdate-0.8.0}/src/pyselfupdate/version.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: pyselfupdate
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.8.0
|
|
4
4
|
Summary: Self-update and update notification for Python CLIs installed with uv tool
|
|
5
5
|
Project-URL: Repository, https://github.com/datapointchris/pyselfupdate
|
|
6
6
|
Project-URL: Issues, https://github.com/datapointchris/pyselfupdate/issues
|
|
@@ -33,7 +33,9 @@ release exists. `update` installs that release when the user asks.
|
|
|
33
33
|
`uv tool upgrade` re-resolves the requirement a tool was installed with, so a
|
|
34
34
|
tool installed at a release tag stays at that tag. `update` asks the release
|
|
35
35
|
source which tag is newest and reinstalls at that tag. A git install is held to
|
|
36
|
-
that tag's `uv.lock`.
|
|
36
|
+
that tag's `uv.lock`. A tool installed from a package index is offered only the
|
|
37
|
+
version its index serves, which can trail a release whose upload has not
|
|
38
|
+
finished.
|
|
37
39
|
|
|
38
40
|
The package has no runtime dependencies. It uses `urllib` for the network,
|
|
39
41
|
`tomllib` for uv's receipt and lock, and its own semver implementation. CI
|
|
@@ -47,8 +49,9 @@ uv add pyselfupdate # the library alone, with no dependencies
|
|
|
47
49
|
uv add 'pyselfupdate[typer]' # adds typer and the ready-made `update` command
|
|
48
50
|
```
|
|
49
51
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
The supported Python versions are `requires-python` in `pyproject.toml`, which
|
|
53
|
+
uv checks before it installs. The floor is the first release carrying
|
|
54
|
+
`tomllib`.
|
|
52
55
|
|
|
53
56
|
## Starting from scratch
|
|
54
57
|
|
|
@@ -94,13 +97,15 @@ A private repository needs a credential. `gh auth login` is enough, because
|
|
|
94
97
|
the check runs `gh auth token` by default.
|
|
95
98
|
|
|
96
99
|
**When the notice never appears, run `mytool update --check` first.** It runs
|
|
97
|
-
the
|
|
98
|
-
|
|
99
|
-
|
|
100
|
+
the steps that can fail and prints what stopped it. Those are reading uv's
|
|
101
|
+
receipt, asking the release source and, for an index install, asking its
|
|
102
|
+
index. The notice stays silent on each. Every other reason it stays silent is
|
|
103
|
+
in the table under `notify`.
|
|
100
104
|
|
|
101
105
|
## `notify` — one line after the command's output, never an error
|
|
102
106
|
|
|
103
|
-
Once per 24 hours, when a newer release
|
|
107
|
+
Once per 24 hours, when a newer release can be installed, one line goes to
|
|
108
|
+
stderr:
|
|
104
109
|
|
|
105
110
|
```text
|
|
106
111
|
mytool v1.4.0 available (running v1.3.2) — run `mytool update`
|
|
@@ -120,7 +125,7 @@ Nothing is printed when any of these hold:
|
|
|
120
125
|
| `NO_AUTO_UPDATE` or `MYTOOL_NO_AUTO_UPDATE` is set | Opted out |
|
|
121
126
|
| `--help` or `-h` comes before any `--` on the command line | typer runs the callback even for a subcommand's help screen, which is not work |
|
|
122
127
|
| stdout or stderr is not a terminal | `mytool list > out 2>&1` must stay clean |
|
|
123
|
-
|
|
|
128
|
+
| A variable in `pyselfupdate.notifier.CI_VARIABLES`, such as `CI`, is set | Not a human |
|
|
124
129
|
| Installed from a local path, an editable checkout, a branch or a commit | Nothing to compare against |
|
|
125
130
|
| Checked within the interval | One request per interval, not per invocation |
|
|
126
131
|
|
|
@@ -154,17 +159,18 @@ from pyselfupdate import Config, check, require_updatable
|
|
|
154
159
|
config = Config(tool='mytool', owner='you')
|
|
155
160
|
|
|
156
161
|
require_updatable(config) # reads uv's receipt; raises on an install update refuses
|
|
157
|
-
result = check(config) #
|
|
162
|
+
result = check(config) # asks the release source, and an index install's index
|
|
158
163
|
if result.update_available:
|
|
159
164
|
print(result.current, '->', result.latest)
|
|
160
165
|
```
|
|
161
166
|
|
|
162
|
-
`check` compares the running version with the newest
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
167
|
+
`check` compares the running version with the newest version an update can
|
|
168
|
+
install. It reads uv's receipt to learn where that version comes from, and
|
|
169
|
+
refuses nothing the receipt describes. A branch build's version can rank below
|
|
170
|
+
the release it is ahead of. Three commits past `v1.2.3`, a tool versioned from
|
|
171
|
+
git tags builds as `1.2.3-post.3+<commit>`, which semver ranks below `v1.2.3`.
|
|
172
|
+
So call `require_updatable` before reporting what `check` found. It refuses
|
|
173
|
+
every install `update` refuses.
|
|
168
174
|
|
|
169
175
|
The typer extra carries the whole command. `add_update_command(app, config)`
|
|
170
176
|
registers `mytool update`. `run_update(config, check_only=...)` is the same
|
|
@@ -206,6 +212,7 @@ caller matches a type rather than message text:
|
|
|
206
212
|
| `SelfUpdateSourceFailure` | A `SourceError` from a transport or protocol failure, as opposed to a missing release |
|
|
207
213
|
| `RateLimitedError` | A `SelfUpdateSourceFailure` for a spent rate limit. `authenticated` says which ceiling, and `resets_at` when it lifts, or None |
|
|
208
214
|
| `LockUnreadableError` | The release's `uv.lock` could not be read, so nothing was installed |
|
|
215
|
+
| `IndexUnreadableError` | uv could not say which version an index install's package index serves, so nothing was offered |
|
|
209
216
|
| `InstallFailedError` | `uv tool install` ran and failed, or uv is not on `PATH` |
|
|
210
217
|
|
|
211
218
|
### A git install is held to the release's `uv.lock`
|
|
@@ -223,10 +230,10 @@ later `uv tool upgrade` stays held to them.
|
|
|
223
230
|
| Carries none | Installs unlocked and sets `lock_missing`. `lock_warning` names the tag, and `run_update` and `update_and_reexec` print it |
|
|
224
231
|
| Will not clone, uv will not export its lock, or git or uv is not on `PATH` | Raises `LockUnreadableError` and installs nothing |
|
|
225
232
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
233
|
+
A tool that is one member of a uv workspace installs as
|
|
234
|
+
`git+<repo>@<tag>#subdirectory=<member>`. `update` keeps the subdirectory, and
|
|
235
|
+
reads the workspace's one `uv.lock` at the repository root for that member's
|
|
236
|
+
dependencies alone.
|
|
230
237
|
|
|
231
238
|
An update reinstalls the tool's own extras, as in `mytool[fast]`, with their
|
|
232
239
|
dependencies held to the lock. Every `--with` and `--with-editable`
|
|
@@ -243,6 +250,26 @@ file can declare one and the reinstall reads that file again. Dropping any
|
|
|
243
250
|
other recorded option changes how the tool resolves or builds, never whether it
|
|
244
251
|
is found.
|
|
245
252
|
|
|
253
|
+
### An index install is offered only what its index serves
|
|
254
|
+
|
|
255
|
+
A release exists on GitHub before its upload to the package index finishes,
|
|
256
|
+
and stays there when the upload fails. So for an index install `check` asks
|
|
257
|
+
the index too, through uv. It runs `uv pip compile --no-deps` on the tool's
|
|
258
|
+
name with the flags above, so uv reads the index with the configuration and
|
|
259
|
+
credentials the reinstall uses. The version uv names becomes `latest`, and
|
|
260
|
+
`index_latest` holds it.
|
|
261
|
+
|
|
262
|
+
| The index serves | What `check` reports |
|
|
263
|
+
| --- | --- |
|
|
264
|
+
| The newest release | `latest` is that release |
|
|
265
|
+
| Another version | `latest` is the index's version, or `current` when that is not newer. `index_warning` names both versions, and `run_update` and `update_and_reexec` print it |
|
|
266
|
+
| Nothing uv can read within `Config.timeout` seconds | Raises `IndexUnreadableError` |
|
|
267
|
+
|
|
268
|
+
An install from an index reads no lock, because a wheel carries none. It
|
|
269
|
+
takes the index's version as a floor, `mytool>=2.0.0`, rather than a pin. uv
|
|
270
|
+
records the specifier in the receipt, and `uv tool upgrade` refuses to move an
|
|
271
|
+
exact pin.
|
|
272
|
+
|
|
246
273
|
## What may be updated is read from uv's receipt, not guessed from the version
|
|
247
274
|
|
|
248
275
|
uv writes `uv-receipt.toml` into the tool's directory at install time. It
|
|
@@ -281,7 +308,7 @@ config = Config(
|
|
|
281
308
|
version='1.2.3', # defaults to that distribution's installed metadata
|
|
282
309
|
token='', # see Authentication below; you almost certainly want the default
|
|
283
310
|
token_func=None, # a source of your own, tried before $GITHUB_TOKEN_COMMAND
|
|
284
|
-
timeout=10.0, # seconds
|
|
311
|
+
timeout=10.0, # seconds per read: the release source's, and uv's read of an index
|
|
285
312
|
tag_prefix='', # 'cli/' for tags like cli/v1.2.3
|
|
286
313
|
allow_prerelease=False,
|
|
287
314
|
source=None, # a custom Source; defaults to a GitHubSource built from the fields above
|
|
@@ -10,7 +10,9 @@ release exists. `update` installs that release when the user asks.
|
|
|
10
10
|
`uv tool upgrade` re-resolves the requirement a tool was installed with, so a
|
|
11
11
|
tool installed at a release tag stays at that tag. `update` asks the release
|
|
12
12
|
source which tag is newest and reinstalls at that tag. A git install is held to
|
|
13
|
-
that tag's `uv.lock`.
|
|
13
|
+
that tag's `uv.lock`. A tool installed from a package index is offered only the
|
|
14
|
+
version its index serves, which can trail a release whose upload has not
|
|
15
|
+
finished.
|
|
14
16
|
|
|
15
17
|
The package has no runtime dependencies. It uses `urllib` for the network,
|
|
16
18
|
`tomllib` for uv's receipt and lock, and its own semver implementation. CI
|
|
@@ -24,8 +26,9 @@ uv add pyselfupdate # the library alone, with no dependencies
|
|
|
24
26
|
uv add 'pyselfupdate[typer]' # adds typer and the ready-made `update` command
|
|
25
27
|
```
|
|
26
28
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
The supported Python versions are `requires-python` in `pyproject.toml`, which
|
|
30
|
+
uv checks before it installs. The floor is the first release carrying
|
|
31
|
+
`tomllib`.
|
|
29
32
|
|
|
30
33
|
## Starting from scratch
|
|
31
34
|
|
|
@@ -71,13 +74,15 @@ A private repository needs a credential. `gh auth login` is enough, because
|
|
|
71
74
|
the check runs `gh auth token` by default.
|
|
72
75
|
|
|
73
76
|
**When the notice never appears, run `mytool update --check` first.** It runs
|
|
74
|
-
the
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
the steps that can fail and prints what stopped it. Those are reading uv's
|
|
78
|
+
receipt, asking the release source and, for an index install, asking its
|
|
79
|
+
index. The notice stays silent on each. Every other reason it stays silent is
|
|
80
|
+
in the table under `notify`.
|
|
77
81
|
|
|
78
82
|
## `notify` — one line after the command's output, never an error
|
|
79
83
|
|
|
80
|
-
Once per 24 hours, when a newer release
|
|
84
|
+
Once per 24 hours, when a newer release can be installed, one line goes to
|
|
85
|
+
stderr:
|
|
81
86
|
|
|
82
87
|
```text
|
|
83
88
|
mytool v1.4.0 available (running v1.3.2) — run `mytool update`
|
|
@@ -97,7 +102,7 @@ Nothing is printed when any of these hold:
|
|
|
97
102
|
| `NO_AUTO_UPDATE` or `MYTOOL_NO_AUTO_UPDATE` is set | Opted out |
|
|
98
103
|
| `--help` or `-h` comes before any `--` on the command line | typer runs the callback even for a subcommand's help screen, which is not work |
|
|
99
104
|
| stdout or stderr is not a terminal | `mytool list > out 2>&1` must stay clean |
|
|
100
|
-
|
|
|
105
|
+
| A variable in `pyselfupdate.notifier.CI_VARIABLES`, such as `CI`, is set | Not a human |
|
|
101
106
|
| Installed from a local path, an editable checkout, a branch or a commit | Nothing to compare against |
|
|
102
107
|
| Checked within the interval | One request per interval, not per invocation |
|
|
103
108
|
|
|
@@ -131,17 +136,18 @@ from pyselfupdate import Config, check, require_updatable
|
|
|
131
136
|
config = Config(tool='mytool', owner='you')
|
|
132
137
|
|
|
133
138
|
require_updatable(config) # reads uv's receipt; raises on an install update refuses
|
|
134
|
-
result = check(config) #
|
|
139
|
+
result = check(config) # asks the release source, and an index install's index
|
|
135
140
|
if result.update_available:
|
|
136
141
|
print(result.current, '->', result.latest)
|
|
137
142
|
```
|
|
138
143
|
|
|
139
|
-
`check` compares the running version with the newest
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
144
|
+
`check` compares the running version with the newest version an update can
|
|
145
|
+
install. It reads uv's receipt to learn where that version comes from, and
|
|
146
|
+
refuses nothing the receipt describes. A branch build's version can rank below
|
|
147
|
+
the release it is ahead of. Three commits past `v1.2.3`, a tool versioned from
|
|
148
|
+
git tags builds as `1.2.3-post.3+<commit>`, which semver ranks below `v1.2.3`.
|
|
149
|
+
So call `require_updatable` before reporting what `check` found. It refuses
|
|
150
|
+
every install `update` refuses.
|
|
145
151
|
|
|
146
152
|
The typer extra carries the whole command. `add_update_command(app, config)`
|
|
147
153
|
registers `mytool update`. `run_update(config, check_only=...)` is the same
|
|
@@ -183,6 +189,7 @@ caller matches a type rather than message text:
|
|
|
183
189
|
| `SelfUpdateSourceFailure` | A `SourceError` from a transport or protocol failure, as opposed to a missing release |
|
|
184
190
|
| `RateLimitedError` | A `SelfUpdateSourceFailure` for a spent rate limit. `authenticated` says which ceiling, and `resets_at` when it lifts, or None |
|
|
185
191
|
| `LockUnreadableError` | The release's `uv.lock` could not be read, so nothing was installed |
|
|
192
|
+
| `IndexUnreadableError` | uv could not say which version an index install's package index serves, so nothing was offered |
|
|
186
193
|
| `InstallFailedError` | `uv tool install` ran and failed, or uv is not on `PATH` |
|
|
187
194
|
|
|
188
195
|
### A git install is held to the release's `uv.lock`
|
|
@@ -200,10 +207,10 @@ later `uv tool upgrade` stays held to them.
|
|
|
200
207
|
| Carries none | Installs unlocked and sets `lock_missing`. `lock_warning` names the tag, and `run_update` and `update_and_reexec` print it |
|
|
201
208
|
| Will not clone, uv will not export its lock, or git or uv is not on `PATH` | Raises `LockUnreadableError` and installs nothing |
|
|
202
209
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
210
|
+
A tool that is one member of a uv workspace installs as
|
|
211
|
+
`git+<repo>@<tag>#subdirectory=<member>`. `update` keeps the subdirectory, and
|
|
212
|
+
reads the workspace's one `uv.lock` at the repository root for that member's
|
|
213
|
+
dependencies alone.
|
|
207
214
|
|
|
208
215
|
An update reinstalls the tool's own extras, as in `mytool[fast]`, with their
|
|
209
216
|
dependencies held to the lock. Every `--with` and `--with-editable`
|
|
@@ -220,6 +227,26 @@ file can declare one and the reinstall reads that file again. Dropping any
|
|
|
220
227
|
other recorded option changes how the tool resolves or builds, never whether it
|
|
221
228
|
is found.
|
|
222
229
|
|
|
230
|
+
### An index install is offered only what its index serves
|
|
231
|
+
|
|
232
|
+
A release exists on GitHub before its upload to the package index finishes,
|
|
233
|
+
and stays there when the upload fails. So for an index install `check` asks
|
|
234
|
+
the index too, through uv. It runs `uv pip compile --no-deps` on the tool's
|
|
235
|
+
name with the flags above, so uv reads the index with the configuration and
|
|
236
|
+
credentials the reinstall uses. The version uv names becomes `latest`, and
|
|
237
|
+
`index_latest` holds it.
|
|
238
|
+
|
|
239
|
+
| The index serves | What `check` reports |
|
|
240
|
+
| --- | --- |
|
|
241
|
+
| The newest release | `latest` is that release |
|
|
242
|
+
| Another version | `latest` is the index's version, or `current` when that is not newer. `index_warning` names both versions, and `run_update` and `update_and_reexec` print it |
|
|
243
|
+
| Nothing uv can read within `Config.timeout` seconds | Raises `IndexUnreadableError` |
|
|
244
|
+
|
|
245
|
+
An install from an index reads no lock, because a wheel carries none. It
|
|
246
|
+
takes the index's version as a floor, `mytool>=2.0.0`, rather than a pin. uv
|
|
247
|
+
records the specifier in the receipt, and `uv tool upgrade` refuses to move an
|
|
248
|
+
exact pin.
|
|
249
|
+
|
|
223
250
|
## What may be updated is read from uv's receipt, not guessed from the version
|
|
224
251
|
|
|
225
252
|
uv writes `uv-receipt.toml` into the tool's directory at install time. It
|
|
@@ -258,7 +285,7 @@ config = Config(
|
|
|
258
285
|
version='1.2.3', # defaults to that distribution's installed metadata
|
|
259
286
|
token='', # see Authentication below; you almost certainly want the default
|
|
260
287
|
token_func=None, # a source of your own, tried before $GITHUB_TOKEN_COMMAND
|
|
261
|
-
timeout=10.0, # seconds
|
|
288
|
+
timeout=10.0, # seconds per read: the release source's, and uv's read of an index
|
|
262
289
|
tag_prefix='', # 'cli/' for tags like cli/v1.2.3
|
|
263
290
|
allow_prerelease=False,
|
|
264
291
|
source=None, # a custom Source; defaults to a GitHubSource built from the fields above
|
|
@@ -18,6 +18,7 @@ lives in `pyselfupdate.typercmd` and is installed with the `typer` extra.
|
|
|
18
18
|
"""
|
|
19
19
|
|
|
20
20
|
from pyselfupdate.config import Config
|
|
21
|
+
from pyselfupdate.errors import IndexUnreadableError
|
|
21
22
|
from pyselfupdate.errors import InstallFailedError
|
|
22
23
|
from pyselfupdate.errors import InvalidConfigError
|
|
23
24
|
from pyselfupdate.errors import LocalInstallError
|
|
@@ -52,6 +53,7 @@ from pyselfupdate.updater import update_and_reexec
|
|
|
52
53
|
__all__ = [
|
|
53
54
|
'Config',
|
|
54
55
|
'GitHubSource',
|
|
56
|
+
'IndexUnreadableError',
|
|
55
57
|
'InstallFailedError',
|
|
56
58
|
'InstallKind',
|
|
57
59
|
'Installation',
|
|
@@ -46,7 +46,10 @@ class Config:
|
|
|
46
46
|
# invocations where the notify gate declines to check.
|
|
47
47
|
token_func: Callable[[], str] | None = None
|
|
48
48
|
|
|
49
|
+
# Seconds that each read a check makes may take: the release source's
|
|
50
|
+
# request, and for an index install uv's read of the package index.
|
|
49
51
|
timeout: float = DEFAULT_TIMEOUT
|
|
52
|
+
|
|
50
53
|
allow_prerelease: bool = False
|
|
51
54
|
|
|
52
55
|
# Selects one release stream in a repository publishing several, as in
|
|
@@ -82,3 +82,12 @@ class LockUnreadableError(SelfUpdateError):
|
|
|
82
82
|
refuses the lock. A tag with no `uv.lock` at all is not this error: it
|
|
83
83
|
installs unlocked and sets `Result.lock_missing`.
|
|
84
84
|
"""
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class IndexUnreadableError(SelfUpdateError):
|
|
88
|
+
"""uv could not say which version of an index-installed tool its package index serves.
|
|
89
|
+
|
|
90
|
+
Raised when uv is not on PATH, takes longer than `Config.timeout`, cannot
|
|
91
|
+
reach the index, or finds no version of the tool there. Nothing is offered,
|
|
92
|
+
because a version the index does not serve cannot be installed.
|
|
93
|
+
"""
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
"""GitHub as a release source.
|
|
2
2
|
|
|
3
|
-
Uses `urllib.request
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
It moves to httpx2 when this package needs a second request shape: a client
|
|
9
|
-
object, streaming, an asset download.
|
|
3
|
+
Uses `urllib.request`, because the package has no runtime dependencies. The
|
|
4
|
+
HTTP client weighed against that, and when to revisit it, are under the
|
|
5
|
+
zero-dependency constraint in the repository's CLAUDE.md.
|
|
6
|
+
`_CredentialScopedRedirects` covers the redirect hazard a client would.
|
|
10
7
|
"""
|
|
11
8
|
|
|
12
9
|
from __future__ import annotations
|
|
@@ -30,6 +30,7 @@ from importlib.metadata import version as installed_version
|
|
|
30
30
|
from itertools import chain
|
|
31
31
|
from pathlib import Path
|
|
32
32
|
|
|
33
|
+
from pyselfupdate.errors import IndexUnreadableError
|
|
33
34
|
from pyselfupdate.errors import InstallFailedError
|
|
34
35
|
from pyselfupdate.errors import LockUnreadableError
|
|
35
36
|
from pyselfupdate.errors import NotInstalledError
|
|
@@ -77,6 +78,10 @@ class Installation:
|
|
|
77
78
|
# or refuses it.
|
|
78
79
|
revision: str = ''
|
|
79
80
|
|
|
81
|
+
# The directory inside the repository holding the tool's project, for a
|
|
82
|
+
# uv workspace member installed with `#subdirectory=`. Empty at the root.
|
|
83
|
+
subdirectory: str = ''
|
|
84
|
+
|
|
80
85
|
extras: tuple[str, ...] = ()
|
|
81
86
|
|
|
82
87
|
# The receipt's other requirements, from `--with` and `--with-editable`, as
|
|
@@ -93,7 +98,7 @@ class Installation:
|
|
|
93
98
|
# `read_installation` records them rather than raising: the notify gate
|
|
94
99
|
# treats a failed read as a local install and prints no notice. `update`
|
|
95
100
|
# raises NotInstalledError on them instead of dropping them.
|
|
96
|
-
|
|
101
|
+
unrebuildable: tuple[str, ...] = field(default=(), repr=False)
|
|
97
102
|
|
|
98
103
|
|
|
99
104
|
def tool_dir() -> Path:
|
|
@@ -156,9 +161,9 @@ def read_installation(tool: str) -> Installation:
|
|
|
156
161
|
else:
|
|
157
162
|
rebuilt.append(line)
|
|
158
163
|
|
|
159
|
-
def installed_as(kind: InstallKind, url: str = '', revision: str = '') -> Installation:
|
|
164
|
+
def installed_as(kind: InstallKind, url: str = '', revision: str = '', subdirectory: str = '') -> Installation:
|
|
160
165
|
extras = tuple(own.get('extras') or ())
|
|
161
|
-
return Installation(tool, kind, url, revision, extras, tuple(rebuilt), _source_flags(recorded), tuple(unrebuildable))
|
|
166
|
+
return Installation(tool, kind, url, revision, subdirectory, extras, tuple(rebuilt), _source_flags(recorded), tuple(unrebuildable))
|
|
162
167
|
|
|
163
168
|
# A local checkout, however uv spelled it. Reinstalling one would
|
|
164
169
|
# discard the working copy the user is developing against.
|
|
@@ -169,7 +174,8 @@ def read_installation(tool: str) -> Installation:
|
|
|
169
174
|
git = own.get('git')
|
|
170
175
|
if git:
|
|
171
176
|
url, query, _ = _split_git(str(git))
|
|
172
|
-
|
|
177
|
+
subdirectory = query.get('subdirectory') or str(own.get('subdirectory') or '')
|
|
178
|
+
return installed_as(InstallKind.GIT, url=url, revision=query.get('rev', ''), subdirectory=subdirectory)
|
|
173
179
|
|
|
174
180
|
return installed_as(InstallKind.INDEX)
|
|
175
181
|
|
|
@@ -275,6 +281,50 @@ def current_version(package: str) -> str:
|
|
|
275
281
|
return ''
|
|
276
282
|
|
|
277
283
|
|
|
284
|
+
INDEX_READ = ('pip', 'compile', '-', '--no-deps', '--no-header', '--no-annotate', '--quiet')
|
|
285
|
+
"""Resolves the requirement read from stdin, and only it, printing `<name>==<version>`."""
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def read_index_latest(installation: Installation, *, timeout: float, allow_prerelease: bool = False) -> str:
|
|
289
|
+
"""The newest version of an index-installed tool that its package index serves, as uv prints it.
|
|
290
|
+
|
|
291
|
+
A release can exist before its upload to the index finishes, and stays when
|
|
292
|
+
the upload fails, so the release source cannot say what an index install
|
|
293
|
+
can take. uv resolves the tool's name alone, with the receipt's package
|
|
294
|
+
sources, and reads the index through the configuration and credentials the
|
|
295
|
+
reinstall uses. The receipt's `--python` is passed back too, so a release
|
|
296
|
+
that has dropped that Python is not offered. With none recorded, uv
|
|
297
|
+
resolves for the running interpreter.
|
|
298
|
+
|
|
299
|
+
The read is bounded by `timeout`, since the notify gate runs it before the
|
|
300
|
+
command someone typed returns. Raises `IndexUnreadableError` when uv is not
|
|
301
|
+
on PATH, outlasts the bound, or names no version.
|
|
302
|
+
"""
|
|
303
|
+
uv = shutil.which('uv')
|
|
304
|
+
if not uv:
|
|
305
|
+
raise IndexUnreadableError(
|
|
306
|
+
f'uv is not on PATH, so the versions of {installation.tool} its package index serves cannot be read. '
|
|
307
|
+
'Add the directory holding uv to PATH, then check again'
|
|
308
|
+
)
|
|
309
|
+
python = () if '--python' in installation.source_flags else ('--python', sys.executable)
|
|
310
|
+
prerelease = ('--prerelease', 'allow') if allow_prerelease else ()
|
|
311
|
+
command = [uv, *INDEX_READ, *installation.source_flags, *python, *prerelease]
|
|
312
|
+
try:
|
|
313
|
+
resolved = run_command(command, stdin=f'{installation.tool}\n', timeout=timeout)
|
|
314
|
+
except subprocess.TimeoutExpired as error:
|
|
315
|
+
raise IndexUnreadableError(
|
|
316
|
+
f'reading which version of {installation.tool} its package index serves took longer than {error.timeout:g}s'
|
|
317
|
+
) from error
|
|
318
|
+
if resolved.returncode != 0:
|
|
319
|
+
raise IndexUnreadableError(f'uv could not read which version of {installation.tool} its package index serves: {_reason(resolved)}')
|
|
320
|
+
pinned = [line.split(';', 1)[0].partition('==')[2].strip() for line in resolved.stdout.splitlines() if '==' in line]
|
|
321
|
+
if len(pinned) != 1 or not pinned[0]:
|
|
322
|
+
raise IndexUnreadableError(
|
|
323
|
+
f'uv resolved {installation.tool} from its package index to {resolved.stdout.strip()!r}, which names no one version'
|
|
324
|
+
)
|
|
325
|
+
return pinned[0]
|
|
326
|
+
|
|
327
|
+
|
|
278
328
|
def requirement_for(installation: Installation, ref: str) -> str:
|
|
279
329
|
"""The requirement string that installs `ref` of an already-installed tool, with the extras it has.
|
|
280
330
|
|
|
@@ -283,7 +333,8 @@ def requirement_for(installation: Installation, ref: str) -> str:
|
|
|
283
333
|
"""
|
|
284
334
|
named = f'{installation.tool}[{",".join(installation.extras)}]' if installation.extras else installation.tool
|
|
285
335
|
if installation.kind is InstallKind.GIT:
|
|
286
|
-
|
|
336
|
+
subdirectory = f'#subdirectory={installation.subdirectory}' if installation.subdirectory else ''
|
|
337
|
+
return f'{named} @ git+{installation.url}@{ref}{subdirectory}'
|
|
287
338
|
return f'{named}>={ref.removeprefix("v")}'
|
|
288
339
|
|
|
289
340
|
|
|
@@ -316,7 +367,7 @@ class Pins:
|
|
|
316
367
|
return flags
|
|
317
368
|
|
|
318
369
|
|
|
319
|
-
def read_lock(url: str, ref: str, *, extras: Sequence[str] = ()) -> Pins | None:
|
|
370
|
+
def read_lock(url: str, ref: str, *, extras: Sequence[str] = (), package: str = '', subdirectory: str = '') -> Pins | None:
|
|
320
371
|
"""What the `uv.lock` at `ref` of a git repository pins, or None when it has none.
|
|
321
372
|
|
|
322
373
|
`extras` are the extras the tool is installed with. Each is passed to
|
|
@@ -324,6 +375,10 @@ def read_lock(url: str, ref: str, *, extras: Sequence[str] = ()) -> Pins | None:
|
|
|
324
375
|
dependencies out. `--all-extras` fails on a project that declares two
|
|
325
376
|
extras as conflicting.
|
|
326
377
|
|
|
378
|
+
`subdirectory` names a uv workspace member, whose lock sits at the
|
|
379
|
+
repository root. The export then takes only `package`'s dependencies, and
|
|
380
|
+
the extras walk starts at that member.
|
|
381
|
+
|
|
327
382
|
Reads a shallow clone of the one ref and lets `uv export` interpret the lock.
|
|
328
383
|
The lock is also read directly for one thing the export drops: the extras
|
|
329
384
|
a dependent requests of a git dependency, which `_override_extras` restores.
|
|
@@ -355,7 +410,8 @@ def read_lock(url: str, ref: str, *, extras: Sequence[str] = ()) -> Pins | None:
|
|
|
355
410
|
lock = checkout / LOCK_NAME
|
|
356
411
|
if not lock.is_file():
|
|
357
412
|
return None
|
|
358
|
-
|
|
413
|
+
member = ('--package', package) if subdirectory and package else ()
|
|
414
|
+
export = [uv, *EXPORT, *member, *chain.from_iterable(('--extra', extra) for extra in extras)]
|
|
359
415
|
try:
|
|
360
416
|
exported = run_command(export, cwd=checkout, timeout=LOCK_READ_TIMEOUT_SECONDS)
|
|
361
417
|
except subprocess.TimeoutExpired as error:
|
|
@@ -363,14 +419,14 @@ def read_lock(url: str, ref: str, *, extras: Sequence[str] = ()) -> Pins | None:
|
|
|
363
419
|
if exported.returncode != 0:
|
|
364
420
|
raise LockUnreadableError(f'uv export would not read the uv.lock at {ref}: {_reason(exported)}')
|
|
365
421
|
try:
|
|
366
|
-
requested = _override_extras(tomllib.loads(lock.read_text(encoding='utf-8')), extras)
|
|
422
|
+
requested = _override_extras(tomllib.loads(lock.read_text(encoding='utf-8')), extras, root=subdirectory or '.')
|
|
367
423
|
except (OSError, tomllib.TOMLDecodeError) as error:
|
|
368
424
|
raise LockUnreadableError(f'cannot read the uv.lock at {ref}: {error}') from error
|
|
369
425
|
return _pins_from_export(exported.stdout, requested)
|
|
370
426
|
|
|
371
427
|
|
|
372
|
-
def _override_extras(lock: dict, extras: Sequence[str]) -> dict[str, tuple[str, ...]]:
|
|
373
|
-
"""The extras requested of each package, walking dependency edges from the project at the lock
|
|
428
|
+
def _override_extras(lock: dict, extras: Sequence[str], root: str = '.') -> dict[str, tuple[str, ...]]:
|
|
429
|
+
"""The extras requested of each package, walking dependency edges from the project at `root` in the lock.
|
|
374
430
|
|
|
375
431
|
An override replaces a requirement whole, extras included, and `uv export`
|
|
376
432
|
writes `gitdep @ git+...` where the tool declared `gitdep[x] @ git+...`.
|
|
@@ -385,7 +441,7 @@ def _override_extras(lock: dict, extras: Sequence[str]) -> dict[str, tuple[str,
|
|
|
385
441
|
packages: dict[str, list[dict]] = {}
|
|
386
442
|
for package in lock.get('package') or []:
|
|
387
443
|
packages.setdefault(package.get('name', ''), []).append(package)
|
|
388
|
-
project = ({'editable':
|
|
444
|
+
project = ({'editable': root}, {'virtual': root})
|
|
389
445
|
roots: list[str] = []
|
|
390
446
|
for name, entries in packages.items():
|
|
391
447
|
roots.extend(name for package in entries if package.get('source') in project)
|
|
@@ -467,14 +523,16 @@ def run_install(
|
|
|
467
523
|
raise InstallFailedError(f'uv tool install failed: {_reason(completed)}')
|
|
468
524
|
|
|
469
525
|
|
|
470
|
-
def run_command(
|
|
526
|
+
def run_command(
|
|
527
|
+
command: list[str], *, cwd: Path | None = None, timeout: float | None = None, stdin: str | None = None
|
|
528
|
+
) -> subprocess.CompletedProcess[str]:
|
|
471
529
|
"""Run a program to completion and capture what it printed.
|
|
472
530
|
|
|
473
531
|
Every process this package starts goes through here. `timeout` bounds the call in seconds. Past it the program is killed and
|
|
474
532
|
`subprocess.TimeoutExpired` is raised, which each caller turns into its own
|
|
475
|
-
failure. None runs unbounded.
|
|
533
|
+
failure. None runs unbounded. `stdin` is written to the program's standard input.
|
|
476
534
|
"""
|
|
477
|
-
return subprocess.run(command, cwd=cwd, capture_output=True, text=True, check=False, timeout=timeout)
|
|
535
|
+
return subprocess.run(command, cwd=cwd, input=stdin, capture_output=True, text=True, check=False, timeout=timeout)
|
|
478
536
|
|
|
479
537
|
|
|
480
538
|
def _reason(completed: subprocess.CompletedProcess[str]) -> str:
|
|
@@ -101,12 +101,14 @@ def run_update(config: Config, *, check_only: bool = False, skip_changelog: bool
|
|
|
101
101
|
|
|
102
102
|
if not result.update_available:
|
|
103
103
|
typer.echo(f'✓ {tool} already at latest: {result.latest}')
|
|
104
|
+
_echo_warnings(tool, result.index_warning)
|
|
104
105
|
return
|
|
105
106
|
|
|
106
107
|
subjects = [] if skip_changelog else changelog(config, result.current, result.latest)
|
|
107
108
|
|
|
108
109
|
if check_only:
|
|
109
110
|
typer.echo(f'✓ {tool} update available: {result.current} → {result.latest}')
|
|
111
|
+
_echo_warnings(tool, result.index_warning)
|
|
110
112
|
_echo_changes(subjects)
|
|
111
113
|
return
|
|
112
114
|
|
|
@@ -117,12 +119,17 @@ def run_update(config: Config, *, check_only: bool = False, skip_changelog: bool
|
|
|
117
119
|
raise typer.Exit(1) from error
|
|
118
120
|
|
|
119
121
|
typer.echo(f'✓ {tool} updated: {result.current} → {result.latest}')
|
|
120
|
-
|
|
121
|
-
typer.echo(f'! {tool}: {installed.lock_warning}', err=True)
|
|
122
|
+
_echo_warnings(tool, installed.lock_warning, installed.index_warning)
|
|
122
123
|
_echo_changes(subjects)
|
|
123
124
|
exit_now()
|
|
124
125
|
|
|
125
126
|
|
|
127
|
+
def _echo_warnings(tool: str, *warnings: str) -> None:
|
|
128
|
+
for warning in warnings:
|
|
129
|
+
if warning:
|
|
130
|
+
typer.echo(f'! {tool}: {warning}', err=True)
|
|
131
|
+
|
|
132
|
+
|
|
126
133
|
def _echo_changes(subjects: list[str]) -> None:
|
|
127
134
|
if not subjects:
|
|
128
135
|
return
|
|
@@ -13,6 +13,7 @@ from pyselfupdate.errors import NoReleaseError
|
|
|
13
13
|
from pyselfupdate.errors import NotInstalledError
|
|
14
14
|
from pyselfupdate.install import Installation
|
|
15
15
|
from pyselfupdate.install import InstallKind
|
|
16
|
+
from pyselfupdate.install import read_index_latest
|
|
16
17
|
from pyselfupdate.install import read_installation
|
|
17
18
|
from pyselfupdate.install import read_lock
|
|
18
19
|
from pyselfupdate.install import reexec
|
|
@@ -30,17 +31,25 @@ class Result:
|
|
|
30
31
|
current: str
|
|
31
32
|
|
|
32
33
|
# The version now installed, or the one `update` would install after a
|
|
33
|
-
# `check`. Equals `current` when nothing
|
|
34
|
+
# `check`. Equals `current` when nothing newer can be installed. An index
|
|
35
|
+
# install takes it from `index_latest` rather than from `release`.
|
|
34
36
|
latest: str
|
|
35
37
|
|
|
36
38
|
applied: bool = False
|
|
39
|
+
|
|
40
|
+
# The newest release the source names, whether or not it is newer.
|
|
37
41
|
release: Release | None = None
|
|
42
|
+
|
|
38
43
|
metadata: dict[str, str] = field(default_factory=dict)
|
|
39
44
|
|
|
40
45
|
# True when a git install ran unlocked because its tag carries no uv.lock.
|
|
41
46
|
# An index install reads no lock, so it leaves this False.
|
|
42
47
|
lock_missing: bool = False
|
|
43
48
|
|
|
49
|
+
# For an index install, the newest version its package index serves,
|
|
50
|
+
# canonicalized. Empty for any other install, which takes the release's tag.
|
|
51
|
+
index_latest: str = ''
|
|
52
|
+
|
|
44
53
|
@property
|
|
45
54
|
def update_available(self) -> bool:
|
|
46
55
|
return self.current != self.latest
|
|
@@ -56,26 +65,53 @@ class Result:
|
|
|
56
65
|
tag = self.release.install_ref() if self.release else self.latest
|
|
57
66
|
return f'{tag} has no uv.lock, so its dependencies were installed at their newest versions'
|
|
58
67
|
|
|
68
|
+
@property
|
|
69
|
+
def index_warning(self) -> str:
|
|
70
|
+
"""A line naming both versions when the index serves other than the newest release, else an empty string.
|
|
71
|
+
|
|
72
|
+
`run_update` and `update_and_reexec` print it to stderr.
|
|
73
|
+
"""
|
|
74
|
+
if not self.index_latest or self.release is None:
|
|
75
|
+
return ''
|
|
76
|
+
released = semver.canonical(self.release.tag)
|
|
77
|
+
if self.index_latest == released:
|
|
78
|
+
return ''
|
|
79
|
+
return f'the newest release is {released}, but the package index holds {self.index_latest}'
|
|
80
|
+
|
|
59
81
|
|
|
60
82
|
def check(config: Config) -> Result:
|
|
61
|
-
"""Report whether a newer
|
|
83
|
+
"""Report whether a newer version can be installed, without installing anything.
|
|
62
84
|
|
|
63
|
-
|
|
85
|
+
Reads uv's receipt to learn where an update would come from. A git install
|
|
86
|
+
takes the source's newest release, whose tag exists once the release does.
|
|
87
|
+
An index install takes the newest version its index serves, which
|
|
88
|
+
`read_index_latest` asks uv for: a release can exist before its upload
|
|
89
|
+
finishes, and stays when the upload fails.
|
|
90
|
+
|
|
91
|
+
Raises `NotInstalledError` when the receipt cannot be read, and refuses no
|
|
92
|
+
install the receipt describes. A caller reporting the result runs
|
|
64
93
|
`require_updatable` first, as `update` and `typercmd.run_update` do.
|
|
65
94
|
`installed_from_release` says why a version alone cannot decide.
|
|
66
95
|
"""
|
|
67
96
|
resolved = config.resolved()
|
|
68
97
|
current = _current_version(resolved)
|
|
98
|
+
installation = read_installation(resolved.tool)
|
|
69
99
|
|
|
70
100
|
release = resolved.require_source().latest_release()
|
|
71
101
|
latest = semver.canonical(release.tag)
|
|
72
102
|
if not semver.is_valid(latest):
|
|
73
103
|
raise NoReleaseError(f'tag {release.tag!r} is not a semantic version')
|
|
74
104
|
|
|
75
|
-
|
|
76
|
-
|
|
105
|
+
index_latest = ''
|
|
106
|
+
if installation.kind is InstallKind.INDEX:
|
|
107
|
+
served = read_index_latest(installation, timeout=resolved.timeout, allow_prerelease=resolved.allow_prerelease)
|
|
108
|
+
index_latest = latest = semver.canonical(served)
|
|
109
|
+
if not semver.is_valid(index_latest):
|
|
110
|
+
raise NoReleaseError(f'the package index serves {resolved.tool} {served}, which is not a semantic version')
|
|
77
111
|
|
|
78
|
-
|
|
112
|
+
if semver.compare(latest, current) <= 0:
|
|
113
|
+
latest = current
|
|
114
|
+
return Result(current=current, latest=latest, release=release, index_latest=index_latest)
|
|
79
115
|
|
|
80
116
|
|
|
81
117
|
def require_updatable(config: Config) -> Installation:
|
|
@@ -124,12 +160,18 @@ def install_release(config: Config, result: Result, installation: Installation,
|
|
|
124
160
|
A git install is held to the `uv.lock` at the release's tag. A tag without
|
|
125
161
|
one installs unlocked and comes back with `lock_missing` set. A lock that
|
|
126
162
|
cannot be read raises `LockUnreadableError` before anything is installed.
|
|
163
|
+
An index install takes `latest`, the version its index serves, as a floor.
|
|
127
164
|
"""
|
|
128
165
|
if not result.update_available or result.release is None:
|
|
129
166
|
return result
|
|
130
167
|
|
|
131
|
-
|
|
132
|
-
|
|
168
|
+
if installation.kind is InstallKind.GIT:
|
|
169
|
+
ref = result.release.install_ref()
|
|
170
|
+
pins = read_lock(
|
|
171
|
+
installation.url, ref, extras=installation.extras, package=installation.tool, subdirectory=installation.subdirectory
|
|
172
|
+
)
|
|
173
|
+
else:
|
|
174
|
+
ref, pins = result.latest, None
|
|
133
175
|
run_install(
|
|
134
176
|
requirement_for(installation, ref),
|
|
135
177
|
quiet=quiet,
|
|
@@ -144,6 +186,7 @@ def install_release(config: Config, result: Result, installation: Installation,
|
|
|
144
186
|
applied=True,
|
|
145
187
|
release=result.release,
|
|
146
188
|
lock_missing=installation.kind is InstallKind.GIT and pins is None,
|
|
189
|
+
index_latest=result.index_latest,
|
|
147
190
|
)
|
|
148
191
|
|
|
149
192
|
|
|
@@ -166,12 +209,13 @@ def update_and_reexec(config: Config, *, quiet: bool = True) -> Result:
|
|
|
166
209
|
|
|
167
210
|
Returns normally only when nothing was installed; otherwise it does not
|
|
168
211
|
return at all. The caller never sees the `Result` of an install, so this
|
|
169
|
-
writes its `lock_warning` to stderr before the re-exec.
|
|
212
|
+
writes its `lock_warning` and `index_warning` to stderr before the re-exec.
|
|
170
213
|
"""
|
|
171
214
|
result = update(config, quiet=quiet)
|
|
172
215
|
if result.applied:
|
|
173
|
-
|
|
174
|
-
|
|
216
|
+
for warning in (result.lock_warning, result.index_warning):
|
|
217
|
+
if warning:
|
|
218
|
+
print(f'! {config.tool}: {warning}', file=sys.stderr)
|
|
175
219
|
reexec()
|
|
176
220
|
return result
|
|
177
221
|
|
|
@@ -213,9 +257,9 @@ def _require_updatable(installation: Installation, tag_prefix: str) -> None:
|
|
|
213
257
|
f'so a release version cannot be compared against it; '
|
|
214
258
|
f'reinstall from a tagged release to enable updates'
|
|
215
259
|
)
|
|
216
|
-
if installation.
|
|
260
|
+
if installation.unrebuildable:
|
|
217
261
|
raise NotInstalledError(
|
|
218
|
-
f'{installation.tool} was installed with {", ".join(installation.
|
|
262
|
+
f'{installation.tool} was installed with {", ".join(installation.unrebuildable)}, '
|
|
219
263
|
f'which an update cannot pass back to uv and would drop. '
|
|
220
264
|
f'Reinstall {installation.tool} by hand with `uv tool install --force`'
|
|
221
265
|
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|