|
| 1 | +From 910b92ba02420cc039f39e6c6907557edd185107 Mon Sep 17 00:00:00 2001 |
| 2 | +From: =?UTF-8?q?Lum=C3=ADr=20=27Frenzy=27=20Balhar?= |
| 3 | + |
| 4 | +Date: Sun, 22 Jun 2025 07:49:14 +0200 |
| 5 | +Subject: [PATCH] tools: make nodedownload module compatible with Python 3.14 |
| 6 | + |
| 7 | +FancyURLopener and URLopener have been deprecated since |
| 8 | +Python 3.3 and they are removed completely from 3.14. |
| 9 | + |
| 10 | +Fixes: https://github.com/nodejs/node/issues/58740 |
| 11 | +PR-URL: https://github.com/nodejs/node/pull/58752 |
| 12 | +Reviewed-By: Luigi Pinca < [email protected]> |
| 13 | +Reviewed-By: Yagiz Nizipli < [email protected]> |
| 14 | +Reviewed-By: James M Snell < [email protected]> |
| 15 | +--- |
| 16 | + tools/configure.d/nodedownload.py | 15 +++++---------- |
| 17 | + 1 file changed, 5 insertions(+), 10 deletions(-) |
| 18 | + |
| 19 | +diff --git a/tools/configure.d/nodedownload.py b/tools/configure.d/nodedownload.py |
| 20 | +index 4f144e0e4b4..0d65c33606b 100644 |
| 21 | +--- a/tools/configure.d/nodedownload.py |
| 22 | ++++ b/tools/configure.d/nodedownload.py |
| 23 | +@@ -7,10 +7,7 @@ import sys |
| 24 | + import zipfile |
| 25 | + import tarfile |
| 26 | + import contextlib |
| 27 | +-try: |
| 28 | +- from urllib.request import FancyURLopener, URLopener |
| 29 | +-except ImportError: |
| 30 | +- from urllib import FancyURLopener, URLopener |
| 31 | ++from urllib.request import build_opener, install_opener, urlretrieve |
| 32 | + |
| 33 | + def formatSize(amt): |
| 34 | + """Format a size as a string in MB""" |
| 35 | +@@ -21,11 +18,6 @@ def spin(c): |
| 36 | + spin = ".:|'" |
| 37 | + return (spin[c % len(spin)]) |
| 38 | + |
| 39 | +-class ConfigOpener(FancyURLopener): |
| 40 | +- """fancy opener used by retrievefile. Set a UA""" |
| 41 | +- # append to existing version (UA) |
| 42 | +- version = '%s node.js/configure' % URLopener.version |
| 43 | +- |
| 44 | + def reporthook(count, size, total): |
| 45 | + """internal hook used by retrievefile""" |
| 46 | + sys.stdout.write(' Fetch: %c %sMB total, %sMB downloaded \r' % |
| 47 | +@@ -38,7 +30,10 @@ def retrievefile(url, targetfile): |
| 48 | + try: |
| 49 | + sys.stdout.write(' <%s>\nConnecting...\r' % url) |
| 50 | + sys.stdout.flush() |
| 51 | +- ConfigOpener().retrieve(url, targetfile, reporthook=reporthook) |
| 52 | ++ opener = build_opener() |
| 53 | ++ opener.addheaders = [('User-agent', f'Python-urllib/{sys.version_info.major}.{sys.version_info.minor} node.js/configure')] |
| 54 | ++ install_opener(opener) |
| 55 | ++ urlretrieve(url, targetfile, reporthook=reporthook) |
| 56 | + print('') # clear the line |
| 57 | + return targetfile |
| 58 | + except IOError as err: |
| 59 | +-- |
| 60 | +2.53.0 |
| 61 | + |
| 62 | +--- a/configure 2026-01-13 02:01:31.000000000 +0000 |
| 63 | ++++ b/configure 2026-02-04 05:46:05.729484536 +0000 |
| 64 | +@@ -25,7 +25,7 @@ |
| 65 | + from distutils.spawn import find_executable as which |
| 66 | + |
| 67 | + print('Node.js configure: Found Python {}.{}.{}...'.format(*sys.version_info)) |
| 68 | +-acceptable_pythons = ((3, 13), (3, 12), (3, 11), (3, 10), (3, 9), (3, 8), (3, 7), (3, 6)) |
| 69 | ++acceptable_pythons = ((3, 14), (3, 13), (3, 12), (3, 11), (3, 10), (3, 9), (3, 8), (3, 7), (3, 6)) |
| 70 | + if sys.version_info[:2] in acceptable_pythons: |
| 71 | + import configure |
| 72 | + else: |
0 commit comments