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

@ -3,6 +3,7 @@ local git = require('dep.git')
local fs = require('dep.fs') local fs = require('dep.fs')
local packager = require('dep.package') local packager = require('dep.package')
local h = require('dep.helpers') local h = require('dep.helpers')
local spec_man = require("dep.spec")
-- all functions for convenience -- all functions for convenience
local M = {} local M = {}
@ -38,14 +39,14 @@ function M.registertree(speclist, overrides)
-- make sure the overrides override and take into account the packages spec -- make sure the overrides override and take into account the packages spec
---@diagnostic disable-next-line: missing-fields ---@diagnostic disable-next-line: missing-fields
over = { over = {
pin = over.pin or spec.pin, pin = overrides.pin or spec.pin,
disable = over.disable or spec.disable disable = overrides.disable or spec.disable
} }
-- While a package can fail to load we just don't care, it will work itself -- While a package can fail to load we just don't care, it will work itself
-- out. The goal is to make sure every plugin that can load does load, not -- out. The goal is to make sure every plugin that can load does load, not
-- keep working plugins from loading because an unrelated one doesn't load. -- keep working plugins from loading because an unrelated one doesn't load.
packager:new(spec, overrides) packager:new(spec, over)
end end
if speclist.modules then if speclist.modules then
@ -63,9 +64,14 @@ function M.registertree(speclist, overrides)
name, module = module, require(module) name, module = module, require(module)
end end
name = module.name or name name = module.name or name
-- allow a module to be a spec
if spec_man.check(module, true) ~= false then
---@diagnostic disable-next-line: cast-local-type
module = { module }
end
local ok, err = pcall(M.registertree, module, overrides) local ok, err = pcall(M.registertree, module, overrides)
if not ok then if not ok then
error(string.format("%s <- %s", err, name)) error(string.format("%s <- %s", err, name))
@ -125,7 +131,7 @@ function M.synctree(tree, cb)
end end
end end
for _, package in ipairs(tree) do for _, package in pairs(tree) do
local co = coroutine.create(function() local co = coroutine.create(function()
-- if the package provided prefers a local source then use the local -- if the package provided prefers a local source then use the local
-- source instead of the git repository -- source instead of the git repository
@ -160,7 +166,8 @@ return function(opts)
-- register all packages -- register all packages
local root = packager:new({ local root = packager:new({
"squibid/dep", "squibid/dep",
url = "https://git.squi.bid/dep", url = "https://git.squi.bid/squibid/dep.git",
branch = "lazy",
pin = true pin = true
}) })
if not root then if not root then
@ -170,7 +177,7 @@ return function(opts)
M.registertree(opts) M.registertree(opts)
-- sort package dependencies -- sort package dependencies
for _, package in ipairs(packager.get_packages()) do for _, package in pairs(packager.get_packages()) do
table.sort(package.requirements, comp) table.sort(package.requirements, comp)
table.sort(package.dependents, comp) table.sort(package.dependents, comp)
end end
@ -183,7 +190,7 @@ return function(opts)
end) end)
-- load packages -- load packages
M.reload() M.reload(false)
--- check if a package should be synced --- check if a package should be synced
---@param package table package table spec ---@param package table package table spec
@ -198,7 +205,7 @@ return function(opts)
-- get all package that need syncing -- get all package that need syncing
local targets = {} local targets = {}
for _, package in ipairs(packager.get_packages()) do for _, package in pairs(packager.get_packages()) do
if shouldsync(package) then if shouldsync(package) then
table.insert(targets, package) table.insert(targets, package)
end end

View File

@ -46,7 +46,6 @@ end
---@param package package package to install ---@param package package package to install
---@param cb function callback ---@param cb function callback
function git.install(package, cb) function git.install(package, cb)
if not package.enabled then if not package.enabled then
cb() cb()
return return
@ -99,13 +98,9 @@ function git.update(package, cb)
return return
end 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) proc.git_rev_parse(package.dir, "HEAD", function(err, before)
if err then if err then
logerr(before) log_err(before)
cb(err) cb(err)
else else
if package.commit then if package.commit then

View File

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

View File

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

View File

@ -43,13 +43,35 @@ function spec:get_name()
return self[1]:match("^[%w-_.]+/([%w-_.]+)$") return self[1]:match("^[%w-_.]+/([%w-_.]+)$")
end end
--- check a spec to see if it's correct --- attempt to correct a spec
---@param self table|string spec to check ---@param self table|string spec to check
---@return spec|false spec if the spec is ok or false ---@return spec spec
function spec:check() function spec:correct_spec()
-- make sure spec is a table
if type(self) == "string" then 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 end
-- make sure all the data is correct -- make sure all the data is correct
@ -176,6 +198,9 @@ function spec:check()
end end
end end
if silent == true then
logger = __logger
end
return self return self
end end