pyselfupdate 0.6.0__tar.gz → 0.7.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: pyselfupdate
3
- Version: 0.6.0
3
+ Version: 0.7.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
@@ -94,13 +96,15 @@ A private repository needs a credential. `gh auth login` is enough, because
94
96
  the check runs `gh auth token` by default.
95
97
 
96
98
  **When the notice never appears, run `mytool update --check` first.** It runs
97
- the two steps that can fail, reading uv's receipt and asking the release
98
- source, and prints what stopped it. The notice stays silent on both. Every
99
- other reason it stays silent is in the table under `notify`.
99
+ the steps that can fail and prints what stopped it. Those are reading uv's
100
+ receipt, asking the release source and, for an index install, asking its
101
+ index. The notice stays silent on each. Every other reason it stays silent is
102
+ in the table under `notify`.
100
103
 
101
104
  ## `notify` — one line after the command's output, never an error
102
105
 
103
- Once per 24 hours, when a newer release exists, one line goes to stderr:
106
+ Once per 24 hours, when a newer release can be installed, one line goes to
107
+ stderr:
104
108
 
105
109
  ```text
106
110
  mytool v1.4.0 available (running v1.3.2) — run `mytool update`
@@ -154,17 +158,18 @@ from pyselfupdate import Config, check, require_updatable
154
158
  config = Config(tool='mytool', owner='you')
155
159
 
156
160
  require_updatable(config) # reads uv's receipt; raises on an install update refuses
157
- result = check(config) # one request to the release source
161
+ result = check(config) # asks the release source, and an index install's index
158
162
  if result.update_available:
159
163
  print(result.current, '->', result.latest)
160
164
  ```
161
165
 
162
- `check` compares the running version with the newest release, and reads
163
- nothing else. A branch build's version can rank below the release it is ahead
164
- of. Three commits past `v1.2.3`, a tool versioned from git tags builds as
165
- `1.2.3-post.3+<commit>`, which semver ranks below `v1.2.3`. So call
166
- `require_updatable` before reporting what `check` found. It refuses every
167
- install `update` refuses.
166
+ `check` compares the running version with the newest version an update can
167
+ install. It reads uv's receipt to learn where that version comes from, and
168
+ refuses nothing the receipt describes. A branch build's version can rank below
169
+ the release it is ahead of. Three commits past `v1.2.3`, a tool versioned from
170
+ git tags builds as `1.2.3-post.3+<commit>`, which semver ranks below `v1.2.3`.
171
+ So call `require_updatable` before reporting what `check` found. It refuses
172
+ every install `update` refuses.
168
173
 
169
174
  The typer extra carries the whole command. `add_update_command(app, config)`
170
175
  registers `mytool update`. `run_update(config, check_only=...)` is the same
@@ -206,6 +211,7 @@ caller matches a type rather than message text:
206
211
  | `SelfUpdateSourceFailure` | A `SourceError` from a transport or protocol failure, as opposed to a missing release |
207
212
  | `RateLimitedError` | A `SelfUpdateSourceFailure` for a spent rate limit. `authenticated` says which ceiling, and `resets_at` when it lifts, or None |
208
213
  | `LockUnreadableError` | The release's `uv.lock` could not be read, so nothing was installed |
214
+ | `IndexUnreadableError` | uv could not say which version an index install's package index serves, so nothing was offered |
209
215
  | `InstallFailedError` | `uv tool install` ran and failed, or uv is not on `PATH` |
210
216
 
211
217
  ### A git install is held to the release's `uv.lock`
@@ -223,11 +229,6 @@ later `uv tool upgrade` stays held to them.
223
229
  | Carries none | Installs unlocked and sets `lock_missing`. `lock_warning` names the tag, and `run_update` and `update_and_reexec` print it |
224
230
  | Will not clone, uv will not export its lock, or git or uv is not on `PATH` | Raises `LockUnreadableError` and installs nothing |
225
231
 
226
- An install from an index reads no lock, because a wheel carries none. It
227
- takes the release as a floor, `mytool>=2.0.0`, rather than a pin. uv records
228
- the specifier in the receipt, and `uv tool upgrade` refuses to move an exact
229
- pin.
230
-
231
232
  An update reinstalls the tool's own extras, as in `mytool[fast]`, with their
232
233
  dependencies held to the lock. Every `--with` and `--with-editable`
233
234
  requirement is passed back to uv as well.
@@ -243,6 +244,26 @@ file can declare one and the reinstall reads that file again. Dropping any
243
244
  other recorded option changes how the tool resolves or builds, never whether it
244
245
  is found.
245
246
 
247
+ ### An index install is offered only what its index serves
248
+
249
+ A release exists on GitHub before its upload to the package index finishes,
250
+ and stays there when the upload fails. So for an index install `check` asks
251
+ the index too, through uv. It runs `uv pip compile --no-deps` on the tool's
252
+ name with the flags above, so uv reads the index with the configuration and
253
+ credentials the reinstall uses. The version uv names becomes `latest`, and
254
+ `index_latest` holds it.
255
+
256
+ | The index serves | What `check` reports |
257
+ | --- | --- |
258
+ | The newest release | `latest` is that release |
259
+ | 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 |
260
+ | Nothing uv can read within `Config.timeout` seconds | Raises `IndexUnreadableError` |
261
+
262
+ An install from an index reads no lock, because a wheel carries none. It
263
+ takes the index's version as a floor, `mytool>=2.0.0`, rather than a pin. uv
264
+ records the specifier in the receipt, and `uv tool upgrade` refuses to move an
265
+ exact pin.
266
+
246
267
  ## What may be updated is read from uv's receipt, not guessed from the version
247
268
 
248
269
  uv writes `uv-receipt.toml` into the tool's directory at install time. It
