@@ -11,36 +11,60 @@ def checkPipDirectory():
1111 configPath = cmd .PythonPluginScriptPath () + '/upyconfig.json'
1212 correctPipPath = cmd .PythonHomeScriptsPath ()
1313
14- #let's test our pip directory path
14+ #compare our current pip directory with the installed one, if they differ reinstall pip
1515 try :
16- with open (configPath ) as data_file :
17- configs = json .load (data_file )
16+ with open (configPath , "r+" ) as configFile :
17+ configs = json .load (configFile )
1818
1919 #grab currently stored path
2020 storedPipPath = configs ['pipDirectoryPath' ]
2121
22- print (storedPipPath )
23- print (tempPath )
22+ print ('upystartup::Checking pip location on startup' )
23+ print ('upystartup::stored loc: ' + storedPipPath )
24+ print ('upystartup::correct loc: ' + correctPipPath )
2425
2526 #compare paths
2627 if (storedPipPath != correctPipPath ):
2728 #if they don't match, remove the pip module and reinstall pip for this module
28-
29+ print ('upystartup::Pip installation directory is stale, re-installing.' )
30+
2931 libPath = cmd .PythonHomePath () + '/Lib/site-packages'
3032 dirs = listdir (libPath )
31- print (libPath )
32- print (dirs )
3333
3434 tempPath = None
35+ #find the directory that contains pip and ends with .dist-info
3536 for directory in dirs :
36- if ('pip' in directory and
37+ #print(directory)
38+ if (directory .startswith ('pip' ) and
3739 directory .endswith ('.dist-info' )):
38- tempPath = libPath + directory
40+ tempPath = libPath + "/" + directory
41+ break
42+
43+ if (tempPath != None ):
44+ #remove the old directory
45+ print ('removing old: ' + tempPath )
46+ cmd .run ('rmdir /S /Q "' + tempPath + '"' )
47+
48+ #install pip
49+ print (cmd .PythonHomePath () + '/get-pip.py' )
50+
51+ print ('Installing pip...' )
52+ cmd .runLogOutput ('InstallPip.bat' )
53+
54+ #update our stored location
55+ configs ['pipDirectoryPath' ] = correctPipPath
56+ configFile .seek (0 )
57+ configFile .write (json .dumps (configs ))
58+ configFile .truncate ()
59+
60+ #done
61+ print ('upystartup::updated pip.exe location in <' + configPath + '>' )
62+
63+ else :
64+ print ('upystartup::pip location is up to date.' )
3965
40- print (tempPath )
41- #rmdir Li
4266 except :
43- e = sys .exc_info ()[ 0 ]
67+ e = sys .exc_info ()
4468 ue .log ('upyconfig.json error: ' + str (e ))
4569
4670#add any startup action you wish to perform in python
0 commit comments