Filed Under (Editors, Python) by Marcin Kuźmiński on November-20-2009

Few days ago there was again a major update on pydev eclipse plugin.
The version 1.5.1. Comes with new refactoring engine PEPTIC, it’s way better than any one before.
Complete list below: visit http://pydev.org for download.

Release 1.5.1

  • Improvements in the AST rewriter
  • Improvements on the refactoring engine:
    • No longer using BRM
    • Merged with the latest PEPTIC
    • Inline local available
    • Extract method bug-fixes
    • Extract local on multi-line
    • Generating properties using coding style defined in preferences
    • Add after current method option added to extract method
    • A bunch of other corner-case situations were fixed
  • Bug-fixes:
    • Minor editor improvements
    • Adding default forced builtins on all platforms (e.g.: time, math, etc) which wouldn’t be on sys.builtin_module_names on some python installations
    • Adding ‘numpy’ and ‘Image’ to the forced builtins always
    • Ctrl+1: Generate docstring minor fixes
    • Ctrl+1: Assign to local now follows coding style preferences properly
    • Exponential with uppercase E working on code-formatting
    • When a set/get method is found in code-completion for a java class an NPE is no longer thrown
    • Backspace properly treated in block mode
    • Setting IRONPYTHONPATH when dealing with Iron Python (projects could not be referenced)
    • No longer giving spurious ’statement has no effect’ inside of lambda and decorators
    • Fixed new exec in python 3k
    • Fixed NPE when breakpoint is related to a resource in a removed project
    • Fixed import problem on regexp that could lead to a recursion.
    • No longer giving NPE when debugging with the register view open
    • List access be treated as __getitem__() in the list — patch from Tassilo Barth
    • Fix for invalid auto-self added when typing


Filed Under (Python) by Marcin Kuźmiński on June-27-2009

UPDATE: i added two small fixes. When a functions is returning let’s pass the return value further, and exception when there’s no parameters.

I began studying more about decorators. I made a simple one for now it can be used to calculate execution time in miliseconds,seconds,minutes or hours of function decorated. It uses closures with wrapper function for handling parameters. Next time i’ll post decorator for running a function in a background using threads.

Here’s the code:

''' @author: marcink '''

import time
from types import FunctionType

class GetExecutionTime:
    '''
    This generic class is meant to be used as decorator for messuring
    simple method execution time it works on class methods as well
    as regular non class functions ;
    Availible parameters:
        'ms' - miliseconds
        's' - seconds
        'm' - minutes
        'h' - hours
    usage: @GetExecutionTime(param)

    samples:
    @GetExecutionTime('s')
    def samplemethod(self,params):
        function body
    will print executions time at end in seconds

    @GetExecutionTime('m')
    def samplemethod(params):
        function body
    will print executions time at end in minutes

     '''

    def __init__(self, *args):
        #in case of calling without parametrs
        #first argument will be the function decorated raise exception than

        if len(args) is 0 or type(args[0]) is FunctionType:
            raise Exception("Calling decorator without parameters is not possible")
        else:
            self.fn = None
            self.d_as = args[0]

        def miliseconds():return 1
        def seconds(): return 10000000000
        def minutes():return seconds() * 60
        def hours(): return minutes() * 60
        def default_():return seconds()

        #this is a cool way to replace switch case with default parameter
        commands = {'ms':miliseconds,
                    's':seconds,
                    'm':minutes,
                    'h':hours}
        self.display_as = commands.get(self.d_as, default_)()

    def __call__(self,fn):

        display_as = self.display_as
        d_as = self.d_as

        def wrapper_function(*args, **kwargs):
            start = time.time()

            ret = fn(*args,**kwargs)

            end = time.time()
            microsec = (end - start) * 10000000000

            print "function %s execution time: %s %s" % (fn.__name__, (microsec) / display_as, d_as)
            if ret:
                return ret
        return wrapper_function

#EXAMPLES:

from time import sleep

@GetExecutionTime('s')
def short_func(max, min):
    for x in range(3):
        sleep(1)
    print max,min
    return (max, min)

short_func(100, 10)

''' prints: function short_func execution time: 3.00342392921 s '''