Skip to content

Commit f505a8e

Browse files
kimadelinekarthiknadig
authored andcommitted
Don't use the PTVSD version in the folder name for the wheel experiment (microsoft#7876)
1 parent 52ad266 commit f505a8e

File tree

6 files changed

+13
-61
lines changed

6 files changed

+13
-61
lines changed

news/2 Fixes/7836.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Do not use the PTVSD package version in the folder name for the wheel experiment.

pythonFiles/install_ptvsd.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ def install_ptvsd():
4040
# Download only if it's a 3.7 wheel.
4141
if not wheel_info["python_version"].endswith(("37", "3.7")):
4242
continue
43-
filename = wheel_info["filename"].rpartition(".")[0] # Trim the file extension.
43+
44+
# Trim the file extension and remove the ptvsd version from the folder name.
45+
filename = wheel_info["filename"].rpartition(".")[0]
46+
filename = filename.replace(f"{version}-", "")
4447
ptvsd_path = path.join(PYTHONFILES, filename)
4548

4649
with urllib.request.urlopen(wheel_info["url"]) as wheel_response:

pythonFiles/ptvsd_folder_name.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66

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

1110
sys.path.insert(0, PYTHONFILES)
1211

13-
from packaging.requirements import Requirement
1412
from packaging.tags import sys_tags
1513

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

22-
with open(REQUIREMENTS, "r", encoding="utf-8") as reqsfile:
23-
for line in reqsfile:
24-
pkgreq = Requirement(line)
25-
if pkgreq.name == "ptvsd":
26-
specs = pkgreq.specifier
27-
try:
28-
spec, = specs
29-
version = spec.version
30-
except:
31-
# Fallpack to use base PTVSD path.
32-
print(PYTHONFILES, end="")
33-
return
34-
break
35-
3620
try:
3721
for tag in sys_tags():
38-
folder_name = f"ptvsd-{version}-{tag.interpreter}-{tag.abi}-{tag.platform}"
22+
folder_name = f"ptvsd-{tag.interpreter}-{tag.abi}-{tag.platform}"
3923
folder_path = os.path.join(PYTHONFILES, folder_name)
4024
if os.path.exists(folder_path):
4125
print(folder_path, end="")

pythonFiles/tests/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@
1010
DEBUG_ADAPTER_ROOT = os.path.join(SRC_ROOT, "debug_adapter")
1111

1212
PYTHONFILES = os.path.join(SRC_ROOT, "lib", "python")
13-
REQUIREMENTS = os.path.join(PROJECT_ROOT, "requirements.txt")

pythonFiles/tests/debug_adapter/test_ptvsd_folder_name.py

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,64 +15,36 @@
1515
from packaging.tags import sys_tags
1616
from ptvsd_folder_name import ptvsd_folder_name
1717

18-
from .. import PYTHONFILES, REQUIREMENTS
19-
20-
21-
def open_requirements_with_ptvsd():
22-
return patch(
23-
"ptvsd_folder_name.open", mock_open(read_data="jedi==0.15.1\nptvsd==5.0.0")
24-
)
25-
26-
27-
def open_requirements_without_ptvsd():
28-
return patch("ptvsd_folder_name.open", mock_open(read_data="jedi==0.15.1\n"))
18+
from .. import PYTHONFILES
2919

3020

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

34-
def test_requirement_exists_folder_exists(self, capsys):
24+
def test_folder_exists(self, capsys):
3525
# Return the first constructed folder path as existing.
3626

3727
patcher = patch("os.path.exists")
3828
mock_exists = patcher.start()
3929
mock_exists.side_effect = lambda p: True
4030
tag = next(sys_tags())
41-
folder = "ptvsd-5.0.0-{}-{}-{}".format(tag.interpreter, tag.abi, tag.platform)
31+
folder = "ptvsd-{}-{}-{}".format(tag.interpreter, tag.abi, tag.platform)
4232

43-
with open_requirements_with_ptvsd():
44-
ptvsd_folder_name()
33+
ptvsd_folder_name()
4534

4635
patcher.stop()
4736
expected = os.path.join(PYTHONFILES, folder)
4837
captured = capsys.readouterr()
4938
assert captured.out == expected
5039

51-
def test_ptvsd_requirement_once(self):
52-
reqs = [
53-
line
54-
for line in open(REQUIREMENTS, "r", encoding="utf-8")
55-
if re.match("ptvsd==", line)
56-
]
57-
assert len(reqs) == 1
58-
59-
def test_no_ptvsd_requirement(self, capsys):
60-
with open_requirements_without_ptvsd() as p:
61-
ptvsd_folder_name()
62-
63-
expected = PYTHONFILES
64-
captured = capsys.readouterr()
65-
assert captured.out == expected
66-
6740
def test_no_wheel_folder(self, capsys):
6841
# Return none of of the constructed paths as existing,
6942
# ptvsd_folder_name() should return the path to default ptvsd.
7043
patcher = patch("os.path.exists")
7144
mock_no_exist = patcher.start()
7245
mock_no_exist.side_effect = lambda p: False
7346

74-
with open_requirements_with_ptvsd() as p:
75-
ptvsd_folder_name()
47+
ptvsd_folder_name()
7648

7749
patcher.stop()
7850
expected = PYTHONFILES

pythonFiles/tests/debug_adapter/test_ptvsd_folder_name_functional.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,15 @@
1313
import subprocess
1414

1515
from packaging.requirements import Requirement
16-
from .. import PYTHONFILES, REQUIREMENTS, SRC_ROOT
16+
from .. import PYTHONFILES, SRC_ROOT
1717

1818
ARGV = ["python", os.path.join(SRC_ROOT, "ptvsd_folder_name.py")]
19-
PREFIX = "ptvsd=="
20-
21-
with open(REQUIREMENTS, "r", encoding="utf-8") as reqsfile:
22-
for line in reqsfile:
23-
if line.startswith(PREFIX):
24-
VERSION = line[len(PREFIX) :].strip()
25-
break
2619

2720

2821
def ptvsd_paths(*platforms):
2922
paths = set()
3023
for platform in platforms:
31-
folder = "ptvsd-{}-cp37-cp37m-{}".format(VERSION, platform)
24+
folder = "ptvsd-cp37-cp37m-{}".format(platform)
3225
paths.add(os.path.join(PYTHONFILES, folder))
3326
return paths
3427

0 commit comments

Comments
 (0)