Skip to content

Commit 1a7d9af

Browse files
authored
Merge d55470e into c4d6fb5
2 parents c4d6fb5 + d55470e commit 1a7d9af

File tree

10 files changed

+87
-27
lines changed

10 files changed

+87
-27
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ source/userConfig
55
build
66
build_debug
77
dist
8+
installed_packages
89
*.dll
910
*.exe
1011
*.manifest

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@
3434
[submodule "include/configobj"]
3535
path = include/configobj
3636
url = https://github.com/DiffSK/configobj.git
37-
[submodule "include/py2exe"]
38-
path = include/py2exe
39-
url = https://github.com/nvaccess/py2exe-bin
4037
[submodule "include/javaAccessBridge32"]
4138
path = include/javaAccessBridge32
4239
url = https://github.com/nvaccess/javaAccessBridge32-bin.git

buildFunctions.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# A part of NonVisual Desktop Access (NVDA)
2+
# Copyright (C) 2020 NV Access Limited, Łukasz Golonka
3+
# This file may be used under the terms of the GNU General Public License, version 2 or later.
4+
# For more details see: https://www.gnu.org/licenses/gpl-2.0.html
5+
6+
"""Functions useful when building NVDA"""
7+
8+
9+
def installCallback(package):
10+
import sys
11+
import subprocess
12+
import sourceEnv
13+
subprocess.check_call(
14+
[sys.executable, "-m", "pip", "install", "-t", sourceEnv.pythonPackagesDir(), str(package)]
15+
)
16+
import importlib
17+
import pkg_resources
18+
# Evenn though this is quite ugly there is no other way to refresh list of available packages.
19+
importlib.reload(pkg_resources)
20+
pkg_resources._initialize_master_working_set()
21+
print(type(pkg_resources.working_set.find(
22+
# `resolve` considers installation to be succesfull only when installed package is
23+
# returned from the callback.
24+
list(pkg_resources.parse_requirements(str(package)))[0]
25+
))
26+
)
27+
return pkg_resources.working_set.find(
28+
# `resolve` considers installation to be succesfull only when installed package is
29+
# returned from the callback.
30+
list(pkg_resources.parse_requirements(str(package)))[0]
31+
)
32+
33+
34+
def requestPackage(requirementsString):
35+
import pkg_resources
36+
import traceback
37+
try:
38+
pkg_resources.working_set.resolve(
39+
pkg_resources.parse_requirements(requirementsString),
40+
installer=installCallback
41+
)
42+
except Exception as e:
43+
print(f"during install {traceback.format_exc()}")

devDocs/conf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import os
1111
import sys
1212
sys.path.insert(0, os.path.abspath('../source'))
13-
import sourceEnv # noqa: F401, E402
13+
import sourceEnv # noqa: E402
14+
15+
sourceEnv.expandPythonPath()
1416

1517
# Initialize languageHandler so that sphinx is able to deal with translatable strings.
1618
import languageHandler # noqa: E402

include/py2exe

Lines changed: 0 additions & 1 deletion
This file was deleted.

readme.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ For reference, the following run time dependencies are included in Git submodule
103103

104104
Additionally, the following build time dependencies are included in Git submodules:
105105

