@@ -20,19 +20,17 @@ public class PythonManager
2020 private readonly string _pythonPath ;
2121 private readonly string _pipelinePath ;
2222 private readonly string _pythonVersion = "3.12.10" ;
23- private readonly IProgress < PipelineProgress > _progressCallback ;
2423
2524 /// <summary>
2625 /// Initializes a new instance of the <see cref="PythonManager"/> class.
2726 /// </summary>
2827 /// <param name="config">The configuration.</param>
2928 /// <param name="progressCallback">The progress callback.</param>
3029 /// <param name="logger">The logger.</param>
31- public PythonManager ( EnvironmentConfig config , IProgress < PipelineProgress > progressCallback = null , ILogger logger = default )
30+ public PythonManager ( EnvironmentConfig config , ILogger logger = default )
3231 {
3332 _logger = logger ;
3433 _config = config ;
35- _progressCallback = progressCallback ;
3634 _pythonPath = Path . GetFullPath ( Path . Join ( _config . Directory , "Python" ) ) ;
3735 _pipelinePath = Path . GetFullPath ( Path . Join ( _config . Directory , "Pipelines" ) ) ;
3836 CopyInternalPipelineFiles ( ) ;
@@ -44,15 +42,15 @@ public PythonManager(EnvironmentConfig config, IProgress<PipelineProgress> progr
4442 /// </summary>
4543 /// <param name="isRebuild">Delete and rebuild the environment</param>
4644 /// <param name="isReinstall">Delete and rebuild the environment and base Python installation</param>
47- public Task < IPythonEnvironment > CreateEnvironmentAsync ( bool isRebuild = false , bool isReinstall = false )
45+ public Task < IPythonEnvironment > CreateEnvironmentAsync ( bool isRebuild = false , bool isReinstall = false , IProgress < PipelineProgress > progressCallback = null )
4846 {
4947 return Task . Run ( async ( ) =>
5048 {
51- await DownloadAsync ( isReinstall ) ;
49+ await DownloadAsync ( isReinstall , progressCallback ) ;
5250 if ( isReinstall || isRebuild )
5351 await DeleteAsync ( ) ;
5452
55- return await CreateAsync ( ) ;
53+ return await CreateAsync ( progressCallback ) ;
5654 } ) ;
5755 }
5856
@@ -75,7 +73,7 @@ private async Task<bool> DeleteAsync()
7573 /// Checks if a environment exists
7674 /// </summary>
7775 /// <param name="name">The name.</param>
78- private bool Exists ( string name )
76+ public bool Exists ( string name )
7977 {
8078 var path = Path . Combine ( _pipelinePath , $ ".{ name } ") ;
8179 return Directory . Exists ( path ) ;
@@ -85,14 +83,14 @@ private bool Exists(string name)
8583 /// <summary>
8684 /// Creates the environment.
8785 /// </summary>
88- private async Task < IPythonEnvironment > CreateAsync ( )
86+ private async Task < IPythonEnvironment > CreateAsync ( IProgress < PipelineProgress > progressCallback = null )
8987 {
9088 var exists = Exists ( _config . Environment ) ;
91- CallbackMessage ( $ "{ ( exists ? "Loading" : "Creating" ) } Python Virtual Environment (.{ _config . Environment } )") ;
89+ progressCallback . SendMessage ( $ "{ ( exists ? "Loading" : "Creating" ) } Python Virtual Environment (.{ _config . Environment } )") ;
9290 var requirementsFile = Path . Combine ( _pipelinePath , "requirements.txt" ) ;
9391 await File . WriteAllLinesAsync ( requirementsFile , _config . Requirements ) ;
9492 var environment = PythonEnvironmentHelper . CreateEnvironment ( _config . Environment , _pythonPath , _pipelinePath , requirementsFile , _pythonVersion , _logger ) ;
95- CallbackMessage ( $ "Python Virtual Environment { ( exists ? "Loaded" : "Created" ) } .") ;
93+ progressCallback . SendMessage ( $ "Python Virtual Environment { ( exists ? "Loaded" : "Created" ) } .") ;
9694 return environment ;
9795 }
9896
@@ -101,22 +99,22 @@ private async Task<IPythonEnvironment> CreateAsync()
10199 /// Downloads and installs Win-Python portable v3.12.10.
102100 /// </summary>
103101 /// <param name="reinstall">if set to <c>true</c> [reinstall].</param>
104- private async Task DownloadAsync ( bool reinstall )
102+ private async Task DownloadAsync ( bool reinstall , IProgress < PipelineProgress > progressCallback = null )
105103 {
106104 var subfolder = "WPy64-312100/python" ;
107105 var exePath = Path . Combine ( _pythonPath , "python.exe" ) ;
108106 var downloadPath = Path . Combine ( _pythonPath , "Winpython64-3.12.10.0dot.zip" ) ;
109107 var pythonUrl = "https://github.com/winpython/winpython/releases/download/15.3.20250425final/Winpython64-3.12.10.0dot.zip" ;
110108 if ( reinstall )
111109 {
112- CallbackMessage ( $ "Reinstalling Python { _pythonVersion } ...") ;
110+ progressCallback . SendMessage ( $ "Reinstalling Python { _pythonVersion } ...") ;
113111 if ( File . Exists ( downloadPath ) )
114112 File . Delete ( downloadPath ) ;
115113
116114 if ( Directory . Exists ( _pythonPath ) )
117115 Directory . Delete ( _pythonPath , true ) ;
118116
119- CallbackMessage ( $ "Python Uninstalled.") ;
117+ progressCallback . SendMessage ( $ "Python Uninstalled.") ;
120118 }
121119
122120 // Create Python
@@ -125,7 +123,7 @@ private async Task DownloadAsync(bool reinstall)
125123 // Download Python
126124 if ( ! File . Exists ( downloadPath ) )
127125 {
128- CallbackMessage ( $ "Download Python { _pythonVersion } ...") ;
126+ progressCallback . SendMessage ( $ "Download Python { _pythonVersion } ...") ;
129127 using ( var httpClient = new HttpClient ( ) )
130128 using ( var response = await httpClient . GetAsync ( pythonUrl ) )
131129 {
@@ -135,13 +133,13 @@ private async Task DownloadAsync(bool reinstall)
135133 await response . Content . CopyToAsync ( stream ) ;
136134 }
137135 }
138- CallbackMessage ( "Python Download Complete." ) ;
136+ progressCallback . SendMessage ( "Python Download Complete." ) ;
139137 }
140138
141139 // Extract ZIP file
142140 if ( ! File . Exists ( exePath ) )
143141 {
144- CallbackMessage ( $ "Installing Python { _pythonVersion } ...") ;
142+ progressCallback . SendMessage ( $ "Installing Python { _pythonVersion } ...") ;
145143 CopyInternalPythonFiles ( ) ;
146144 using ( var archive = ZipFile . OpenRead ( downloadPath ) )
147145 {
@@ -164,25 +162,10 @@ private async Task DownloadAsync(bool reinstall)
164162 }
165163 }
166164 }
167- CallbackMessage ( $ "Python Install Complete.") ;
165+ progressCallback . SendMessage ( $ "Python Install Complete.") ;
168166 }
169167 }
170168
171-
172- /// <summary>
173- /// Send a callback message.
174- /// </summary>
175- /// <param name="message">The message.</param>
176- private void CallbackMessage ( string message )
177- {
178- _progressCallback ? . Report ( new PipelineProgress
179- {
180- Message = message ,
181- Process = "Initialize"
182- } ) ;
183- }
184-
185-
186169 /// <summary>
187170 /// Copies the internal python files.
188171 /// </summary>
0 commit comments