Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ source/userConfig
build
build_debug
dist
installed_packages
*.dll
*.exe
*.manifest
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
[submodule "include/configobj"]
path = include/configobj
url = https://github.com/DiffSK/configobj.git
[submodule "include/py2exe"]
path = include/py2exe
url = https://github.com/nvaccess/py2exe-bin
[submodule "include/javaAccessBridge32"]
path = include/javaAccessBridge32
url = https://github.com/nvaccess/javaAccessBridge32-bin.git
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ build_script:
Set-AppveyorBuildVariable "sconsOutTargets" $sconsOutTargets
Set-AppveyorBuildVariable "sconsArgs" $sconsArgs
- 'echo scons args: %sconsArgs%'
- py -m pip install --upgrade pip
- py scons.py source %sconsArgs%
# We don't need launcher to run checkPot, so run the checkPot before launcher.
- py scons.py checkPot %sconsArgs%
Expand All @@ -119,7 +120,6 @@ build_script:

before_test:
# install required packages
- py -m pip install --upgrade pip
- py -m pip install -r tests/system/requirements.txt -r tests/lint/lintInstall/requirements.txt
- mkdir testOutput
- mkdir testOutput\unit
Expand Down
49 changes: 49 additions & 0 deletions buildFunctions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# A part of NonVisual Desktop Access (NVDA)
# Copyright (C) 2021 NV Access Limited, Łukasz Golonka
# This file may be used under the terms of the GNU General Public License, version 2 or later.
# For more details see: https://www.gnu.org/licenses/gpl-2.0.html

"""Functions useful when building NVDA"""

import os


def pythonPackagesDir() -> str:
"""Returns path to the directory in which packages installed using pip should be placed.
The directory would be created if it does not exist.
"""
PACKAGES_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "installed_packages"))
os.makedirs(PACKAGES_DIR, exist_ok=True)
return PACKAGES_DIR


def installCallback(package):
import importlib
import pkg_resources
importlib.reload(pkg_resources)
requestedPackage = pkg_resources.working_set.find(
list(pkg_resources.parse_requirements(str(package)))[0]
)
if requestedPackage:
return requestedPackage
import sys
import subprocess
subprocess.check_call(
[sys.executable, "-m", "pip", "install", "-t", pythonPackagesDir(), str(package)]
)
import pkg_resources
# Evenn though this is quite ugly there is no other way to refresh list of available packages.
importlib.reload(pkg_resources)
return pkg_resources.working_set.find(
# `resolve` considers installation to be succesfull only when installed package is
# returned from the callback.
list(pkg_resources.parse_requirements(str(package)))[0]
)


def requestPackage(requirementsString):
import pkg_resources
pkg_resources.working_set.resolve(
pkg_resources.parse_requirements(requirementsString),
installer=installCallback
)
4 changes: 3 additions & 1 deletion devDocs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import os
import sys
sys.path.insert(0, os.path.abspath('../source'))
import sourceEnv # noqa: F401, E402
import sourceEnv # noqa: E402

sourceEnv.expandPythonPath()

# Initialize languageHandler so that sphinx is able to deal with translatable strings.
import languageHandler # noqa: E402
Expand Down
1 change: 0 additions & 1 deletion include/py2exe
Submodule py2exe deleted from c496ae
7 changes: 5 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ For reference, the following run time dependencies are included in Git submodule

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

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

### Other Dependencies
Some dependencies are installed automatically via pip as needed.
Developers may wish to first configure a Python Virtual Environment to ensure their general install is not affected.

