Skip to content

Commit f80ece7

Browse files
committed
Add initial support for downloading musl-built nodejs from the unofficial builds
1 parent 67a6899 commit f80ece7

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
pip install -r requirements.txt
2424
- name: Build Wheels
2525
run: |
26+
mkdir dist
2627
python make_wheels.py
2728
- name: Show built files
2829
run: |

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ nodejs-cmd/*.egg-info
55
.DS_Store
66
env*/
77
__pycache__/
8-
*.py[cod]
8+
*.py[cod]
9+
venv
10+
package.json
11+
node_modules
12+
package-lock.json

make_wheels.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import hashlib
3+
import pathlib
34
import urllib.request
45
import libarchive
56
from email.message import EmailMessage
@@ -45,8 +46,17 @@
4546
'linux-x64': 'manylinux_2_12_x86_64.manylinux2010_x86_64',
4647
'linux-armv7l': 'manylinux_2_17_armv7l.manylinux2014_armv7l',
4748
'linux-arm64': 'manylinux_2_17_aarch64.manylinux2014_aarch64',
49+
'linux-x64-musl': 'musllinux_1_1_x86_64'
4850
}
4951

52+
# https://github.com/nodejs/unofficial-builds/
53+
# Versions added here should match the keys above
54+
UNOFFICIAL_NODEJS_BUILDS = {'linux-x64-musl'}
55+
56+
_mismatched_versions = UNOFFICIAL_NODEJS_BUILDS - set(PLATFORMS.keys())
57+
if _mismatched_versions:
58+
raise Exception(f"A version mismatch occurred. Check the usage of {_mismatched_versions}")
59+
5060

5161
class ReproducibleWheelFile(WheelFile):
5262
def writestr(self, zinfo, *args, **kwargs):
@@ -113,6 +123,11 @@ def write_nodejs_wheel(out_dir, *, node_version, version, platform, archive):
113123
entry_points = {}
114124
init_imports = []
115125

126+
# Create the output directory if it does not exist
127+
out_dir_path = pathlib.Path(out_dir)
128+
if not out_dir_path.exists():
129+
out_dir_path.mkdir(parents=True)
130+
116131
with libarchive.memory_reader(archive) as archive:
117132
for entry in archive:
118133
entry_name = '/'.join(entry.name.split('/')[1:])
@@ -246,13 +261,16 @@ def main() -> None:
246261
""").encode('ascii')
247262

248263
contents['nodejs/__init__.py'] = (cleandoc("""
264+
import sys
249265
from .node import path as path, main as main, call as call, run as run, Popen as Popen
250-
{init_imports}
266+
if not '-m' in sys.argv:
267+
{init_imports}
251268
252269
__version__ = "{version}"
253270
node_version = "{node_version}"
254271
""")).format(
255-
init_imports='\n'.join(init_imports),
272+
# Note: two space indentation above and below is necessary to align
273+
init_imports='\n '.join(init_imports),
256274
version=version,
257275
node_version=node_version,
258276
).encode('ascii')
@@ -294,10 +312,13 @@ def make_nodejs_version(node_version, suffix=''):
294312
print('Suffix:', suffix)
295313

296314
for node_platform, python_platform in PLATFORMS.items():
297-
print(f'- Making Wheel for {node_platform}')
298-
node_url = f'https://nodejs.org/dist/v{node_version}/node-v{node_version}-{node_platform}.' + \
299-
('zip' if node_platform.startswith('win-') else 'tar.xz')
300-
315+
filetype = 'zip' if node_platform.startswith('win-') else 'tar.xz'
316+
if node_platform in UNOFFICIAL_NODEJS_BUILDS:
317+
node_url = f'https://unofficial-builds.nodejs.org/download/release/v{node_version}/node-v{node_version}-{node_platform}.{filetype}'
318+
else:
319+
node_url = f'https://nodejs.org/dist/v{node_version}/node-v{node_version}-{node_platform}.{filetype}'
320+
321+
print(f'- Making Wheel for {node_platform} from {node_url}')
301322
try:
302323
with urllib.request.urlopen(node_url) as request:
303324
node_archive = request.read()

0 commit comments

Comments
 (0)