pretext icon indicating copy to clipboard operation
pretext copied to clipboard

FITB: fix host-platform for extracting dynamic substitutions

Open dbrianwalton opened this issue 6 months ago • 10 comments

When trying to build a complete target (e.g. sample-book) for runestone, the CLI calls the extract dynamic substitutions routine with the target platform as runestone. However, the stand-alone pages that are produced for extraction are actually being hosted locally and so need to use host-platform as web.

Modified pretext.py to override the stringparam for host-platform for this call.

dbrianwalton avatar Jun 12 '25 20:06 dbrianwalton

Question: Should I have made a copy of the stringparams and modified the entry in a copy? I just realized that the CLI isn't calling the pretext/pretext script for each resource — it is sequentially calling internal functions with the stringparams as it works through the resource list. So modifying the stringparams internally in the dynamic_substitutions function may have a downstream side-effect.

@oscarlevin might have insight on this

dbrianwalton avatar Jun 13 '25 12:06 dbrianwalton

@dbrianwalton when I looked at your PR my first thought was, II hope the stringparam dictionary isn't global so that this messes up later actions. My hunch is you should make a copy.

bnmnetp avatar Jun 13 '25 13:06 bnmnetp

Thanks @bnmnetp for confirming.

dbrianwalton avatar Jun 13 '25 13:06 dbrianwalton

Yes, almost(?) all the functions that manipulate the stringparams make a copy first

oscarlevin avatar Jun 13 '25 14:06 oscarlevin

Oscar and I were just chatting during drop in... Is generating dynamic substitutions for a Runestone build even necessary? If so, then Oscar will want to add a check to ensure that playwright is installed.

bnmnetp avatar Jun 16 '25 15:06 bnmnetp

I really don't think it should be required for Runestone since that is a dynamic build, not a static build. It shouldn't really be required for a web build either. During the assembly pre-processor stage presumably while numbering is being generated, the extractions are being looked at (because it is a layer in the assembly for a static build) but never actually used. So if dynamic substitutions are not present, there would be some warnings generated but I don't think it interrupts the process.

dbrianwalton avatar Jun 16 '25 16:06 dbrianwalton

I just tried to build sample-book with pretext/pretext/pretext (not CLI) with the substitutions were not available. I used the noparts publication file with format html and platform runestone and I didn't see that it ever looked for the substitutions. Maybe I was remembering something else. [When I tried using the runestone publication file, my installation choked on something related to a custom theme, which is why I tried noparts]

dbrianwalton avatar Jun 16 '25 16:06 dbrianwalton

What would be helpful in terms of the CLI is to know which formats really require the dynamic_substitution function to run. Currently this is set up to be required for all formats. But if we can remove it from HTML, that would be great.

On Mon, Jun 16, 2025 at 10:37 AM dbrianwalton @.***> wrote:

dbrianwalton left a comment (PreTeXtBook/pretext#2557) https://github.com/PreTeXtBook/pretext/pull/2557#issuecomment-2977310205

I just tried to build sample-book with pretext/pretext/pretext (not CLI) with the substitutions were not available. I used the noparts publication file with format html and platform runestone and I didn't see that it ever looked for the substitutions. Maybe I was remembering something else. [When I tried using the runestone publication file, my installation choked on something related to a custom theme, which is why I tried noparts]

— Reply to this email directly, view it on GitHub https://github.com/PreTeXtBook/pretext/pull/2557#issuecomment-2977310205, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABRUBFAKVVHY4DOLGN3P2JL3D3XEJAVCNFSM6AAAAAB7GNRJKCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSNZXGMYTAMRQGU . You are receiving this because you were mentioned.Message ID: @.***>

oscarlevin avatar Jun 16 '25 19:06 oscarlevin

The dynamic formats, html and runestone, do not need the substitutions because they run the actual javascript.

All static formats (everything else?) will need the substitutions.

dbrianwalton avatar Jun 16 '25 19:06 dbrianwalton

Perfect. Then I'll make the change for the CLI so there will be no need for playwright on Runestone builds.

On Mon, Jun 16, 2025 at 1:49 PM dbrianwalton @.***> wrote:

dbrianwalton left a comment (PreTeXtBook/pretext#2557) https://github.com/PreTeXtBook/pretext/pull/2557#issuecomment-2977906778

The dynamic formats, html and runestone, do not need the substitutions because they run the actual javascript.

All static formats (everything else?) will need the substitutions.

— Reply to this email directly, view it on GitHub https://github.com/PreTeXtBook/pretext/pull/2557#issuecomment-2977906778, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABRUBFET4MHOXVCD5Y22BVT3D4NV3AVCNFSM6AAAAAB7GNRJKCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSNZXHEYDMNZXHA . You are receiving this because you were mentioned.Message ID: @.***>

oscarlevin avatar Jun 16 '25 19:06 oscarlevin

We (@bnmnetp and @sean-fitzpatrick and I) just discovered that even though the dynamic substitutions are not needed in Runestone, the dynamic_substitutions.xml file apparently is for the preprocessor to generate other assets. I'll follow up on the -dev thread here: https://groups.google.com/g/pretext-dev/c/Ij8TJdKxX6U/m/zxSigmr-AgAJ

oscarlevin avatar Jun 27 '25 15:06 oscarlevin

This PR got hung up because I would like the copy authored identically to the numerous other places where it is routinely done. In the extreme (not now) it could be a utility function. Brian and I discussed this in Drop-In, but I may not have been clear enough.

rbeezer avatar Jun 27 '25 22:06 rbeezer

Yes, @oscarlevin, this file should only be consulted for output formats with "dynamic" exercise styles, which means broadly interactive, not Brian's use of the word dynamic. And only consulted if the source has any of Brian's FITB exercises.

In other words, JS-enabled HTML output formats only.

rbeezer avatar Jun 27 '25 22:06 rbeezer

Sorry, @rbeezer, I did misunderstand. I had copied what was being done in the cli. I'll shortly push another commit that matches the pretext.py model.

dbrianwalton avatar Jun 28 '25 00:06 dbrianwalton

Thanks, @dbrianwalton. Sorry to be picky - it just helps to make maintenance easier and thus makes the code less buggy.

rbeezer avatar Jun 28 '25 00:06 rbeezer

It should look much cleaner now.

dbrianwalton avatar Jun 28 '25 00:06 dbrianwalton

Yes, thanks for the quick work. Should be able to merge soon after I am back home. Landing right now

rbeezer avatar Jun 28 '25 00:06 rbeezer

OK, down to a copy, and then a reset on the host platform, so we aren't all mixed-up with Runestone id's. Thanks for working this one out.

Still need to sort out the dynamic and static variants of the various extraction templates.

rbeezer avatar Jun 28 '25 22:06 rbeezer