Skip to content

Commit 7fc478d

Browse files
authored
Merge 8e2a334 into 33ee524
2 parents 33ee524 + 8e2a334 commit 7fc478d

9 files changed

Lines changed: 51 additions & 43 deletions

File tree

source/NVDAHelper.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# A part of NonVisual Desktop Access (NVDA)
2-
# Copyright (C) 2008-2020 NV Access Limited, Peter Vagner, Davy Kager, Mozilla Corporation, Google LLC,
2+
# Copyright (C) 2008-2022 NV Access Limited, Peter Vagner, Davy Kager, Mozilla Corporation, Google LLC,
33
# Leonard de Ruijter
44
# This file is covered by the GNU General Public License.
55
# See the file COPYING for more details.
66

77
import os
8-
import sys
98
import winreg
109
import msvcrt
1110
import versionInfo
@@ -34,8 +33,10 @@
3433
versionedLib64Path = os.path.join(globalVars.appDir, 'libArm64')
3534
else:
3635
versionedLib64Path = os.path.join(globalVars.appDir, 'lib64')
37-
if getattr(sys,'frozen',None):
38-
# Not running from source. Libraries are in a version-specific directory
36+
37+
38+
if not globalVars.runningAsSource:
39+
# When running as a py2exe build, libraries are in a version-specific directory
3940
versionedLibPath=os.path.join(versionedLibPath,versionInfo.version)
4041
versionedLib64Path=os.path.join(versionedLib64Path,versionInfo.version)
4142

