From cc034be21b840334753e9188f5033464883a3e33 Mon Sep 17 00:00:00 2001 From: James Teh Date: Wed, 14 Aug 2013 10:07:52 +1000 Subject: [PATCH 1/3] logHandler: Refactor code to get the fully qualified module name so that it doesn't fail when the module is on a drive different to NVDA itself. This code works, but the check for external paths isn't optimised and will break in some cases. Re #3370. --- source/logHandler.py | 40 +++++++++------------------------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/source/logHandler.py b/source/logHandler.py index 2f6c7e6d60c..f397fd516da 100755 --- a/source/logHandler.py +++ b/source/logHandler.py @@ -24,36 +24,6 @@ RPC_E_CALL_REJECTED = -2147418111 RPC_E_DISCONNECTED = -2147417848 -moduleCache={} - -def makeModulePathFromFilePath(path): - """calculates the pythonic dotted module path from a file path of a python module. - @param path: the relative or absolute path to the module - @type path: string - @returns: the Pythonic dotted module path - @rtype: string - """ - if path in moduleCache: - return moduleCache[path] - modPathList = [] - # Work through the path components from right to left. - curPath = path - while curPath: - curPath, curPathCom = os.path.split(curPath) - if not curPathCom: - break - curPathCom = os.path.splitext(curPathCom)[0] - # __init__ is the root module of a package, so skip it. - if curPathCom != "__init__": - modPathList.insert(0, curPathCom) - if curPath in sys.path: - # curPath is in the Python search path, so the Pythonic module path is relative to curPath. - break - modulePath = ".".join(modPathList) - if modulePath: - moduleCache[path] = modulePath - return modulePath - def getCodePath(f): """Using a frame object, gets its module path (relative to the current directory).[className.[funcName]] @param f: the frame object to use @@ -61,7 +31,15 @@ def getCodePath(f): @returns: the dotted module.class.attribute path @rtype: string """ - path=makeModulePathFromFilePath(os.path.relpath(f.f_code.co_filename)) + fn=f.f_code.co_filename + if fn[0] != "<" and (not fn.startswith(sys.path[0] + "\\") or fn.startswith(globalVars.appArgs.configPath + "\\")): + path="external:" + else: + path="" + try: + path+=f.f_globals["__name__"] + except KeyError: + path+=fn funcName=f.f_code.co_name if funcName.startswith('<'): funcName="" From c418dba3d4caddc4d3b5022f859265cb7d43dd92 Mon Sep 17 00:00:00 2001 From: Michael Curran Date: Wed, 14 Aug 2013 21:01:02 +1000 Subject: [PATCH 2/3] Simplify loghandler check for external modules to increase performance. Anything inside sys.path[0] is considered not external --- source/logHandler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/logHandler.py b/source/logHandler.py index f397fd516da..b01a0adb525 100755 --- a/source/logHandler.py +++ b/source/logHandler.py @@ -32,7 +32,7 @@ def getCodePath(f): @rtype: string """ fn=f.f_code.co_filename - if fn[0] != "<" and (not fn.startswith(sys.path[0] + "\\") or fn.startswith(globalVars.appArgs.configPath + "\\")): + if fn[0] != "<" and not fn.startswith(sys.path[0] + "\\"): path="external:" else: path="" From 441885e50031a4bebac66221f2bfffff4f0f853c Mon Sep 17 00:00:00 2001 From: James Teh Date: Fri, 23 Aug 2013 12:19:51 +1000 Subject: [PATCH 3/3] Fix issue with external: being logged for all modules in binary builds. If the code object's file name is not an absolute path, never treat it as external, as code in library.zip reports relative paths in binary builds. Re #3370. --- source/logHandler.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/logHandler.py b/source/logHandler.py index b01a0adb525..0a380ec1b0f 100755 --- a/source/logHandler.py +++ b/source/logHandler.py @@ -32,7 +32,11 @@ def getCodePath(f): @rtype: string """ fn=f.f_code.co_filename - if fn[0] != "<" and not fn.startswith(sys.path[0] + "\\"): + if fn[0] != "<" and os.path.isabs(fn) and not fn.startswith(sys.path[0] + "\\"): + # This module is external because: + # the code comes from a file (fn doesn't begin with "<"); + # it has an absolute file path (code bundled in binary builds reports relative paths); and + # it is not part of NVDA's Python code (not beneath sys.path[0]). path="external:" else: path=""