From 0e117fc87cbecc71234c2d52c451fb9286eea286 Mon Sep 17 00:00:00 2001 From: Albert Larsan <74931857+albertlarsan68@users.noreply.github.com> Date: Fri, 16 Dec 2022 16:39:27 +0100 Subject: [PATCH 1/3] Make x tool work with MS store's installed python --- src/tools/x/src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tools/x/src/main.rs b/src/tools/x/src/main.rs index 02c364dabf960..8443aed7cbdf9 100644 --- a/src/tools/x/src/main.rs +++ b/src/tools/x/src/main.rs @@ -28,12 +28,12 @@ fn python() -> &'static str { for dir in env::split_paths(&val) { // `python` should always take precedence over python2 / python3 if it exists - if dir.join(PYTHON).with_extension(EXE_EXTENSION).exists() { + if dir.join(PYTHON).with_extension(EXE_EXTENSION).try_exists().is_ok() { return PYTHON; } - python2 |= dir.join(PYTHON2).with_extension(EXE_EXTENSION).exists(); - python3 |= dir.join(PYTHON3).with_extension(EXE_EXTENSION).exists(); + python2 |= dir.join(PYTHON2).with_extension(EXE_EXTENSION).try_exists().is_ok(); + python3 |= dir.join(PYTHON3).with_extension(EXE_EXTENSION).try_exists().is_ok(); } // try 3 before 2 From ed310171b9636565703317a78d4aa494794c46fd Mon Sep 17 00:00:00 2001 From: Albert Larsan <74931857+albertlarsan68@users.noreply.github.com> Date: Fri, 16 Dec 2022 18:37:32 +0100 Subject: [PATCH 2/3] "Add comment explaining the change" --- src/tools/x/src/main.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/tools/x/src/main.rs b/src/tools/x/src/main.rs index 8443aed7cbdf9..a522f0cdc6d7f 100644 --- a/src/tools/x/src/main.rs +++ b/src/tools/x/src/main.rs @@ -28,6 +28,9 @@ fn python() -> &'static str { for dir in env::split_paths(&val) { // `python` should always take precedence over python2 / python3 if it exists + + // The checks are `try_exists().is_ok()` because of magic trickery used by Microsoft Store's + // Python installation with symlinks. if dir.join(PYTHON).with_extension(EXE_EXTENSION).try_exists().is_ok() { return PYTHON; } From bd04726a3fd6ea265bbd3caf2d09cca3f0d2f8f1 Mon Sep 17 00:00:00 2001 From: Albert Larsan <74931857+albertlarsan68@users.noreply.github.com> Date: Sat, 17 Dec 2022 15:19:49 +0100 Subject: [PATCH 3/3] Make the change actually work correctly --- src/tools/x/src/main.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/tools/x/src/main.rs b/src/tools/x/src/main.rs index a522f0cdc6d7f..5e2eeb3b26c5a 100644 --- a/src/tools/x/src/main.rs +++ b/src/tools/x/src/main.rs @@ -29,14 +29,14 @@ fn python() -> &'static str { for dir in env::split_paths(&val) { // `python` should always take precedence over python2 / python3 if it exists - // The checks are `try_exists().is_ok()` because of magic trickery used by Microsoft Store's - // Python installation with symlinks. - if dir.join(PYTHON).with_extension(EXE_EXTENSION).try_exists().is_ok() { + // The checks are `symlink_metadata().is_ok()` because of magic trickery used by Microsoft Store's + // Python installation with symlinks: they appear as symlinks with no targets. + if dir.join(PYTHON).with_extension(EXE_EXTENSION).symlink_metadata().is_ok() { return PYTHON; } - python2 |= dir.join(PYTHON2).with_extension(EXE_EXTENSION).try_exists().is_ok(); - python3 |= dir.join(PYTHON3).with_extension(EXE_EXTENSION).try_exists().is_ok(); + python2 |= dir.join(PYTHON2).with_extension(EXE_EXTENSION).symlink_metadata().is_ok(); + python3 |= dir.join(PYTHON3).with_extension(EXE_EXTENSION).symlink_metadata().is_ok(); } // try 3 before 2