Show info for packages that aren't installed
- `orbit info` finds a package that isn't installed, or a `channel::` / `@constraint` build, in the cached channel listings used by search - Channel indexes record each version's manifest digest, so a repeated info needs no network - Versions without a digest, or indexes built before digests were added, are resolved in the registry - Show the docs link, channel, digest, bins and dependencies for available builds
This commit is contained in:
1 parent
022898ed65
commit
a00c87bf04
7 files changed
+176
-29
No files matched your search
@@ -85,13 +85,14 @@ A channel can hold an index of its packages at `<channel url>/orbit-index:latest
|
|||||||
The manifest has `artifactType` `application/vnd.latha.orbit.index.v1` and one JSON layer (`application/vnd.latha.orbit.index.v1+json`):
|
The manifest has `artifactType` `application/vnd.latha.orbit.index.v1` and one JSON layer (`application/vnd.latha.orbit.index.v1+json`):
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{"packages":[{"name":"mytool","version":"1.4.0","description":"...","versions":["1.4.0"]}]}
|
{"packages":[{"name":"mytool","version":"1.4.0","description":"...","versions":["1.4.0"],"digest":"sha256:..."}]}
|
||||||
```
|
```
|
||||||
|
|
||||||
- `orbit publish` adds the package to the index, and creates the index from the catalog if there is none. `--no-index` skips this.
|
- `orbit publish` adds the package to the index, and creates the index from the catalog if there is none. `--no-index` skips this.
|
||||||
- `orbit index [--channel <name>]` rebuilds it from the catalog. Use it after deleting a package, or if two publishes ran at once and one entry was lost. On a registry without a catalog, name the packages: `orbit index mytool othertool`.
|
- `orbit index [--channel <name>]` rebuilds it from the catalog. Use it after deleting a package, or if two publishes ran at once and one entry was lost. On a registry without a catalog, name the packages: `orbit index mytool othertool`.
|
||||||
|
- `digest` is the manifest digest of `version`. Indexes built before it was added lack it; `orbit index` adds it.
|
||||||
- Installs and version lookups never read the index, so a stale one can't change what is installed.
|
- Installs and version lookups never read the index, so a stale one can't change what is installed.
|
||||||
- Search keeps a copy of each channel's list in `~/.orbit/cache/indexes/` and uses it for an hour without touching the network. After that it fetches the list again, or uses the old copy with a warning if the registry can't be reached. `orbit search --refresh` fetches now. Your own `publish`, `index`, `login` and `logout` drop the copies they affect. A channel without an index is cached too, if it has at most 100 repositories.
|
- Search and `orbit info` keep a copy of each channel's list in `~/.orbit/cache/indexes/` and use it for an hour without touching the network. After that it fetches the list again, or uses the old copy with a warning if the registry can't be reached. `orbit search --refresh` fetches now. Your own `publish`, `index`, `login` and `logout` drop the copies they affect. A channel without an index is cached too, if it has at most 100 repositories.
|
||||||
- The index is built with the publisher's login. On a registry where packages in one namespace can be private while others are public, a public index reveals the private names, descriptions and versions. Gitea sets visibility per owner, so this doesn't apply there.
|
- The index is built with the publisher's login. On a registry where packages in one namespace can be private while others are public, a public index reveals the private names, descriptions and versions. Gitea sets visibility per owner, so this doesn't apply there.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@@ -277,7 +278,7 @@ src/main/
|
|||||||
model.mbt orbit.json / state.json / config.json (+ tests)
|
model.mbt orbit.json / state.json / config.json (+ tests)
|
||||||
registry.mbt OCI registry ops: tags, resolve, cached manifests, fetch, publish, login
|
registry.mbt OCI registry ops: tags, resolve, cached manifests, fetch, publish, login
|
||||||
index.mbt channel index: build, publish, read (+ tests)
|
index.mbt channel index: build, publish, read (+ tests)
|
||||||
index_cache.mbt local copies of channel listings for search (+ tests)
|
index_cache.mbt local copies of channel listings for search and info (+ tests)
|
||||||
details.mbt package details shown by install and info (+ tests)
|
details.mbt package details shown by install and info (+ tests)
|
||||||
solver.mbt lazy Resolvo-style CDCL SAT solver & UNSAT explainer (+ tests)
|
solver.mbt lazy Resolvo-style CDCL SAT solver & UNSAT explainer (+ tests)
|
||||||
ops.mbt SAT-backed global install/upgrade, remove/rollback/gc/search
|
ops.mbt SAT-backed global install/upgrade, remove/rollback/gc/search
|
||||||
@@ -307,5 +308,5 @@ Fixes needed for current MoonBit, kept here in case you build with an older comp
|
|||||||
|
|
||||||
- There's no lock file for concurrent runs, and no install hooks, by design.
|
- There's no lock file for concurrent runs, and no install hooks, by design.
|
||||||
- `orbit gc` only preserves global current and rollback builds (run `orbit install` / `orbit sync` in a project to re-populate missing store entries from its `orbit.lock`).
|
- `orbit gc` only preserves global current and rollback builds (run `orbit install` / `orbit sync` in a project to re-populate missing store entries from its `orbit.lock`).
|
||||||
- `orbit info <name>` reads installed package details (the project's, then the global ones) without contacting the registry. Use `orbit versions <name>` to check published versions.
|
- `orbit info <name>` reads installed package details (the project's, then the global ones) without contacting the registry. A package that isn't installed, or `orbit info [channel::]<name>@<constraint>` for another build, is looked up in the same cached channel listings as `orbit search`: it shows the newest version's description, documentation link, digest, bins, dependencies and conflicts. With the digest from the index and the config blob in the manifest cache, a repeated `info` needs no network; another version, or an index without digests, is resolved in the registry. Use `orbit versions <name>` to list published versions.
|
||||||
- `search` needs a channel index or the registry's catalog API (Gitea has it, also without a login). Otherwise use `orbit versions <name>`.
|
- `search` needs a channel index or the registry's catalog API (Gitea has it, also without a login). Otherwise use `orbit versions <name>`.
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
data:
|
||||||
|
priority: normal
|
||||||
|
status: done
|
||||||
|
type: feature
|
||||||
|
id: k7q3m
|
||||||
|
title: Show info for packages that aren't installed
|
||||||
|
---
|
||||||
|
`orbit info <name>` only worked for installed packages. It should also describe a package that is in a channel.
|
||||||
|
|
||||||
|
Outcome: when the package isn't installed (or `channel::` / `@constraint` asks for a build other than the installed one), `orbit info` finds the package in the same cached channel listings as `orbit search` (`channel_listing`). Index entries now record the `digest` of their version's manifest, so with the config blob in the digest-keyed manifest cache a repeated `info` takes ~8 ms with no network; another version, or an index built before digests, falls back to resolving in the registry. It and prints its description, documentation link, channel, digest, packaged bins, dependencies and conflicts. In a project it still prefers the locked package. `available_details` in `src/main/details.mbt`.
|
||||||
@@ -61,6 +61,36 @@ fn package_details(
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// The details of a build in a channel that isn't installed: it has no paths
|
||||||
|
/// yet, so bins are shown as they sit in the package.
|
||||||
|
fn available_details(
|
||||||
|
m : Manifest,
|
||||||
|
channel~ : String,
|
||||||
|
digest~ : String,
|
||||||
|
) -> Array[Detail] {
|
||||||
|
let bins = m.bins.copy()
|
||||||
|
if bins.is_empty() {
|
||||||
|
bins.push("(none)")
|
||||||
|
}
|
||||||
|
let specs = fn(reqs : Map[String, String]) {
|
||||||
|
let out : Array[String] = []
|
||||||
|
for n, c in reqs {
|
||||||
|
out.push(n + "@" + c)
|
||||||
|
}
|
||||||
|
join(out, " ")
|
||||||
|
}
|
||||||
|
[
|
||||||
|
("description", [m.description]),
|
||||||
|
("docs", [m.documentation]),
|
||||||
|
("channel", [channel]),
|
||||||
|
("digest", [digest]),
|
||||||
|
("bin", bins),
|
||||||
|
("depends", [specs(m.depends)]),
|
||||||
|
("conflicts", [specs(m.conflicts)]),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
fn installed_details(ctx : Ctx, p : Installed) -> Array[Detail] {
|
fn installed_details(ctx : Ctx, p : Installed) -> Array[Detail] {
|
||||||
package_details(
|
package_details(
|
||||||
@@ -116,3 +146,17 @@ test "package details show paths and every bin" {
|
|||||||
"bin: (none)",
|
"bin: (none)",
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "available details show bins as packaged and the docs link" {
|
||||||
|
let m = parse_manifest(
|
||||||
|
"{\"name\":\"t\",\"version\":\"1.0.0\",\"description\":\"A tool\",\"documentation\":\"https://x/t\",\"bin\":[\"bin/a\"],\"depends\":{\"x\":\"^1\"}}",
|
||||||
|
)
|
||||||
|
assert_eq(
|
||||||
|
detail_lines(available_details(m, channel="main", digest="sha256:ab"), ""),
|
||||||
|
[
|
||||||
|
"description: A tool", "docs: https://x/t", "channel: main", "digest: sha256:ab",
|
||||||
|
"bin: bin/a", "depends: x@^1",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
}
|
||||||
+21
-2
@@ -20,6 +20,7 @@ struct IndexEntry {
|
|||||||
version : String
|
version : String
|
||||||
description : String
|
description : String
|
||||||
versions : Array[String] // newest first
|
versions : Array[String] // newest first
|
||||||
|
digest : String // of the `version` manifest; "" in older indexes
|
||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
@@ -33,6 +34,9 @@ fn index_object(entries : Array[IndexEntry]) -> Map[String, Json] {
|
|||||||
o["version"] = Json::string(e.version)
|
o["version"] = Json::string(e.version)
|
||||||
o["description"] = Json::string(e.description)
|
o["description"] = Json::string(e.description)
|
||||||
o["versions"] = strs_json(e.versions)
|
o["versions"] = strs_json(e.versions)
|
||||||
|
if e.digest != "" {
|
||||||
|
o["digest"] = Json::string(e.digest)
|
||||||
|
}
|
||||||
pkgs.push(Json::object(o))
|
pkgs.push(Json::object(o))
|
||||||
}
|
}
|
||||||
let top : Map[String, Json] = Map([])
|
let top : Map[String, Json] = Map([])
|
||||||
@@ -64,6 +68,7 @@ fn parse_index(text : String) -> Array[IndexEntry] raise OrbitError {
|
|||||||
version: jstr(o, "version", ""),
|
version: jstr(o, "version", ""),
|
||||||
description: jstr(o, "description", ""),
|
description: jstr(o, "description", ""),
|
||||||
versions: jstrs(o, "versions"),
|
versions: jstrs(o, "versions"),
|
||||||
|
digest: jstr(o, "digest", ""),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -186,13 +191,15 @@ async fn read_index_entry(
|
|||||||
return None
|
return None
|
||||||
}
|
}
|
||||||
let tag = if tags.contains("latest") { "latest" } else { tags[0] }
|
let tag = if tags.contains("latest") { "latest" } else { tags[0] }
|
||||||
match orbit_info(fetch_raw_manifest(ch, name, tag)) {
|
let raw = fetch_raw_manifest_bytes(ch, name, tag)
|
||||||
|
match orbit_info(utf8_decode(raw)) {
|
||||||
Some(info) =>
|
Some(info) =>
|
||||||
Some(IndexEntry::{
|
Some(IndexEntry::{
|
||||||
name,
|
name,
|
||||||
version: info.version,
|
version: info.version,
|
||||||
description: info.description,
|
description: info.description,
|
||||||
versions: sorted_versions(tags),
|
versions: sorted_versions(tags),
|
||||||
|
digest: sha256_digest(raw),
|
||||||
})
|
})
|
||||||
None => None
|
None => None
|
||||||
}
|
}
|
||||||
@@ -334,7 +341,13 @@ async fn index_published(ch : Channel, name : String) -> Unit noraise {
|
|||||||
///|
|
///|
|
||||||
test "index round-trips, sorted, without unusable names" {
|
test "index round-trips, sorted, without unusable names" {
|
||||||
let entry = fn(name : String) {
|
let entry = fn(name : String) {
|
||||||
IndexEntry::{ name, version: "1.0.0", description: "d", versions: ["1.0.0"] }
|
IndexEntry::{
|
||||||
|
name,
|
||||||
|
version: "1.0.0",
|
||||||
|
description: "d",
|
||||||
|
versions: ["1.0.0"],
|
||||||
|
digest: "sha256:ab",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let parsed = parse_index(
|
let parsed = parse_index(
|
||||||
index_json([
|
index_json([
|
||||||
@@ -346,6 +359,12 @@ test "index round-trips, sorted, without unusable names" {
|
|||||||
)
|
)
|
||||||
assert_eq(parsed.map(fn(e) { e.name }), ["a", "zed"])
|
assert_eq(parsed.map(fn(e) { e.name }), ["a", "zed"])
|
||||||
assert_eq(parsed[0].versions, ["1.0.0"])
|
assert_eq(parsed[0].versions, ["1.0.0"])
|
||||||
|
assert_eq(parsed[0].digest, "sha256:ab")
|
||||||
|
// Indexes written before digests were recorded still parse.
|
||||||
|
let old = parse_index(
|
||||||
|
"{\"packages\":[{\"name\":\"a\",\"version\":\"1.0.0\",\"description\":\"d\",\"versions\":[\"1.0.0\"]}]}",
|
||||||
|
)
|
||||||
|
assert_eq(old[0].digest, "")
|
||||||
// Only an index artifact is used, and it is not an Orbit package.
|
// Only an index artifact is used, and it is not an Orbit package.
|
||||||
assert_true(index_layer_digest("{\"artifactType\":\"x\"}") is None)
|
assert_true(index_layer_digest("{\"artifactType\":\"x\"}") is None)
|
||||||
assert_true(
|
assert_true(
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// Local copies of channel listings, so that a repeated search needs no network.
|
// Local copies of channel listings, so that a repeated search or info needs no
|
||||||
// Installs and version lookups never read them.
|
// network. Installs and version lookups never read them.
|
||||||
|
|
||||||
///|
|
///|
|
||||||
/// How long a copy is used before it is fetched again.
|
/// How long a copy is used before it is fetched again.
|
||||||
@@ -91,7 +91,8 @@ async fn drop_cached_indexes(root : String) -> Unit noraise {
|
|||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
/// A channel's packages for search, which still has to match `term`: a fresh
|
/// A channel's packages for search and info, which still have to match `term`
|
||||||
|
/// (a large channel without an index only lists those that do): a fresh
|
||||||
/// copy, else its index, else the registry's catalog. If the registry fails, an
|
/// copy, else its index, else the registry's catalog. If the registry fails, an
|
||||||
/// old copy is used. None means the channel couldn't be listed.
|
/// old copy is used. None means the channel couldn't be listed.
|
||||||
async fn channel_listing(
|
async fn channel_listing(
|
||||||
@@ -177,6 +178,7 @@ async fn list_catalog(
|
|||||||
version: info.version,
|
version: info.version,
|
||||||
description: info.description,
|
description: info.description,
|
||||||
versions: [],
|
versions: [],
|
||||||
|
digest: "",
|
||||||
})
|
})
|
||||||
None => ()
|
None => ()
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -41,8 +41,9 @@ let usage : String =
|
|||||||
#| orbit upgrade [-g] [name...] jointly upgrade within constraints
|
#| orbit upgrade [-g] [name...] jointly upgrade within constraints
|
||||||
#| orbit rollback <name> switch to the previous global build
|
#| orbit rollback <name> switch to the previous global build
|
||||||
#| orbit list [-g] installed global packages
|
#| orbit list [-g] installed global packages
|
||||||
#| orbit info [-g] [channel::]<name> details of an installed package: paths,
|
#| orbit info [-g] [channel::]<name>[@constraint]
|
||||||
#| bins, dependencies (local only)
|
#| details of an installed package, else of
|
||||||
|
#| the newest matching build in a channel
|
||||||
#| orbit versions <name> published versions
|
#| orbit versions <name> published versions
|
||||||
#| orbit search [--refresh] [term] list packages (cached for an hour)
|
#| orbit search [--refresh] [term] list packages (cached for an hour)
|
||||||
#| orbit gc delete unused builds from the store
|
#| orbit gc delete unused builds from the store
|
||||||
@@ -349,7 +350,7 @@ async fn dispatch(args : Array[String]) -> Unit raise OrbitError {
|
|||||||
None => cmd_list(load_ctx())
|
None => cmd_list(load_ctx())
|
||||||
}
|
}
|
||||||
"info" => {
|
"info" => {
|
||||||
need(pos, 1, "info [channel::]<name>")
|
need(pos, 1, "info [channel::]<name>[@constraint]")
|
||||||
match resolve_project_or_none(force_global, manifest_path) {
|
match resolve_project_or_none(force_global, manifest_path) {
|
||||||
Some(mf) => cmd_project_info(load_ctx(), mf, pos[0])
|
Some(mf) => cmd_project_info(load_ctx(), mf, pos[0])
|
||||||
None => cmd_info(load_ctx(), pos[0])
|
None => cmd_info(load_ctx(), pos[0])
|
||||||
|
|||||||
+86
-17
@@ -764,25 +764,94 @@ async fn locate_spec(
|
|||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
fn cmd_info(ctx : Ctx, spec : String) -> Unit raise OrbitError {
|
/// Find a build for info in the channel listings that search caches: the
|
||||||
let (pin, name) = split_channel(spec)
|
/// pinned channel, else the one it is installed from, else by priority. None
|
||||||
let p = match ctx.state.get(name) {
|
/// if no listing has a matching version with a known digest, so the registry
|
||||||
Some(p) => p
|
/// has to be asked.
|
||||||
None => raise OrbitError("\{spec} is not installed")
|
async fn listed_build(
|
||||||
|
ctx : Ctx,
|
||||||
|
name : String,
|
||||||
|
pin : String?,
|
||||||
|
constraint : String,
|
||||||
|
) -> (Channel, String, String)? raise OrbitError {
|
||||||
|
let wanted = match pin {
|
||||||
|
Some(c) => Some(c)
|
||||||
|
None => ctx.state.get(name).map(i => i.channel)
|
||||||
}
|
}
|
||||||
if pin is Some(channel) && channel != p.channel {
|
let channels = match wanted {
|
||||||
raise OrbitError("\{spec} is not installed (installed from '\{p.channel}')")
|
Some(c) => [find_channel(ctx, c)]
|
||||||
|
None => ctx.channels
|
||||||
}
|
}
|
||||||
println("\{name} \{p.version} (installed)")
|
for ch in channels {
|
||||||
print_details(installed_details(ctx, p), " ")
|
let entries = match channel_listing(ctx.root, ch, name, false) {
|
||||||
print_details(
|
Some(es) => es
|
||||||
[
|
None => continue
|
||||||
("constraint", [p.constraint]),
|
}
|
||||||
("needed by", [join(reverse_deps(ctx, name), " ")]),
|
match find_entry(entries, name) {
|
||||||
("rollback", [join(p.history.map(g => g.version), " ")]),
|
Some(e) =>
|
||||||
],
|
if e.digest != "" && satisfies_all(e.version, [constraint]) {
|
||||||
" ",
|
return Some((ch, e.version, e.digest))
|
||||||
)
|
} else {
|
||||||
|
// Another version, or no digest: the registry knows its digest.
|
||||||
|
return None
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// Details of an installed package, or of the newest matching build in a
|
||||||
|
/// channel when it isn't installed (or `channel::` / `@constraint` asks for
|
||||||
|
/// another build).
|
||||||
|
async fn cmd_info(ctx : Ctx, spec : String) -> Unit raise OrbitError {
|
||||||
|
let (pin, name, constraint, explicit) = parse_spec_full(spec)
|
||||||
|
match ctx.state.get(name) {
|
||||||
|
Some(p) =>
|
||||||
|
if (pin is None || pin == Some(p.channel)) &&
|
||||||
|
(!explicit || satisfies_all(p.version, [constraint])) {
|
||||||
|
println("\{name} \{p.version} (installed)")
|
||||||
|
print_details(installed_details(ctx, p), " ")
|
||||||
|
print_details(
|
||||||
|
[
|
||||||
|
("constraint", [p.constraint]),
|
||||||
|
("needed by", [join(reverse_deps(ctx, name), " ")]),
|
||||||
|
("rollback", [join(p.history.map(g => g.version), " ")]),
|
||||||
|
],
|
||||||
|
" ",
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
None => ()
|
||||||
|
}
|
||||||
|
let (ch, version, digest) = match listed_build(ctx, name, pin, constraint) {
|
||||||
|
Some(found) => found
|
||||||
|
None => {
|
||||||
|
let wanted = match pin {
|
||||||
|
Some(c) => Some(c)
|
||||||
|
None => ctx.state.get(name).map(i => i.channel)
|
||||||
|
}
|
||||||
|
let (ch, tags) = locate(ctx, name, wanted)
|
||||||
|
let versions = sorted_versions(tags)
|
||||||
|
let version = match
|
||||||
|
versions.search_by(v => satisfies_all(v, [constraint])) {
|
||||||
|
Some(i) => versions[i]
|
||||||
|
None =>
|
||||||
|
raise OrbitError(
|
||||||
|
"no version of \{ch.name}::\{name} matches '\{constraint}'",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
(ch, version, resolve_digest(ch, name, version))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let m = fetch_manifest_cached(ctx.root, ch, name, digest)
|
||||||
|
let status = match ctx.state.get(name) {
|
||||||
|
Some(p) => "not installed; \{p.version} from \{p.channel} is"
|
||||||
|
None => "not installed"
|
||||||
|
}
|
||||||
|
println("\{name} \{version} (\{status})")
|
||||||
|
print_details(available_details(m, channel=ch.name, digest~), " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
|
|||||||
Reference in new issue
Block a user