106-
* [Py2Exe](https://github.com/albertosottile/py2exe/), version 0.9.3.2 commit b372a8e
107106
* [Python Windows Extensions](https://sourceforge.net/projects/pywin32/ ), build 224, required by py2exe
108107
* [txt2tags](https://txt2tags.org/), version 2.5
109108
* [SCons](https://www.scons.org/), version 4.0.1
@@ -113,8 +112,12 @@ Additionally, the following build time dependencies are included in Git submodul
113112
* [Boost Optional (stand-alone header)](https://github.com/akrzemi1/Optional), from commit [3922965](https://github.com/akrzemi1/Optional/commit/3922965396fc455c6b1770374b9b4111799588a9)
114113

115114
### Other Dependencies
115+
Some dependencies are installed automatically via pip as needed.
116+
Developers may wish to first configure a Python Virtual Environment to ensure their general install is not affected.
117+
118+
To build binary version of NVDA py2exe version 0.10.1.0 is installed automatically when executing `scons dist`
116119
To lint using Flake 8 locally using our SCons integration, some dependencies are installed (automatically) via pip.
117-
Although this [must be run manually](#linting-your-changes), developers may wish to first configure a Python Virtual Environment to ensure their general install is not affected.
120+
This [must be run manually](#linting-your-changes).
118121
* Flake8
119122
* Flake8-tabs
120123

sconstruct

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# A part of NonVisual Desktop Access (NVDA)
2-
# Copyright (C) 2010-2020 NV Access Limited, James Teh, Michael Curran, Peter Vágner, Joseph Lee, Reef Turner, Babbage B.V., Leonard de Ruijter, Łukasz Golonka, Accessolutions, Julien Cochuyt # noqa: E501
2+
# Copyright (C) 2010-2021 NV Access Limited, James Teh, Michael Curran, Peter Vágner, Joseph Lee,
3+
# Reef Turner, Babbage B.V., Leonard de Ruijter, Łukasz Golonka, Accessolutions, Julien Cochuyt
34
# This file may be used under the terms of the GNU General Public License, version 2 or later.
45
# For more details see: https://www.gnu.org/licenses/gpl-2.0.html
56

@@ -41,10 +42,10 @@ if sys.version_info.micro == 6:
4142
sourceEnvPath = os.path.abspath(os.path.join(Dir('.').srcnode().path, "source"))
4243
sys.path.append(sourceEnvPath)
4344
import sourceEnv
45+
sourceEnv.expandPythonPath()
4446
sys.path.remove(sourceEnvPath)
4547
import time
4648
from glob import glob
47-
from py2exe.dllfinder import pydll
4849
import importlib.util
4950
import winreg
5051

@@ -265,8 +266,13 @@ for t2tFile in env.Glob(os.path.join(userDocsDir.path,'*','*.t2t')):
265266
# Build unicode CLDR dictionaries
266267
env.SConscript('cldrDict_sconscript',exports=['env', 'sourceDir'])
267268

269+
270+
REQUIRED_PY2EXE_VER = "py2exe==0.10.1.0"
271+
268272
# A builder to generate an NVDA distribution.
269273
def NVDADistGenerator(target, source, env, for_signature):
274+
import buildFunctions
275+
buildFunctions.requestPackage(REQUIRED_PY2EXE_VER)
270276
buildVersionFn = os.path.join(str(source[0]), "_buildVersion.py")
271277
# Make the NVDA build use the specified version.
272278
# We don't do this using normal scons mechanisms because we want it to be cleaned up immediately after this builder
@@ -299,11 +305,6 @@ def NVDADistGenerator(target, source, env, for_signature):
299305

300306
action.append(buildCmd)
301307

302-
# Python3 has started signing its main python dll.
303-
# However, Py2exe currently tries to add a string resource to it, invalidating the signature and possibly currupting the certificate.
304-
# Therefore, copy a fresh version of the dll one more time once py2exe has completed.
305-
action.append(Copy(target[0],pydll))
306-
307308
# #10031: Apps written in Python 3 require Universal CRT to be installed. We cannot assume users have it on their systems.
308309
# Therefore , copy required libraries from Windows 10 SDK.
309310
try:

source/nvda.pyw

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ if getattr(sys, "frozen", None):
1919
appDir = sys.prefix
2020
else:
2121
import sourceEnv
22+
sourceEnv.expandPythonPath()
2223
#We should always change directory to the location of this module (nvda.pyw), don't rely on sys.path[0]
2324
appDir = os.path.normpath(os.path.dirname(__file__))
2425
appDir = os.path.abspath(appDir)

source/sourceEnv.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# A part of NonVisual Desktop Access (NVDA)
2-
# Copyright (C) 2013-2020 NV Access Limited, Leonard de Ruijter
2+
# Copyright (C) 2013-2021 NV Access Limited, Leonard de Ruijter
33
# This file is covered by the GNU General Public License.
44
# See the file COPYING for more details.
55

@@ -11,21 +11,35 @@
1111

1212
# Get the path to the top of the repo; i.e. where include and miscDeps are.
1313
TOP_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
14+
15+
16+
def pythonPackagesDir() -> str:
17+
"""Returns path to the directory in which packages installed using pip should be placed.
18+
The directory would be created if it does not exist.
19+
"""
20+
PACKAGES_DIR = os.path.abspath(os.path.join(TOP_DIR, "installed_packages"))
21+
os.makedirs(PACKAGES_DIR, exist_ok=True)
22+
return PACKAGES_DIR
23+
24+
1425
# Directories containing Python modules included in git submodules.
1526
PYTHON_DIRS = (
1627
os.path.join(TOP_DIR, "include", "pyserial"),
1728
os.path.join(TOP_DIR, "include", "comtypes"),
1829
os.path.join(TOP_DIR, "include", "configobj", "src"),
1930
os.path.join(TOP_DIR, "include", "wxPython"),
20-
os.path.join(TOP_DIR, "include", "py2exe"),
2131
os.path.join(TOP_DIR, "miscDeps", "python"),
32+
pythonPackagesDir(),
2233
)
2334

24-
#Check for existance of each Python dir
25-
for path in PYTHON_DIRS:
26-
if not os.path.exists(path):
27-
raise OSError("Path %s does not exist. Perhaps try running git submodule update --init"%path)
2835

29-
# sys.path[0] will always be the current dir, which should take precedence.
30-
# Insert our include paths after that.
31-
sys.path[1:1] = PYTHON_DIRS
36+
def expandPythonPath() -> None:
37+
"""Adds `PYTHON_DIRS` to the `PythonPath` of the current interpreter
38+
raising appropriate exceptions if any of the dirs does not exist."""
39+
# Check for existance of each Python dir
40+
for path in PYTHON_DIRS:
41+
if not os.path.exists(path):
42+
raise OSError("Path %s does not exist. Perhaps try running git submodule update --init" % path)
43+
# sys.path[0] will always be the current dir, which should take precedence.
44+
# Insert our include paths after that.
45+
sys.path[1:1] = PYTHON_DIRS

tests/unit/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# tests/unit/__init__.py
21
# A part of NonVisual Desktop Access (NVDA)
32
# This file is covered by the GNU General Public License.
43
# See the file COPYING for more details.
@@ -31,9 +30,9 @@
3130
SOURCE_DIR = os.path.join(TOP_DIR, "source")
3231
# Let us import modules from the NVDA source.
3332
sys.path.insert(1, SOURCE_DIR)
34-
# Suppress Flake8 warning F401 (module imported but unused)
35-
# as this module is imported to expand the system path.
36-
import sourceEnv # noqa: F401
33+
34+
import sourceEnv
35+
sourceEnv.expandPythonPath()
3736

3837
import globalVars
3938

0 commit comments

Comments
 (0)