From b3737f1185990022cada2ae2388953868a751e7a Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Tue, 5 Nov 2024 09:39:26 -0800 Subject: [PATCH] Fix bug with substituting `~` (#579) --- dev-requirements.txt | 36 +++++++++---------- src/common/settings.ts | 4 ++- .../tests/common/settings.unit.test.ts | 4 +++ 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index f8a866d..0cf51f9 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -4,9 +4,9 @@ # # pip-compile --generate-hashes ./dev-requirements.in # -argcomplete==3.5.0 \ - --hash=sha256:4349400469dccfb7950bb60334a680c58d88699bff6159df61251878dc6bf74b \ - --hash=sha256:d4bcf3ff544f51e16e54228a7ac7f486ed70ebf2ecfe49a63a91171c76bf029b +argcomplete==3.5.1 \ + --hash=sha256:1a1d148bdaa3e3b93454900163403df41448a248af01b6e849edc5ac08e6c363 \ + --hash=sha256:eb1ee355aa2557bd3d0145de7b06b2a45b0ce461e1e7813f5d066039ab4177b4 # via nox black==24.8.0 \ --hash=sha256:09cdeb74d494ec023ded657f7092ba518e8cf78fa8386155e4a03fdcc44679e6 \ @@ -32,9 +32,9 @@ black==24.8.0 \ --hash=sha256:f490dbd59680d809ca31efdae20e634f3fae27fba3ce0ba3208333b713bc3920 \ --hash=sha256:fb6e2c0b86bbd43dee042e48059c9ad7830abd5c94b0bc518c0eeec57c3eddc1 # via -r ./dev-requirements.in -build==1.2.2 \ - --hash=sha256:119b2fb462adef986483438377a13b2f42064a2a3a4161f24a0cca698a07ac8c \ - --hash=sha256:277ccc71619d98afdd841a0e96ac9fe1593b823af481d3b0cea748e8894e0613 +build==1.2.2.post1 \ + --hash=sha256:1d61c0887fa860c01971625baae8bdd338e517b836a2f70dd1f7aa3a6b2fc5b5 \ + --hash=sha256:b36993e92ca9375a219c99e606a122ff365a760a2d4bba0caa09bd5278b608b7 # via pip-tools click==8.1.7 \ --hash=sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28 \ @@ -49,13 +49,13 @@ colorama==0.4.6 \ # build # click # colorlog -colorlog==6.8.2 \ - --hash=sha256:3e3e079a41feb5a1b64f978b5ea4f46040a94f11f0e8bbb8261e3dbbeca64d44 \ - --hash=sha256:4dcbb62368e2800cb3c5abd348da7e53f6c362dda502ec27c560b2e58a66bd33 +colorlog==6.9.0 \ + --hash=sha256:5906e71acd67cb07a71e779c47c4bcb45fb8c2993eebe9e5adcd6a6f1b283eff \ + --hash=sha256:bfba54a1b93b94f54e1f4fe48395725a3d92fd2a4af702f6bd70946bdc0c6ac2 # via nox -distlib==0.3.8 \ - --hash=sha256:034db59a0b96f8ca18035f36290806a9a6e6bd9d1ff91e45a7f172eb17e51784 \ - --hash=sha256:1530ea13e350031b6312d8580ddb6b27a104275a31106523b8f123787f494f64 +distlib==0.3.9 \ + --hash=sha256:47f8c22fd27c27e25a65601af709b38e4f0a45ea4fc2e710f65755fa8caaaf87 \ + --hash=sha256:a60f20dea646b8a33f3e7772f74dc0b2d0772d2837ee1342a00645c81edf9403 # via virtualenv filelock==3.16.1 \ --hash=sha256:2082e5703d51fbf98ea75855d9d5527e33d8ff23099bec374a134febee6946b0 \ @@ -86,9 +86,9 @@ mypy-extensions==1.0.0 \ --hash=sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d \ --hash=sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782 # via black -nox==2024.4.15 \ - --hash=sha256:6492236efa15a460ecb98e7b67562a28b70da006ab0be164e8821177577c0565 \ - --hash=sha256:ecf6700199cdfa9e5ea0a41ff5e6ef4641d09508eda6edb89d9987864115817f +nox==2024.10.9 \ + --hash=sha256:1d36f309a0a2a853e9bccb76bbef6bb118ba92fa92674d15604ca99adeb29eab \ + --hash=sha256:7aa9dc8d1c27e9f45ab046ffd1c3b2c4f7c91755304769df231308849ebded95 # via -r ./dev-requirements.in packaging==24.1 \ --hash=sha256:026ed72c8ed3fcce5bf8950572258698927fd1dbda10a5e981cdf0ac37f4f002 \ @@ -138,9 +138,9 @@ typing-extensions==4.12.2 \ --hash=sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d \ --hash=sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8 # via black -virtualenv==20.26.6 \ - --hash=sha256:280aede09a2a5c317e409a00102e7077c6432c5a38f0ef938e643805a7ad2c48 \ - --hash=sha256:7345cc5b25405607a624d8418154577459c3e0277f5466dd79c49d5e492995f2 +virtualenv==20.27.1 \ + --hash=sha256:142c6be10212543b32c6c45d3d3893dff89112cc588b7d0879ae5a1ec03a47ba \ + --hash=sha256:f11f1b8a29525562925f745563bfd48b189450f61fb34c4f9cc79dd5aa32a1f4 # via nox wheel==0.44.0 \ --hash=sha256:2376a90c98cc337d18623527a97c31797bd02bad0033d41547043a1cbfbe448f \ diff --git a/src/common/settings.ts b/src/common/settings.ts index fbb2ca9..114b8d4 100644 --- a/src/common/settings.ts +++ b/src/common/settings.ts @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +import * as path from 'path'; import { ConfigurationChangeEvent, ConfigurationScope, WorkspaceConfiguration, WorkspaceFolder } from 'vscode'; import { traceLog, traceWarn } from './logging'; import { getInterpreterDetails } from './python'; @@ -42,7 +43,8 @@ function resolveVariables( const home = process.env.HOME || process.env.USERPROFILE; if (home) { substitutions.set('${userHome}', home); - substitutions.set('~', home); + substitutions.set(`~/`, `${home}/`); + substitutions.set(`~\\`, `${home}\\`); // Adding both path seps '/' and '\\' explicitly handle and preserve the path separators. } if (workspace) { substitutions.set('${workspaceFolder}', workspace.uri.fsPath); diff --git a/src/test/ts_tests/tests/common/settings.unit.test.ts b/src/test/ts_tests/tests/common/settings.unit.test.ts index 3268530..1081083 100644 --- a/src/test/ts_tests/tests/common/settings.unit.test.ts +++ b/src/test/ts_tests/tests/common/settings.unit.test.ts @@ -263,6 +263,8 @@ suite('Settings Tests', () => { '${workspaceFolder:workspace1}/lib/python', '${cwd}/lib/python', '~/lib/python', + '/usr/~projects', + '~projects', ]) .verifiable(TypeMoq.Times.atLeastOnce()); pythonConfigMock @@ -288,6 +290,8 @@ suite('Settings Tests', () => { `${workspace1.uri.fsPath}/lib/python`, `${process.cwd()}/lib/python`, `${process.env.HOME || process.env.USERPROFILE}/lib/python`, + '/usr/~projects', + '~projects', ]); configMock.verifyAll();