the spec no longer fixes itself...

modules are more reliable
cleanup some typos
This commit is contained in:
2025-06-23 00:18:33 -04:00
parent 30cc9a8d50
commit 71b78bfca4
5 changed files with 59 additions and 31 deletions

View File

@ -46,7 +46,6 @@ end
---@param package package package to install
---@param cb function callback
function git.install(package, cb)
if not package.enabled then
cb()
return
@ -99,13 +98,9 @@ function git.update(package, cb)
return
end
local function logerr(err)
logger:log("error", "failed to update %s; reason: %s", package.id, err)
end
proc.git_rev_parse(package.dir, "HEAD", function(err, before)
if err then
logerr(before)
log_err(before)
cb(err)
else
if package.commit then

View File

@ -65,7 +65,7 @@ function package:new(spec, overrides)
overrides = overrides or {}
-- ensure that the spec is ok
local new_spec = spec_man.check(spec)
local new_spec = spec_man.check(spec_man.correct_spec(spec))
if new_spec == false then
logger:log("spec", vim.inspect(spec))
logger:log("error", "spec check failed, check DepLog")
@ -144,7 +144,7 @@ function package:new(spec, overrides)
if spec.reqs then
---it is the correct type as asserted in check_spec()
---@diagnostic disable-next-line: param-type-mismatch
for _, req in ipairs(spec.reqs) do
for _, req in pairs(spec.reqs) do
local pkg = package:new(req)
if type(pkg) == "table" then
o:link_dependency(pkg, o)
@ -156,7 +156,7 @@ function package:new(spec, overrides)
if spec.deps then
---it is the correct type as asserted in check_spec()
---@diagnostic disable-next-line: param-type-mismatch
for _, dep in ipairs(spec.deps) do
for _, dep in pairs(spec.deps) do
local pkg = package:new(dep)
if not pkg then
return false
@ -206,7 +206,7 @@ function package.get_root()
end
--- get the packages in dep
---@return package root
---@return package[] packages
---@nodiscard
function package.get_packages()
return packages
@ -254,7 +254,7 @@ function package:ensureadded(force)
---@param pkg package
local function loadpkg(pkg)
-- make sure to load the dependencies first
for _, p in ipairs(pkg.requirements) do
for _, p in pairs(pkg.requirements) do
if not p.loaded then
p:ensureadded(true)
end
@ -335,7 +335,7 @@ function package:loadtree(force)
-- if the package isn't lazy check that it's requirements are loaded
if not self.lazy then
for _, requirement in ipairs(self.requirements) do
for _, requirement in pairs(self.requirements) do
if not requirement.loaded and not requirement.lazy then
return false
end
@ -355,7 +355,7 @@ function package:loadtree(force)
self.subtree_loaded = true
-- make sure the dependants are loaded
for _, dependant in ipairs(self.dependents) do
for _, dependant in pairs(self.dependents) do
self.subtree_loaded = dependant:loadtree(force) and self.subtree_loaded
end
@ -365,12 +365,12 @@ end
--- unconfigure a packages tree
function package:unconfiguretree()
-- unconfigure requirements
for _, requirement in ipairs(self.requirements) do
for _, requirement in pairs(self.requirements) do
requirement.subtree_loaded = false
end
-- unconfigure dependents
for _, dependant in ipairs(self.dependents) do
for _, dependant in pairs(self.dependents) do
dependant.loaded = false
dependant.added = false
dependant.configured = false
@ -431,7 +431,7 @@ function package.findcycle(pkgs)
end
-- actually check the cycle
for _, pkg in ipairs(pkgs) do
for _, pkg in pairs(pkgs) do
if not indexes[package.id] then
local cycle = connect(pkg)
if cycle then

View File

@ -122,7 +122,8 @@ function proc.git_resolve_branch(url, branch, cb)
end
end
end
})
}
)
end
return proc

View File

@ -43,13 +43,35 @@ function spec:get_name()
return self[1]:match("^[%w-_.]+/([%w-_.]+)$")
end
--- check a spec to see if it's correct
--- attempt to correct a spec
---@param self table|string spec to check
---@return spec|false spec if the spec is ok or false
function spec:check()
-- make sure spec is a table
---@return spec spec
function spec:correct_spec()
if type(self) == "string" then
self = { self }
return { self }
elseif type(self) == "table" then
repeat
if type(self[1]) ~= "string" then
self = self[1]
end
until type(self[1]) == "string"
end
return self
end
-- store the logger temporarily to prevent any logs from being printed when
-- being run in silent mode
local __logger
--- check a spec to see if it's correct
---@param self table spec to check
---@param silent boolean? should the checker report errors
---@return spec|false spec if the spec is ok or false
function spec:check(silent)
if silent == true then
__logger = logger
logger = { log = function() end }
end
-- make sure all the data is correct
@ -176,6 +198,9 @@ function spec:check()
end
end
if silent == true then
logger = __logger
end
return self
end