source/core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def restartUnsafely():
160160
except ValueError:
161161
pass
162162
options = []
163-
if not hasattr(sys, "frozen"):
163+
if globalVars.runningAsSource:
164164
options.append(os.path.basename(sys.argv[0]))
165165
_startNewInstance(NewNVDAInstance(
166166
sys.executable,
@@ -185,7 +185,7 @@ def restart(disableAddons=False, debugLogging=False):
185185
except ValueError:
186186
pass
187187
options = []
188-
if not hasattr(sys, "frozen"):
188+
if globalVars.runningAsSource:
189189
options.append(os.path.basename(sys.argv[0]))
190190
if disableAddons:
191191
options.append('--disable-addons')
@@ -678,7 +678,7 @@ def handlePowerStatusChange(self):
678678
# initialize wxpython localization support
679679
wxLocaleObj = wx.Locale()
680680
wxLang = getWxLangOrNone()
681-
if hasattr(sys,'frozen'):
681+
if not globalVars.runningAsSource:
682682
wxLocaleObj.AddCatalogLookupPathPrefix(os.path.join(globalVars.appDir, "locale"))
683683
if wxLang:
684684
try:

source/diffHandler.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# A part of NonVisual Desktop Access (NVDA)
2+
# Copyright (C) 2020-2022 NV Access Limited, Bill Dengler
23
# This file is covered by the GNU General Public License.
34
# See the file COPYING for more details.
4-
# Copyright (C) 2020 Bill Dengler
55

66
import config
77
import globalVars
@@ -44,12 +44,12 @@ def _initialize(self):
4444
@note: This should be run from within the context of an acquired lock."""
4545
if not DiffMatchPatch._proc:
4646
log.debug("Starting diff-match-patch proxy")
47-
if hasattr(sys, "frozen"):
48-
dmp_path = (os.path.join(globalVars.appDir, "nvda_dmp.exe"),)
49-
else:
47+
if globalVars.runningAsSource:
5048
dmp_path = (sys.executable, os.path.join(
5149
globalVars.appDir, "..", "include", "nvda_dmp", "nvda_dmp.py"
5250
))
51+
else:
52+
dmp_path = (os.path.join(globalVars.appDir, "nvda_dmp.exe"),)
5353
DiffMatchPatch._proc = subprocess.Popen(
5454
dmp_path,
5555
creationflags=subprocess.CREATE_NO_WINDOW,

source/documentationUtils.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
# -*- coding: UTF-8 -*-
22
# A part of NonVisual Desktop Access (NVDA)
3-
# Copyright (C) 2006-2021 NV Access Limited, Łukasz Golonka
3+
# Copyright (C) 2006-2022 NV Access Limited, Łukasz Golonka
44
# This file may be used under the terms of the GNU General Public License, version 2 or later.
55
# For more details see: https://www.gnu.org/licenses/gpl-2.0.html
66

77
import os
8-
import sys
98

109
import globalVars
1110
import languageHandler
1211

1312

1413
def getDocFilePath(fileName, localized=True):
1514
if not getDocFilePath.rootPath:
16-
if hasattr(sys, "frozen"):
17-
getDocFilePath.rootPath = os.path.join(globalVars.appDir, "documentation")
18-
else:
15+
if globalVars.runningAsSource:
1916
getDocFilePath.rootPath = os.path.join(globalVars.appDir, "..", "user_docs")
17+
else:
18+
getDocFilePath.rootPath = os.path.join(globalVars.appDir, "documentation")
2019

2120
if localized:
2221
lang = languageHandler.getLanguage()
@@ -42,7 +41,7 @@ def getDocFilePath(fileName, localized=True):
4241
return None
4342
else:
4443
# Not localized.
45-
if not hasattr(sys, "frozen") and fileName in ("copying.txt", "contributors.txt"):
44+
if globalVars.runningAsSource and fileName in ("copying.txt", "contributors.txt"):
4645
# If running from source, these two files are in the root dir.
4746
return os.path.join(globalVars.appDir, "..", fileName)
4847
else:

source/globalVars.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import argparse
1919
import os
20+
import sys
2021
import typing
2122

2223
if typing.TYPE_CHECKING:
@@ -79,3 +80,9 @@ class DefaultAppArgs(argparse.Namespace):
7980
Note that deprecated code may be imported at runtime,
8081
and as such, this value cannot be changed at runtime to test compliance.
8182
"""
83+
84+
runningAsSource: bool = getattr(sys, 'frozen', None) is None
85+
"""
86+
True if NVDA is running as a source copy.
87+
When running as an installed copy, py2exe sets sys.frozen to 'windows_exe'.
88+
"""

source/gui/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import time
99
import os
10-
import sys
1110
import threading
1211
import ctypes
1312
import wx
@@ -453,7 +452,7 @@ def __init__(self, frame: MainFrame):
453452
# Translators: The label of a menu item to open the Add-ons Manager.
454453
item = menu_tools.Append(wx.ID_ANY, _("Manage &add-ons..."))
455454
self.Bind(wx.EVT_MENU, frame.onAddonsManagerCommand, item)
456-
if not globalVars.appArgs.secure and not config.isAppX and getattr(sys,'frozen',None):
455+
if not globalVars.appArgs.secure and not config.isAppX and not globalVars.runningAsSource:
457456
# Translators: The label for the menu item to create a portable copy of NVDA from an installed or another portable version.
458457
item = menu_tools.Append(wx.ID_ANY, _("Create portable copy..."))
459458
self.Bind(wx.EVT_MENU, frame.onCreatePortableCopyCommand, item)

source/logHandler.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# A part of NonVisual Desktop Access (NVDA)
2-
# Copyright (C) 2007-2020 NV Access Limited, Rui Batista, Joseph Lee, Leonard de Ruijter, Babbage B.V.,
2+
# Copyright (C) 2007-2022 NV Access Limited, Rui Batista, Joseph Lee, Leonard de Ruijter, Babbage B.V.,
33
# Accessolutions, Julien Cochuyt
44
# This file is covered by the GNU General Public License.
55
# See the file COPYING for more details.
@@ -125,15 +125,16 @@ def shouldPlayErrorSound() -> bool:
125125

126126

127127
# Function to strip the base path of our code from traceback text to improve readability.
128-
if getattr(sys, "frozen", None):
129-
# We're running a py2exe build.
130-
stripBasePathFromTracebackText = lambda text: text
131-
else:
128+
if globalVars.runningAsSource:
132129
BASE_PATH = os.path.split(__file__)[0] + os.sep
133130
TB_BASE_PATH_PREFIX = ' File "'
134131
TB_BASE_PATH_MATCH = TB_BASE_PATH_PREFIX + BASE_PATH
135132
def stripBasePathFromTracebackText(text):
136133
return text.replace(TB_BASE_PATH_MATCH, TB_BASE_PATH_PREFIX)
134+
else:
135+
def stripBasePathFromTracebackText(text: str) -> str:
136+
return text
137+
137138

138139
class Logger(logging.Logger):
139140
# Import standard levels for convenience.
@@ -379,12 +380,14 @@ def redirectStdout(logger):
379380
#: The singleton log handler instance.
380381
logHandler: Optional[logging.Handler] = None
381382

383+
382384
def _getDefaultLogFilePath():
383-
if getattr(sys, "frozen", None):
385+
if globalVars.runningAsSource:
386+
return os.path.join(globalVars.appDir, "nvda.log")
387+
else:
384388
import tempfile
385389
return os.path.join(tempfile.gettempdir(), "nvda.log")
386-
else:
387-
return os.path.join(globalVars.appDir, "nvda.log")
390+
388391

389392
def _excepthook(*exc_info):
390393
log.exception(exc_info=exc_info, codepath="unhandled exception")

source/nvda.pyw

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: UTF-8 -*-
22
# A part of NonVisual Desktop Access (NVDA)
3-
# Copyright (C) 2006-2021 NV Access Limited, Aleksey Sadovoy, Babbage B.V., Joseph Lee, Łukasz Golonka
3+
# Copyright (C) 2006-2022 NV Access Limited, Aleksey Sadovoy, Babbage B.V., Joseph Lee, Łukasz Golonka
44
# This file is covered by the GNU General Public License.
55
# See the file COPYING for more details.
66

@@ -28,13 +28,7 @@ _log = logging.Logger(name="preStartup", level=logging.INFO)
2828
_log.addHandler(logging.NullHandler(level=logging.INFO))
2929

3030
customVenvDetected = False
31-
if getattr(sys, "frozen", None):
32-
# We are running as an executable.
33-
# Append the path of the executable to sys so we can import modules from the dist dir.
34-
sys.path.append(sys.prefix)
35-
appDir = sys.prefix
36-
else:
37-
# we are running from source
31+
if globalVars.runningAsSource:
3832
# Ensure we are inside the NVDA build system's Python virtual environment.
3933
nvdaVenv = os.getenv("NVDA_VENV")
4034
virtualEnv = os.getenv("VIRTUAL_ENV")
@@ -51,6 +45,11 @@ else:
5145
import sourceEnv
5246
#We should always change directory to the location of this module (nvda.pyw), don't rely on sys.path[0]
5347
appDir = os.path.normpath(os.path.dirname(__file__))
48+
else:
49+
# Append the path of the executable to sys so we can import modules from the dist dir.
50+
sys.path.append(sys.prefix)
51+
appDir = sys.prefix
52+
5453
appDir = os.path.abspath(appDir)
5554
os.chdir(appDir)
5655
globalVars.appDir = appDir

source/nvda_slave.pyw

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
#nvda_slave.pyw
2-
#A part of NonVisual Desktop Access (NVDA)
3-
#Copyright (C) 2009-2017 NV Access Limited
4-
#This file is covered by the GNU General Public License.
5-
#See the file COPYING for more details.
1+
# A part of NonVisual Desktop Access (NVDA)
2+
# Copyright (C) 2009-2022 NV Access Limited
3+
# This file is covered by the GNU General Public License.
4+
# See the file COPYING for more details.
65

76
"""NVDA slave process
87
Performs miscellaneous tasks which need to be performed in a separate process.
@@ -17,12 +16,13 @@ import monkeyPatches.comtypesMonkeyPatches
1716
monkeyPatches.comtypesMonkeyPatches.appendComInterfacesToGenSearchPath()
1817

1918

20-
if hasattr(sys, "frozen"):
19+
if globalVars.runningAsSource:
20+
globalVars.appDir = os.path.abspath(os.path.dirname(__file__))
21+
else:
2122
# Error messages (which are only for debugging) should not cause the py2exe log message box to appear.
2223
sys.stderr = sys.stdout
2324
globalVars.appDir = sys.prefix
24-
else:
25-
globalVars.appDir = os.path.abspath(os.path.dirname(__file__))
25+
2626

2727
# #2391: some functions may still require the current directory to be set to NVDA's app dir
2828
os.chdir(globalVars.appDir)

0 commit comments

Comments
 (0)