Repository: nvaccess/nvda

Issue:
Allow developers to use different version of SCons than the one bundled in the repository
### Is your feature request related to a problem? Please describe.
On some hosts current version of SCons is not working which prevents building. For real examples see:
- #9990
- https://github.com/SCons/scons/issues/3572

The latter report is especially problematic for me, because it makes it impossible for me to build on my main machines.
In both these cases it is possible to build with more recent / self-modified version of SCons.

It is understandable that SCons in the repository is updated only when there are beneficial changes for NVDA, but often the gaps between updates are quite long (for example if someone suffered from #9990 he had to wait more than half a year to be able to build again).
### Describe the solution you'd like
It should be possible for a developer to specify different folder containing SCons, perhaps via command line. @feerrenrut Would you be able to give your opinion here?
 ### Describe alternatives you've considered
Stop including SCons as a submodule and require developers to install it via pip.
### Additional context
While such errors affects only minority of users they make it impossible to contribute, for them so I would appreciate commends.


Discussion:
I think the simplest way for someone to modify their version of SCons is to update the submodule locally. But this doesn't necessarily mean it is compatible with our sconscripts, there isn't much we can do about that. In the future I would like the NVDA repo to configure and enable a python virtual environment as a first step in the build / run from source. It could then install python dependencies via pip. This would make it easier to test new dependency versions / upgrade python, and reduce the chance of interference from different dev setups. For this particular issue I don't think it would make much difference.
Couldn't you just run scons by executing `"C:\Python37\Scripts\scons.bat"`?
Not in the current state. Our SConscript requires sourceEnv which is being added to PYTHONPATH by scons.py from the main dir of the repo.
It seems to be possible to reorganize this in a way which would allow to use installed version of SCons if invoked explicitly falling back to the bundled one in all other cases.
@feerrenrut Would you accept such enhancement to the build system?
hello 
I think we can use GitHub Actions to solve this problem, we can write an NVDA actions build script, if developers who need to build and test NVDA can directly use this script to build.
thanks
@lukaszgo1 Yes, as long as we can be confident it doesn't affect the main use case (building from bundled scons). 
@dingpengyu There would be quite some work to convert from Appveyor builds. It's not just a conversion, but generalizing the build process to separate the NV Access specific steps from the steps required for everyone. That said, if you wish to do this in your own fork of NVDA it would be possible.
> @lukaszgo1 Yes, as long as we can be confident it doesn't affect the main use case (building from bundled scons).
> @dingpengyu There would be quite some work to convert from Appveyor builds. It's not just a conversion, but generalizing the build process to separate the NV Access specific steps from the steps required for everyone. That said, if you wish to do this in your own fork of NVDA it would be possible.

thank you for your reply
In fact, it can be used in conjunction with appveyor. My idea is based on the following items.
[Action-OpenWrt](https://github.com/P3TERX/Actions-OpenWrt)
thanks
This is the component of my current environment for compiling NVDA. I hope it can help everyone:
visual studio: 2019-16.4x
python: 3.7.7
scons: latest
virtualenv: latest
thanks
Hi @lukaszgo1,
What does prevent you from building NVDA from within a Python virtual environment?
Doing so would isolate your installed SCons from the one bundled with NVDA.
(I actually use only virtual environments, and thus never install anything in my bare Python installations.)

Resolving patch:
diff --git a/scons.py b/scons.py
--- a/scons.py
+++ b/scons.py
@@ -3,22 +3,12 @@
 
 import sys
 import os
-import platform
-# Variables for storing required version of Python, and the version which is used to run this script.
-requiredPythonMajor ="3"
-requiredPythonMinor = "7"
-requiredPythonArchitecture = "32bit"
-installedPythonMajor = str(sys.version_info.major)
-installedPythonMinor = str(sys.version_info.minor)
-installedPythonArchitecture = platform.architecture()[0]
-# Ensure, that we are running with required version of Python, otherwise inform the user and exit.
-if installedPythonArchitecture != requiredPythonArchitecture or installedPythonMajor != requiredPythonMajor or installedPythonMinor != requiredPythonMinor:
-	print("This script is started with Python %s.%s %s, however to build NVDA you have to use Python %s.%s %s." %(installedPythonMajor, installedPythonMinor, installedPythonArchitecture, requiredPythonMajor, requiredPythonMinor, requiredPythonArchitecture))
-	print("Please install the needed version of Python and launch SCons again, or if you have mulltiple versions of Python installed start this script with required version explicitly.")
-	sys.exit(1)
-sys.path.append(os.path.abspath(
-	os.path.join(__file__, "..", "source")))
-import sourceEnv
-del sys.path[-1]
-import SCons.Script
-SCons.Script.main()
+
+sconsPath = os.path.abspath(os.path.join(os.path.dirname(__file__), "include", "scons", "src", "engine"))
+
+if os.path.exists(sconsPath):
+	sys.path.append(sconsPath)
+	import SCons.Script
+	SCons.Script.main()
+else:
+	raise OSError("Path %s does not exist. Perhaps try running git submodule update --init" % sconsPath)
diff --git a/source/sourceEnv.py b/source/sourceEnv.py
--- a/source/sourceEnv.py
+++ b/source/sourceEnv.py
@@ -1,8 +1,7 @@
-#sourceEnv.py
-#A part of NonVisual Desktop Access (NVDA)
-#Copyright (C) 2013-2018 NV Access Limited, Leonard de Ruijter
-#This file is covered by the GNU General Public License.
-#See the file COPYING for more details.
+# A part of NonVisual Desktop Access (NVDA)
+# Copyright (C) 2013-2020 NV Access Limited, Leonard de Ruijter
+# This file is covered by the GNU General Public License.
+# See the file COPYING for more details.
 
 """Set up the Python environment when running from source.
 """
@@ -14,7 +13,6 @@
 TOP_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
 # Directories containing Python modules included in git submodules.
 PYTHON_DIRS = (
-	os.path.join(TOP_DIR, "include", "scons", "src", "engine"),
 	os.path.join(TOP_DIR, "include", "pyserial"),
 	os.path.join(TOP_DIR, "include", "comtypes"),
 	os.path.join(TOP_DIR, "include", "configobj", "src"),


Test patch: