1919
2020def check_app_alias (cmd ):
2121 LOGGER .debug ("Checking app execution aliases" )
22- from _native import read_alias_package
22+ from _native import get_current_package , read_alias_package
23+ # Expected identities:
24+ # Side-loaded MSIX
25+ # * "PythonSoftwareFoundation.PythonManager_3847v3x7pw1km",
26+ # Store package
27+ # * "PythonSoftwareFoundation.PythonManager_qbz5n2kfra8p0",
28+ # Development build
29+ # * "PythonSoftwareFoundation.PythonManager_m8z88z54g2w36",
30+ # MSI/dev install
31+ # * None
32+ try :
33+ pkg = get_current_package ()
34+ except OSError :
35+ LOGGER .debug ("Failed to get current package name." , exc_info = True )
36+ pkg = None
37+ if not pkg :
38+ pkg = ""
39+ #LOGGER.debug("Check skipped: MSI install can't do this check")
40+ #return True
41+ LOGGER .debug ("Checking for %s" , pkg )
2342 root = Path (os .environ ["LocalAppData" ]) / "Microsoft/WindowsApps"
2443 for name in ["py.exe" , "pyw.exe" , "python.exe" , "pythonw.exe" , "python3.exe" , "pymanager.exe" ]:
2544 exe = root / name
2645 try :
2746 LOGGER .debug ("Reading from %s" , exe )
28- package = (read_alias_package (exe ) or "" ).split ("\0 " )
29- LOGGER .debug ("Data: %r" , package )
30- if package [1 ] not in (
31- # Side-loaded MSIX
32- "PythonSoftwareFoundation.PythonManager_3847v3x7pw1km" ,
33- # Store packaged
34- "PythonSoftwareFoundation.PythonManager_qbz5n2kfra8p0" ,
35- # Development build
36- "PythonSoftwareFoundation.PythonManager_m8z88z54g2w36" ,
37- ):
47+ package = read_alias_package (exe )
48+ LOGGER .debug ("Package: %r" , package )
49+ if package not in pkg :
3850 LOGGER .debug ("Check failed: package did not match identity" )
51+ return False
3952 except FileNotFoundError :
4053 LOGGER .debug ("Check failed: did not find %s" , exe )
4154 return False
@@ -59,7 +72,10 @@ def check_long_paths(cmd):
5972
6073def check_py_on_path (cmd ):
6174 LOGGER .debug ("Checking for legacy py.exe on PATH" )
62- from _native import read_alias_package
75+ from _native import get_current_package , read_alias_package
76+ if not get_current_package ():
77+ LOGGER .debug ("Check skipped: MSI install can't do this check" )
78+ return True
6379 for p in os .environ ["PATH" ].split (";" ):
6480 if not p :
6581 continue
@@ -230,7 +246,7 @@ def first_run(cmd):
230246if __name__ == "__main__" :
231247 class TestCommand :
232248 enabled = True
233- global_dir = r".\test- bin"
249+ global_dir = Path ( os . path . expandvars ( r"%LocalAppData%\Python\ bin"))
234250 explicit = False
235251 confirm = True
236252 check_app_alias = True
@@ -241,7 +257,16 @@ class TestCommand:
241257 check_default_tag = True
242258
243259 def get_installs (self , * args , ** kwargs ):
244- return []
260+ import json
261+ root = Path (os .path .expandvars (r"%LocalAppData%\Python" ))
262+ result = []
263+ for d in root .iterdir ():
264+ inst = d / "__install__.json"
265+ try :
266+ result .append (json .loads (inst .read_text ()))
267+ except FileNotFoundError :
268+ pass
269+ return result
245270
246271 def _ask (self , fmt , * args , yn_text = "Y/n" , expect_char = "y" ):
247272 if not self .confirm :
0 commit comments