FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
setup-python/src/install-pypy.ts at main · FsDenzel/setup-python · GitHub
FsDenzel
/
setup-python
Public
forked from
actions/setup-python
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
setup-python
/
src
/
install-pypy.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
231 lines (199 loc) · 6.39 KB
Breadcrumbs
setup-python
/
src
/
install-pypy.ts
Copy path
File metadata and controls
231 lines (199 loc) · 6.39 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import
*
as
path
from
'path'
;
import
*
as
core
from
'@actions/core'
;
import
*
as
tc
from
'@actions/tool-cache'
;
import
*
as
semver
from
'semver'
;
import
*
as
httpm
from
'@actions/http-client'
;
import
*
as
exec
from
'@actions/exec'
;
import
fs
from
'fs'
;
import
{
IS_WINDOWS
,
WINDOWS_ARCHS
,
WINDOWS_PLATFORMS
,
IPyPyManifestRelease
,
createSymlinkInFolder
,
isNightlyKeyword
,
writeExactPyPyVersionFile
}
from
'./utils'
;
export
async
function
installPyPy
(
pypyVersion
:
string
,
pythonVersion
:
string
,
architecture
:
string
)
{
let
downloadDir
;
const
releases
=
await
getAvailablePyPyVersions
(
)
;
if
(
!
releases
||
releases
.
length
===
0
)
{
throw
new
Error
(
'No release was found in PyPy version.json'
)
;
}
const
releaseData
=
findRelease
(
releases
,
pythonVersion
,
pypyVersion
,
architecture
)
;
if
(
!
releaseData
||
!
releaseData
.
foundAsset
)
{
throw
new
Error
(
`PyPy version
${
pythonVersion
}
(
${
pypyVersion
}
) with arch
${
architecture
}
not found`
)
;
}
const
{
foundAsset
,
resolvedPythonVersion
,
resolvedPyPyVersion
}
=
releaseData
;
let
downloadUrl
=
`
${
foundAsset
.
download_url
}
`
;
core
.
info
(
`Downloading PyPy from "
${
downloadUrl
}
" ...`
)
;
const
pypyPath
=
await
tc
.
downloadTool
(
downloadUrl
)
;
core
.
info
(
'Extracting downloaded archive...'
)
;
if
(
IS_WINDOWS
)
{
downloadDir
=
await
tc
.
extractZip
(
pypyPath
)
;
}
else
{
downloadDir
=
await
tc
.
extractTar
(
pypyPath
,
undefined
,
'x'
)
;
}
// root folder in archive can have unpredictable name so just take the first folder
// downloadDir is unique folder under TEMP and can't contain any other folders
const
archiveName
=
fs
.
readdirSync
(
downloadDir
)
[
0
]
;
const
toolDir
=
path
.
join
(
downloadDir
,
archiveName
)
;
let
installDir
=
toolDir
;
if
(
!
isNightlyKeyword
(
resolvedPyPyVersion
)
)
{
installDir
=
await
tc
.
cacheDir
(
toolDir
,
'PyPy'
,
resolvedPythonVersion
,
architecture
)
;
}
writeExactPyPyVersionFile
(
installDir
,
resolvedPyPyVersion
)
;
const
binaryPath
=
getPyPyBinaryPath
(
installDir
)
;
await
createPyPySymlink
(
binaryPath
,
resolvedPythonVersion
)
;
await
installPip
(
binaryPath
)
;
return
{
installDir
,
resolvedPythonVersion
,
resolvedPyPyVersion
}
;
}
async
function
getAvailablePyPyVersions
(
)
{
const
url
=
'https://downloads.python.org/pypy/versions.json'
;
const
http
:
httpm
.
HttpClient
=
new
httpm
.
HttpClient
(
'tool-cache'
)
;
const
response
=
await
http
.
getJson
<
IPyPyManifestRelease
[
]
>
(
url
)
;
if
(
!
response
.
result
)
{
throw
new
Error
(
`Unable to retrieve the list of available PyPy versions from '
${
url
}
'`
)
;
}
return
response
.
result
;
}
async
function
createPyPySymlink
(
pypyBinaryPath
:
string
,
pythonVersion
:
string
)
{
const
version
=
semver
.
coerce
(
pythonVersion
)
!
;
const
pythonBinaryPostfix
=
semver
.
major
(
version
)
;
const
pypyBinaryPostfix
=
pythonBinaryPostfix
===
2
?
''
:
'3'
;
let
binaryExtension
=
IS_WINDOWS
?
'.exe'
:
''
;
core
.
info
(
'Creating symlinks...'
)
;
createSymlinkInFolder
(
pypyBinaryPath
,
`pypy
${
pypyBinaryPostfix
}
${
binaryExtension
}
`
,
`python
${
pythonBinaryPostfix
}
${
binaryExtension
}
`
,
true
)
;
createSymlinkInFolder
(
pypyBinaryPath
,
`pypy
${
pypyBinaryPostfix
}
${
binaryExtension
}
`
,
`python
${
binaryExtension
}
`
,
true
)
;
}
async
function
installPip
(
pythonLocation
:
string
)
{
core
.
info
(
'Installing and updating pip'
)
;
const
pythonBinary
=
path
.
join
(
pythonLocation
,
'python'
)
;
await
exec
.
exec
(
`
${
pythonBinary
}
-m ensurepip`
)
;
await
exec
.
exec
(
`
${
pythonLocation
}
/python -m pip install --ignore-installed pip`
)
;
}
export
function
findRelease
(
releases
:
IPyPyManifestRelease
[
]
,
pythonVersion
:
string
,
pypyVersion
:
string
,
architecture
:
string
)
{
const
filterReleases
=
releases
.
filter
(
item
=>
{
const
isPythonVersionSatisfied
=
semver
.
satisfies
(
semver
.
coerce
(
item
.
python_version
)
!
,
pythonVersion
)
;
const
isPyPyNightly
=
isNightlyKeyword
(
pypyVersion
)
&&
isNightlyKeyword
(
item
.
pypy_version
)
;
const
isPyPyVersionSatisfied
=
isPyPyNightly
||
semver
.
satisfies
(
pypyVersionToSemantic
(
item
.
pypy_version
)
,
pypyVersion
)
;
const
isArchPresent
=
item
.
files
&&
(
IS_WINDOWS
?
isArchPresentForWindows
(
item
)
:
isArchPresentForMacOrLinux
(
item
,
architecture
,
process
.
platform
)
)
;
return
isPythonVersionSatisfied
&&
isPyPyVersionSatisfied
&&
isArchPresent
;
}
)
;
if
(
filterReleases
.
length
===
0
)
{
return
null
;
}
const
sortedReleases
=
filterReleases
.
sort
(
(
previous
,
current
)
=>
{
return
(
semver
.
compare
(
semver
.
coerce
(
pypyVersionToSemantic
(
current
.
pypy_version
)
)
!
,
semver
.
coerce
(
pypyVersionToSemantic
(
previous
.
pypy_version
)
)
!
)
||
semver
.
compare
(
semver
.
coerce
(
current
.
python_version
)
!
,
semver
.
coerce
(
previous
.
python_version
)
!
)
)
;
}
)
;
const
foundRelease
=
sortedReleases
[
0
]
;
const
foundAsset
=
IS_WINDOWS
?
findAssetForWindows
(
foundRelease
)
:
findAssetForMacOrLinux
(
foundRelease
,
architecture
,
process
.
platform
)
;
return
{
foundAsset
,
resolvedPythonVersion
:
foundRelease
.
python_version
,
resolvedPyPyVersion
:
foundRelease
.
pypy_version
}
;
}
/** Get PyPy binary location from the tool of installation directory
* - On Linux and macOS, the Python interpreter is in 'bin'.
* - On Windows, it is in the installation root.
*/
export
function
getPyPyBinaryPath
(
installDir
:
string
)
{
const
_binDir
=
path
.
join
(
installDir
,
'bin'
)
;
return
IS_WINDOWS
?
installDir
:
_binDir
;
}
export
function
pypyVersionToSemantic
(
versionSpec
:
string
)
{
const
prereleaseVersion
=
/
(
\d
+
\.
\d
+
\.
\d
+
)
(
(?:
a
|
b
|
r
c
)
)
(
\d
*
)
/
g
;
return
versionSpec
.
replace
(
prereleaseVersion
,
'$1-$2.$3'
)
;
}
export
function
isArchPresentForWindows
(
item
:
any
)
{
return
item
.
files
.
some
(
(
file
:
any
)
=>
WINDOWS_ARCHS
.
includes
(
file
.
arch
)
&&
WINDOWS_PLATFORMS
.
includes
(
file
.
platform
)
)
;
}
export
function
isArchPresentForMacOrLinux
(
item
:
any
,
architecture
:
string
,
platform
:
string
)
{
return
item
.
files
.
some
(
(
file
:
any
)
=>
file
.
arch
===
architecture
&&
file
.
platform
===
platform
)
;
}
export
function
findAssetForWindows
(
releases
:
any
)
{
return
releases
.
files
.
find
(
(
item
:
any
)
=>
WINDOWS_ARCHS
.
includes
(
item
.
arch
)
&&
WINDOWS_PLATFORMS
.
includes
(
item
.
platform
)
)
;
}
export
function
findAssetForMacOrLinux
(
releases
:
any
,
architecture
:
string
,
platform
:
string
)
{
return
releases
.
files
.
find
(
(
item
:
any
)
=>
item
.
arch
===
architecture
&&
item
.
platform
===
platform
)
;
}
Back
|
FazBrowse Home
|
New Git URL