Penlight icon indicating copy to clipboard operation
Penlight copied to clipboard

Single file version of penlight?

Open kalekje opened this issue 2 years ago • 8 comments

I'm sorry that this isn't an issue per se but more of a query. I am looking into deploying penlight as a LaTeX library, however most TeX distributions prefer a small number of files and non generic (ie. init.lua in penlight would be problematic). Ideally, a single file version of penlight would solve this problem. Just curious if anyone here has merged the penlight modules into a single file, or has had luck using any existing tools (amalg, many2one)?

Thank you

kalekje avatar Sep 20 '21 16:09 kalekje

Quite some time ago I packed a subset of Penlight along with other Lua modules using https://github.com/mihacooper/luacc and I think it should still be reasonably easy to do something like this if you need to.

catwell avatar Sep 20 '21 17:09 catwell

@catwell Can you show how to do it?

myselfghost avatar Dec 01 '21 02:12 myselfghost

Another tool for this is squish

daurnimator avatar Dec 01 '21 03:12 daurnimator

@catwell Can you show how to do it?

Yes, here is an example for just stringx (which depends on utils and compat).

First (this is a trick because luacc expects a main script) create a file that just contains do end, call it empty.lua and put it the lua directory of Penlight sources (there are other solutions, this is the simplest to explain).

Then run:

lua bin/luacc.lua \
    -o penlight-amalg.lua -i "/path/to/Penlight/lua" \
    "empty" "pl.compat" "pl.utils" "pl.stringx"

You can now do this:

Screenshot from 2021-12-01 09-48-09

luacc won't do any automagic dependency resolution, you have to do it manually, but I personally prefer this as it makes the build more robust...

catwell avatar Dec 01 '21 08:12 catwell

@catwell Can you show how to do it?

Yes, here is an example for just stringx (which depends on utils and compat).

First (this is a trick because luacc expects a main script) create a file that just contains do end, call it empty.lua and put it the lua directory of Penlight sources (there are other solutions, this is the simplest to explain).

Then run:

lua bin/luacc.lua \
    -o penlight-amalg.lua -i "/path/to/Penlight/lua" \
    "empty" "pl.compat" "pl.utils" "pl.stringx"

You can now do this:

Screenshot from 2021-12-01 09-48-09

luacc won't do any automagic dependency resolution, you have to do it manually, but I personally prefer this as it makes the build more robust...

thank you very much

myselfghost avatar Dec 01 '21 08:12 myselfghost

@myselfghost feel free to download penlight.lua from here: https://github.com/kalekje/penlight

Otherwise, I had luck following these steps.

  1. Download the luacc (https://github.com/mihacooper/luacc) repo and all dependencies with either luarocks or just unzipping the packages the same working folder (what I did)
  2. Make a file penlightReturnImportInto.lua contain this line of code: return require('pl.import_into')()
  3. Run this command (on windows, NOTE, I use the lualatex/texlua distribution. You should have luck replacing it with lua): texlua luacc.lua -o penlight.lua penlightReturnImportInto pl.xml pl.app pl.array2d pl.class pl.compat pl.comprehension pl.config pl.data pl.Date pl.dir pl.file pl.func pl.import_into pl.init pl.input pl.lapp pl.lexer pl.List pl.luabalanced pl.Map pl.MultiMap pl.operator pl.OrderedMap pl.path pl.permute pl.pretty pl.seq pl.Set pl.sip pl.strict pl.stringio pl.stringx pl.tablex pl.template pl.test pl.text pl.types pl.url pl.utils

After you have penlight.lua, as long as it's in path, useage is simply pl = require'penlight'.

kalekje avatar Dec 01 '21 12:12 kalekje

Adding a build rule to the Penlight sources for a single-file version is something I would consider if you want to keep this open. There is probably still room for your LuaLaTeX specific packaging repo, but a single file version could have other utility and building it in CI and attaching it to releases is something we could look into.

alerque avatar Dec 27 '21 14:12 alerque

Okay I can re-open it--I had closed it because I found a solution, but it does seem like there is some general interest in this.

kalekje avatar Dec 27 '21 16:12 kalekje