Skip to content
Merged
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
25 changes: 22 additions & 3 deletions venvUtils/ensureAndActivate.bat
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
@echo off
rem this script ensures the NVDA build system Python virtual environment is created and up to date,
rem and then activates it.
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.
rem E.g. an Appveyor build.
rem This is an internal script and should not be used directly.

rem Ensure the environment is created and up to date
py -3.8-32 "%~dp0\ensureVenv.py"
if ERRORLEVEL 1 goto :EOF
call "%~dp0\..\.venv\scripts\activate.bat"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have comments that delineate the following set of steps as having been adapted from the activate.bat script. This will help us to understand their origin and how to update them if they stop working (eg the requirements of the activate.bat script change).


rem Set the necessary environment variables to have Python use this virtual environment.
rem This should set all the necessary environment variables that the standard .venv\scripts\activate.bat does
rem Except that we set VIRTUAL_ENV to a path relative to this script,
rem rather than it being hard-coded to where the virtual environment was first created.

rem unset the PYTHONHOME variable so as to ensure that Python does not use a customized Python standard library.
set PYTHONHOME=
rem set the VIRTUAL_ENV variable instructing Python to use a virtual environment
rem py.exe will honor VIRTUAL_ENV and launch the python.exe that it finds in %VIRTUAL_ENV%\scripts.
rem %VIRTUAL_ENV%\scripts\python.exe will find pyvenv.cfg in its parent directory,
rem which is actually what then causes Python to use the site-packages found in this virtual environment.
set VIRTUAL_ENV=%~dp0..\.venv
rem Add the virtual environment's scripts directory to the path
set PATH=%VIRTUAL_ENV%\scripts;%PATH%
rem Set an NVDA-specific variable to identify this official NVDA virtual environment from other 3rd party ones
set NVDA_VENV=%VIRTUAL_ENV%
rem mention the environment in the prompt to make it obbvious it is active
rem just in case this script is executed outside of a local block and not cleaned up.
set PROMPT=[NVDA Venv] %PROMPT%
4 changes: 3 additions & 1 deletion venvUtils/venvCmd.bat
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ if "%VIRTUAL_ENV%" NEQ "" (
goto :EOF
)

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does deactivate.bat do? shouldn't those environment variables be cleaned up in some way?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deactivate.bat sets particular environment variables back to their old values.
However, as we called setlocal before ensureAndActivate.bat, all the environment variables will go back to their original values once either endlocal is called, the script ends, or the script is aborted with control+c.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ok. Might be worth a comment to point that out. Otherwise this all looks good.

endlocal