Hi,

I'm still working on the same project (an extraction script for the memoize 
package written in (tex)lua (see [1])). Now in the python version of that 
script there is that function `find_out` which is supposed to find a proper 
location for an output file. I see, the analog thing for input files can be 
done via `kpse.find_file` but I cannot find something implementing this for 
input files (which do not exist yet).
At first I thought, this function may be a bit weird, why not just directly use 
the path and why search multiple locations where to place this file, but 
according to the author [2], this is how TeX does writing output files as well 
(I wouldn't know as I'm not that deep into TeX stuff in this regard).
Therefore, if this is such a standard routine, I suspected there might be a 
similar function somewhere in the libraries included in luatex, but I can't 
find one. Am I just not good enough at searching, or is such a function just 
not available and I need to write it myself (again needing to implement more 
and more functions regarding pathutil stuff)?

For reference, the python implementation I'm speaking of [3]:

# This function finds the location for an output file, respecting
# |TEXMF_OUTPUT_DIRECTORY| and |TEXMFOUTPUT|, and the permissions in the
# filesystem.  It returns an absolute file as-is.  For a relative file, it
# tries |TEXMF_OUTPUT_DIRECTORY| (if defined), the current directory (unless
# |TEXMF_OUTPUT_DIRECTORY| is defined), and |TEXMFOUTPUT| directory (if
# defined), in this order.  The first writable file found is returned; if no
# writable file is found, the file in either the current or the output
# directory is returned.
def find_out(f):
    sanitize_filename(f)
    if f.is_absolute():
        return f
    for df in (texmf_output_directory / f if texmf_output_directory else None,
               f if not texmf_output_directory else None,
               texmfoutput / f if texmfoutput else None):
        if df and access_out(df):
            return df
    return texmf_output_directory / f if texmf_output_directory else f



With kind regards
Lukas


[1]: https://github.com/atticus-sullivan/memoize/tree/feat-texlua-script
[2]: https://github.com/atticus-sullivan/memoize/pull/2#issuecomment-2602732069
[3]: 
https://github.com/sasozivanovic/memoize/blob/ea88a43c3c7af71c9470b7d5e124dd236ea7f90c/memoize-extract.py#L218

Reply via email to