Skip to content

Commit a8ae841

Browse files
Merge d5a3ef2 into 5fbe05d
2 parents 5fbe05d + d5a3ef2 commit a8ae841

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

venvUtils/ensureAndActivate.bat

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
@echo off
22
rem this script ensures the NVDA build system Python virtual environment is created and up to date,
33
rem and then activates it.
4-
rem this script should be used only in the case where many commands will be executed within the environment and the shell will be eventually thrown away.
5-
rem E.g. an Appveyor build.
4+
rem This is an internal script and should not be used directly.
5+
6+
rem Ensure the environment is created and up to date
67
py -3.8-32 "%~dp0\ensureVenv.py"
78
if ERRORLEVEL 1 goto :EOF
8-
call "%~dp0\..\.venv\scripts\activate.bat"
9+
10+
rem Set the necessary environment variables to have Python use this virtual environment.
11+
rem This should set all the necessary environment variables that the standard .venv\scripts\activate.bat does
12+
rem Except that we set VIRTUAL_ENV to a path relative to this script,
13+
rem rather than it being hard-coded to where the virtual environment was first created.
14+
15+
rem unset the PYTHONHOME variable so as to ensure that Python does not use a customized Python standard library.
16+
set PYTHONHOME=
17+
rem set the VIRTUAL_ENV variable instructing Python to use a virtual environment
18+
rem py.exe will honor VIRTUAL_ENV and launch the python.exe that it finds in %VIRTUAL_ENV%\scripts.
19+
rem %VIRTUAL_ENV%\scripts\python.exe will find pyvenv.cfg in its parent directory,
20+
rem which is actually what then causes Python to use the site-packages found in this virtual environment.
21+
set VIRTUAL_ENV=%~dp0..\.venv
22+
rem Add the virtual environment's scripts directory to the path
23+
set PATH=%VIRTUAL_ENV%\scripts;%PATH%
24+
rem Set an NVDA-specific variable to identify this official NVDA virtual environment from other 3rd party ones
925
set NVDA_VENV=%VIRTUAL_ENV%
26+
rem mention the environment in the prompt to make it obbvious it is active
27+
rem just in case this script is executed outside of a local block and not cleaned up.
28+
set PROMPT=[NVDA Venv] %PROMPT%

venvUtils/venvCmd.bat

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ if "%VIRTUAL_ENV%" NEQ "" (
1616
goto :EOF
1717
)
1818

19+
rem call setlocal to make sure that any environment variable changes made by activating the virtual environment
20+
rem can be completely undone when endlocal is called or this script exits.
1921
setlocal
2022
echo Ensuring NVDA Python virtual environment
2123
call "%~dp0\ensureAndActivate.bat"
2224
if ERRORLEVEL 1 goto :EOF
2325
echo call %*
2426
call %*
27+
rem the virtual environment will now be deactivated as endlocal will be reached.
2528
echo Deactivating NVDA Python virtual environment
26-
call "%~dp0\..\.venv\scripts\deactivate.bat"
2729
endlocal

0 commit comments

Comments
 (0)