|
1 | 1 | import os |
2 | 2 | import hashlib |
| 3 | +import pathlib |
3 | 4 | import urllib.request |
4 | 5 | import libarchive |
5 | 6 | from email.message import EmailMessage |
|
45 | 46 | 'linux-x64': 'manylinux_2_12_x86_64.manylinux2010_x86_64', |
46 | 47 | 'linux-armv7l': 'manylinux_2_17_armv7l.manylinux2014_armv7l', |
47 | 48 | 'linux-arm64': 'manylinux_2_17_aarch64.manylinux2014_aarch64', |
| 49 | + 'linux-x64-musl': 'musllinux_1_1_x86_64' |
48 | 50 | } |
49 | 51 |
|
| 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 | + |
50 | 60 |
|
51 | 61 | class ReproducibleWheelFile(WheelFile): |
52 | 62 | def writestr(self, zinfo, *args, **kwargs): |
@@ -113,6 +123,11 @@ def write_nodejs_wheel(out_dir, *, node_version, version, platform, archive): |
113 | 123 | entry_points = {} |
114 | 124 | init_imports = [] |
115 | 125 |
|
| 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 | + |
116 | 131 | with libarchive.memory_reader(archive) as archive: |
117 | 132 | for entry in archive: |
118 | 133 | entry_name = '/'.join(entry.name.split('/')[1:]) |
@@ -246,13 +261,16 @@ def main() -> None: |
246 | 261 | """).encode('ascii') |
247 | 262 |
|
248 | 263 | contents['nodejs/__init__.py'] = (cleandoc(""" |
| 264 | + import sys |
249 | 265 | 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} |
251 | 268 |
|
252 | 269 | __version__ = "{version}" |
253 | 270 | node_version = "{node_version}" |
254 | 271 | """)).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), |
256 | 274 | version=version, |
257 | 275 | node_version=node_version, |
258 | 276 | ).encode('ascii') |
@@ -294,10 +312,13 @@ def make_nodejs_version(node_version, suffix=''): |
294 | 312 | print('Suffix:', suffix) |
295 | 313 |
|
296 | 314 | 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}') |
301 | 322 | try: |
302 | 323 | with urllib.request.urlopen(node_url) as request: |
303 | 324 | node_archive = request.read() |
|
0 commit comments