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

Allow pub_file (now pub_file_info) to be a dictionary of pub_vars #2404

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

oscarlevin
Copy link
Member

This is an add on to the draft PR of @ascholerChemeketa (#2403) which would allow the CLI or other front ends to be in charge of maintaining the publisher variables dictionary.

@rbeezer
Copy link
Collaborator

rbeezer commented Mar 4, 2025

#2403 is merged, so this could get sorted now. Thanks.

@oscarlevin oscarlevin marked this pull request as ready for review March 4, 2025 22:21
@oscarlevin
Copy link
Member Author

Okay, this is all fixed up as a single commit. I think it is quite clever, but understand if you think it's too clever.

Summary of changes:

  • The big idea: the pub_file variable that is in the signature of almost every function here is changing from a string (a path to the publication file) to either a string or dictionary.
    • If it is a string, then everything works as before.
    • If it is a dictionary, then one of the keys in the dictionary will be "publisher" with value the string-type path to the publication file.
  • To remind us of this, variable name has changed from pub_file to pub_file_info.
  • There are three ways we currently use the pub_file:
    1. Add it's path to stringparams. This is now done with the function add_pub_file_to_params() which checks if the type is a dictionary or string and does the right thing accordingly.
    2. Use the get_publisher_variable_report() to create a dictionary of pub_vars and then get_publisher_variable() to get the value of a particular variable. All instances of the former have been replaced with ensure_publisher_variables() which either does nothing (if already a dictionary) or calls get_publisher_variable_report().
    3. Use lxml to parse the publication file directly. This happens in two places: as part of the braille conversion and part of the get_managed_directories() function. I think in both cases these could be refactored to use the get_publisher_variable() function, but until then, we define pub_file to be the path appropriately.

Why all this? It is to address the Runestone use case of starting a worker to runs pretext, through the CLI's API. Previously this was a problem because as soon as the pub_vars dictionary was created, that would either persist between book builds, or (core) pretext would need to rebuild the dictionary for every step of building a book (generating each asset and building output). With this change, the CLI can create pub_file_info as a dictionary once for each book and use that in all the build/generate steps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants