Skip to content

Allow NVDA build system to still function if NvDA repository is moved or copied to another location#12184

Merged
michaelDCurran merged 4 commits into
masterfrom
relocatableVenv
Mar 18, 2021
Merged

Allow NVDA build system to still function if NvDA repository is moved or copied to another location#12184
michaelDCurran merged 4 commits into
masterfrom
relocatableVenv

Conversation

@michaelDCurran

@michaelDCurran michaelDCurran commented Mar 16, 2021

Copy link
Copy Markdown
Member

Link to issue number:

Replaces #12171
Closes #12166

Summary of the issue:

When creating a Python virtual environment, Python's venv package hard-codes the absolute path where the environment was created, in its activation script. This therefore means that it is impossible to use a Python virtual environment if it has been copied or moved to a different location.

Description of how this pull request fixes the issue:

Rather than relying on the generated venv's standard activation script, our ensureAndActivate script now sets the needed environment variables (such as VIRTUAL_ENV, PATH etc) manually, and ensures the path to the venv is relative to our script.
this allows the NVDA repository to be renamed or moved, and the virtual environment can still successfully be activated.
However, if you want to run the build system or NvDA from source on another machine via a shared network drive, Python must be installed at the same location on both systems. there is no workaround for this.

Testing strategy:

Ran the NVDA build system commands such as scons, runnvda, runlint successfully.
Renamed the NVDA repository and performed the above test again.

Known issues with pull request:

None known.

Change log entry:

None needed.

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.
Mark items you have considered by checking them.
You can do this when editing the Pull request description with an x: [ ] becomes [x].
You can also check the checkboxes after the PR is created.

  • Pull Request description is up to date.
  • Unit tests.
  • System (end to end) tests.
  • Manual tests.
  • User Documentation.
  • Change log entry.
  • Context sensitive help for GUI changes.

…ivate.bat from the generated .venv, set the necessary environment variables manually, and make VIRTUAL_ENV be relative to this script, rather than a hard-coded path.

This allows the NVDA repository to be moved or copied somewhere else on the same system and the environment used without having to be recreated.
…activate.bat so deactivate.bat may do the wrong thing. But more importantly, we already call endlocal which dumps all changes to the environment anyway, thus it is not needed.
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).

Comment thread venvUtils/venvCmd.bat
echo call %*
call %*
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.

@CyrilleB79

Copy link
Copy Markdown
Contributor

I have tested this PR's branch in the following situations:

  • renaming NVDA source folder
  • moving NVDA source folder on the same drive
  • moving NVDA source folder to another drive of the same computer
    In all these tests, NVDA can be run directly and the environment is not recreated.

@michaelDCurran

Copy link
Copy Markdown
Member Author

@feerrenrut I think I have added all the commenting you requested now.

@AppVeyorBot

Copy link
Copy Markdown

See test results for failed build of commit a8ae841ae1

@feerrenrut feerrenrut left a comment

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.

Looks good, thanks @michaelDCurran

@michaelDCurran michaelDCurran merged commit 7139a9c into master Mar 18, 2021
@michaelDCurran michaelDCurran deleted the relocatableVenv branch March 18, 2021 08:07
@nvaccessAuto nvaccessAuto added this to the 2021.1 milestone Mar 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Last NVDA alpha - Unable to rename folder of source code

5 participants