-
Notifications
You must be signed in to change notification settings - Fork 45
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
Extend \includescore #58
Conversation
Behavior Change: \includescore#1 now performs the following checks: -- If #1 is a `gabc` file and there already is an `-auto.gtex` file then gregoriotex will check the api version of the gtex file for compatibility and recompile the `gabc` file if necessary. -- If #1 is a `gtex` file then gregoriotex will: -- check for a `gtex` file and if none exists then compile one from a `gabc` file if that exists. -- check the api version of the `gtex` file for compatibility and recompile the `gabc` file if necessary. -- compare the timestamp of the `gtex` file against the `gabc` file and recompile if the `gtex` is older. Note: #1 should either end with .gabc or .gtex
Your solution will work and we can merge it for now, but I fear it's not the most efficient: in case of a .gtex file with the correct version (which we can consider the most common case), it opens it twice: once to check the version, then once to really include the score, which is quite inefficient (file input/output is quite costy in most computers). On short documents, it might get unnoticed, but on big documents (Gregorio is used on documents of over 1000 pages) it will certainly make a difference. I see two solutions for this:
What do you think? |
Concerning point two: I did a quick test. As the code is in this commit my test file runs in
With your suggestion to read the whole file and pass it to tex:
Quite a big difference for such a small test file. I need to look closer at your first solution to see when it would be best to check api version. |
if gtex_timestamp < gabc_timestamp then | ||
gregoriotex.compile_gabc(gabc_file, gtex_file) | ||
else | ||
log("using the file %s without recompiling, as %s hasn't changed since last compilation.", gtex_file, gabc_file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This log message isn't entirely true, because you won't know if you're actually using the file until you've checked the api version. Perhaps delete everything up to the comma?
Brainstorm thought. Applications often have a "Version Number" property. Could this sort of thing be applied here to prevent us having to open the file to check its API version? If Gregorio could set a file property to the API version number, then the lua script wouldn't need to open the file. |
@rpspringuel do you mean some sort of file metadata ? It doesn't seem possible here... but the idea is good, here are two possibilities to go in your direction:
What do you think? |
I reworked the api test in lua. The meta-data idea is interesting. Or we could let @eroux Putting the API in the filename, simple. But then do we require all gtex files to be autogen? |
@eschwab I was originally thinking about your first solution, but maybe the new ideas are a bit cleaner... I admit I have to dig a little more in the changes you did to have a clearer view of what's happening in the different cases... but the philosophy is: keep old documents compiling (maybe less efficiently, with a warning), and make new documents compile in the best way (and autogenerating everything seems a good solution)... |
My goal was to reduce the i/o to once per score either with reading the entire file in lua then passing it to tex with |
@eroux, I was referring to file metadata. I don't know how, or even if, C can write metadata to a file, but it seems that if we're worried about processing overhead, then we should avoid reading the file until we know it's good if at all possible. If metadata per se isn't possible, then replacing the "auto" in the file name with the API version is a decent substitute. |
Eureka! (I was in the shower when I thought of this, so it's appropriate.) The API version number is a date. Check the gtex file modification date against it. If the modification date is before the date in the API version number then it's out of date and needs to be recompiled. No need to manipulate any metadata that isn't already being set and checked. |
Humm, I don't want to hijack the file creation date. That sounds like trouble. But to check fhe date against the API version, brilliant. I'll look into that. |
That is a lot cleaner now. Using the file modification date works nicely. |
Hijacking the creation date is just terrible, this means that people (like me) who sort their file list (in their file explorer) by date will have everything broken... Comparing with the creation date works in many cases, but there still need to be a mechanism for files having wrong dates: it's perfectly possible for someone to use an old version of gregorio in a recent date... But I don't think we should worry too much for these optimizations, as the double I/O operations will take place only the first time the document is compiled against a new version, not every time, I don't think it's a big problem if one compilation every year is a bit slower than usual... What do you think? |
In the case of a bad creation date that lua thinks is fine there is still a backup check in |
To be honest, I believe eschwab@fd2966c is quite a regression... it will speed up a little when upgrading Gregorio, but will prevent autogeneration in the following (very common) case:
while in this common case, the state before the commit was ok for him, even though it took a bit longer to upgrade to a recent Gregorio for people upgrading Gregorio everyday (which is not at all the majority of users)... What do you think? Or is there something I didn't understand? |
@eroux has a good point. While checking the modification date will catch use cases where someone is resurrecting an old project, it won't catch use cases where the upgrade wasn't on the API release date. It seems that unless we can find a way to attach the API version number itself to the file metadata, then we're going to have to look inside the file to see what it is. In that instance, eschwab@ 0a08835 was a pretty good go. Guess my "Eureka" wasn't much of one. |
Here is where I think we are at:
Now a solution I see is to change the syntax of
Then It may then be a good idea to change the default output filename of gregorio from How does all of this effect the compiling of old projects? I don't think there should be a problem as long as the user still has the gabc files in the same dir. Thoughts? |
I agree, thought there should still be a way to include a .tex file directly (without automatic compilation, like current behaviour) for users with specific needs... But on the overall yes, I think it will improve user experience! |
Well if a user does |
I realize this isn't how gregoriotex currently behaves, but what's wrong with just asking users to use |
Juste in case we need to wrap input into something else... It never harms to have a bit of abstraction... |
Perhaps, then a optional argument that forces inclusion? I.e. |
Why not, though it's not really easy to do in plain TeX (but it should be feasible) |
Edit: Opps. For got an |
NEW BEHAVIOR: The behavior of `\includescore` has changed. It now has an optional argument. When called without the optional argument i.e. `\includescore{antiphon}`: -- Gregoriotex will now check for the existence of antiphon-APIVERSION.gtex. If that file does not exist it will be compiled from antiphon.gabc. -- If antiphon-APIVERSION.gtex exists, the APIVERSION will be checked against the current gregoriotexapiversion. If there is a mismatch, antiphon.gabc will be recompiled. -- antiphon-APIVERSION.gtex will be checked against the modification time of antiphon.gabc. The gabc will be recompiled if newer than the gtex. -- APIVERSION is a number automatically added by gregoriotex. When called *with* the optional argument i.e. `\includescore[f]{antiphon.gtex}`: -- The file will be immediately passed to TeX. No checks will be made until the one in `\gregoriotexapiversion`. -- The value of the optional argument can be anything. `[f]` is recommended, signifying `Forced`.
Changed due to the refactoring of `\includescore`.
Refactor NEW BEHAVIOR: The behavior of When called without the optional argument -- Gregoriotex will now check for the existence of -- If antiphon-APIVERSION.gtex exists, the APIVERSION will be checked -- antiphon-APIVERSION.gtex will be checked against the modification -- APIVERSION is a number automatically added by gregoriotex. When called with the optional argument -- The file will be immediately passed to TeX. No checks will be made -- The value of the optional argument can be anything. The only issue I see is that eventually there may be a little collection of outdated |
Thank you very much! About the outdated files, you're right, I think they should be removed... Otherwise it seems fine to me! |
Right now I can't think of a good way to cleanup the outdated files, in lua atleast. |
I might be a bit costy, but when the file with the correct api version is not found, you could remove all |
If I'm thinking correctly, this should do it. |
If it works, then it's perfect! |
From what my tests,
but I am wondering if that is portable between *NIX, Mac, Windows. |
That won't be portable to Windows because Windows doesn't have an rm command. To get something portable you need to avoid To get past the wildcard problem, you might try bringing the list of files in the directory into lua, using lua to identify which filed in the list need to be deleted, and then issuing separate |
You'll find some help in here for this, you can \RequirePackage{lualibs} to use it. |
I received an unexpected assignment. I will not have time to tackle this last issue for a week or two. |
No problem, thank you very much for your work, I'm merging the current state, even if it's not 100% finished. |
Thank you both for the ideas and critiques. |
Continuation of #53
Behavior Change: \includescore#1 now performs the following checks:
-- If #1 is a
gabc
file and there already is an-auto.gtex
filethen gregoriotex will check the api version of the gtex file for
compatibility and recompile the
gabc
file if necessary.-- If #1 is a
gtex
file then gregoriotex will:gtex
file and if none exists then compile one froma
gabc
file if that exists.gtex
file for compatibility andrecompile the
gabc
file if necessary.gtex
file against thegabc
fileand recompile if the
gtex
is older.Note: #1 should either end with .gabc or .gtex
If someone could test, I'm not 100% sure of this. I don't think I tested all the possible use cases of
\includescore
.