-
-
Notifications
You must be signed in to change notification settings - Fork 655
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
Conversation
* SConstruct: specify Pyhton 3.8. * SConstruct: remove Python 3.7.6 check. The latest version of Python 3.7 is 3.7.9 (as of February 2021). Therefore remove 3.7.6 check. * SConstruct: update copyright year * SCons.bat: run SCons under Python 3.8 (32-bit). * Revert "SConstruct: update copyright year" This reverts commit 096f61b due to impending Py2Exe upgrade that will update copyright header. * scons.bat: update comment * Readme: mention Python 3.8. * appveyor.yml: Instruct appveyor to use Python 3.8 Co-authored-by: Michael Curran <[email protected]>
…f the repository. Remove the existing requirements.txt files and logic for devDocs and system tests and linting. Have appveyor fetch all Python dependencies at the beginning of the build.
…scons.exe rather than our scons.py Remove scons.bat and scons.py.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Please add .venv to the .gitignore.
- Why exactly you've deleted
scons.bat
andsconns.py
when we would look into automating this process they probably would need to be reintroduced in some form.
appveyor.yml
Outdated
# Ensure we have the latest version of pip | ||
- py -m pip install --upgrade pip | ||
# Create a Python virtual environment | ||
- py -3.8-32 -m venv .venv |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
…s as it is set globally.
…ly import some of our modules and then break because of globalVars.appDir not existing yet.
…d_dll_directory (#12020) * Louis helper: update copyright header * Louis helper/Python 3.8: call os.add_dll_directory when importing libluis DLL. Python 3.8 adds os.add_dll_directory to securely load DLL's from known locations, which affects Louis helper when trying to load liblouis.dll from NVDA executable folder. Therefore add NVDA executable path to known DLL directories through os.add_dll_directory, which resolves ModuleNotFoundError. * Louis helper: remove header comment, use globalVars.appDir as executable path. Reviewed by Lukasz Golonka: remove file name from header comment. Also, because __file__ will point to library.zip, use globalVars.appDir to locate NVDA executable where liblouis.dll actually resides. * Louis helper: use globalVars.appDir directly rather than going through os.path.dirname. Pointed out by Lukasz Golonka: globalVars.appDir records the actual path to the executable, including in source code version (nvda.pyw). Therefore use app dir directly.
… source version of NVDA
…required for locating unit tests in Python 3.8.
…ger executes callbacks while NVDA's main thread is within apopup menu or message box. (#12072) Monkeypatch wx.CallAfter to post a WM_NULL message to our top-level window after calling the original CallAfter, which causes wx's event loop to wake up enough to execute the callback.
…ystem tests by robotremoteserver, but it can't seem to be imported from our NVDA profile directory.
readme.md
Outdated
To activate the virtual environment: | ||
``` | ||
.venv\scripts\activate.bat | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I would switch the paragraphs around and simply instruct users to first create a virtual environment and then run the pip command. Since this is what AppVeyor will also do, and it is good practice anyway, why bother with howevers and maybes? Just my 2 Cents.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I think we should move all the "doing a local build" stuff into a dedicated file or at least section. It should be ordered so it can be followed step by step.
… system. It is now possible to run the scons command the same way you normally would, with out worrying about having to create or activate a virtual environment. This is now done behind the scenes for you. Note that you must execute scons, or scons.bat though, not py -m SCons or some other invocation. To run NVDA from source, it is now necessary to execute runnvda (runnvda.bat) in the root of the repository. This script will block until NVDA exits, though you can still run it in the background by doing ``` start /b runnvda ``` Note that trying to execute source\nvda.pyw directly will now display an error as the NVDA build system Python virtual environment will not be detected doing it this way. Behind the scenes, SCons and runnvda ensure that the Python virtual environment is created and up to date, activates the environment, runs the command and then deactivates. All transparently. A developer should not have to know about the Python virtual environment at all. venvUtils/ensureVenv.py contains the logic to check for, create and update the virtual environment. If a previous virtual environment exists but has a miss-matching Python version or pip package requirements have changed, The virtual environement is recreated with the updated version of Python and packages. If a virtual environement is found but does not seem to be ours, the user is asked if it should be overwritten or not. This script also detects if it is being run from an existing 3rd party Python virtual environment and aborts if so. thus, it is impossible to execute SScons or NVDA from source within another Python virtual environment. venvUtils/ensureAndActivate.bat can be used to ensure the virtual environment exists and is up to date, and then activates it in the current shell, ready for other commands to be executed in the context of NVDA's build system Python virtual environment. this would never nroamlly be executed by itself, though appveyor uses it at the beginning of its execution and leaves the environment active for the remainder of its execution. venvUtils/venvCmd.bat is a script that runs a single command within the context of the NVDA build system Python virtual environment. It ensures and activates the environment, executes the command, and then deactivates the environment. this script is what scons.bat and runnvda.bat use internally. SConstruct, and source/nvda.pyw both contain logic that detects the NVDA build system Python virtual environment, and abort if it is not active.
…herwise appveyor renders some messages in the wrong order.
nvdaHelper/espeak/sconscript
Outdated
@@ -1,4 +1,4 @@ | |||
from include.scons.SCons.Util import CLVar | |||
from SCons.Util import CLVar |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
@@ -10,6 +10,7 @@ | |||
import sys | |||
import os | |||
import globalVars | |||
import ctypes |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
appveyor.yml
Outdated
@@ -59,6 +59,12 @@ init: | |||
clone_depth: 1 | |||
|
|||
install: | |||
# Ensure we have the latest version of pip | |||
- py -m pip install --upgrade pip |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
Also for whatever reason NVDA fails to exit properly after install on AppVeyor with the following log:
|
…shell, or at least in onFinish, the Python environement is not maintained over commands, and therefore we were fetching the global list.
…--in pgettext (#12109) * Add-on handler/pgettext: remove pgettext namespace definition. Re #9207. As gettext.pgettext is present, there is no need to manually assign NVDA's own pgettext function to built-in namespace for add-ons. Therefore remove this assignment. * Language handler/pgettext: remove nVDA-specific pgettext function. re #9207. As Python 3.8 includes gettext.pgettext, there is no need for NVDA's implementation of pgettext function. Therefore remove makePgettext and builtins namespace assignment from language handler. * Language handler: remove unused builtins namespace import. * Language handler/pgettext: add 'pgettext' to built-in namespace. Re #9207. As Python 3.8 includes gettext.pgettext, add it to built-in namespace by using 'names' parameter of translation.install method. * Update copyright header * Revert "Add-on handler/pgettext: remove pgettext namespace definition. Re #9207." This reverts commit 991de43 so add-on translations will work. * Add-on handler/pgettext: replace NVDA-specific pgettext call with Python's pgettext function. Re #9207. Add-on initialization will still require assigning pgettext to add-on namespace, therefore use translations.pgettext instead of now removed NVDA-specific implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Let's rebase this on master and merge straight to master.
On second thoughts, no rebase is necessary. Just make sure this is up to date with master and change the target (base) branch to master. |
Note that #11912 is not yet part of master. Also this should be up to date with the py3.8 branch before merged into master, I assume? |
Link to issue number: None - Fixes regression introduced in PR #12075 Summary of the issue: When executing system tests ensuring that NVDA starts and exits correctly we rely on the status of its process i.e. when the process is running NVDA is supposed to be running. While this works well for installed copies source copies are not started directly rather intermediate .bat file is used to start pythonw in a separate process. As a consequence when trying to retrieve status of an NVDA process during tests we get wrong results (the bat file is never running). Description of how this pull request fixes the issue: To avoid relying on the state of the process system tests use the NVDA's message window to determine if NVDA is running or not.
Link to issue number:
Fixes #11056
Fixes #11794
Fixes #12059
Fixes #12060
Fixes #12061
Fixes #12062
Fixes #12063
Fixes #12065
Fixes #12116
Summary of the issue:
NVDA and its build system have has many Python dependencies, the majority of which are fetched as git submodules to official git repositories, some are git submodules for our own git repositories containing pre-built dependencies (E.g.
wxPython
) and some are fetched viapip
. And even the ones viapip
are fetched differ as to where they are fetched into our build system.The current approach to Python dependencies as the following issues:
wxPython
, there is a great deal of extra work to pre-build and store in a git repository each time we want to upgrade to a new version of that dependencyAs we move to
Python 3.8
, some of our Python dependencies (namelywxPython
,pySerial
andpy2exe
) need to be upgraded. We should take this opportunity to standardize on a cleaner way of fetching Python dependencies that address all the above issues.Description of how this pull request fixes the issue:
A Python virtual environment is now used transparently by the NVDA build system, and all Python dependencies are installed into this environment using pip.
From a developer's perspective using the NVDA build system, there is no need to worry about the Python virtual environment behind the scenes, nor should you create and or activate one manually. All NVDA build system commands will handle this transparently.
Behind the scenes, the above batch files (scons, runnvda, rununittests, runsystemtests and runlint) ensure that the Python virtual environment is created and up to date, activates the environment, runs the command and then deactivates. All transparently. A developer should not have to know about the Python virtual environment at all.
The first time one of these commands are run, the virtual environment will be created, and all required Python dependencies will be installed with pip. You can see the entire list of packages and their exact versions that pip will use, in requirements.txt in the root of the repository.
venvUtils/ensureVenv.py contains the logic to check for, create and update the virtual environment.
If a previous virtual environment exists but has a miss-matching Python version or pip package requirements have changed, The virtual environment is recreated with the updated version of Python and packages.
If a virtual environment is found but does not seem to be ours, the user is asked if it should be overwritten or not.
This script also detects if it is being run from an existing 3rd party Python virtual environment and aborts if so. thus, it is impossible to execute SCons or NVDA from source within another Python virtual environment.
venvUtils/ensureAndActivate.bat can be used to ensure the virtual environment exists and is up to date, and then activates it in the current shell, ready for other commands to be executed in the context of NVDA's build system Python virtual environment. this would never normally be executed by itself, though appVeyor uses it at the beginning of its execution and leaves the environment active for the remainder of its execution.
venvUtils/venvCmd.bat is a script that runs a single command within the context of the NVDA build system Python virtual environment. It ensures and activates the environment, executes the command, and then deactivates the environment. this script is what all the high-level batch files use internally.
SConstruct, and source/nvda.pyw both contain logic that detects the NVDA build system Python virtual environment, and abort if it is not active.
As this PR is specific for Python 3.8, it also upgrades the following Python dependencies:
Testing strategy:
scons source
,scons dist
andscons launcher
Known issues with pull request:
None so far.
Change log entry:
Changes for developers:
Code Review Checklist:
This checklist is a reminder of things commonly forgotten in a new PR.
Authors, please do a self-review and confirm you have considered the following items.