[PATCH] D89186: [lit] Avoid calling realpath() for every printed message

Julian Lettner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 13 10:55:09 PDT 2020


yln added inline comments.


================
Comment at: llvm/utils/lit/lit/LitConfig.py:181
         f = f.f_back.f_back
-        file,line,_,_,_ = inspect.getframeinfo(f)
-        location = '%s:%d' % (file, line)
-
-        sys.stderr.write('%s: %s: %s: %s\n' % (self.progname, location,
-                                               kind, message))
+        file = os.path.normpath(os.path.abspath(inspect.getsourcefile(f)))
+        line = inspect.getlineno(f)
----------------
arichardson wrote:
> ldionne wrote:
> > I don't think you need to call `normpath()` after calling `abspath()`. >From the Python docs:
> > 
> > > `os.path.abspath(path)`
> > > Return a normalized absolutized version of the pathname path. On most platforms, this is equivalent to calling the function `normpath()` as follows: `normpath(join(os.getcwd(), path))`.
> > 
> Thanks I didn't read the docs and just assumed it would behave the same as pathlib Path.absolute():
> ```
> >>> os.chdir("/usr/bin"); (os.getcwd(), os.path.abspath(".."), Path("..").absolute())
> ('/usr/bin', '/usr', PosixPath('/usr/bin/..'))
> ```
Good catch, thanks Louis!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89186/new/

https://reviews.llvm.org/D89186



More information about the llvm-commits mailing list