To build binary version of NVDA py2exe version 0.10.1.0 is installed automatically when executing `scons dist`
To lint using Flake 8 locally using our SCons integration, some dependencies are installed (automatically) via pip.
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.
This [must be run manually](#linting-your-changes).
* Flake8
* Flake8-tabs

Expand Down
21 changes: 12 additions & 9 deletions sconstruct
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# A part of NonVisual Desktop Access (NVDA)
# 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
# Copyright (C) 2010-2021 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
# This file may be used under the terms of the GNU General Public License, version 2 or later.
# For more details see: https://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -41,10 +42,10 @@ if sys.version_info.micro == 6:
sourceEnvPath = os.path.abspath(os.path.join(Dir('.').srcnode().path, "source"))
sys.path.append(sourceEnvPath)
import sourceEnv
sourceEnv.expandPythonPath()
sys.path.remove(sourceEnvPath)
import time
from glob import glob
from py2exe.dllfinder import pydll
import importlib.util
import winreg

Expand Down Expand Up @@ -281,15 +282,22 @@ for t2tFile in env.Glob(os.path.join(userDocsDir.path,'*','*.t2t')):
# Build unicode CLDR dictionaries
env.SConscript('cldrDict_sconscript',exports=['env', 'sourceDir'])


REQUIRED_PY2EXE_VER = "py2exe==0.10.1.0"

# A builder to generate an NVDA distribution.
def NVDADistGenerator(target, source, env, for_signature):
action = []
action.append(
[sys.executable, "-c", f"import buildFunctions; buildFunctions.requestPackage('{REQUIRED_PY2EXE_VER}');"]
)
buildVersionFn = os.path.join(str(source[0]), "_buildVersion.py")
# Make the NVDA build use the specified version.
# We don't do this using normal scons mechanisms because we want it to be cleaned up immediately after this builder
# and py2exe will cause bytecode files to be created for it which scons doesn't know about.
updateVersionType = env["updateVersionType"] or None
# Any '\n' characters written are translated to the system default line separator, os.linesep.
action = [lambda target, source, env: open(buildVersionFn, "w", encoding="utf-8").write(
action.append([lambda target, source, env: open(buildVersionFn, "w", encoding="utf-8").write(
'version = {version!r}\n'
'publisher = {publisher!r}\n'
'updateVersionType = {updateVersionType!r}\n'
Expand All @@ -298,7 +306,7 @@ def NVDADistGenerator(target, source, env, for_signature):
)
# In Python 3 write returns the number of characters written,
# which scons treats as an error code.
and None]
and None][0])

buildCmd = ["cd", source[0].path, "&&",
sys.executable]
Expand All @@ -315,11 +323,6 @@ def NVDADistGenerator(target, source, env, for_signature):

action.append(buildCmd)

# Python3 has started signing its main python dll.
# However, Py2exe currently tries to add a string resource to it, invalidating the signature and possibly currupting the certificate.
# Therefore, copy a fresh version of the dll one more time once py2exe has completed.
action.append(Copy(target[0],pydll))

# #10031: Apps written in Python 3 require Universal CRT to be installed. We cannot assume users have it on their systems.
# Therefore , copy required libraries from Windows 10 SDK.
try:
Expand Down
1 change: 1 addition & 0 deletions source/nvda.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ if getattr(sys, "frozen", None):
appDir = sys.prefix
else:
import sourceEnv
sourceEnv.expandPythonPath()
#We should always change directory to the location of this module (nvda.pyw), don't rely on sys.path[0]
appDir = os.path.normpath(os.path.dirname(__file__))
appDir = os.path.abspath(appDir)
Expand Down
33 changes: 24 additions & 9 deletions source/sourceEnv.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# A part of NonVisual Desktop Access (NVDA)
# Copyright (C) 2013-2020 NV Access Limited, Leonard de Ruijter
# Copyright (C) 2013-2021 NV Access Limited, Leonard de Ruijter
# This file is covered by the GNU General Public License.
# See the file COPYING for more details.

Expand All @@ -11,21 +11,36 @@

# Get the path to the top of the repo; i.e. where include and miscDeps are.
TOP_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))


def getBuildFunctions():
try:
import buildFunctions
except ImportError:
sys.path.append(TOP_DIR)
import buildFunctions
sys.path.remove(TOP_DIR)
return buildFunctions


# Directories containing Python modules included in git submodules.
PYTHON_DIRS = (
os.path.join(TOP_DIR, "include", "pyserial"),
os.path.join(TOP_DIR, "include", "comtypes"),
os.path.join(TOP_DIR, "include", "configobj", "src"),
os.path.join(TOP_DIR, "include", "wxPython"),
os.path.join(TOP_DIR, "include", "py2exe"),
os.path.join(TOP_DIR, "miscDeps", "python"),
getBuildFunctions().pythonPackagesDir(),
)

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

# sys.path[0] will always be the current dir, which should take precedence.
# Insert our include paths after that.
sys.path[1:1] = PYTHON_DIRS
def expandPythonPath() -> None:
"""Adds `PYTHON_DIRS` to the `PythonPath` of the current interpreter
raising appropriate exceptions if any of the dirs does not exist."""
# Check for existance of each Python dir
for path in PYTHON_DIRS:
if not os.path.exists(path):
raise OSError("Path %s does not exist. Perhaps try running git submodule update --init" % path)
# sys.path[0] will always be the current dir, which should take precedence.
# Insert our include paths after that.
sys.path[1:1] = PYTHON_DIRS
7 changes: 3 additions & 4 deletions tests/unit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# tests/unit/__init__.py
# A part of NonVisual Desktop Access (NVDA)
# This file is covered by the GNU General Public License.
# See the file COPYING for more details.
Expand Down Expand Up @@ -31,9 +30,9 @@
SOURCE_DIR = os.path.join(TOP_DIR, "source")
# Let us import modules from the NVDA source.
sys.path.insert(1, SOURCE_DIR)
# Suppress Flake8 warning F401 (module imported but unused)
# as this module is imported to expand the system path.
import sourceEnv # noqa: F401

import sourceEnv # noqa: E402
sourceEnv.expandPythonPath()

import globalVars

Expand Down