Add pixi-style channels configured in config.toml
The built-in main channel is always included. Priority is strict, packages remember their channel, and only a missing repository falls through to the next channel. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
32714325a7
commit
61ebc21fce
11 files changed
+639
-164
No files matched your search
+101
-45
@@ -4,6 +4,7 @@
|
||||
/// One package in an install plan.
|
||||
struct Step {
|
||||
name : String
|
||||
channel : String
|
||||
version : String
|
||||
digest : String
|
||||
manifest : Manifest
|
||||
@@ -62,7 +63,7 @@ fn constraints_for(
|
||||
}
|
||||
}
|
||||
for other, st in p.steps {
|
||||
if other != name && !(p.ctx.state.contains(other)) {
|
||||
if other != name && !p.ctx.state.contains(other) {
|
||||
match st.manifest.depends.get(name) {
|
||||
Some(c) => cons.push(c)
|
||||
None => ()
|
||||
@@ -78,10 +79,16 @@ fn visit(
|
||||
name : String,
|
||||
requested : String,
|
||||
explicit : Bool,
|
||||
pin : String?, // channel the user asked for
|
||||
) -> Unit raise OrbitError {
|
||||
match p.steps.get(name) {
|
||||
Some(st) => {
|
||||
if !(satisfies_all(st.version, [requested])) {
|
||||
if pin is Some(c) && c != st.channel {
|
||||
raise OrbitError(
|
||||
"conflict: \{name} is planned from channel '\{st.channel}' but '\{c}' was requested",
|
||||
)
|
||||
}
|
||||
if !satisfies_all(st.version, [requested]) {
|
||||
raise OrbitError(
|
||||
"conflict: \{name} \{st.version} is planned but '\{requested}' is required",
|
||||
)
|
||||
@@ -97,10 +104,15 @@ fn visit(
|
||||
let cons = constraints_for(p, name, requested)
|
||||
let upgrading = p.upgrade.contains(name)
|
||||
match p.ctx.state.get(name) {
|
||||
Some(inst) =>
|
||||
if !(upgrading) && satisfies_all(inst.version, cons) {
|
||||
Some(inst) => {
|
||||
let same_channel = match pin {
|
||||
Some(c) => c == inst.channel
|
||||
None => true
|
||||
}
|
||||
if !upgrading && same_channel && satisfies_all(inst.version, cons) {
|
||||
let st = Step::{
|
||||
name,
|
||||
channel: inst.channel,
|
||||
version: inst.version,
|
||||
digest: inst.digest,
|
||||
manifest: manifest_of_installed(inst),
|
||||
@@ -116,23 +128,30 @@ fn visit(
|
||||
p.order.push(st)
|
||||
return
|
||||
}
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
let tags = list_tags(p.ctx, name)
|
||||
// An installed package stays on its channel unless the user names another.
|
||||
let wanted = match pin {
|
||||
Some(c) => Some(c)
|
||||
None => p.ctx.state.get(name).map(fn(i) { i.channel })
|
||||
}
|
||||
let (ch, tags) = locate(p.ctx, name, wanted)
|
||||
let tag = match pick_tag(tags, cons) {
|
||||
Some(t) => t
|
||||
None => {
|
||||
let avail = sorted_versions(tags)
|
||||
raise OrbitError(
|
||||
"no version of \{name} satisfies [\{join(cons, ", ")}]; available: \{join(avail, ", ")}",
|
||||
"no version of \{name} in channel '\{ch.name}' satisfies [\{join(cons, ", ")}]; available: \{join(avail, ", ")}",
|
||||
)
|
||||
}
|
||||
}
|
||||
let digest = resolve_digest(p.ctx, name, tag)
|
||||
let m = fetch_manifest(p.ctx, name, digest)
|
||||
let digest = resolve_digest(ch, name, tag)
|
||||
let m = fetch_manifest(ch, name, digest)
|
||||
let prev = p.ctx.state.get(name)
|
||||
let st = Step::{
|
||||
name,
|
||||
channel: ch.name,
|
||||
version: m.version,
|
||||
digest,
|
||||
manifest: m,
|
||||
@@ -157,19 +176,20 @@ fn visit(
|
||||
// Register before recursing so dependency cycles terminate.
|
||||
p.steps[name] = st
|
||||
for dep, dc in m.depends {
|
||||
visit(p, dep, dc, false)
|
||||
visit(p, dep, dc, false, None)
|
||||
}
|
||||
p.order.push(st)
|
||||
}
|
||||
|
||||
///|
|
||||
/// "name" or "name@constraint"
|
||||
fn parse_spec(spec : String) -> (String, String) raise OrbitError {
|
||||
let (name, c) = split_first(spec, '@')
|
||||
if !(valid_name(name)) {
|
||||
/// "[channel::]name[@constraint]"
|
||||
fn parse_spec(spec : String) -> (String?, String, String) raise OrbitError {
|
||||
let (channel, rest) = split_channel(spec)
|
||||
let (name, c) = split_first(rest, '@')
|
||||
if !valid_name(name) {
|
||||
raise OrbitError("invalid package name '\{name}'")
|
||||
}
|
||||
(name, if c == "" { "*" } else { c })
|
||||
(channel, name, if c == "" { "*" } else { c })
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -230,7 +250,8 @@ fn check_bin_conflicts(
|
||||
///|
|
||||
/// Switch `name` to a fetched build, keeping the old one for rollback.
|
||||
fn activate(ctx : Ctx, st : Step) -> Unit raise OrbitError {
|
||||
let dir = fetch_into_store(ctx, st.name, st.digest)
|
||||
let ch = find_channel(ctx, st.channel)
|
||||
let dir = fetch_into_store(ctx, ch, st.name, st.digest)
|
||||
for b in st.manifest.bins {
|
||||
if sh("test -f " + sq(dir + "/" + b)) != 0 {
|
||||
raise OrbitError("\{st.name}: bin '\{b}' missing from package contents")
|
||||
@@ -241,6 +262,7 @@ fn activate(ctx : Ctx, st : Step) -> Unit raise OrbitError {
|
||||
Some(inst) => {
|
||||
unlink_bins(ctx, inst.bins)
|
||||
inst.history.push(Gen::{
|
||||
channel: inst.channel,
|
||||
version: inst.version,
|
||||
digest: inst.digest,
|
||||
bins: inst.bins,
|
||||
@@ -249,6 +271,7 @@ fn activate(ctx : Ctx, st : Step) -> Unit raise OrbitError {
|
||||
while inst.history.length() > 2 {
|
||||
inst.history.remove(0) |> ignore
|
||||
}
|
||||
inst.channel = st.channel
|
||||
inst.version = st.version
|
||||
inst.digest = st.digest
|
||||
inst.bins = st.manifest.bins
|
||||
@@ -262,6 +285,7 @@ fn activate(ctx : Ctx, st : Step) -> Unit raise OrbitError {
|
||||
None => {
|
||||
ctx.state[st.name] = Installed::{
|
||||
name: st.name,
|
||||
channel: st.channel,
|
||||
version: st.version,
|
||||
digest: st.digest,
|
||||
explicit: st.explicit,
|
||||
@@ -285,6 +309,7 @@ fn apply_plan(ctx : Ctx, p : Planner) -> Unit raise OrbitError {
|
||||
if st.keep {
|
||||
match ctx.state.get(st.name) {
|
||||
Some(inst) => {
|
||||
inst.channel = st.channel
|
||||
inst.explicit = st.explicit
|
||||
inst.constraint = st.constraint
|
||||
}
|
||||
@@ -309,12 +334,12 @@ fn new_planner(ctx : Ctx, upgrade : Array[String]) -> Planner {
|
||||
///|
|
||||
fn cmd_install(ctx : Ctx, specs : Array[String]) -> Unit raise OrbitError {
|
||||
if specs.length() == 0 {
|
||||
raise OrbitError("usage: orbit install <name>[@constraint]...")
|
||||
raise OrbitError("usage: orbit install [channel::]<name>[@constraint]...")
|
||||
}
|
||||
let p = new_planner(ctx, [])
|
||||
for s in specs {
|
||||
let (name, c) = parse_spec(s)
|
||||
visit(p, name, c, true)
|
||||
let (channel, name, c) = parse_spec(s)
|
||||
visit(p, name, c, true, channel)
|
||||
}
|
||||
apply_plan(ctx, p)
|
||||
}
|
||||
@@ -330,7 +355,7 @@ fn cmd_upgrade(ctx : Ctx, names : Array[String]) -> Unit raise OrbitError {
|
||||
}
|
||||
} else {
|
||||
for n in names {
|
||||
if !(ctx.state.contains(n)) {
|
||||
if !ctx.state.contains(n) {
|
||||
raise OrbitError("\{n} is not installed")
|
||||
}
|
||||
targets.push(n)
|
||||
@@ -339,7 +364,7 @@ fn cmd_upgrade(ctx : Ctx, names : Array[String]) -> Unit raise OrbitError {
|
||||
let p = new_planner(ctx, targets)
|
||||
for n in targets {
|
||||
match ctx.state.get(n) {
|
||||
Some(inst) => visit(p, n, "*", inst.explicit)
|
||||
Some(inst) => visit(p, n, "*", inst.explicit, None)
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
@@ -378,7 +403,7 @@ fn autoremove(ctx : Ctx) -> Unit raise OrbitError {
|
||||
changed = false
|
||||
let orphans : Array[String] = []
|
||||
for name, p in ctx.state {
|
||||
if !(p.explicit) && reverse_deps(ctx, name).length() == 0 {
|
||||
if !p.explicit && reverse_deps(ctx, name).length() == 0 {
|
||||
orphans.push(name)
|
||||
}
|
||||
}
|
||||
@@ -399,18 +424,18 @@ fn cmd_remove(
|
||||
raise OrbitError("usage: orbit remove <name>...")
|
||||
}
|
||||
for n in names {
|
||||
if !(ctx.state.contains(n)) {
|
||||
if !ctx.state.contains(n) {
|
||||
raise OrbitError("\{n} is not installed")
|
||||
}
|
||||
}
|
||||
for n in names {
|
||||
let users : Array[String] = []
|
||||
for u in reverse_deps(ctx, n) {
|
||||
if !(names.contains(u)) {
|
||||
if !names.contains(u) {
|
||||
users.push(u)
|
||||
}
|
||||
}
|
||||
if users.length() > 0 && !(force) {
|
||||
if users.length() > 0 && !force {
|
||||
raise OrbitError(
|
||||
"\{n} is required by \{join(users, ", ")} (use --force to remove anyway)",
|
||||
)
|
||||
@@ -435,18 +460,20 @@ fn cmd_rollback(ctx : Ctx, name : String) -> Unit raise OrbitError {
|
||||
None => raise OrbitError("\{name} has no previous version to roll back to")
|
||||
}
|
||||
let dir = store_dir(ctx, name, prev.digest)
|
||||
if !(exists(dir)) {
|
||||
if !exists(dir) {
|
||||
raise OrbitError(
|
||||
"previous build of \{name} (\{prev.version}) is no longer in the store",
|
||||
)
|
||||
}
|
||||
unlink_bins(ctx, inst.bins)
|
||||
inst.history.push(Gen::{
|
||||
channel: inst.channel,
|
||||
version: inst.version,
|
||||
digest: inst.digest,
|
||||
bins: inst.bins,
|
||||
depends: inst.depends,
|
||||
})
|
||||
inst.channel = prev.channel
|
||||
let from = inst.version
|
||||
inst.version = prev.version
|
||||
inst.digest = prev.digest
|
||||
@@ -460,7 +487,7 @@ fn cmd_rollback(ctx : Ctx, name : String) -> Unit raise OrbitError {
|
||||
for dep, c in inst.depends {
|
||||
match ctx.state.get(dep) {
|
||||
Some(d) =>
|
||||
if !(satisfies_all(d.version, [c])) {
|
||||
if !satisfies_all(d.version, [c]) {
|
||||
missing.push(dep + "@" + c)
|
||||
}
|
||||
None => missing.push(dep + "@" + c)
|
||||
@@ -477,7 +504,7 @@ fn cmd_rollback(ctx : Ctx, name : String) -> Unit raise OrbitError {
|
||||
/// Delete store entries that are neither current nor kept for rollback.
|
||||
fn cmd_gc(ctx : Ctx) -> Unit raise OrbitError {
|
||||
let store = ctx.root + "/store"
|
||||
if !(exists(store)) {
|
||||
if !exists(store) {
|
||||
println("store is empty")
|
||||
return
|
||||
}
|
||||
@@ -494,7 +521,7 @@ fn cmd_gc(ctx : Ctx) -> Unit raise OrbitError {
|
||||
keep.push(store_id(g.digest))
|
||||
}
|
||||
for id in lines(capture("ls -1 " + sq(store + "/" + pkg))) {
|
||||
if !(keep.contains(id)) {
|
||||
if !keep.contains(id) {
|
||||
sh_ok("rm -rf " + sq(store + "/" + pkg + "/" + id))
|
||||
freed = freed + 1
|
||||
}
|
||||
@@ -515,15 +542,34 @@ fn cmd_list(ctx : Ctx) -> Unit {
|
||||
}
|
||||
for name, p in ctx.state {
|
||||
let kind = if p.explicit { "" } else { " (dependency)" }
|
||||
println("\{name} \{p.version}\{kind}")
|
||||
let from = if p.channel == MAIN_CHANNEL { "" } else { " [\{p.channel}]" }
|
||||
println("\{name} \{p.version}\{from}\{kind}")
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
fn cmd_info(ctx : Ctx, name : String) -> Unit raise OrbitError {
|
||||
/// Where to look up "[channel::]name": the channel asked for, else the one it
|
||||
/// was installed from, else by priority.
|
||||
fn locate_spec(
|
||||
ctx : Ctx,
|
||||
spec : String,
|
||||
) -> (String, Channel, Array[String]) raise OrbitError {
|
||||
let (pin, name) = split_channel(spec)
|
||||
let wanted = match pin {
|
||||
Some(c) => Some(c)
|
||||
None => ctx.state.get(name).map(fn(i) { i.channel })
|
||||
}
|
||||
let (ch, tags) = locate(ctx, name, wanted)
|
||||
(name, ch, tags)
|
||||
}
|
||||
|
||||
///|
|
||||
fn cmd_info(ctx : Ctx, spec : String) -> Unit raise OrbitError {
|
||||
let (_, name) = split_channel(spec)
|
||||
match ctx.state.get(name) {
|
||||
Some(p) => {
|
||||
println("\{name} \{p.version} (installed)")
|
||||
println(" channel: \{p.channel}")
|
||||
println(" digest: \{p.digest}")
|
||||
println(" constraint: \{p.constraint}")
|
||||
println(" bin: \{join(p.bins, " ")}")
|
||||
@@ -542,11 +588,11 @@ fn cmd_info(ctx : Ctx, name : String) -> Unit raise OrbitError {
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
let tags = list_tags(ctx, name)
|
||||
let (_, ch, tags) = locate_spec(ctx, spec)
|
||||
match pick_tag(tags, ["*"]) {
|
||||
Some(t) => {
|
||||
let m = fetch_manifest(ctx, name, resolve_digest(ctx, name, t))
|
||||
println("\{name} \{m.version} (latest in \{ctx.cfg.registry})")
|
||||
let m = fetch_manifest(ch, name, resolve_digest(ch, name, t))
|
||||
println("\{name} \{m.version} (latest in \{ch.name}: \{ch.url})")
|
||||
if m.description != "" {
|
||||
println(" \{m.description}")
|
||||
}
|
||||
@@ -556,10 +602,11 @@ fn cmd_info(ctx : Ctx, name : String) -> Unit raise OrbitError {
|
||||
}
|
||||
|
||||
///|
|
||||
fn cmd_versions(ctx : Ctx, name : String) -> Unit raise OrbitError {
|
||||
for v in sorted_versions(list_tags(ctx, name)) {
|
||||
fn cmd_versions(ctx : Ctx, spec : String) -> Unit raise OrbitError {
|
||||
let (name, ch, tags) = locate_spec(ctx, spec)
|
||||
for v in sorted_versions(tags) {
|
||||
let mark = match ctx.state.get(name) {
|
||||
Some(p) => if p.version == v { " *" } else { "" }
|
||||
Some(p) => if p.version == v && p.channel == ch.name { " *" } else { "" }
|
||||
None => ""
|
||||
}
|
||||
println(v + mark)
|
||||
@@ -568,15 +615,24 @@ fn cmd_versions(ctx : Ctx, name : String) -> Unit raise OrbitError {
|
||||
|
||||
///|
|
||||
fn cmd_search(ctx : Ctx, term : String) -> Unit raise OrbitError {
|
||||
let out = capture(oras(ctx, "repo ls " + sq(ctx.cfg.registry))) catch {
|
||||
_ =>
|
||||
raise OrbitError(
|
||||
"registry does not allow listing repositories (catalog API); try `orbit info <name>`",
|
||||
)
|
||||
}
|
||||
for r in lines(out) {
|
||||
if contains_str(r, term) {
|
||||
println(r)
|
||||
let mut listed = 0
|
||||
for ch in ctx.channels {
|
||||
let out = capture(oras(ch, "repo ls " + sq(ch.url))) catch {
|
||||
_ => {
|
||||
println("warning: channel '\{ch.name}' does not allow listing packages")
|
||||
continue
|
||||
}
|
||||
}
|
||||
listed = listed + 1
|
||||
for r in lines(out) {
|
||||
if contains_str(r, term) {
|
||||
println("\{ch.name}::\{r}")
|
||||
}
|
||||
}
|
||||
}
|
||||
if listed == 0 {
|
||||
raise OrbitError(
|
||||
"no channel allows listing packages (catalog API); try `orbit info <name>`",
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user