Skip to content
Merged
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
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.
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