system shell explainer fixes
@@ -42,6 +42,7 @@ def list_commands(prefix, highlighted_reals, highlighted_dirs):
cmd = prefix + suffix
target = shutil.which(cmd)
if target is not None:
+ target = normpath_with_actual_case(target)
real = equivalent_realpath(target)
if target == real:
@@ -55,32 +56,63 @@ def list_commands(prefix, highlighted_reals, highlighted_dirs):
or os.path.dirname(target) in highlight_dirs):
print("\033[1m" + line + "\033[0m")
else:
- print(line)
+ print("\033[2m" + line + "\033[0m")
+
+def normpath_with_actual_case(name):
+ """In Windows return the path with the case it is stored in the filesystem"""
+ # copied from thonny.common to make this script independent
+ assert os.path.isabs(name)
+ assert os.path.exists(name)
+
+ if os.name == "nt":
+ name = os.path.realpath(name)
+
+ from ctypes import create_unicode_buffer, windll
+
+ buf = create_unicode_buffer(512)
+ windll.kernel32.GetShortPathNameW(name, buf, 512) # @UndefinedVariable
+ windll.kernel32.GetLongPathNameW(buf.value, buf, 512) # @UndefinedVariable
+ assert len(buf.value) >= 2
+
+ result = buf.value
+ assert isinstance(result, str)
+
+ if result[1] == ":":
+ # ensure drive letter is capital
+ return result[0].upper() + result[1:]
+ else:
+ return result
+ else:
+ return os.path.normpath(name)
+
+
if __name__ == "__main__":
_clear_screen()
print("*" * 80)
print("Some Python commands in PATH:")
- sys_real = equivalent_realpath(sys.executable)
- if is_virtual_exe(sys.executable):
- highlight_dirs = os.path.dirname(sys.executable)
+ sys_real = normpath_with_actual_case(equivalent_realpath(sys.executable))
+ sys_executable = normpath_with_actual_case(sys.executable)
+
+ if is_virtual_exe(sys_executable):
+ highlight_dirs = [os.path.dirname(sys_executable)]
else:
highlight_dirs = []
if platform.system() == "Windows":
# Add Scripts for pip
highlight_dirs.append(os.path.join(os.path.dirname(sys_real), "Scripts"))
- highlight_dirs.append(os.path.join(os.path.dirname(sys.executable), "Scripts"))
+ highlight_dirs.append(os.path.join(os.path.dirname(sys_executable), "Scripts"))
list_commands("python", [sys_real], highlight_dirs)
likely_pips = []
if sys_real[-9:-1] == "python3.":
likely_pips.append(sys_real[:-9] + "pip3." + sys_real[-1])
- if sys.executable.endswith("/python3"):
+ if sys_executable.endswith("/python3"):
# This is not as likely match as previous, but still quite likely
- likely_pips.append(sys.executable.replace("/python3", "/pip3"))
+ likely_pips.append(sys_executable.replace("/python3", "/pip3"))
list_commands("pip", likely_pips, highlight_dirs)
