[Python-apps-team] SPE & pychecker2

Emilio Pozuelo Monfort pochu at ubuntu.com
Tue Nov 27 23:15:04 UTC 2007


[ CCing bug 453092, request for pychecker2 packaging ]

Kenneth Pronovici:
> You've probably already checked before filing this bug report... but
> has the Spe version of this code diverged at all from the Pychecker
> version?  Or did they copy it verbatim and leave it untouched?  I'm
> just curious whether I (or upstream) will have to merge in any
> changes.

We were still discussing it when I filled the report, and I didn't know the
details yet. I should probably have waited until I knew them. Sorry for this.

Kenneth, could you please take a look at the changes (which are few and only in
one file, pychecker2/main.py) and let us know what do you think about them? And
if you think they could be forwarded upstream.

Anyway, here we have them. As Stani said,
> There is only a modification for pychecker. All the others are fine
> upstream. The change for pychecker doesn't make sense for pychecker
> on itself, but only to interact with pychecker from an external program.
> I don't know if pychecker authors would be open for this. 


SPE Stani's Python Editor wrote:
>> Emilio Pozuelo Monfort schreef:
> 
>>  > Ok, I've downloaded the pychecker source package and it includes
>> pychecker2.
>>  > I've filled bug requesting its packaging.
>>  >
>>  > http://bugs.debian.org/453092
>>  >
>>  > I'm curious about your modifications... what kind of changes were
>> them? If they
>>  > are suitable for upstream we could forward them.
> 
> I'll show the changes I did.  SPE uses pychecker2 which is dependent
> on pychecker. The file _spe/plugins/Pycheck.py executes in a wxpython
> process:
> python pychecker2/main.py --incremental foo.py
> 
> This has the advantage that:
> - it is executed in a seperate process without blocking spe or using
> threads (which are not possible in a blender environment)
> - the resulting report can be shown incrementally in the sidebar
> 
> As the patches are only in pychecker2 we could consider of stripping
> out pychecker and only leaving in pychecker2 in the spe plugins
> directory as Debian doesn't seem to ship pychecker2. Even if it would
> it has to be patched anyway for spe.

That's an option, yes. We can remove pychecker at build time and link it to the
system one. If your modifications ever go upstream, then we can remove pychecker
entirely.

> 
> Globally speaking I did two changes for pychecker2/main.py, which are
> clearly marked with comments:
> 
> *1* In the original pychecker2 the CACHE_FILE is defined as '/tmp/t'.
> I prefer to have a solution to use ~/.pychecker_cache in a way which
> works cross-platform also on Windows and Mac.

This sounds good. I guess upstream wants the module to work in as many places as
possible :) although it should be something more generic than
userPath(".pychecker_cache") ;-)

> 
> @@ -1,5 +1,29 @@
>  import sys
>  from os.path import dirname, realpath
> +
> +#---Patched by Stani http://pythonide.stani.be (begin)
> +import os
> +def userPath(dirname=''):
> +    """'safer' function to find user path."""
> +    # 'safer' function to find user path: look for one of these directories
> +    try:
> +        path = os.path.expanduser("~")
> +        if os.path.isdir(path):
> +            return os.path.join(path, dirname)
> +    except:
> +        pass
> +    for evar in ('HOME', 'USERPROFILE', 'TMP'):
> +        try:
> +            path = os.environ[evar]
> +            if os.path.isdir(path):
> +                return os.path.join(path, dirname)
> +        except:
> +            pass
> +    #if no match found, use module directory
> +    return os.path.join(os.path.dirname(os.path.abspath(__file__)), dirname)
> +
> +CACHE_FILE = userPath(".pychecker_cache")
> +#Patched by Stani http://pythonide.stani.be (end)
>  sys.path.append(dirname(dirname(realpath(sys.argv[0]))))
> 
>  from pychecker2.Check import CheckList
> @@ -16,7 +40,6 @@
>  from pychecker2 import ConditionalChecks
>  from pychecker2 import FormatStringChecks
> 
> -CACHE_FILE = '/tmp/t'
> 
>  def print_warnings(f, out):
>      if not f.warnings:
> 
> 
> 
> *2* pychecker2 fails to load local modules relative to the file which
> is being checked. This solves it.
> @@ -69,7 +92,8 @@
>      options = Options.Options()
>      try:
>          checker = cPickle.load(open(CACHE_FILE, 'rb'))
> -    except (EOFError, IOError):
> +    #---Patched by Stani http://pythonide.stani.be (added ImportError)
> +    except (EOFError, IOError, ImportError):
>          checker = create_checklist(options)
> 
>      try:
> @@ -79,10 +103,18 @@
>          options.usage(sys.argv[0], sys.stderr)
>          return 1
> 
> +    #---Patched by Stani http://pythonide.stani.be (begin)
> +    sys_path    = sys.path[:]
>      for f in files:
> +        f_dir   = dirname(f.name)
> +        sys.path= sys_path[:]
> +        if f_dir not in sys.path:
> +            sys.path.insert(0,f_dir)
>          checker.check_file(f)
>          if options.incremental and not options.profile:
>              print_warnings(f, sys.stdout)
> +    sys.path    = sys_path
> +    #Patched by Stani http://pythonide.stani.be (end)
> 
>      result = 0
>      if not options.incremental and not options.profile:
> 
> 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: OpenPGP digital signature
Url : http://lists.alioth.debian.org/pipermail/python-apps-team/attachments/20071128/c1c82220/attachment.pgp 


More information about the Python-apps-team mailing list