mjolnirapp / mjolnir

Lightweight automation and productivity app for OS X
5.21k stars 128 forks source link

Packages not found after brew upgrade #569

Closed rileyjshaw closed 6 years ago

rileyjshaw commented 6 years ago

During a routine upgrade of Homebrew, my Lua version upgraded. Mjolnir couldn't find some packages so I reinstalled them, eg:

$ luarocks install mjolnir.hotkey
Installing http://rocks.moonscript.org/mjolnir.hotkey-0.3-1.macosx-x86_64.rock
mjolnir.hotkey 0.3-1 is now installed in /usr/local (license: MIT)

I installed everything I use in my init.lua (included at bottom), but the console indicates that it can't find the packages. Console output:

Welcome to the Mjolnir Console!
You can run any Lua code in here.

-- Loading ~/.mjolnir/init.lua
Some packages appear to be missing.
At least one package was missing. Have you installed the packages? See README.md.
/Users/rileyshaw/.mjolnir/init.lua:1: module 'mjolnir.bg.grid' not found:
    no field package.preload['mjolnir.bg.grid']
    no file '/usr/local/share/lua/5.2/mjolnir/bg/grid.lua'
    no file '/usr/local/share/lua/5.2/mjolnir/bg/grid/init.lua'
    no file '/usr/local/lib/lua/5.2/mjolnir/bg/grid.lua'
    no file '/usr/local/lib/lua/5.2/mjolnir/bg/grid/init.lua'
    no file './mjolnir/bg/grid.lua'
    no file '/usr/local/lib/lua/5.2/mjolnir/bg/grid.so'
    no file '/usr/local/lib/lua/5.2/loadall.so'
    no file './mjolnir/bg/grid.so'
    no file '/usr/local/lib/lua/5.2/mjolnir.so'
    no file '/usr/local/lib/lua/5.2/loadall.so'
    no file './mjolnir.so'
/Users/rileyshaw/.mjolnir/init.lua:2: module 'mjolnir.window' not found:
    no field package.preload['mjolnir.window']
    no file '/usr/local/share/lua/5.2/mjolnir/window.lua'
    no file '/usr/local/share/lua/5.2/mjolnir/window/init.lua'
    no file '/usr/local/lib/lua/5.2/mjolnir/window.lua'
    no file '/usr/local/lib/lua/5.2/mjolnir/window/init.lua'
    no file './mjolnir/window.lua'
    no file '/usr/local/lib/lua/5.2/mjolnir/window.so'
    no file '/usr/local/lib/lua/5.2/loadall.so'
    no file './mjolnir/window.so'
    no file '/usr/local/lib/lua/5.2/mjolnir.so'
    no file '/usr/local/lib/lua/5.2/loadall.so'
    no file './mjolnir.so'
/Users/rileyshaw/.mjolnir/init.lua:3: module 'mjolnir.hotkey' not found:
    no field package.preload['mjolnir.hotkey']
    no file '/usr/local/share/lua/5.2/mjolnir/hotkey.lua'
    no file '/usr/local/share/lua/5.2/mjolnir/hotkey/init.lua'
    no file '/usr/local/lib/lua/5.2/mjolnir/hotkey.lua'
    no file '/usr/local/lib/lua/5.2/mjolnir/hotkey/init.lua'
    no file './mjolnir/hotkey.lua'
    no file '/usr/local/lib/lua/5.2/mjolnir/hotkey.so'
    no file '/usr/local/lib/lua/5.2/loadall.so'
    no file './mjolnir/hotkey.so'
    no file '/usr/local/lib/lua/5.2/mjolnir.so'
    no file '/usr/local/lib/lua/5.2/loadall.so'
    no file './mjolnir.so'
/Users/rileyshaw/.mjolnir/init.lua:5: module 'mjolnir.fnutils' not found:
    no field package.preload['mjolnir.fnutils']
    no file '/usr/local/share/lua/5.2/mjolnir/fnutils.lua'
    no file '/usr/local/share/lua/5.2/mjolnir/fnutils/init.lua'
    no file '/usr/local/lib/lua/5.2/mjolnir/fnutils.lua'
    no file '/usr/local/lib/lua/5.2/mjolnir/fnutils/init.lua'
    no file './mjolnir/fnutils.lua'
    no file '/usr/local/lib/lua/5.2/mjolnir/fnutils.so'
    no file '/usr/local/lib/lua/5.2/loadall.so'
    no file './mjolnir/fnutils.so'
    no file '/usr/local/lib/lua/5.2/mjolnir.so'
    no file '/usr/local/lib/lua/5.2/loadall.so'
    no file './mjolnir.so'
/Users/rileyshaw/.mjolnir/init.lua:26: attempt to index local 'grid' (a string value)
stack traceback:
    /Users/rileyshaw/.mjolnir/init.lua:26: in main chunk
    [C]: in function 'xpcall'
    /Applications/Mjolnir.app/Contents/Resources/setup.lua:73: in main chunk

