Hi Uwe,
On Thu, Nov 12, 2009 at 9:47 AM, Uwe Stöhr <[email protected]> wrote:
> I'm confused now. Alex, can you please tell me why the version that we
> currently have in trunk don't work for you?:
Sure. It doesn't work because it tries to run eLyXer as a script, and
the script is nowhere to be found. On my Debian machine:
$ python -tt elyxer
python: can't open file 'elyxer': [Errno 2] No such file or directory
It does not work even when eLyXer is installed as a module:
$ python -m elyxer cBN-Uli.lyx cBN-Uli.html
... does its stuff.
$ python -tt elyxer cBN-Uli.lyx cBN-Uli.html
python: can't open file 'elyxer': [Errno 2] No such file or directory
Changing it to elyxer.py is no good:
$ python -tt elyxer.py cBN-Uli.lyx cBN-Uli.html
python: can't open file 'elyxer.py': [Errno 2] No such file or directory
If we happen to run it from the same directory where elyxer.py
resides, then it works:
$ python -tt elyxer.py cBN-Uli.lyx cBN-Uli.html
but this is not a practical solution since it will normally be run
from the documents directory.
Keep in mind that I have installed eLyXer as a Debian package, so this
line in trunk does not work for the Debian package nor when eLyXer is
installed as a module. (The module detection code will work however
for eLyXer installed as a module.)
> elyxer.py is a python script, so we can run it via
>
> python -tt elyxer
Nope, this line will work neither for Debian nor for eLyXer as a
module. The -tt option is immaterial; it just validates the spacing in
the script file.
> This must work according to the Python documentation and we call all our
> other scripts. The detection of eLyXer does hereby not matter. The detection
> doesn't determine whether elyxer is a program or not, it only checks if
> there is a file named "elyxer.py".
I am afraid that I did not explain myself clearly the last time around
this issue was discussed (with you in private, if I recall correctly).
Allow me to give a lengthier explanation this time. The detection code
checks for a file named "elyxer" or "elyxer.py" in the execution path.
Actually it tries to run
$ elyxer
$ elyxer.py
and checks if it works. It must then be run as an executable script
using the same command. It worked for me on Debian and Windows, but
for some reason (probably related to how Python was installed on your
machines) it did not parse arguments correctly on your test machines.
So we had to try something else.
Running
$ python elyxer
or
$ python elyxer.py
or
$ python -tt elyxer.py
or even
$ python -tt elyxer
will not work, even after having correctly detected that eLyXer is
somewhere in the path. It would work if elyxer.py is in the current
directory, or if the full path is given:
$ python /path/to/elyxer.py
This is what you did last time, placing elyxer.py in the scripts
folder and then using the line
$ python -tt $$s/scripts/elyxer.py
where, remember, the -tt option is immaterial. Now we have a better
solution (which I learned on this list) which is to run eLyXer as a
module:
$ python -m elyxer
for which eLyXer must be in the Python script path (e.g. on Debian in
/usr/lib/python2.5/site-packages/). This is easily achievable on Linux
running the setup.py script:
$ python setup.py
and it works even on Windows without admin privileges and with a
minimal Python install, because further directories can be placed in
the Python path.
So, to recapitulate, we have three ways of running eLyXer (or for that
matter any Python script):
- As an executable file: works on most machines, both as elyxer and
as elyxer.py, but fails on some Windows installations.
- As a Python script (with or without the -tt option): works only if
run from the same directory where the script resides, or if full path
is given. Not useful unless elyxer.py is installed to a fixed location
(as the rest of the LyX scripts).
- As a module: works on every machine, requires admin privileges to
install _or_ placing further directories in the Python path.
My latest patches detected eLyXer as a module and as an executable
file, and could run whatever was detected first (as a module or as an
executable). Your current code in trunk first tries to detect as a
module. If it is not found then it tries to detect eLyXer as an
executable:
624 path, elyxer = checkProg('a LyX -> HTML converter',
['elyxer.py', 'elyxer'],
625 rc_entry = '')
and if found then runs it as a Python script.
626 if elyxer.find('elyxer') >= 0:
627 elyxerfound = True
628 addToRC(r'''\converter lyx html "python -tt
elyxer.py --directory $$r $$i $$o" ""''')
This behavior is inconsistent and doomed to fail in any case. The
correct code has to be in all cases that in branch 1_6_X:
408 path, elyxer = checkProg('a LyX -> HTML converter',
['elyxer.py --directory $$r $$i $$o', 'elyxer --directory $$r $$i
$$o'],
409 rc_entry = [ r'\converter lyx html "%%" ""' ])
410 if elyxer.find('elyxer') >= 0:
411 elyxerfound = True
The "%%" ensures that whatever line is found ('elyxer.py --directory
$$r $$i $$o' or 'elyxer --directory $$r $$i $$o') will be run as is.
Revision 31950 was good, just adding the removed comment line (for
info and consistency with other versions) should be enough. Please
find attached the patch.
Thanks,
Alex.
Index: lib/configure.py
===================================================================
--- lib/configure.py (revisión: 31958)
+++ lib/configure.py (copia de trabajo)
@@ -621,11 +621,10 @@
if elyxerfound:
addToRC(r'''\converter lyx html "python -m elyxer --directory $$r $$i $$o" ""''')
else:
- path, elyxer = checkProg('a LyX -> HTML converter', ['elyxer.py', 'elyxer'],
- rc_entry = '')
+ path, elyxer = checkProg('a LyX -> HTML converter', ['elyxer.py --directory $$r $$i $$o', 'elyxer --directory $$r $$i $$o'],
+ rc_entry = [ r'\converter lyx html "%%" ""' ])
if elyxer.find('elyxer') >= 0:
elyxerfound = True
- addToRC(r'''\converter lyx html "python -tt elyxer.py --directory $$r $$i $$o" ""''')
if elyxerfound:
addToRC(r'''\copier html "python -tt $$s/scripts/ext_copy.py -e html,png,jpg,jpeg,css $$i $$o"''')