forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathptvsd_folder_name.py
More file actions
53 lines (41 loc) · 1.6 KB
/
ptvsd_folder_name.py
File metadata and controls
53 lines (41 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import sys
import os.path
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)
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_path = os.path.join(PYTHONFILES, folder_name)
if os.path.exists(folder_path):
print(folder_path, end="")
return
except:
# Fallback to use base PTVSD path no matter the exception.
print(PYTHONFILES, end="")
return
# Default fallback to use base PTVSD path.
print(PYTHONFILES, end="")
if __name__ == "__main__":
ptvsd_folder_name()