Skip to content

Cherry picking fixes into release #8032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions experiments.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,26 @@
{
"name": "DebugAdapterFactory - control",
"salt": "DebugAdapterFactory",
"min": 80,
"max": 90
"min": 0,
"max": 0
},
{
"name": "DebugAdapterFactory - experiment",
"salt": "DebugAdapterFactory",
"min": 10,
"max": 20
"min": 0,
"max": 0
},
{
"name": "PtvsdWheels37 - control",
"salt": "DebugAdapterFactory",
"min": 87,
"max": 90
"min": 0,
"max": 0
},
{
"name": "PtvsdWheels37 - experiment",
"salt": "DebugAdapterFactory",
"min": 10,
"max": 13
"min": 0,
"max": 0
},
{
"name": "LS - enabled",
Expand Down
1 change: 1 addition & 0 deletions news/2 Fixes/7836.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Do not use the PTVSD package version in the folder name for the wheel experiment.
2 changes: 1 addition & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"Experiments.inGroup": "User belongs to experiment group '{0}'",
"Interpreters.RefreshingInterpreters": "Refreshing Python Interpreters",
"Interpreters.LoadingInterpreters": "Loading Python Interpreters",
"Interpreters.condaInheritEnvMessage": "We noticed you're using a conda environment. If you are experiencing issues with this environment in the integrated terminal, we suggest the \"terminal.integrated.inheritEnv\" setting to be changed to false. Would you like to update this setting?",
"Interpreters.condaInheritEnvMessage": "We noticed you're using a conda environment. If you are experiencing issues with this environment in the integrated terminal, we recommend that you let the Python extension change \"terminal.integrated.inheritEnv\" to false in your user settings.",
"Logging.CurrentWorkingDirectory": "cwd:",
"Common.doNotShowAgain": "Do not show again",
"Common.reload": "Reload",
Expand Down
5 changes: 4 additions & 1 deletion pythonFiles/install_ptvsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ def install_ptvsd():
# Download only if it's a 3.7 wheel.
if not wheel_info["python_version"].endswith(("37", "3.7")):
continue
filename = wheel_info["filename"].rpartition(".")[0] # Trim the file extension.

# Trim the file extension and remove the ptvsd version from the folder name.
filename = wheel_info["filename"].rpartition(".")[0]
filename = filename.replace(f"{version}-", "")
ptvsd_path = path.join(PYTHONFILES, filename)

with urllib.request.urlopen(wheel_info["url"]) as wheel_response:
Expand Down
18 changes: 1 addition & 17 deletions pythonFiles/ptvsd_folder_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PYTHONFILES = os.path.join(ROOT, "pythonFiles", "lib", "python")
REQUIREMENTS = os.path.join(ROOT, "requirements.txt")

sys.path.insert(0, PYTHONFILES)

from packaging.requirements import Requirement
from packaging.tags import sys_tags

sys.path.remove(PYTHONFILES)
Expand All @@ -19,23 +17,9 @@
def ptvsd_folder_name():
"""Return the folder name for the bundled PTVSD wheel compatible with the new debug adapter."""

with open(REQUIREMENTS, "r", encoding="utf-8") as reqsfile:
for line in reqsfile:
pkgreq = Requirement(line)
if pkgreq.name == "ptvsd":
specs = pkgreq.specifier
try:
spec, = specs
version = spec.version
except:
# Fallpack to use base PTVSD path.
print(PYTHONFILES, end="")
return
break

try:
for tag in sys_tags():
folder_name = f"ptvsd-{version}-{tag.interpreter}-{tag.abi}-{tag.platform}"
folder_name = f"ptvsd-{tag.interpreter}-{tag.abi}-{tag.platform}"
folder_path = os.path.join(PYTHONFILES, folder_name)
if os.path.exists(folder_path):
print(folder_path, end="")
Expand Down
1 change: 0 additions & 1 deletion pythonFiles/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@
DEBUG_ADAPTER_ROOT = os.path.join(SRC_ROOT, "debug_adapter")

PYTHONFILES = os.path.join(SRC_ROOT, "lib", "python")
REQUIREMENTS = os.path.join(PROJECT_ROOT, "requirements.txt")
38 changes: 5 additions & 33 deletions pythonFiles/tests/debug_adapter/test_ptvsd_folder_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,64 +15,36 @@
from packaging.tags import sys_tags
from ptvsd_folder_name import ptvsd_folder_name

from .. import PYTHONFILES, REQUIREMENTS


def open_requirements_with_ptvsd():
return patch(
"ptvsd_folder_name.open", mock_open(read_data="jedi==0.15.1\nptvsd==5.0.0")
)


def open_requirements_without_ptvsd():
return patch("ptvsd_folder_name.open", mock_open(read_data="jedi==0.15.1\n"))
from .. import PYTHONFILES


class TestPtvsdFolderName:
"""Unit tests for the script retrieving the PTVSD folder name for the PTVSD wheels experiment."""

def test_requirement_exists_folder_exists(self, capsys):
def test_folder_exists(self, capsys):
# Return the first constructed folder path as existing.

patcher = patch("os.path.exists")
mock_exists = patcher.start()
mock_exists.side_effect = lambda p: True
tag = next(sys_tags())
folder = "ptvsd-5.0.0-{}-{}-{}".format(tag.interpreter, tag.abi, tag.platform)
folder = "ptvsd-{}-{}-{}".format(tag.interpreter, tag.abi, tag.platform)

with open_requirements_with_ptvsd():
ptvsd_folder_name()
ptvsd_folder_name()

patcher.stop()
expected = os.path.join(PYTHONFILES, folder)
captured = capsys.readouterr()
assert captured.out == expected

def test_ptvsd_requirement_once(self):
reqs = [
line
for line in open(REQUIREMENTS, "r", encoding="utf-8")
if re.match("ptvsd==", line)
]
assert len(reqs) == 1

def test_no_ptvsd_requirement(self, capsys):
with open_requirements_without_ptvsd() as p:
ptvsd_folder_name()

expected = PYTHONFILES
captured = capsys.readouterr()
assert captured.out == expected

def test_no_wheel_folder(self, capsys):
# Return none of of the constructed paths as existing,
# ptvsd_folder_name() should return the path to default ptvsd.
patcher = patch("os.path.exists")
mock_no_exist = patcher.start()
mock_no_exist.side_effect = lambda p: False

with open_requirements_with_ptvsd() as p:
ptvsd_folder_name()
ptvsd_folder_name()

patcher.stop()
expected = PYTHONFILES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,15 @@
import subprocess

from packaging.requirements import Requirement
from .. import PYTHONFILES, REQUIREMENTS, SRC_ROOT
from .. import PYTHONFILES, SRC_ROOT

ARGV = ["python", os.path.join(SRC_ROOT, "ptvsd_folder_name.py")]
PREFIX = "ptvsd=="

with open(REQUIREMENTS, "r", encoding="utf-8") as reqsfile:
for line in reqsfile:
if line.startswith(PREFIX):
VERSION = line[len(PREFIX) :].strip()
break


def ptvsd_paths(*platforms):
paths = set()
for platform in platforms:
folder = "ptvsd-{}-cp37-cp37m-{}".format(VERSION, platform)
folder = "ptvsd-cp37-cp37m-{}".format(platform)
paths.add(os.path.join(PYTHONFILES, folder))
return paths

Expand Down
2 changes: 1 addition & 1 deletion src/client/common/utils/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export namespace Experiments {
export namespace Interpreters {
export const loading = localize('Interpreters.LoadingInterpreters', 'Loading Python Interpreters');
export const refreshing = localize('Interpreters.RefreshingInterpreters', 'Refreshing Python Interpreters');
export const condaInheritEnvMessage = localize('Interpreters.condaInheritEnvMessage', 'We noticed you\'re using a conda environment. If you are experiencing issues with this environment in the integrated terminal, we suggest the \"terminal.integrated.inheritEnv\" setting to be changed to false. Would you like to update this setting?');
export const condaInheritEnvMessage = localize('Interpreters.condaInheritEnvMessage', 'We noticed you\'re using a conda environment. If you are experiencing issues with this environment in the integrated terminal, we recommend that you let the Python extension change \"terminal.integrated.inheritEnv\" to false in your user settings.');
export const environmentPromptMessage = localize('Interpreters.environmentPromptMessage', 'We noticed a new virtual environment has been created. Do you want to select it for the workspace folder?');
export const selectInterpreterTip = localize('Interpreters.selectInterpreterTip', 'Tip: you can change the Python interpreter used by the Python extension by clicking on the Python version in the status bar');
}
Expand Down
11 changes: 8 additions & 3 deletions src/client/interpreter/virtualEnvs/condaInheritEnvPrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { ConfigurationTarget, Uri } from 'vscode';
import { IExtensionActivationService } from '../../activation/types';
import { IApplicationShell, IWorkspaceService } from '../../common/application/types';
import { traceDecorators, traceError } from '../../common/logger';
import { IPersistentStateFactory } from '../../common/types';
import { InteractiveShiftEnterBanner, Interpreters } from '../../common/utils/localize';
import { IPlatformService } from '../../common/platform/types';
import { IBrowserService, IPersistentStateFactory } from '../../common/types';
import { Common, InteractiveShiftEnterBanner, Interpreters } from '../../common/utils/localize';
import { sendTelemetryEvent } from '../../telemetry';
import { EventName } from '../../telemetry/constants';
import { IInterpreterService, InterpreterType } from '../contracts';
Expand All @@ -21,8 +22,9 @@ export class CondaInheritEnvPrompt implements IExtensionActivationService {
@inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService,
@inject(IApplicationShell) private readonly appShell: IApplicationShell,
@inject(IPersistentStateFactory) private readonly persistentStateFactory: IPersistentStateFactory,
@inject(IPlatformService) private readonly platformService: IPlatformService,
@optional() public hasPromptBeenShownInCurrentSession: boolean = false
) { }
) {}

public async activate(resource: Uri): Promise<void> {
this.initializeInBackground(resource).ignoreErrors();
Expand Down Expand Up @@ -62,6 +64,9 @@ export class CondaInheritEnvPrompt implements IExtensionActivationService {
if (this.hasPromptBeenShownInCurrentSession) {
return false;
}
if (this.platformService.isWindows) {
return false;
}
const interpreter = await this.interpreterService.getActiveInterpreter(resource);
if (!interpreter || interpreter.type !== InterpreterType.Conda) {
return false;
Expand Down
Loading