FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonVSCode/pythonFiles/install_ptvsd.py at master · iVerb/pythonVSCode · GitHub
iVerb
/
pythonVSCode
Public
forked from
DonJayamanne/pythonVSCode
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonVSCode
/
pythonFiles
/
install_ptvsd.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
56 lines (46 loc) · 2.31 KB
Breadcrumbs
pythonVSCode
/
pythonFiles
/
install_ptvsd.py
Copy path
File metadata and controls
56 lines (46 loc) · 2.31 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
54
55
56
from
io
import
BytesIO
from
os
import
path
from
zipfile
import
ZipFile
import
json
import
urllib
.
request
import
sys
ROOT_DIRNAME
=
path
.
dirname
(
path
.
dirname
(
path
.
abspath
(
__file__
)))
REQUIREMENTS_PATH
=
path
.
join
(
ROOT_DIRNAME
,
"requirements.txt"
)
PYTHONFILES_PATH
=
path
.
join
(
ROOT_DIRNAME
,
"pythonFiles"
,
"lib"
,
"python"
)
PYPI_PTVSD_URL
=
"https://pypi.org/pypi/ptvsd/json"
def
install_ptvsd
():
# If we are in CI use the packaging module installed in PYTHONFILES_PATH.
if
len
(
sys
.
argv
)
==
2
and
sys
.
argv
[
1
]
==
"--ci"
:
sys
.
path
.
insert
(
0
,
PYTHONFILES_PATH
)
from
packaging
.
requirements
import
Requirement
with
open
(
REQUIREMENTS_PATH
,
"r"
,
encoding
=
"utf-8"
)
as
requirements
:
for
line
in
requirements
:
package_requirement
=
Requirement
(
line
)
if
package_requirement
.
name
!=
"ptvsd"
:
continue
requirement_specifier
=
package_requirement
.
specifier
ptvsd_version
=
next
(
requirement_specifier
.
__iter__
()).
version
# Response format: https://warehouse.readthedocs.io/api-reference/json/#project
with
urllib
.
request
.
urlopen
(
PYPI_PTVSD_URL
)
as
response
:
json_response
=
json
.
loads
(
response
.
read
())
releases
=
json_response
[
"releases"
]
# Release metadata format: https://github.com/pypa/interoperability-peps/blob/master/pep-0426-core-metadata.rst
for
wheel_info
in
releases
[
ptvsd_version
]:
# 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.
ptvsd_path
=
path
.
join
(
PYTHONFILES_PATH
,
filename
)
with
urllib
.
request
.
urlopen
(
wheel_info
[
"url"
])
as
wheel_response
:
wheel_file
=
BytesIO
(
wheel_response
.
read
())
# Extract only the contents of the ptvsd subfolder.
prefix
=
path
.
join
(
f"ptvsd-
{
ptvsd_version
}
.data"
,
"purelib"
,
"ptvsd"
)
with
ZipFile
(
wheel_file
,
"r"
)
as
wheel
:
for
zip_info
in
wheel
.
infolist
():
if
not
zip_info
.
filename
.
startswith
(
prefix
):
continue
# Flatten the folder structure.
zip_info
.
filename
=
zip_info
.
filename
.
split
(
prefix
)[
-
1
]
wheel
.
extract
(
zip_info
,
ptvsd_path
)
if
__name__
==
"__main__"
:
install_ptvsd
()
Back
|
FazBrowse Home
|
New Git URL