@@ -32,63 +32,73 @@ public async Task<bool> InstallPyApp(Action<string> response, Func<string, strin
3232 {
3333 response . Invoke ( "Setting up directories" ) ;
3434 var destination = Path . Combine ( Directories . Dependencies , "python" ) ;
35+
36+ var pythonPath = OperatingSystem . IsWindows ( )
37+ ? Path . Combine ( destination , "python.exe" )
38+ : Path . Combine ( destination , "bin" , "python3.13" ) ;
39+ var doesHavePython = false ;
3540
36- if ( Directory . Exists ( destination ) )
41+ if ( File . Exists ( pythonPath ) )
3742 {
38- logger . LogInformation ( "Deleting prior Python installation" ) ;
39- try
43+ var checkPyVersionResult = await runPyFunc ( pythonPath , "--version" ) ;
44+ doesHavePython = checkPyVersionResult . Success && checkPyVersionResult . Result . StartsWith ( "Python 3.13" ) ;
45+ }
46+
47+ if ( ! doesHavePython )
48+ {
49+ if ( Directory . Exists ( destination ) )
4050 {
41- await ITaskService . Run ( ( ) =>
51+ logger . LogInformation ( "Deleting prior Python installation" ) ;
52+ try
4253 {
43- Directory . Delete ( destination , true ) ;
44- } ) ;
45- }
46- catch ( TaskCanceledException )
47- {
48- // Do Nothing
54+ await ITaskService . Run ( ( ) =>
55+ {
56+ Directory . Delete ( destination , true ) ;
57+ } ) ;
58+ }
59+ catch ( TaskCanceledException )
60+ {
61+ // Do Nothing
62+ }
4963 }
50- }
51-
52- EnsureFolders ( destination ) ;
5364
54- var tempFile = Path . Combine ( Directories . TempFolder , "python.tar.gz" ) ;
55- var url = OperatingSystem . IsWindows ( ) ? PythonWindowsDownloadUrl : PythonLinuxDownloadUrl ;
65+ EnsureFolders ( destination ) ;
5666
57- response . Invoke ( "Downloading Python" ) ;
58- if ( ! await DownloadFileAsync ( url , tempFile ) )
59- {
60- return false ;
61- }
67+ var tempFile = Path . Combine ( Directories . TempFolder , "python.tar.gz" ) ;
68+ var url = OperatingSystem . IsWindows ( ) ? PythonWindowsDownloadUrl : PythonLinuxDownloadUrl ;
6269
63- response . Invoke ( "Extracting Python files " ) ;
64- if ( ! await ExtractTarGzFile ( tempFile , Directories . Dependencies ) )
65- {
66- return false ;
67- }
70+ response . Invoke ( "Downloading Python" ) ;
71+ if ( ! await DownloadFileAsync ( url , tempFile ) )
72+ {
73+ return false ;
74+ }
6875
69- var pythonPath = OperatingSystem . IsWindows ( )
70- ? Path . Combine ( destination , "python.exe" )
71- : Path . Combine ( destination , "bin" , "python3.13" ) ;
76+ response . Invoke ( "Extracting Python files" ) ;
77+ if ( ! await ExtractTarGzFile ( tempFile , Directories . Dependencies ) )
78+ {
79+ return false ;
80+ }
7281
73- if ( OperatingSystem . IsLinux ( ) )
74- {
75- File . SetUnixFileMode ( pythonPath ,
76- UnixFileMode . UserRead | UnixFileMode . UserWrite | UnixFileMode . UserExecute ) ;
77- }
82+ if ( OperatingSystem . IsLinux ( ) )
83+ {
84+ File . SetUnixFileMode ( pythonPath ,
85+ UnixFileMode . UserRead | UnixFileMode . UserWrite | UnixFileMode . UserExecute ) ;
86+ }
7887
79- response . Invoke ( "Verifying Python version" ) ;
88+ response . Invoke ( "Verifying Python version" ) ;
8089
81- var runPyResult = await runPyFunc ( pythonPath , "--version" ) ;
82- if ( ! runPyResult . Success || ! runPyResult . Result . StartsWith ( "Python 3" ) )
83- {
84- logger . LogError ( "Python version response incorrect: {Response} | {Error}" , runPyResult . Result ,
85- runPyResult . Error ) ;
86- return false ;
90+ var verifyPythonInstallResult = await runPyFunc ( pythonPath , "--version" ) ;
91+ if ( ! verifyPythonInstallResult . Success || ! verifyPythonInstallResult . Result . StartsWith ( "Python 3.13" ) )
92+ {
93+ logger . LogError ( "Python version response incorrect: {Response} | {Error}" , verifyPythonInstallResult . Result ,
94+ verifyPythonInstallResult . Error ) ;
95+ return false ;
96+ }
8797 }
88-
98+
8999 response . Invoke ( "Installing companion app" ) ;
90100
91- runPyResult = await runPyFunc ( pythonPath , "-m pip install py-msu-scripter-app" ) ;
101+ var runPyResult = await runPyFunc ( pythonPath , "-m pip install --upgrade py-msu-scripter-app" ) ;
92102 if ( ! runPyResult . Success && ! runPyResult . Error . StartsWith ( "[notice]" ) )
93103 {
94104 logger . LogError ( "Failed to install Python companion app: {Error}" , runPyResult . Error ) ;
0 commit comments