@memoize
def get_parent_until(path):
 dirname = osp.dirname(path)
 try:
  mod = osp.basename(path)
  mod = osp.splitext(mod)[0]
  imp.find_module(mod, [dirname])
 except ImportError:
  return
 items = [mod]
 while 1:
  items.append(osp.basename(dirname))
  try:
   dirname = osp.dirname(dirname)
   imp.find_module('__init__', [(dirname + os.sep)])
  except ImportError:
   break
 return '.'.join(reversed(items))

@ memoize def get_parent_until ( path ) : dirname = osp . dirname ( path ) try : mod = osp . basename ( path ) mod = osp . splitext ( mod ) [ 0 ] imp . find_module ( mod , [ dirname ] ) except ImportError : return items = [ mod ] while 1 : items . append ( osp . basename ( dirname ) ) try : dirname = osp . dirname ( dirname ) imp . find_module ( '__init__' , [ ( dirname + os . sep ) ] ) except ImportError : break return '.' . join ( reversed ( items ) )
given a file path .