On Thursday 28 November 2002 21:22, Detlev Offenbach wrote:
> Hi Arno,
>
> > Hi Arno,
> >
> > what about subscribing PyKDE? Pretty low traffic ML.
> >
> > On Tuesday 26 November 2002 12:47, you wrote:
> > > Hi,
> > >
> > > when single-stepping through some of my python files with eric3
> > > I get an error dialog with the message
> > >
> > > The file
> > > /var/tmp/python-2.2.1-build/usr/lib/python2.2/sre.py
> > > could not be opened.
> > >
> > > I am using python-2.2.1-45 from SuSE 8.1. I also have the rpm
> > > python-nothreads-2.2.1-45 installed, not sure whether that
> > > maytters. The same python files run fine outside of eric3.
> > >
> > > The filename in the message looks like a leftover from a build.
>
> I am using SuSE 8.1 as well and haven't seen the described behaviour so
> far. Would it be possible for you, to send me one of your scripts that
> fails to run. The only difference I can see from your description is,
> that I don't have the python-nothreads-2.2.1-45 package installed. It
> could be possible, that your Python tries to execute a script
> compiled/optimized with one version with the other one. At the moment I
> don't have any other clue.
>
> > The problem seems to be related to the way, how eric resolves
> > the path of the source (using the path provided in the *.py{c,o}
> > files). This clashes with the way, SuSE built their python package,
> > which leads to these strange messages from eric. I solved this
> > problem with the attached script:
>
> Hans-Peter, what do you mean by that. I am not aware of any special path
> resolving in eric (but maybe that's deep in the old code that I haven't
> touched).

Detlev, please try this:
strings -f /usr/lib/python2.2/*.py[co] | grep "/var/tmp/"
I bet, you will find a lot of matches. Try single stepping through one of 
these, and you should see. 

Attached is a significantly speeded up version of my compile script.
(works with a pipe and two, not n+1 python processes)

> Detlev

Hans-Peter
#! /usr/bin/env python
"""
usage: %s [-arv] [dirs/files] ...
       byte-compiles python files/dirs
       -a compile all files of current python installation
       -o optimized compile, too
       -r recursive behaviour
       -v verbose level (cumulative)
       dirs/files: to compile
"""
# (c)reated by Hans-Peter Jansen, LISA GmbH, Berlin
#
# Licence:      GPL   http://www.gnu.org/licenses/gpl.html
#
# 2002-11-27    hp    initial version
# 2002-11-28    hp    pipe for optimized compile
#
# TODO:
# - testing
#
# vim:set et ts=4 sw=4:

import sys, os
import getopt
import glob
import py_compile

argv0 = os.path.basename(sys.argv[0])
optimize = 0
verbose = 0
optpipe = None

def out(lvl, arg):
    if lvl > verbose:
        return
    err(arg, sys.stdout)

def err(arg, ch = sys.stderr):
    if arg:
        ch.write(arg)
        if arg[-1] != "\n":
            ch.write("\n")
    else:
        ch.write("\n")
    ch.flush()

def exit(ret=0, arg=None):
    if arg:
        out(0, "%s: %s" % (argv0, arg))
    sys.exit(ret)

def usage(ret=0, arg=None):
    if arg:
        out(0, "%s: %s" % (argv0, arg))
    out(0, __doc__ % (argv0))
    sys.exit(ret)

def pycompile(path, recursive = 0, depth = 0):
    if os.path.isdir(path):
        for p in glob.glob(os.path.join(path, "*")):
            if depth == 0 or recursive:
                pycompile(p, recursive, depth + 1)
    elif os.path.isfile(path):
        if path[-3:] == '.py':
            out(1, "compiling %s" % (path))
            py_compile.compile(path)
            if optimize:
                out(1, "compiling %s (opt)" % (path))
                optpipe.write("%s\n" % path)
                optpipe.flush()
    else:
        out(1, "%s ignored" % (path))

if __name__ == '__main__':
    #global verbose, optimize
    try:
        optlist, args = getopt.getopt(sys.argv[1:], "aorvO")
    except getopt.error, msg:
        usage(1, msg)

    all = 0
    optimize = 0
    recursive = 0
    optproc = 0
    for opt, par in optlist:
        if opt == '-a':
            all = 1
        elif opt == '-o':
            optimize = 1
        elif opt == '-r':
            recursive = 1
        elif opt == '-v':
            verbose += 1
        elif opt == '-O':
            optproc = 1

    if optimize:
        # create a pipe to a slave process for optimized compile
        optpipe, stdout = os.popen2("python -O %s -O" % (sys.argv[0]))
    elif optproc:
        # handle optimized compile here
        while 1:
            l = sys.stdin.readline()
            if not l:
                sys.exit(0)
            py_compile.compile(l[:-1])

    if all:
        pyFullVers = sys.version.split()[0]
        vl = pyFullVers.split(".")
        pyVers = vl[0] + "." + vl[1]
        pycompile(os.path.join(sys.prefix, "lib/python" + pyVers), 1)
    else:
        for p in args:
            pycompile(p, recursive)
    if optpipe:
        optpipe.close()

Reply via email to