Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Py3.8: Transparently use a Python virtual environment under the hood #12075

Merged
merged 72 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
adf131a
Build NVDA with Python 3.8 32-bit (#12042)
josephsl Feb 15, 2021
5e87120
Remove any git submodules to distributions we can instead fetch with …
michaelDCurran Feb 15, 2021
c8fc42b
List all required Python packages in a requirements.txt in the root o…
michaelDCurran Feb 15, 2021
9c9d1e1
Ssconscripts: import SCons correctly.
michaelDCurran Feb 15, 2021
3878133
Appveyor: Create and activate a Python virtual environment. Also use …
michaelDCurran Feb 15, 2021
90a7183
Update readme.md
michaelDCurran Feb 15, 2021
cd4a3cf
appveyor.yml: no need to specifify python version in specific command…
michaelDCurran Feb 16, 2021
9503492
.gitignore: ignore the .venv directory
michaelDCurran Feb 16, 2021
fd890d3
setup.py: don't package numpy with NVDA.
michaelDCurran Feb 16, 2021
4a852d9
Use py2exe 0.10.1.0 rather than py2exe 0.10.2.0 which seems to actual…
michaelDCurran Feb 16, 2021
5795e76
Python 3.8/liblouis helper: add NVDA executable path by calling os.ad…
josephsl Feb 16, 2021
6d58baa
Merge branch 'py3.8' into py3.8_manualVenv
michaelDCurran Feb 16, 2021
3025d74
Use comtypes 1.1.7.
michaelDCurran Feb 16, 2021
8074fa1
System tests: don't specify Python 3.7 when running system tests with…
michaelDCurran Feb 16, 2021
c22b7b3
appveyor: run nose with the --traverse-namespace option as it is now …
michaelDCurran Feb 17, 2021
0179e48
Update to miscDeps containing brlAPI for Python 3.8
michaelDCurran Feb 17, 2021
f70b0e8
Work around for issue #12058: In wxPython >= 4.1, wx.CallAfter no lon…
michaelDCurran Feb 17, 2021
cbd21be
Merge remote-tracking branch 'origin/py3.8' into py3.8_manualVenv
michaelDCurran Feb 17, 2021
6f427af
Explicitly include xmlrpc.server with py2exe, as it is required for s…
michaelDCurran Feb 17, 2021
e59018e
sourceEnv: stop the user from running with no virtual environment.
michaelDCurran Feb 22, 2021
daf53a1
Integrate the Python virtual environment transparently into the build…
michaelDCurran Feb 24, 2021
ef52123
Fix typo
michaelDCurran Feb 24, 2021
e7a54fd
ensureVenv.py: flush standard out before running any sub processes ot…
michaelDCurran Feb 24, 2021
713397c
remove some unneeded imports.
michaelDCurran Feb 25, 2021
c60975e
Update pip within the virtual environment, not before, as a stock-sta…
michaelDCurran Feb 25, 2021
da159ae
ensureVenv: address review commnts.
michaelDCurran Feb 25, 2021
2a9df26
core.main: FreeConsole returns 0 on failure rather than raising an ex…
michaelDCurran Feb 25, 2021
459e3a3
Added runnvdaw.bat which runs NVDA without blocking. this provides th…
michaelDCurran Feb 25, 2021
12ae5a8
Merge branch 'master' into py3.8
michaelDCurran Mar 1, 2021
ada0b85
Merge branch 'py3.8' into py3.8_manualVenv
michaelDCurran Mar 1, 2021
73c8490
appveyor: push the list of installed python packages directly as an …
michaelDCurran Mar 1, 2021
19120dd
linting for venvUtils/ensureVenv.py
michaelDCurran Mar 1, 2021
e924a87
Linting for source/setup.py
michaelDCurran Mar 1, 2021
1b827b6
add rununittests.bat to provide a faster way of running the unit test…
michaelDCurran Mar 1, 2021
1039dc5
Add runsystemtests.bat as a quick way of running the system tests, wi…
michaelDCurran Mar 1, 2021
8a13814
Add runlint.bat which provides a quicker way of linting. Rather than …
michaelDCurran Mar 1, 2021
91193e2
Add diff-match-patch as a Python package requirement as NVDA_DMP need…
michaelDCurran Mar 3, 2021
f47db8e
Sync with latest nvda_dmp. (#12113)
codeofdusk Mar 3, 2021
8375c3e
Cnfigobj is now fetched by pip, rather than it being a git submodule.
michaelDCurran Mar 3, 2021
2f01c39
Address review comments: final line ending / extra spaces.
michaelDCurran Mar 3, 2021
f1eb3e9
venvCmd.bat: allow executing a command when already inside an NVDA Py…
michaelDCurran Mar 3, 2021
89922ec
appveyor: abort on failure of scons and other commands.
michaelDCurran Mar 3, 2021
b834a4e
Ensure that scons.bat and other high-level commands correctly propaga…
michaelDCurran Mar 3, 2021
2039871
Revert "core.main: FreeConsole returns 0 on failure rather than raisi…
michaelDCurran Mar 4, 2021
e2e23ed
core.main: revert addition of FreeConsole. This will be handled in a …
michaelDCurran Mar 4, 2021
34e7107
For now runnvda.bat (python) has been removed, and runnvdaw.bat (pyth…
michaelDCurran Mar 4, 2021
711eb37
garbageHandler: revert fix to "Nonetype is not callable" when Python …
michaelDCurran Mar 4, 2021
ed432bf
Remove targets for unit tests, system tests and linting from SCons as…
michaelDCurran Mar 4, 2021
b0cb717
Appveyor now calls runlint, rununittests and runsystemtests rather th…
michaelDCurran Mar 7, 2021
7eb2584
Update system tests readme to talk about runsystemtests, and not SCons.
michaelDCurran Mar 7, 2021
ee498f3
readme: briefly mention Nose and Robot and providing them extra argum…
michaelDCurran Mar 7, 2021
7b125c6
tests/sconscript: remove all code unrelated to checkPot.
michaelDCurran Mar 7, 2021
b59263d
appveyor: call our batch files as a relative path otherise Powershell…
michaelDCurran Mar 7, 2021
e820763
appveyor: py3.8 is a branch we should run builds for.
michaelDCurran Mar 7, 2021
d8a89c0
runlint.bat: fix path.
michaelDCurran Mar 7, 2021
d5e480c
add a description of the build system to the devDocs directory.
michaelDCurran Mar 7, 2021
e0f9c6b
NVDA build system commands no longer refuse to run if not in NVDA's s…
michaelDCurran Mar 8, 2021
c6c13e0
Linting
michaelDCurran Mar 8, 2021
dd70ba8
Apply suggestions from code review
michaelDCurran Mar 8, 2021
95339d6
System tests: use runnvda.bat rather than pyw source\nvda.pyw directly.
michaelDCurran Mar 8, 2021
9ab0f6d
scons dist: copy crt dlls from the latest installed sdk (I.e. the one…
michaelDCurran Mar 9, 2021
e008f1d
appveyor: Move generation of the installed_python_packages.txt file t…
michaelDCurran Mar 9, 2021
110edc1
Call pip freeze from a batch file in appveyor, as it seems that power…
michaelDCurran Mar 9, 2021
778e512
Update buildSystemNotes
feerrenrut Mar 10, 2021
06411a0
buildSystemNotes: address some typos.
michaelDCurran Mar 11, 2021
9b1c16a
Remove workaround for issue #9762 (#12142)
lukaszgo1 Mar 11, 2021
cc7d219
Python 3.8: Mention additional system requirements for Windows 7 (#12…
lukaszgo1 Mar 11, 2021
0b78587
Python 3.8/gettext: replace custom pgettext implementation with built…
josephsl Mar 11, 2021
0dbdaed
Merge branch 'master' into py3.8
michaelDCurran Mar 11, 2021
49ea5ae
Merge branch 'py3.8' into py3.8_manualVenv
michaelDCurran Mar 11, 2021
7a6fc4d
Update what's new
michaelDCurran Mar 11, 2021
cca866a
appveyor: remove mention of py3.8 branch, no longer needed.
michaelDCurran Mar 11, 2021
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 @@ -42,3 +42,4 @@ tests/unit/nvda.ini
source/locale/*/cldr.dic
.vscode
.vs
.venv
19 changes: 0 additions & 19 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,9 @@
path = include/sonic
url = https://github.com/waywardgeek/sonic.git
ignore = untracked
[submodule "include/pyserial"]
path = include/pyserial
url = https://github.com/pyserial/pyserial.git
ignore = untracked
[submodule "include/comtypes"]
path = include/comtypes
url = https://github.com/nvaccess/comtypes-bin
[submodule "include/scons"]
path = include/scons
url = https://github.com/SCons/scons
[submodule "include/ia2"]
path = include/ia2
url = https://github.com/LinuxA11y/IAccessible2.git
[submodule "include/wxPython"]
path = include/wxPython
url = https://github.com/nvaccess/wxPython-bin.git
[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
48 changes: 25 additions & 23 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ branches:
- master
- beta
- rc
- py3.8
- /try-.*/
# For tags, branch = tag if GitHub couldn't work out the base branch.
- /release-.*/

environment:
PY_PYTHON: 3.7-32
PY_PYTHON: 3.8-32
encFileKey:
secure: ekOvuyywHuDdGZmRmoj+b3jfrq39A2xlx4RD5ZUGd/8=
mozillaSymsAuthToken:
Expand Down Expand Up @@ -95,12 +96,15 @@ build_script:
Set-AppveyorBuildVariable "sconsOutTargets" $sconsOutTargets
Set-AppveyorBuildVariable "sconsArgs" $sconsArgs
- 'echo scons args: %sconsArgs%'
- py scons.py source %sconsArgs%
- scons source %sconsArgs%
- if ERRORLEVEL 1 exit %ERRORLEVEL%
# We don't need launcher to run checkPot, so run the checkPot before launcher.
- py scons.py checkPot %sconsArgs%
- scons checkPot %sconsArgs%
feerrenrut marked this conversation as resolved.
Show resolved Hide resolved
- if ERRORLEVEL 1 exit %ERRORLEVEL%
# The pot gets built by tests, but we don't actually need it as a build artifact.
- 'echo scons output targets: %sconsOutTargets%'
- py scons.py %sconsOutTargets% %sconsArgs%
- scons %sconsOutTargets% %sconsArgs%
- if ERRORLEVEL 1 exit %ERRORLEVEL%
# Build symbol store.
- ps: |
foreach ($syms in
Expand All @@ -115,12 +119,10 @@ build_script:
}
- cd symbols
- 7z a -tzip -r ..\output\symbols.zip *.dl_ *.ex_ *.pd_
- if ERRORLEVEL 1 exit %ERRORLEVEL%
- cd ..

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
- mkdir testOutput\system
Expand Down Expand Up @@ -153,7 +155,7 @@ test_script:
$errorCode=0
$outDir = (Resolve-Path .\testOutput\unit\)
$unitTestsXml = "$outDir\unitTests.xml"
py -m nose -sv --with-xunit --xunit-file="$unitTestsXml" ./tests/unit
.\rununittests.bat --with-xunit --xunit-file="$unitTestsXml"
if($LastExitCode -ne 0) {
$errorCode=$LastExitCode
Add-AppveyorMessage "Unit test failure"
Expand All @@ -168,12 +170,14 @@ test_script:
if($env:APPVEYOR_PULL_REQUEST_NUMBER) {
$lintOutput = (Resolve-Path .\testOutput\lint\)
$lintSource = (Resolve-Path .\tests\lint\)
git fetch -q origin $env:APPVEYOR_REPO_BRANCH
$prDiff = "$lintOutput\prDiff.patch"
git diff -U0 FETCH_HEAD...HEAD > $prDiff
$flake8Config = "$lintSource\flake8.ini"
$flake8Output = "$lintOutput\PR-Flake8.txt"
type "$prDiff" | py -Xutf8 -m flake8 --diff --output-file="$flake8Output" --tee --config="$flake8Config"
# When Appveyor runs for a pr,
# the build is made from a new temporary commit,
# resulting from the pr branch being merged into its base branch.
# Therefore to create a diff for linting, we must fetch the head of the base branch.
# In a PR, APPVEYOR_REPO_BRANCH points to the head of the base branch.
git fetch -q origin $env:APPVEYOR_REPO_BRANCH
$flake8Output = "$lintOutput\PR-Flake8.txt"
.\runlint.bat FETCH_HEAD "$flake8Output"
if($LastExitCode -ne 0) {
$errorCode=$LastExitCode
Add-AppveyorMessage "PR introduces Flake8 errors"
Expand All @@ -191,19 +195,14 @@ test_script:
- ps: |
$testOutput = (Resolve-Path .\testOutput\)
$systemTestOutput = (Resolve-Path "$testOutput\system")
$testSource = ".\tests\system\robot"

$robotArgs = '--argumentfile', '.\tests\system\robotArgs.robot'
# useInstalledNVDA must come after args file to override the whichNVDA value
$useInstalledNVDA = '--variable', 'whichNVDA:installed'

py -m robot $robotArgs $useInstalledNVDA $testSource
Compress-Archive -Path "$systemTestOutput\*" -DestinationPath "$testOutput\systemTestResult.zip"
Push-AppveyorArtifact "$testOutput\systemTestResult.zip"

.\runsystemtests.bat --variable whichNVDA:installed
if($LastExitCode -ne 0) {
$errorCode=$LastExitCode
Add-AppveyorMessage "System test failure"
}
Compress-Archive -Path "$systemTestOutput\*" -DestinationPath "$testOutput\systemTestResult.zip"
Push-AppveyorArtifact "$testOutput\systemTestResult.zip"
$wc = New-Object 'System.Net.WebClient'
$wc.UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path "$systemTestOutput\systemTests.xml"))
if($errorCode -ne 0) { $host.SetShouldExit($errorCode) }
Expand Down Expand Up @@ -273,6 +272,9 @@ deploy_script:
on_finish:
# add a message to point to the NVDA build, to make testing PR's easier.
- ps: |
# Save an exact list of the actual Python packages and their versions that got installed, to aide in reproducing a build
.\venvUtils\exportPackageList.bat installed_python_packages.txt
Push-AppveyorArtifact installed_python_packages.txt
$appVeyorUrl = "https://ci.appveyor.com"
$exe = Get-ChildItem -Name output\*.exe
if($?){
Expand Down
74 changes: 74 additions & 0 deletions devDocs/buildSystemNotes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Build System Notes
A Python virtual environment is used transparently by the NVDA build system,
and all Python dependencies are installed into this environment using `pip`.

NVDA's build system commands will handle all aspects of the virtual environment.
Developers should not create or activate the virtual environment manually, unless
working on the build system itself.

For the documentation on how to _use_ the build system (E.G. building,
running NVDA or tests) see the main repository readme file.

## How the build system works

The virtual environment system used is `venv`.
Dependencies are installed with `pip` via the `requirements.txt` file.
Version numbers for dependencies should be used to lock in a version.

The virtual environment is recreated if it is outdated, either due to:
- Python version.
- `pip` requirements.

The user is consulted before modifying / removing a virtual environment that can't be identified
as having been created by NVDA's build system.

### Entry points to the build system

These are the only files expected to be executed directly by a user/developer:
- `scons.bat`
- `runnvda.bat`
- `rununittests.bat`
- `runsystemtests.bat`
- `runlint.bat`

**Note:** The `runnvda.bat` script intentionally uses `pyw.exe` to run NVDA as
this is the more common and expected way to run NVDA.
Run NVDA with `py.exe` in order to have standard output/error output to the console.
This is particularly useful if there is an error in NVDA before logging is initialised.
To do this, modify the `runnvda.bat` file.

**Note:** Executing `source/nvda.pyw` outside of a virtual environment will produce an error message
and early termination.

### Main implementation files:
The following files contain the main implementation of the virtual environment setup.

#### `venvUtils/ensureAndActivate.bat`
- Activates the virtual environment.
- If necessary, creates and configures it first.
- The virtual environment is left active.
#### `venvUtils/venvCmd.bat`
- Uses `ensureAndActivate.bat` to run a command within the context
of the virtual environment.
- The virtual environment is deactivated after the command
completes.
- All entry point scripts depend on this.
#### `venvUtils/ensureVenv.py`
- Does the actual work to create and configure the virtual
environment.

## Motivation for using virtual environments

Ensures the build environment is clean, and there are no conflicts with other installed packages.

NVDA and its build system have many Python dependencies.
Using `pip` and a virtual environment means:
- Updating is easier than git submodules.
E.G. wxPython no longer has to be pre-built and stored in our bin repo.
- Developers need to sync/update their submodules less often.
- More consistency for dependencies.
- IDE's can be configured more easily.
- No conflict between NVDA dependencies and Python packages already installed globally on the
developer's system.
- Don't interfere with the developer's system. Installing packages globally may break things
outside of NVDA.
1 change: 0 additions & 1 deletion devDocs/devDocsInstall/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions devDocs/devDocsInstall/requirements.txt

This file was deleted.

35 changes: 0 additions & 35 deletions devDocs/devDocsInstall/sconscript

This file was deleted.

5 changes: 0 additions & 5 deletions devDocs/sconscript
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ Import("env", "outputDir", "sourceDir", "t2tBuildConf")

env = env.Clone()

devDocsInstall = env.SConscript("devDocsInstall/sconscript", exports=["env"])
env.Depends(devDocsInstall, env.Dir("devDocs/devDocsInstall/requirements.txt"))
env.Alias("devDocsInstall", devDocsInstall)

devDocsOutputDir=outputDir.Dir('devDocs')

#Build the developer guide and move it to the output directory
Expand Down Expand Up @@ -69,7 +65,6 @@ sphinxAPIDocs = env.Command(
] + [f"{sourceDir}\\{f}" for f in ignorePaths]
]
)
env.Depends(sphinxAPIDocs, devDocsInstall)
sphinxHtml = env.Command(
"_build",
sphinxAPIDocs,
Expand Down
1 change: 0 additions & 1 deletion include/comtypes
Submodule comtypes deleted from 8c4558
1 change: 0 additions & 1 deletion include/configobj
Submodule configobj deleted from f9a265
2 changes: 1 addition & 1 deletion include/nvda_dmp
1 change: 0 additions & 1 deletion include/py2exe
Submodule py2exe deleted from c496ae
1 change: 0 additions & 1 deletion include/pyserial
Submodule pyserial deleted from c54c81
1 change: 0 additions & 1 deletion include/scons
Submodule scons deleted from dfcc78
1 change: 0 additions & 1 deletion include/wxPython
Submodule wxPython deleted from 11de93
2 changes: 0 additions & 2 deletions nvdaHelper/espeak/sconscript
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from include.scons.SCons.Util import CLVar

Import([
'thirdPartyEnv',
'sourceDir',
Expand Down
4 changes: 2 additions & 2 deletions nvdaHelper/liblouis/sconscript
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import re
import glob
from SCons.Tool.MSCommon.vc import find_vc_pdir
import typing
from include.scons.SCons.Environment import Environment
from include.scons.SCons.Environment import Base
from SCons.Environment import Environment
from SCons.Environment import Base

Import([
"thirdPartyEnv",
Expand Down
Loading