call site 15 for path.local.dirpath
apigen/source/testing/test_browser.py - line 28
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
   def test_browser():
       tmp = py.test.ensuretemp("sourcebrowser")
       tmp.ensure("a.py").write(py.code.Source("""
       def f():
           pass
       
       def g():
           pass
           
       class X:
           pass
           
       class Z(object):
           x = 1
           def zzz(self):
               1
               2
               3
               4
       """))
->     mod = parse_path(tmp.join("a.py"))
       assert isinstance(mod.g, Function)
       assert isinstance(mod.Z, Class)
       py.test.raises(AttributeError, "mod.zzz")
       assert mod.g.firstlineno == 5
       assert mod.g.name == "g"
       assert mod.g.endlineno == 6
       assert mod.X.firstlineno == 8
       assert mod.X.endlineno == 9
       assert mod.Z.bases == ["object"]
       assert isinstance(mod.Z.zzz, Method)
       assert mod.Z.zzz.firstlineno == 13
       assert mod.Z.zzz.endlineno == 17
apigen/source/browser.py - line 133
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
   def parse_path(path):
       if not isinstance(path, PathBase):
           path = py.path.local(path)
       buf = path.open().read()
       st = parse(buf)
       # first go - we get all functions and classes defined on top-level
       nodes = dir_nodes(st)
       function_ast = [i for i in nodes if isinstance(i, ast.Function)]
       classes_ast = [i for i in nodes if isinstance(i, ast.Class)]
       mod_dict = dict([(i.name, function_from_ast(i, None)) for i in function_ast]
          + [(i.name, class_from_ast(i)) for i in classes_ast])
       # we check all the elements, if they're really there
       try:
->         mod = path.pyimport()
       except (KeyboardInterrupt, SystemExit):
           raise
       except:  # catch all other import problems generically
           # XXX some import problem: we probably should not
           # pretend to have an empty module 
           pass
       else:
           update_mod_dict(mod, mod_dict)
       return Module(path, mod_dict)
path/local/local.py - line 415
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
   def pyimport(self, modname=None, ensuresyspath=True):
       """ return path as an imported python module.
               if modname is None, look for the containing package
               and construct an according module name.
               The module will be put/looked up in sys.modules.
           """
       if not self.check():
           raise py.error.ENOENT(self)
       #print "trying to import", self
       pkgpath = None
       if modname is None:
           #try:
           #    return self._module
           #except AttributeError:
           #    pass
           pkgpath = self.pypkgpath()
           if pkgpath is not None:
               if ensuresyspath:
                   self._prependsyspath(pkgpath.dirpath())
               pkg = __import__(pkgpath.basename, None, None, [])
                   
               if hasattr(pkg, '__pkg__'):
                   modname = pkg.__pkg__.getimportname(self)
                   assert modname is not None, "package %s doesn't know %s" % (
                                               pkg.__name__, self)
                   
               else:
                   names = self.new(ext='').relto(pkgpath.dirpath())
                   names = names.split(self.sep)
                   modname = ".".join(names)
           else:
               # no package scope, still make it possible
               if ensuresyspath:
->                 self._prependsyspath(self.dirpath())
               modname = self.purebasename
           mod = __import__(modname, None, None, ['__doc__'])
           #self._module = mod
           return mod
       else:
           try:
               return sys.modules[modname]
           except KeyError:
               # we have a custom modname, do a pseudo-import
               mod = py.std.new.module(modname)
               mod.__file__ = str(self)
               sys.modules[modname] = mod
               try:
                   execfile(str(self), mod.__dict__)
               except:
                   del sys.modules[modname]
                   raise
               return mod