@@ -281,7 +302,7 @@ config = Config(
281
302
  version='1.2.3', # defaults to that distribution's installed metadata
282
303
  token='', # see Authentication below; you almost certainly want the default
283
304
  token_func=None, # a source of your own, tried before $GITHUB_TOKEN_COMMAND
284
- timeout=10.0, # seconds, per request
305
+ timeout=10.0, # seconds per read: the release source's, and uv's read of an index
285
306
  tag_prefix='', # 'cli/' for tags like cli/v1.2.3
286
307
  allow_prerelease=False,
287
308
  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
@@ -71,13 +73,15 @@ A private repository needs a credential. `gh auth login` is enough, because
71
73
  the check runs `gh auth token` by default.
72
74
 
73
75
  **When the notice never appears, run `mytool update --check` first.** It runs
74
- the two steps that can fail, reading uv's receipt and asking the release
75
- source, and prints what stopped it. The notice stays silent on both. Every
76
- other reason it stays silent is in the table under `notify`.
76
+ the steps that can fail and prints what stopped it. Those are reading uv's
77
+ receipt, asking the release source and, for an index install, asking its
78
+ index. The notice stays silent on each. Every other reason it stays silent is
79
+ in the table under `notify`.
77
80
 
78
81
  ## `notify` — one line after the command's output, never an error
79
82
 
80
- Once per 24 hours, when a newer release exists, one line goes to stderr:
83
+ Once per 24 hours, when a newer release can be installed, one line goes to
84
+ stderr:
81
85
 
82
86
  ```text
83
87
  mytool v1.4.0 available (running v1.3.2) — run `mytool update`
@@ -131,17 +135,18 @@ from pyselfupdate import Config, check, require_updatable
131
135
  config = Config(tool='mytool', owner='you')
132
136
 
133
137
  require_updatable(config) # reads uv's receipt; raises on an install update refuses
134
- result = check(config) # one request to the release source
138
+ result = check(config) # asks the release source, and an index install's index
135
139
  if result.update_available:
136
140
  print(result.current, '->', result.latest)
137
141
  ```
138
142
 
139
- `check` compares the running version with the newest release, and reads
140
- nothing else. A branch build's version can rank below the release it is ahead
141
- of. Three commits past `v1.2.3`, a tool versioned from git tags builds as
142
- `1.2.3-post.3+<commit>`, which semver ranks below `v1.2.3`. So call
143
- `require_updatable` before reporting what `check` found. It refuses every
144
- install `update` refuses.
143
+ `check` compares the running version with the newest version an update can
144
+ install. It reads uv's receipt to learn where that version comes from, and
145
+ refuses nothing the receipt describes. A branch build's version can rank below
146
+ the release it is ahead of. Three commits past `v1.2.3`, a tool versioned from
147
+ git tags builds as `1.2.3-post.3+<commit>`, which semver ranks below `v1.2.3`.
148
+ So call `require_updatable` before reporting what `check` found. It refuses
149
+ every install `update` refuses.
145
150
 
146
151
  The typer extra carries the whole command. `add_update_command(app, config)`
147
152
  registers `mytool update`. `run_update(config, check_only=...)` is the same
@@ -183,6 +188,7 @@ caller matches a type rather than message text:
183
188
  | `SelfUpdateSourceFailure` | A `SourceError` from a transport or protocol failure, as opposed to a missing release |
184
189
  | `RateLimitedError` | A `SelfUpdateSourceFailure` for a spent rate limit. `authenticated` says which ceiling, and `resets_at` when it lifts, or None |
185
190
  | `LockUnreadableError` | The release's `uv.lock` could not be read, so nothing was installed |
191
+ | `IndexUnreadableError` | uv could not say which version an index install's package index serves, so nothing was offered |
186
192
  | `InstallFailedError` | `uv tool install` ran and failed, or uv is not on `PATH` |
187
193
 
188
194
  ### A git install is held to the release's `uv.lock`
@@ -200,11 +206,6 @@ later `uv tool upgrade` stays held to them.
200
206
  | Carries none | Installs unlocked and sets `lock_missing`. `lock_warning` names the tag, and `run_update` and `update_and_reexec` print it |
201
207
  | Will not clone, uv will not export its lock, or git or uv is not on `PATH` | Raises `LockUnreadableError` and installs nothing |
202
208
 
203
- An install from an index reads no lock, because a wheel carries none. It
204
- takes the release as a floor, `mytool>=2.0.0`, rather than a pin. uv records
205
- the specifier in the receipt, and `uv tool upgrade` refuses to move an exact
206
- pin.
207
-
208
209
  An update reinstalls the tool's own extras, as in `mytool[fast]`, with their
209
210
  dependencies held to the lock. Every `--with` and `--with-editable`
210
211
  requirement is passed back to uv as well.
@@ -220,6 +221,26 @@ file can declare one and the reinstall reads that file again. Dropping any
220
221
  other recorded option changes how the tool resolves or builds, never whether it
221
222
  is found.
222
223
 
224
+ ### An index install is offered only what its index serves
225
+
226
+ A release exists on GitHub before its upload to the package index finishes,
227
+ and stays there when the upload fails. So for an index install `check` asks
228
+ the index too, through uv. It runs `uv pip compile --no-deps` on the tool's
229
+ name with the flags above, so uv reads the index with the configuration and
230
+ credentials the reinstall uses. The version uv names becomes `latest`, and
231
+ `index_latest` holds it.
232
+
233
+ | The index serves | What `check` reports |
234
+ | --- | --- |
235
+ | The newest release | `latest` is that release |
236
+ | 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 |
237
+ | Nothing uv can read within `Config.timeout` seconds | Raises `IndexUnreadableError` |
238
+
239
+ An install from an index reads no lock, because a wheel carries none. It
240
+ takes the index's version as a floor, `mytool>=2.0.0`, rather than a pin. uv
241
+ records the specifier in the receipt, and `uv tool upgrade` refuses to move an
242
+ exact pin.
243
+
223
244
  ## What may be updated is read from uv's receipt, not guessed from the version
224
245
 
225
246
  uv writes `uv-receipt.toml` into the tool's directory at install time. It
@@ -258,7 +279,7 @@ config = Config(
258
279
  version='1.2.3', # defaults to that distribution's installed metadata
259
280
  token='', # see Authentication below; you almost certainly want the default
260
281
  token_func=None, # a source of your own, tried before $GITHUB_TOKEN_COMMAND
261
- timeout=10.0, # seconds, per request
282
+ timeout=10.0, # seconds per read: the release source's, and uv's read of an index
262
283
  tag_prefix='', # 'cli/' for tags like cli/v1.2.3
263
284
  allow_prerelease=False,
264
285
  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
+ """
@@ -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
@@ -93,7 +94,7 @@ class Installation:
93
94
  # `read_installation` records them rather than raising: the notify gate
94
95
  # treats a failed read as a local install and prints no notice. `update`
95
96
  # raises NotInstalledError on them instead of dropping them.
96
- _unrebuildable: tuple[str, ...] = field(default=(), repr=False)
97
+ unrebuildable: tuple[str, ...] = field(default=(), repr=False)
97
98
 
98
99
 
99
100
  def tool_dir() -> Path:
@@ -275,6 +276,50 @@ def current_version(package: str) -> str:
275
276
  return ''
276
277
 
277
278
 
279
+ INDEX_READ = ('pip', 'compile', '-', '--no-deps', '--no-header', '--no-annotate', '--quiet')
280
+ """Resolves the requirement read from stdin, and only it, printing `<name>==<version>`."""
281
+
282
+
283
+ def read_index_latest(installation: Installation, *, timeout: float, allow_prerelease: bool = False) -> str:
284
+ """The newest version of an index-installed tool that its package index serves, as uv prints it.
285
+
286
+ A release can exist before its upload to the index finishes, and stays when
287
+ the upload fails, so the release source cannot say what an index install
288
+ can take. uv resolves the tool's name alone, with the receipt's package
289
+ sources, and reads the index through the configuration and credentials the
290
+ reinstall uses. The receipt's `--python` is passed back too, so a release
291
+ that has dropped that Python is not offered. With none recorded, uv
292
+ resolves for the running interpreter.
293
+
294
+ The read is bounded by `timeout`, since the notify gate runs it before the
295
+ command someone typed returns. Raises `IndexUnreadableError` when uv is not
296
+ on PATH, outlasts the bound, or names no version.
297
+ """
298
+ uv = shutil.which('uv')
299
+ if not uv:
300
+ raise IndexUnreadableError(
301
+ f'uv is not on PATH, so the versions of {installation.tool} its package index serves cannot be read. '
302
+ 'Add the directory holding uv to PATH, then check again'
303
+ )
304
+ python = () if '--python' in installation.source_flags else ('--python', sys.executable)
305
+ prerelease = ('--prerelease', 'allow') if allow_prerelease else ()
306
+ command = [uv, *INDEX_READ, *installation.source_flags, *python, *prerelease]
307
+ try:
308
+ resolved = run_command(command, stdin=f'{installation.tool}\n', timeout=timeout)
309
+ except subprocess.TimeoutExpired as error:
310
+ raise IndexUnreadableError(
311
+ f'reading which version of {installation.tool} its package index serves took longer than {error.timeout:g}s'
312
+ ) from error
313
+ if resolved.returncode != 0:
314
+ raise IndexUnreadableError(f'uv could not read which version of {installation.tool} its package index serves: {_reason(resolved)}')
315
+ pinned = [line.split(';', 1)[0].partition('==')[2].strip() for line in resolved.stdout.splitlines() if '==' in line]
316
+ if len(pinned) != 1 or not pinned[0]:
317
+ raise IndexUnreadableError(
318
+ f'uv resolved {installation.tool} from its package index to {resolved.stdout.strip()!r}, which names no one version'
319
+ )
320
+ return pinned[0]
321
+
322
+
278
323
  def requirement_for(installation: Installation, ref: str) -> str:
279
324
  """The requirement string that installs `ref` of an already-installed tool, with the extras it has.
280
325
 
@@ -467,14 +512,16 @@ def run_install(
467
512
  raise InstallFailedError(f'uv tool install failed: {_reason(completed)}')
468
513
 
469
514
 
470
- def run_command(command: list[str], *, cwd: Path | None = None, timeout: float | None = None) -> subprocess.CompletedProcess[str]:
515
+ def run_command(
516
+ command: list[str], *, cwd: Path | None = None, timeout: float | None = None, stdin: str | None = None
517
+ ) -> subprocess.CompletedProcess[str]:
471
518
  """Run a program to completion and capture what it printed.
472
519
 
473
520
  Every process this package starts goes through here. `timeout` bounds the call in seconds. Past it the program is killed and
474
521
  `subprocess.TimeoutExpired` is raised, which each caller turns into its own
475
- failure. None runs unbounded.
522
+ failure. None runs unbounded. `stdin` is written to the program's standard input.
476
523
  """
477
- return subprocess.run(command, cwd=cwd, capture_output=True, text=True, check=False, timeout=timeout)
524
+ return subprocess.run(command, cwd=cwd, input=stdin, capture_output=True, text=True, check=False, timeout=timeout)
478
525
 
479
526
 
480
527
  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
- if installed.lock_warning:
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 is newer.
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 release exists, without installing anything.
83
+ """Report whether a newer version can be installed, without installing anything.
62
84
 
63
- Compares versions and reads nothing else. A caller reporting the result runs
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
- if semver.compare(latest, current) <= 0:
76
- return Result(current=current, latest=current)
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
- return Result(current=current, latest=latest, release=release)
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,16 @@ 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
- ref = result.release.install_ref()
132
- pins = read_lock(installation.url, ref, extras=installation.extras) if installation.kind is InstallKind.GIT else None
168
+ if installation.kind is InstallKind.GIT:
169
+ ref = result.release.install_ref()
170
+ pins = read_lock(installation.url, ref, extras=installation.extras)
171
+ else:
172
+ ref, pins = result.latest, None
133
173
  run_install(
134
174
  requirement_for(installation, ref),
135
175
  quiet=quiet,
@@ -144,6 +184,7 @@ def install_release(config: Config, result: Result, installation: Installation,
144
184
  applied=True,
145
185
  release=result.release,
146
186
  lock_missing=installation.kind is InstallKind.GIT and pins is None,
187
+ index_latest=result.index_latest,
147
188
  )
148
189
 
149
190
 
@@ -166,12 +207,13 @@ def update_and_reexec(config: Config, *, quiet: bool = True) -> Result:
166
207
 
167
208
  Returns normally only when nothing was installed; otherwise it does not
168
209
  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.
210
+ writes its `lock_warning` and `index_warning` to stderr before the re-exec.
170
211
  """
171
212
  result = update(config, quiet=quiet)
172
213
  if result.applied:
173
- if result.lock_warning:
174
- print(f'! {config.tool}: {result.lock_warning}', file=sys.stderr)
214
+ for warning in (result.lock_warning, result.index_warning):
215
+ if warning:
216
+ print(f'! {config.tool}: {warning}', file=sys.stderr)
175
217
  reexec()
176
218
  return result
177
219
 
@@ -213,9 +255,9 @@ def _require_updatable(installation: Installation, tag_prefix: str) -> None:
213
255
  f'so a release version cannot be compared against it; '
214
256
  f'reinstall from a tagged release to enable updates'
215
257
  )
216
- if installation._unrebuildable:
258
+ if installation.unrebuildable:
217
259
  raise NotInstalledError(
218
- f'{installation.tool} was installed with {", ".join(installation._unrebuildable)}, '
260
+ f'{installation.tool} was installed with {", ".join(installation.unrebuildable)}, '
219
261
  f'which an update cannot pass back to uv and would drop. '
220
262
  f'Reinstall {installation.tool} by hand with `uv tool install --force`'
221
263
  )
File without changes
File without changes