Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single file version of penlight? #390

Open
kalekje opened this issue Sep 20, 2021 · 8 comments
Open

Single file version of penlight? #390

kalekje opened this issue Sep 20, 2021 · 8 comments

Comments

@kalekje
Copy link
Contributor

kalekje commented Sep 20, 2021

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
Copy link
Member

catwell commented Sep 20, 2021

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
Copy link

@catwell Can you show how to do it?

@daurnimator
Copy link

Another tool for this is squish

@catwell
Copy link
Member

catwell commented Dec 1, 2021

@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
Copy link

@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
Copy link
Contributor Author

kalekje commented Dec 1, 2021

@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 kalekje closed this as completed Dec 26, 2021
@alerque
Copy link
Member

alerque commented Dec 27, 2021

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
Copy link
Contributor Author

kalekje commented Dec 27, 2021

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 kalekje reopened this Dec 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants