On Thursday 19 February 2004 13:44, Jean-Marc Lasgouttes wrote:
> I just nothing some rather unfortunate fact: in the 1.3.4 distribution
> I have:
>
> fantomas[ssh]: ll lyx-1.3.4/lib/lyx2lyx/
> total 113
> -rw-r--r--   1 lasgoutt preval      1232 Feb 10 16:56 error.py
> -rw-r--r--   1 lasgoutt preval      1081 Oct 20 16:17 error.pyc
> -rwxr--r--   1 lasgoutt preval      5071 Feb 10 16:56 lyx2lyx
> -rw-r--r--   1 lasgoutt preval      7103 Feb  9 17:55 lyxconvert_210.py
> -rw-r--r--   1 lasgoutt preval      4395 Feb 10 16:56 lyxconvert_215.py
> -rw-r--r--   1 lasgoutt preval      5587 Jun 17  2003 lyxconvert_215.pyc
> -rw-r--r--   1 lasgoutt preval      9527 Feb 10 16:56 lyxconvert_216.py
> -rw-r--r--   1 lasgoutt preval      8083 Jun 17  2003 lyxconvert_216.pyc
> -rw-r--r--   1 lasgoutt preval      4850 Feb 10 16:56 lyxconvert_217.py
> -rw-r--r--   1 lasgoutt preval      5234 Apr  2  2003 lyxconvert_217.pyc
> -rw-r--r--   1 lasgoutt preval     14645 Feb 10 16:56 lyxconvert_218.py
> -rw-r--r--   1 lasgoutt preval     17120 Dec  4 11:03 lyxconvert_218.pyc
> -rw-r--r--   1 lasgoutt preval      2853 Feb 10 16:56 lyxconvert_220.py
> -rw-r--r--   1 lasgoutt preval      2822 Oct 20 16:17 lyxconvert_220.pyc
> -rw-r--r--   1 lasgoutt preval      4974 Feb 10 16:56 parser_tools.py
> -rw-r--r--   1 lasgoutt preval      9433 Oct 20 16:17 parser_tools.pyc
>
> Or interest here are the various .pyc files with various timestamps.
> AFAIK, they are useful since they are supposed to speed-up the python
> loading. However they are only created when some python script is
> used, whence the irregularity of their creation dates (when they exist
> at all).

  Yes. That is correct.

  Also I'm afraid that python could use the wrong version, that is, if the 
precompiled version is available then use it instead of the original file.

> Unfortunately, a user who do not have write access to lyx_dir/lyx2lyx/
> (that is, most users) will never be able to have these files created.
>
> Jose', would it be possible to have these files generated at 'make'
> time? Alternatively, we could stop distributing them.

  From the python site:

7.1   How do I create a .pyc file?

When a module is imported for the first time (or when the source is more 
recent than the current compiled file) a .pyc file containing the compiled 
code should be created in the same directory as the .py file.

One reason that a .pyc file may not be created is permissions problems with 
the directory. This can happen, for example, if you develop as one user but 
run as another, such as if you are testing with a web server. Creation of 
a .pyc file is automatic if you're importing a module and Python has the 
ability (permissions, free space, etc...) to write the compiled module back 
to the directory.

Running Python on a top level script is not considered an import and no .pyc 
will be created. For example, if you have a top-level module abc.py that 
imports another module xyz.py, when you run abc, xyz.pyc will be created 
since xyz is imported, but no abc.pyc file will be created since abc.py 
isn't being imported.

If you need to create abc.pyc -- that is, to create a .pyc file for a module 
that is not imported -- you can, using the py_compile and compileall 
modules.

The py_compile module can manually compile any module. One way is to use the 
compile() function in that module interactively:

>>> import py_compile
>>> py_compile.compile('abc.py')

This will write the .pyc to the same location as abc.py (or you can override 
that with the optional parameter cfile).

You can also automatically compile all files in a directory or directories 
using the compileall module. You can do it from the shell prompt by running 
compileall.py and providing the path of a directory containing Python files 
to compile:

python compileall.py .

-----------------------------------------------------------------------------------------------------
  So something like:
%.pyc : %.py
python -c "import py_compile; import sys; py_compile.compile(sys.argv[1])" 
%.py

  With the last line indented by a tab, and the %.py in the same line...

  Notice that we should not apply this to lyx2lyx only to the other files. 
So the above rule is enough. (I don't know how much of a gnuism this 
is) :-)

> JMarc

-- 
José Abílio

LyX and docbook, a perfect match. :-)

Reply via email to