@@ -52,23 +52,13 @@ def fetchRequirementsSet(path: str) -> Set[str]:
5252 return set (lines )
5353
5454
55- def createVenvAndPopulate ():
55+ def populate ():
5656 """
57- Creates the NVDA build system's Python virtual environment and installs all required packages.
58- this function will overwrite any existing virtual environment found at c{venv_path}.
57+ Installs all required packages within the virtual environment.
58+ When called stand alone, this function only ensures that NVDA's package requirements are met,
59+ without recreating the full environment.
60+ This means that transitive dependencies can get out of sync with those used in automated builds.
5961 """
60- print ("Creating virtual environment..." , flush = True )
61- subprocess .run (
62- [
63- sys .executable ,
64- "-m" , "venv" ,
65- "--clear" ,
66- venv_path ,
67- ],
68- check = True
69- )
70- with open (venv_python_version_path , "w" ) as f :
71- f .write (sys .version )
7262 print ("Installing packages in virtual environment..." , flush = True )
7363 subprocess .run (
7464 [
@@ -89,12 +79,32 @@ def createVenvAndPopulate():
8979 shutil .copy (requirements_path , venv_orig_requirements_path )
9080
9181
82+ def createVenvAndPopulate ():
83+ """
84+ Creates the NVDA build system's Python virtual environment and installs all required packages.
85+ This function will overwrite any existing virtual environment found at c{venv_path}.
86+ """
87+ print ("Creating virtual environment..." , flush = True )
88+ subprocess .run (
89+ [
90+ sys .executable ,
91+ "-m" , "venv" ,
92+ "--clear" ,
93+ venv_path ,
94+ ],
95+ check = True
96+ )
97+ with open (venv_python_version_path , "w" ) as f :
98+ f .write (sys .version )
99+ populate ()
100+
101+
92102def ensureVenvAndRequirements ():
93103 """
94104 Ensures that the NVDA build system's Python virtual environment is created and up to date.
95105 If a previous virtual environment exists but has a miss-matching Python version
96- or pip package requirements have changed,
97- The virtual environment is recreated with the updated version of Python and packages .
106+ the virtual environment is recreated with the updated version of Python.
107+ When pip package requirements have changed, this function asks the user to recreate the environment .
98108 If a virtual environment is found but does not seem to be ours,
99109 This function asks the user if it should be overwritten or not.
100110 """
@@ -121,8 +131,17 @@ def ensureVenvAndRequirements():
121131 newRequirements = fetchRequirementsSet (requirements_path )
122132 addedRequirements = newRequirements - oldRequirements
123133 if addedRequirements :
124- print (f"Added or changed package requirements. { addedRequirements } " )
125- return createVenvAndPopulate ()
134+ if askYesNoQuestion (
135+ f"Added or changed package requirements. { addedRequirements } \n "
136+ "You are encouraged to recreate the virtual environment. "
137+ "If you choose no, the new requirements will be installed without recreating. "
138+ "This means that transitive dependencies can get out of sync "
139+ "with those used in automated builds. "
140+ "Would you like to continue recreating the environment?"
141+ ):
142+ return createVenvAndPopulate ()
143+ else :
144+ return populate ()
126145
127146
128147if __name__ == '__main__' :
0 commit comments