-
-
Notifications
You must be signed in to change notification settings - Fork 101
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
De-conflate script & require #1385
Comments
c.f. #1373 |
On the same vein of ideas, we might perhaps want some way to know whether a package is loaded (rather, e.g. than testing if one of its command exists)? |
Technically that is already possible using Lua idoms: the ./sile -e 'SU.dump(pl.tablex.keys(package.loaded));os.exit()' For example you could test to see if a package is loaded: -- truthy in anything derived from the plain class:
package.loaded["packages/bidi"]
-- falsey out of the gate
package.loaded["packages/rebox"]
-- truthy after required
SILE.require("packages/rebox")
package.loaded["packages/rebox"] This has several pitfalls though:
All that to say "yes", I agree we should probably have a standardized API for querying "is X package loaded in the current document class", and possibly also a standardized API for querying a loaded package to ask whether it is active/inactive/etc. |
I think dealing with Instead starting in #1373 I started adding much more explicit commands and options that do much more predictable things. For example An upcoming Currently no plan to deprecate |
|
The I wouldn't mind |
That's a path to As for package unloading, the problem I have with it is that it is not something I expect to use frequently. I mean, the only use case might be documentation (where we may want to load a package, demonstrate, unload it), but for 99% of real usages (producing content), this will not occur. I also fear that the pattern could be abused e.g. I unload a package that was a dependency of some other package, it will likely have hard-to-debug side effects. In other terms, I am not sure package unloading should even be exposed as a SIL command. It's something that could stay internal (e.g. autodoc could use it), but not exposed in the wild... Also, outside documentation, it doesn't seem to me it addresses any obvious end-user need so far. |
No it isn't. It's a module name that will get processed though a long string of fallbacks including Lua's |
Then...
|
(Or even EDIT: or even |
It this point I'm headed toward forcing things like "packages/" in the path for the more automatic functions. I expect 3rd party packages to be able to add more than just strictly packages: they can add classes or inputters or shapers or typesetters or whatever. Not having some structure to those things would make the internal interfaces very complex and brittle. Assuming if we want to load a shaper that it will be found in a Having this distinction will also make it easier to do things like test if a package is loaded, if we are in a certain class, which shaper is active, etc. Why does |
P.S. I thought about |
Sometimes we have things with colons, e.g. I don't want to be rude either, but I don't get what's so important for end-users to invoke |
The importance here is that the user needs some control over whether what they are loading is loaded using the SILE package path and a module loader or directly from a file system path, and also whether what they are running is a loader (as in I've had trouble with my own projects because it was guessing wrong and had to override SILE internals. I shouldn't have had to do this, hence why I am looking for more explicit alternatives to cover at least some of the 4 scenarios with more targeted tooling. |
I'm pretty convinced of the need for more specific commands that one multi-purpose Since I expect to be able to load more than strictly packages (e.g. shapers or typesetters or outputters, perhaps While not currently implemented by any packages, using the content field to pass a module name keeps our options open to pass options like this:
|
You said it all here. ^^ |
If I had, I was wrong. I was initially going to say I didn't understand how packages could be expected to take advantage of a feature we hadn't given them access too yet, but it turns out even that would have been wrong. We did expose this and some packages did implement it—one example is the autodoc package which accepts theme values only on initialization. The caveat was we didn't expose any way to pass these values from SIL markup. It was reachable via Lua if you loaded the package yourself, but not if you loaded it from declarative document markup. The remaining naming choice I think we have to make is whether to have separate loaders for different module types or one common one.
Of course in both these "use" could be "load" or something else as well, but the principle of having one generic command vs. multiple special purpose ones is the question here in my mind. |
To answer my own question, after playing around with both "option 1" has a significant advantage of not locking users into the file layout we picked and allowing them to load a package from something other than a |
One more thinking between
There are already cases where we conflate the two of them. E.g. while giving a thought to the indexer, I frowned at Both are workable, but one feels more natural to me (and that's not the one using the content). |
Very good point. Thanks for taking the time to try to convince me. We can't immediately fix the existing instances without more breaking changes, but heading towards a future where I'll have another go at this with that in mind. It will make it a little more awkward to separate and pass arguments to modules we load up, but maybe that's a reasonable price to pay. I'm still sorting through options for how to read Lua input too. So far we have the ability for a Lua script to:
Right now the The new Without immediately breaking every project out there I think we need to steer people away from the last of those for most use cases. There are valid use cases for it and for the foreseeable future it will still be an option, but the more people try to do with it that could be done with one of the other mechanisms the harder is going to be to get them upgraded when SILE is fully modular and well enough compartmentalized to start swapping in modules in other languages (C, Rust, etc.). I want it like it is now so that any component may be replaced dynamically from Lua, but with each component being self contained with known inputs and outputs. Once we stop relying on so many globals and side effects ourselves we can reasonably start swapping components. Avoiding globals and side effects will also make it much easier to tease out bugs. It is VERY difficult right now to even reason about or inspect what the typesetter is doing to figure out our long standing push back bugs because there are so many side effects going on it defies inspection. |
Current thought:
Some commands might optionally take either (but not both) of these, but the path handling expectation should be stricter than it is now (i.e. no automatic fallback to the other if one fails). |
That's a part of the problem, which I tried to discuss earlier (on the issue related to TOC and PDF bookmarks), but things sometimes need time to mature (and it also took me time, either, to understand these): The Take, e.g. a Mardown title:
This would, likely end up as some equivalent of Now, one expects to be able to have a link to that section. What Pandoc and others offer is an implicit hash such as "why-italics-are-important". Say we want this, i.e. The |
The current iteration in #1482 has Also I introduced |
On the Lua side of this we are fine, but on the SILE
\script
side we have conflated two different operations:require
anddofile
are fundamentally different and we should have both. So far we keep using\script[src=package/foo]
as if running a script was the same as loading a library, but it is not. Loading a library happens once and then even running it again will have (or should have) no effect. On the other hand a document should be able to execute an external script more than once and have it run all over again.I think we need to unscramble this and make the
\script[src=...]
always re-execute the external code (previously loaded or not) and add a new\require
or\package
or something to that effect that runsSILE.require()
.The text was updated successfully, but these errors were encountered: