Skip to content

Commit

Permalink
feat(rocks): use hererocks to install luarocks when luarocks is not f…
Browse files Browse the repository at this point in the history
…ound
  • Loading branch information
folke committed Jun 25, 2024
1 parent dea1f68 commit d87da76
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lua/lazy/core/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ M.defaults = {
enabled = true,
root = vim.fn.stdpath("data") .. "/lazy-rocks",
server = "https://nvim-neorocks.github.io/rocks-binaries/",
-- use hererocks to install luarocks.
hererocks = vim.fn.executable("luarocks") == 0,
},
dev = {
---@type string | fun(plugin: LazyPlugin): string directory where you store your local plugin projects
Expand Down
8 changes: 8 additions & 0 deletions lua/lazy/core/meta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ function M:load_pkgs()
if not Config.options.pkg.enabled then
return
end
local have_rockspec = false
for _, pkg in ipairs(Pkg.get()) do
have_rockspec = have_rockspec or pkg.source == "rockspec"
local meta, fragment = self:add(pkg.spec)
if meta and fragment then
meta._.pkg = pkg
Expand All @@ -46,6 +48,12 @@ function M:load_pkgs()
self.pkgs[pkg.dir] = fragment.id
end
end
if have_rockspec then
local hererocks = Pkg.hererocks()
if hererocks then
self:add(hererocks)
end
end
end

--- Remove a plugin and all its fragments.
Expand Down
4 changes: 3 additions & 1 deletion lua/lazy/core/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,10 @@ function M.update_rocks_state()
end)

for _, plugin in pairs(Config.plugins) do
if plugin._.pkg and plugin._.pkg.source == "rockspec" and plugin.build == "rockspec" then
if plugin.build == "rockspec" then
plugin._.build = not installed[plugin.name]
elseif plugin.name == "hererocks" then
plugin._.build = not vim.uv.fs_stat(Config.options.rocks.root .. "/hererocks")
end
end
end
Expand Down
20 changes: 19 additions & 1 deletion lua/lazy/manage/task/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,25 @@ local B = {}

---@param task LazyTask
function B.rockspec(task)
---@type table<string, string>
local env = {}

if Config.options.rocks.hererocks then
local hererocks = Config.options.rocks.root .. "/hererocks"
local sep = jit.os:find("Windows") and ";" or ":"
local path = vim.split(vim.env.PATH, sep)
table.insert(path, 1, hererocks .. "/bin")
env = {
PATH = table.concat(path, sep),
}
local plugin = Config.plugins.hererocks
-- hererocks is still building, so skip for now
if plugin and plugin._.build then
return
end
end

local root = Config.options.rocks.root .. "/" .. task.plugin.name
vim.fn.mkdir(root, "p")
task:spawn("luarocks", {
args = {
"--tree",
Expand All @@ -33,6 +50,7 @@ function B.rockspec(task)
"--force-fast",
},
cwd = task.plugin.dir,
env = env,
})
end

Expand Down
26 changes: 26 additions & 0 deletions lua/lazy/pkg/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,32 @@ local function _load()
Util.track()
end

---@return LazyPluginSpec?, string?
function M.hererocks()
if not (Config.options.rocks.enabled and Config.options.rocks.hererocks) then
return
end

local root = Config.options.rocks.root .. "/hererocks"

local cmd = {
"python",
"hererocks.py",
"--verbose",
"-l",
"5.1",
"-r",
"latest",
root,
}

return {
"luarocks/hererocks",
lazy = true,
build = table.concat(cmd, " "),
}, root
end

---@param dir string
---@return LazyPkg?
---@overload fun():LazyPkg[]
Expand Down

12 comments on commit d87da76

@max397574
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So basically users now just need to have python installed (or lua and luarocks) to get luarocks working with lazy?

@folke
Copy link
Owner Author

@folke folke commented on d87da76 Jun 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, exactly

@idk-r-n
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@folke why do we need luarocks?

@max397574
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

luarocks is used for installing plugins with a rockspec
which makes dependencies managment way easier (can be done by plugin instead of user) and allows installing any rock from luarocks

@icefed
Copy link

@icefed icefed commented on d87da76 Jun 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to install Python, what should I do?

@folke
Copy link
Owner Author

@folke folke commented on d87da76 Jun 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intall luarocks or set opts.rocks.enabled = false

@icefed
Copy link

@icefed icefed commented on d87da76 Jun 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intall luarocks or set opts.rocks.enabled = false

Thanks.

@milanglacier
Copy link

@milanglacier milanglacier commented on d87da76 Jun 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

luarocks is used for installing plugins with a rockspec which makes dependencies managment way easier (can be done by plugin instead of user) and allows installing any rock from luarocks

I just feel luarocks’s versioning will conflict with a git centric way of how people now use Neovim plugin.

say some plugin specify a luarocks dependency of a fixed version of a neovim plugin, but other plugin using git assumes an up to date version for that dependency……

Or the user already installed that package in lazy spec , and do not want to use luarocks to install that dependency.

I just feel using luarocks to manage neovim plugin dependency would make everything complicated…… If you are using external lua packages, then using luarocks is fine, but if you are using luarocks to specify Neovim dependencies, that might cause a lot of unexpected behavior…

@folke
Copy link
Owner Author

@folke folke commented on d87da76 Jun 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I totally agree. Feel free to post your feedback in that issue about luarocks and python in this repo. I'm not home right now.

@idk-r-n
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

luarocks is used for installing plugins with a rockspec which makes dependencies managment way easier (can be done by plugin instead of user) and allows installing any rock from luarocks

Seems like lazy should ask you if you want this before installing

@max397574
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussion is happening here #1548 @idk-r-n

@idk-r-n
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@max397574 thanks

Please sign in to comment.