Skip to content

Commit ebb05fe

Browse files
authored
Logging: No longer mark log messages from nvda.pyw as coming from external code when running from sources (#13827)
Summary of the issue: When starting NVDA from sources messages logged from nvda.pyw are shown as external. Example message: INFO - external:__main__ (17:20:02.477) - MainThread (4316): Starting NVDA version source-master-b817b03 This is clearly wrong. The problem is caused by the trailing backslash added in bat scripts (%~dp0 is already terminated with one and adding a second backslash causes logHandler.isPathExternalToNVDA to think that the path is external). Description of user facing changes Log messages from nvda.pyw are no longer marked as external. Description of development approach All usages of %~dp0 are inspected and trailing backslash is no longer added to the paths. To make logHandler.isPathExternalToNVDA more resilient to invalid paths the path is normalized before checking if it is the same as sys.path.
1 parent ac7215b commit ebb05fe

10 files changed

+66
-14
lines changed

runlint.bat

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
@echo off
22
rem runlint <base commit> [<output file>]
33
rem Lints any changes after base commit up to and including current HEAD, plus any uncommitted changes.
4-
call "%~dp0\venvUtils\venvCmd.bat" py "%~dp0\tests\lint\genDiff.py" %1 "%~dp0\tests\lint\_lint.diff"
4+
set hereOrig=%~dp0
5+
set here=%hereOrig%
6+
if #%hereOrig:~-1%# == #\# set here=%hereOrig:~0,-1%
7+
set scriptsDir=%here%\venvUtils
8+
set lintFilesPath=%here%\tests\lint
9+
10+
call "%scriptsDir%\venvCmd.bat" py "%lintFilesPath%\genDiff.py" %1 "%lintFilesPath%\_lint.diff"
511
if ERRORLEVEL 1 exit /b %ERRORLEVEL%
6-
set flake8Args=--diff --config="%~dp0\tests\lint\flake8.ini"
12+
set flake8Args=--diff --config="%lintFilesPath%\flake8.ini"
713
if "%2" NEQ "" set flake8Args=%flake8Args% --tee --output-file=%2
8-
type "%~dp0\tests\lint\_lint.diff" | call "%~dp0\venvUtils\venvCmd.bat" py -Xutf8 -m flake8 %flake8Args%
14+
type "%lintFilesPath%\_lint.diff" | call "%scriptsDir%\venvCmd.bat" py -Xutf8 -m flake8 %flake8Args%
915

runnvda.bat

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
@echo off
2-
call "%~dp0\venvUtils\venvCmd.bat" start pyw "%~dp0\source\nvda.pyw" %*
2+
set hereOrig=%~dp0
3+
set here=%hereOrig%
4+
if #%hereOrig:~-1%# == #\# set here=%hereOrig:~0,-1%
5+
set scriptsDir=%here%\venvUtils
6+
set sourceDirPath=%here%\source
7+
8+
call "%scriptsDir%\venvCmd.bat" start pyw "%sourceDirPath%\nvda.pyw" %*

runsettingsdiff.bat

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
@echo off
2-
call "%~dp0\venvUtils\venvCmd.bat" py -m robot --argumentfile "%~dp0\tests\system\guiDiff.robot" %* "%~dp0\tests\system\robot"
2+
set hereOrig=%~dp0
3+
set here=%hereOrig%
4+
if #%hereOrig:~-1%# == #\# set here=%hereOrig:~0,-1%
5+
set scriptsDir=%here%\venvUtils
6+
set systemTestsPath=%here%\tests\system
7+
8+
call "%scriptsDir%\venvCmd.bat" py -m robot --argumentfile "%systemTestsPath%\guiDiff.robot" %* "%systemTestsPath%\robot"

runsystemtests.bat

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
@echo off
2-
call "%~dp0\venvUtils\venvCmd.bat" py -m robot --argumentfile "%~dp0\tests\system\robotArgs.robot" %* "%~dp0\tests\system\robot"
2+
set hereOrig=%~dp0
3+
set here=%hereOrig%
4+
if #%hereOrig:~-1%# == #\# set here=%hereOrig:~0,-1%
5+
set scriptsDir=%here%\venvUtils
6+
set systemTestsPath=%here%\tests\system
37

8+
call "%scriptsDir%\venvCmd.bat" py -m robot --argumentfile "%systemTestsPath%\robotArgs.robot" %* "%systemTestsPath%\robot"

rununittests.bat

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
@echo off
2-
call "%~dp0\venvUtils\venvCmd.bat" py -m nose -sv --traverse-namespace -w "%~dp0\tests\unit" %*
2+
set hereOrig=%~dp0
3+
set here=%hereOrig%
4+
if #%hereOrig:~-1%# == #\# set here=%hereOrig:~0,-1%
5+
set scriptsDir=%here%\venvUtils
6+
set unitTestsPath=%here%\tests\unit
7+
8+
call "%scriptsDir%\venvCmd.bat" py -m nose -sv --traverse-namespace -w "%unitTestsPath%" %*

scons.bat

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
@echo off
22
rem Executes SScons within the NVDA build system's Python virtual environment.
3-
call "%~dp0\venvUtils\venvCmd.bat" py -m SCons %*
3+
set hereOrig=%~dp0
4+
set here=%hereOrig%
5+
if #%hereOrig:~-1%# == #\# set here=%hereOrig:~0,-1%
6+
set scriptsDir=%here%\venvUtils
7+
call "%scriptsDir%\venvCmd.bat" py -m SCons %*

source/logHandler.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,14 @@
3030
EVENT_E_ALL_SUBSCRIBERS_FAILED = -2147220991
3131
LOAD_WITH_ALTERED_SEARCH_PATH=0x8
3232

33-
def isPathExternalToNVDA(path):
33+
34+
def isPathExternalToNVDA(path: str) -> bool:
3435
""" Checks if the given path is external to NVDA (I.e. not pointing to built-in code). """
35-
if path[0] != "<" and os.path.isabs(path) and not path.startswith(sys.path[0] + "\\"):
36+
if(
37+
path[0] != "<"
38+
and os.path.isabs(path)
39+
and not os.path.normpath(path).startswith(sys.path[0] + "\\")
40+
):
3641
# This module is external because:
3742
# the code comes from a file (fn doesn't begin with "<");
3843
# it has an absolute file path (code bundled in binary builds reports relative paths); and

venvUtils/ensureAndActivate.bat

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22
rem this script ensures the NVDA build system Python virtual environment is created and up to date,
33
rem and then activates it.
44
rem This is an internal script and should not be used directly.
5+
set hereOrig=%~dp0
6+
set here=%hereOrig%
7+
if #%hereOrig:~-1%# == #\# set here=%hereOrig:~0,-1%
8+
set scriptsDir=%here%
9+
set venvLocation=%here%\..\.venv
510

611
rem Ensure the environment is created and up to date
7-
py -3.7-32 "%~dp0\ensureVenv.py"
12+
py -3.7-32 "%scriptsDir%\ensureVenv.py"
813
if ERRORLEVEL 1 goto :EOF
914

1015
rem Set the necessary environment variables to have Python use this virtual environment.
@@ -18,7 +23,7 @@ rem set the VIRTUAL_ENV variable instructing Python to use a virtual environment
1823
rem py.exe will honor VIRTUAL_ENV and launch the python.exe that it finds in %VIRTUAL_ENV%\scripts.
1924
rem %VIRTUAL_ENV%\scripts\python.exe will find pyvenv.cfg in its parent directory,
2025
rem which is actually what then causes Python to use the site-packages found in this virtual environment.
21-
set VIRTUAL_ENV=%~dp0..\.venv
26+
set VIRTUAL_ENV=%venvLocation%
2227
rem Add the virtual environment's scripts directory to the path
2328
set PATH=%VIRTUAL_ENV%\scripts;%PATH%
2429
rem Set an NVDA-specific variable to identify this official NVDA virtual environment from other 3rd party ones

venvUtils/exportPackageList.bat

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
@echo off
2+
set hereOrig=%~dp0
3+
set here=%hereOrig%
4+
if #%hereOrig:~-1%# == #\# set here=%hereOrig:~0,-1%
5+
set scriptsDir=%here%
6+
27
setlocal
38
if "%VIRTUAL_ENV%" == "" (
4-
call "%~dp0\ensureAndActivate.bat"
9+
call "%scriptsDir%\ensureAndActivate.bat"
510
if ERRORLEVEL 1 goto :EOF
611
)
712
py -m pip freeze >%1

venvUtils/venvCmd.bat

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ if "%VIRTUAL_ENV%" NEQ "" (
1515
call %*
1616
goto :EOF
1717
)
18+
set hereOrig=%~dp0
19+
set here=%hereOrig%
20+
if #%hereOrig:~-1%# == #\# set here=%hereOrig:~0,-1%
21+
set scriptsDir=%here%
1822

1923
rem call setlocal to make sure that any environment variable changes made by activating the virtual environment
2024
rem can be completely undone when endlocal is called or this script exits.
2125
setlocal
2226
echo Ensuring NVDA Python virtual environment
23-
call "%~dp0\ensureAndActivate.bat"
27+
call "%scriptsDir%\ensureAndActivate.bat"
2428
if ERRORLEVEL 1 goto :EOF
2529
echo call %*
2630
call %*

0 commit comments

Comments
 (0)