Skip to content

Commit 6ca3700

Browse files
authored
Drop support for running emrun on python2 (#25597)
The original idea here was the emrun script is standalone and could be copied to a target system along with generated program. python2 used to fairly common especially on older macOS devices where it used to come pre-installed. However, this pre-installed python was removed back in macOS 12.3. See emscripten-core/emsdk#1592 Testing of emrun is particularly tricky and testing in standalone mode is still trickier. Trying to *also* make it work with older versions of python going back to python2 seems unnecessary given how few folks are likely stuck on python2 at this point.
1 parent ec0e813 commit 6ca3700

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ See docs/process.md for more on how version tagging works.
2020

2121
4.0.18 (in development)
2222
-----------------------
23+
- The `emrun.py` script no longer support running on python2. (#25597)
2324
- `-sUSE_WEBGPU` was removed in favor of the external port Emdawnwebgpu which
2425
are used via `--use-port=emdawnwebgpu`. See 4.0.10 release notes for details.
2526
- A new `CROSS_ORIGIN` setting was added in order to work around issues hosting

emrun.py

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,22 @@
2828
import shlex
2929
import shutil
3030
import socket
31+
import socketserver
3132
import stat
3233
import struct
3334
import subprocess
3435
import sys
3536
import tempfile
3637
import threading
3738
import time
39+
from http.server import HTTPServer, SimpleHTTPRequestHandler
3840
from operator import itemgetter
41+
from urllib.parse import unquote, urlsplit
3942

40-
if sys.version_info.major == 2:
41-
from urllib import unquote
42-
43-
import SocketServer as socketserver
44-
from BaseHTTPServer import HTTPServer
45-
from SimpleHTTPServer import SimpleHTTPRequestHandler
46-
from urlparse import urlsplit
47-
else:
48-
import socketserver
49-
from http.server import HTTPServer, SimpleHTTPRequestHandler
50-
from urllib.parse import unquote, urlsplit
43+
# We depend on python 3.8 features
44+
if sys.version_info < (3, 8): # noqa: UP036
45+
print(f'error: emrun requires python 3.8 or above ({sys.executable} {sys.version})', file=sys.stderr)
46+
sys.exit(1)
5147

5248
# Populated from cmdline params
5349
emrun_options = None
@@ -87,7 +83,7 @@
8783
# launcher.exe that runs the actual opera browser. So killing browser_process
8884
# would just kill launcher.exe and not the opera
8985
# browser itself.
90-
processname_killed_atexit = ""
86+
processname_killed_atexit = ''
9187

9288
# Using "0.0.0.0" means "all interfaces", which should allow connecting to this
9389
# server via LAN addresses. Using "localhost" should allow only connecting from
@@ -121,8 +117,6 @@
121117

122118
# Returns wallclock time in seconds.
123119
def tick():
124-
# Would like to return time.clock() since it's apparently better for
125-
# precision, but it is broken on macOS 10.10 and Python 2.7.8.
126120
return time.time()
127121

128122

@@ -680,7 +674,7 @@ def do_POST(self): # # noqa: DC04
680674
global page_exit_code, have_received_messages
681675

682676
(_, _, path, query, _) = urlsplit(self.path)
683-
logv('POST: "' + self.path + '" (path: "' + path + '", query: "' + query + '")')
677+
logv(f'POST: "{self.path}" (path: "{path}", query: "{query}")')
684678
if query.startswith('file='):
685679
# Binary file dump/upload handling. Requests to
686680
# "stdio.html?file=filename" will write binary data to the given file.
@@ -758,12 +752,8 @@ def do_POST(self): # # noqa: DC04
758752

759753

760754
# Returns stdout by running command with universal_newlines=True
761-
def check_output(cmd, universal_newlines=True, *args, **kwargs):
762-
if hasattr(subprocess, "run"):
763-
return subprocess.run(cmd, universal_newlines=universal_newlines, stdout=subprocess.PIPE, check=True, *args, **kwargs).stdout
764-
else:
765-
# check_output is considered as an old API so prefer subprocess.run if possible
766-
return subprocess.check_output(cmd, universal_newlines=universal_newlines, *args, **kwargs)
755+
def check_output(cmd, *args, **kwargs):
756+
return subprocess.run(cmd, text=True, stdout=subprocess.PIPE, check=True, *args, **kwargs).stdout
767757

768758

769759
# From http://stackoverflow.com/questions/4842448/getting-processor-information-in-python
@@ -862,7 +852,7 @@ def find_gpu_model(model):
862852

863853
try:
864854
driverDate = winreg.QueryValueEx(hVideoCardReg, 'DriverDate')[0]
865-
VideoCardDescription += ' (' + driverDate + ')'
855+
VideoCardDescription += f' ({driverDate})'
866856
except WindowsError:
867857
pass
868858

@@ -1896,9 +1886,9 @@ def run(cmd):
18961886

18971887
def main(args):
18981888
returncode = run(args)
1899-
logv('emrun quitting with process exit code ' + str(returncode))
1889+
logv(f'emrun quitting with process exit code {returncode}')
19001890
if temp_firefox_profile_dir is not None:
1901-
logi('Warning: Had to leave behind a temporary Firefox profile directory ' + temp_firefox_profile_dir + ' because --safe-firefox-profile was set and the browser did not quit before emrun did.')
1891+
logi(f'Warning: Had to leave behind a temporary Firefox profile directory {temp_firefox_profile_dir} because --safe-firefox-profile was set and the browser did not quit before emrun did.')
19021892
return returncode
19031893

19041894

0 commit comments

Comments
 (0)