lunarmodules / Penlight

A set of pure Lua libraries focusing on input data handling (such as reading configuration files), functional programming (such as map, reduce, placeholder expressions,etc), and OS path management. Much of the functionality is inspired by the Python standard libraries.
https://lunarmodules.github.io/Penlight/
MIT License
1.93k stars 242 forks source link

Single file version of penlight? #390

Open kalekje opened 3 years ago

kalekje commented 3 years ago

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

catwell commented 3 years ago

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.

myselfghost commented 2 years ago

@catwell Can you show how to do it?

daurnimator commented 2 years ago

Another tool for this is squish

catwell commented 2 years ago

@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...

myselfghost commented 2 years ago

@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

kalekje commented 2 years ago

@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'.

alerque commented 2 years ago

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.

kalekje commented 2 years ago

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.