[tex-live] Package preparation question (directory structure)

Urs Liska ul at openlilylib.org
Mon Sep 9 01:33:10 CEST 2013


Am 09.09.2013 01:15, schrieb Urs Liska:
> Am 08.09.2013 00:25, schrieb Karl Berry:
>
>>
>>      Exactly, this is 'import'ed by the other scripts.  I do not see why
>>      this complicates things,
>>
>> Because the gen*Command scripts will be in the bin/ directory, but
>> lilyglyphs_common.py should not be, since it's not meant to be invoked
>> directly.  PATH directories should not be cluttered with
>> non-user-level-executables.
>>
>> ...
>>
>> I think the most reliable way to find it is by running something like
>> (sh-ish syntax for example):
>> com=`kpsewhich --progname=lilyglyphs --format=texmfscripts 
>> lilyglyphs_common.py`
>> And then read in $com.  I don't know how hard or easy that may be in the
>> Python world.
>
> I had suspected that kind of thing should _not_ be too hard in the 
> Python world, and it seems I was right :-)
> Although I probably wouldn't have easily found out about the exact 
> kpsewhich call.
>
> import os, sys
> # import common library, depending on its location
> scr_path, scr_name = os.path.split(sys.argv[0])
> if not 'lilyglyphs_common.py' in os.listdir(scr_path):
>     # the library is not in the same dir as the script
>     # so we assume we're in a TeX installation.
>     try:
>         # use TeX's kpsewhich tool to locate the library file
>         # in the TeX installation
>         import subprocess
>         lib = subprocess.check_output(["kpsewhich",
>                                        "--progname=lilyglyphs",
>                                        "--format=texmfscripts",
>                                        "lilyglyphs_common.py"])
>     except:
>         print '\nCommon library \"lilyglyphs_common.py\" not found.'
>         print 'Please refer to the manual for possible solutions.'
>         sys.exit(2)
>     # add the found path to Python's search path
>     sys.path.append(os.path.split(lib)[0])
> import lilyglyphs_common
>
> What I did to verify is:
> - rename the lib in my project folder (so it isn't found by default)
> - copy it to texmf-dist/scripts/lilyglyphs/lilyglyphs_common.py in my 
> TeXLive installation (Linux)
> - run texhash
> - run the above code
>
Oh my, now I _do_ have to ask back already with two questions:

a)
where should I place the common library file(s, because they will 
probably become more than one, once I continue making the Python stuff 
more generic and versatile)?
You say they would go to texmf-dist/scripts (in TL), but should I put 
all scripts in the scripts/ directory? And how would you then know to 
differentiate between user-callable and library scripts?
b)
kpsewhich only seems to find the library when it is stored in the 
texlive installation directory, and not if it is located in my personal 
~/texmf tree. Is there a way around that (because TeX finds anything 
there but Python surely not)?
As it stands I see:
- directory structure from my Git repository:
   library is a sibling of the script and is directly found
- TeX distro installation:
   library is found through kpsewhich
- Installation from CTAN zip:
   library is in a different directory but not found through kpsewhich.
   I only see the option to introduce a different check and determine 
the relative path (-> '../source')

Any recommendations?

Best
Urs


More information about the tex-live mailing list