The README specifies that Lua 5.2 should be used, but it's getting difficult; brew doesn't have a lua@5.2 package, and depends on 5.3. I would have to build Lua and luarocks from source, but that would likely conflict with the version brew requires.

I saw FAQ 4 and tried adding various 5.3 paths, but the packages aren't installing anywhere that Mjolnir expects them:

find . -type f | grep fnutils.lua
./Cellar/lua/5.3.4_2/share/lua/5.3/mjolnir_fnutils_0_1_1-mjolnir/fnutils.lua

If it's useful, here's my init.lua:

local griderr, grid  = pcall(function() return require "mjolnir.bg.grid" end)
local windowerr, window = pcall(function() return require "mjolnir.window" end)
local hotkeyerr, hotkey = pcall(function() return require "mjolnir.hotkey" end)
local alerterr, alert = pcall(function() return require "mjolnir.alert" end)
local fnutilserr, fnutils = pcall(function() return require "mjolnir.fnutils" end)

function print_if_not_table(var)
    if not(type(var) == "table") then print(var) end
end

if not griderr or not windowerr or not hotkeyerr or not alerterr then
    mjolnir.showerror("Some packages appear to be missing.")
    print("At least one package was missing. Have you installed the packages? See README.md.")
    print_if_not_table(grid)
    print_if_not_table(window)
    print_if_not_table(hotkey)
    print_if_not_table(alert)
    print_if_not_table(fnutils)
end

mash = {"cmd", "alt", "ctrl"}
MARGIN = 2
GRIDWIDTH = 12
GRIDHEIGHT = 9

grid.MARGINX = MARGIN
grid.MARGINY = MARGIN

-- ternary if
function tif(cond, a, b)
    if cond then return a else return b end
end

function reset_granularity()
    grid.GRIDWIDTH = GRIDWIDTH
    grid.GRIDHEIGHT = GRIDHEIGHT
end

reset_granularity()

function change_granularity(iswidth, delta)
    if iswidth then
        grid.GRIDWIDTH = grid.GRIDWIDTH + delta
    else
        grid.GRIDHEIGHT = grid.GRIDHEIGHT + delta
    end

    alert.show(grid.GRIDWIDTH.." x "..grid.GRIDHEIGHT)
end

function centerpoint()
    w = grid.GRIDWIDTH - 2
    h = grid.GRIDHEIGHT - 2
    return { x = 1, y = 1, w = w, h = h }
end

function fullheightatcolumn(column)
    return { x = column - 1, y = 0, w = 1, h = grid.GRIDHEIGHT }
end

function ifwin(fn)
    return function()
        local win = window.focusedwindow()
        if win then fn(win) end
    end
end

local grid_shortcuts = {
    R = mjolnir.reload,
    [";"] = ifwin(grid.snap),
    up = ifwin(grid.pushwindow_up),
    left = ifwin(grid.pushwindow_left),
    right = ifwin(grid.pushwindow_right),
    down = ifwin(grid.pushwindow_down),
-- 4 reserved for OSX screenshot
    A = ifwin(grid.resizewindow_thinner),
    D = ifwin(grid.resizewindow_wider),
    W = ifwin(grid.resizewindow_shorter),
    S = ifwin(grid.resizewindow_taller),
    space = ifwin(grid.maximize_window),
    F = ifwin(grid.pushwindow_nextscreen),
    C = ifwin(function(win) grid.set(win, centerpoint(), win:screen()) end),
    H = function() change_granularity(true, 1) end,
    J = function() change_granularity(false, 1) end,
    K = function() change_granularity(false, -1) end,
    L = function() change_granularity(true, -1) end,
-- Q reserved for Sip
    ["0"] = function() reset_granularity() alert.show(GRIDWIDTH.." x "..GRIDHEIGHT) end
}

for key, func in pairs(grid_shortcuts) do
    hotkey.bind(mash, key, func)
end

alert.show(" 🎩\n 💀")

Thanks! I really hope to get this working again..

thesoftwarephilosopher commented 6 years ago

This sounds like a Homebrew issue. They shouldn’t have just removed Lua 5.2 entirely. Some packages depend on it. I’ll check out their issues later and try to track down the source of this and file a new issue if need be.

thesoftwarephilosopher commented 6 years ago

Created Homebrew/homebrew-core#24409 to open this discussion.

rileyjshaw commented 6 years ago

Looks like there's a response on Homebrew/homebrew-core#24409 - any thoughts?

thesoftwarephilosopher commented 6 years ago

They closed the discussion based on policy. We have two choices moving forward: upgrade Mjolnir to Lua 5.3, or add a custom tap for Lua 5.2 and encourage new users to install that. I think the first one makes more sense, but is a bit more likely to cause some breakage.

thesoftwarephilosopher commented 6 years ago

Just opened #570 to take the place of this issue.

jbenet commented 6 years ago

ran into this issue on a fresh install.

i set up the following symlinks (bad hack, don't do it if you use other lua things) and worked for my simple config:

/usr/local/lib/lua/5.2 -> 5.3
/usr/local/lib/luarocks/rocks-5.2 -> rocks-5.3
/usr/local/share/lua/5.2 -> 5.3