Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,6 @@ jobs:
- checkout
- pip-install
- run: ruff check
# TODO (cclauss): When ruff supports rules these errors without --preview, remove following line
- run: ruff check --preview --select=E20,E30,E221,E225,E226,E275
vulture:
executor: ubuntu-lts
steps:
Expand Down
6 changes: 3 additions & 3 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def make_relative(filename):
reproduce_file.add(utils.path_from_root('emscripten-version.txt'), os.path.join(root, 'version.txt'))

with shared.get_temp_files().get_file(suffix='.tar') as rsp_name:
with open(rsp_name, 'w') as rsp:
with open(rsp_name, 'w', encoding='utf-8') as rsp:
ignore_next = False
output_arg = None

Expand Down Expand Up @@ -371,7 +371,7 @@ def get_next_arg():
add_link_arg(get_next_arg())
elif arg == '-s' or arg.startswith(('-l', '-L', '--js-library=', '-z', '-u')):
add_link_arg(arg)
elif not arg.startswith('-o') and arg not in ('-nostdlib', '-nostartfiles', '-nolibc', '-nodefaultlibs', '-s'):
elif not arg.startswith('-o') and arg not in {'-nostdlib', '-nostartfiles', '-nolibc', '-nodefaultlibs', '-s'}:
# All other flags are for the compiler
compiler_args.append(arg)
if skip:
Expand Down Expand Up @@ -415,7 +415,7 @@ def phase_setup(state):
# If we get here then the user specified both DISABLE_EXCEPTION_CATCHING and EXCEPTION_CATCHING_ALLOWED
# on the command line. This is no longer valid so report either an error or a warning (for
# backwards compat with the old `DISABLE_EXCEPTION_CATCHING=2`
if user_settings['DISABLE_EXCEPTION_CATCHING'] in ('0', '2'):
if user_settings['DISABLE_EXCEPTION_CATCHING'] in {'0', '2'}:
diagnostics.warning('deprecated', 'DISABLE_EXCEPTION_CATCHING=X is no longer needed when specifying EXCEPTION_CATCHING_ALLOWED')
else:
exit_with_error('DISABLE_EXCEPTION_CATCHING and EXCEPTION_CATCHING_ALLOWED are mutually exclusive')
Expand Down
2 changes: 1 addition & 1 deletion emcmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Main run() function
#
def run():
if len(sys.argv) < 2 or sys.argv[1] in ('--version', '--help'):
if len(sys.argv) < 2 or sys.argv[1] in {'--version', '--help'}:
print('''\
emcmake is a helper for cmake, setting various environment
variables so that emcc etc. are used. Typical usage:
Expand Down
2 changes: 1 addition & 1 deletion emconfigure.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# Main run() function
#
def run():
if len(sys.argv) < 2 or sys.argv[1] in ('--version', '--help'):
if len(sys.argv) < 2 or sys.argv[1] in {'--version', '--help'}:
print('''\
emconfigure is a helper for configure, setting various environment
variables so that emcc etc. are used. Typical usage:
Expand Down
2 changes: 1 addition & 1 deletion emmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# Main run() function
#
def run():
if len(sys.argv) < 2 or sys.argv[1] in ('--version', '--help'):
if len(sys.argv) < 2 or sys.argv[1] in {'--version', '--help'}:
print('''\
emmake is a helper for make, setting various environment
variables so that emcc etc. are used. Typical usage:
Expand Down
30 changes: 14 additions & 16 deletions emrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@
from operator import itemgetter
from urllib.parse import unquote, urlsplit

# We depend on python 3.8 features
if sys.version_info < (3, 8): # noqa: UP036
print(f'error: emrun requires python 3.8 or above ({sys.executable} {sys.version})', file=sys.stderr)
sys.exit(1)
assert sys.version_info >= (3, 10), f'emscripten requires python 3.10 or above ({sys.executable} {sys.version})'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this change from 3.8 to 3.10?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should always have been in sync I think but it was just overlooked the last time we bumped.


# Populated from cmdline params
emrun_options = None
Expand Down Expand Up @@ -109,7 +106,7 @@
LINUX = True
elif platform.system() == 'FreeBSD':
FREEBSD = True
elif platform.mac_ver()[0] != '':
elif platform.mac_ver()[0]:
MACOS = True
import plistlib

Expand Down Expand Up @@ -225,7 +222,7 @@ def delete_emrun_safe_firefox_profile():
def create_emrun_safe_firefox_profile():
global temp_firefox_profile_dir
temp_firefox_profile_dir = tempfile.mkdtemp(prefix='temp_emrun_firefox_profile_')
with open(os.path.join(temp_firefox_profile_dir, 'prefs.js'), 'w') as f:
with open(os.path.join(temp_firefox_profile_dir, 'prefs.js'), 'w', encoding='utf-8') as f:
f.write('''
// Old Firefox browsers have a maxPerDomain limit of 20. Newer Firefox browsers default to 512. Match the new
// default here to help test spawning a lot of threads also on older Firefox versions.
Expand Down Expand Up @@ -780,7 +777,7 @@ def get_cpu_info():
logical_cores = int(check_output(['sysctl', '-n', 'machdep.cpu.thread_count']).strip())
frequency = int(check_output(['sysctl', '-n', 'hw.cpufrequency']).strip()) // 1000000
elif LINUX:
for line in open('/proc/cpuinfo').readlines():
for line in open('/proc/cpuinfo', encoding='utf-8').readlines():
if 'model name' in line:
cpu_name = re.sub('.*model name.*:', '', line, count=1).strip()
lscpu = check_output(['lscpu'])
Expand Down Expand Up @@ -1031,7 +1028,7 @@ def win_get_file_properties(fname):
strInfo = {}
for propName in propNames:
strInfoPath = u'\\StringFileInfo\\%04X%04X\\%s' % (lang, codepage, propName)
## print str_info
# print str_info
strInfo[propName] = win32api.GetFileVersionInfo(fname, strInfoPath)

props['StringFileInfo'] = strInfo
Expand All @@ -1043,7 +1040,7 @@ def get_computer_model():
try:
if MACOS:
try:
with open(os.path.join(os.getenv("HOME"), '.emrun.hwmodel.cached'), 'r') as f:
with open(os.path.join(os.getenv("HOME"), '.emrun.hwmodel.cached'), encoding='utf-8') as f:
model = f.read()
return model
except IOError:
Expand All @@ -1059,7 +1056,7 @@ def get_computer_model():
model = check_output(cmd)
model = re.search('<configCode>(.*)</configCode>', model)
model = model.group(1).strip()
with open(os.path.join(os.getenv("HOME"), '.emrun.hwmodel.cached'), 'w') as fh:
with open(os.path.join(os.getenv("HOME"), '.emrun.hwmodel.cached'), 'w', encoding='utf-8') as fh:
fh.write(model) # Cache the hardware model to disk
return model
except Exception:
Expand Down Expand Up @@ -1089,7 +1086,7 @@ def get_computer_model():


def get_os_version():
bitness = ' (64bit)' if platform.machine() in ['AMD64', 'x86_64'] else ' (32bit)'
bitness = ' (64bit)' if platform.machine() in {'AMD64', 'x86_64'} else ' (32bit)'
try:
if WINDOWS:
versionHandle = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion")
Expand All @@ -1116,7 +1113,7 @@ def get_system_memory():
if emrun_options.android:
lines = check_output([ADB, 'shell', 'cat', '/proc/meminfo']).split('\n')
else:
mem = open('/proc/meminfo', 'r')
mem = open('/proc/meminfo', encoding='utf-8')
lines = mem.readlines()
mem.close()
for i in lines:
Expand Down Expand Up @@ -1383,13 +1380,14 @@ def get_system_info(format_json):
return info.strip()
else:
try:
with open(os.path.expanduser('~/.emrun.generated.guid')) as fh:
with open(os.path.expanduser('~/.emrun.generated.guid'), encoding='utf-8') as fh:
unique_system_id = fh.read().strip()
except Exception:
import uuid
unique_system_id = str(uuid.uuid4())
try:
open(os.path.expanduser('~/.emrun.generated.guid'), 'w').write(unique_system_id)
with open(os.path.expanduser('~/.emrun.generated.guid'), 'w', encoding='utf-8') as f:
f.write(unique_system_id)
except Exception as e:
logv(e)

Expand Down Expand Up @@ -1822,13 +1820,13 @@ def run(cmd):

if options.log_stdout:
global browser_stdout_handle
browser_stdout_handle = open(options.log_stdout, 'a')
browser_stdout_handle = open(options.log_stdout, 'a', encoding='utf-8')
if options.log_stderr:
global browser_stderr_handle
if options.log_stderr == options.log_stdout:
browser_stderr_handle = browser_stdout_handle
else:
browser_stderr_handle = open(options.log_stderr, 'a')
browser_stderr_handle = open(options.log_stderr, 'a', encoding='utf-8')
if options.run_browser:
logv("Starting browser: %s" % ' '.join(browser))
# if browser[0] == 'cmd':
Expand Down
13 changes: 13 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
requires-python = ">=3.10"

[tool.ruff]
preview = true
line-length = 100
indent-width = 2
exclude = [
"./cache/",
"./node_modules/",
Expand Down Expand Up @@ -38,15 +40,26 @@ lint.ignore = [
"B011", # See https://github.com/PyCQA/flake8-bugbear/issues/66
"B023",
"B026",
"E272",
"E402",
"E241",
"E266",
"E501",
"E721",
"E741",
"E111", # Does not seem to honor `indent-width = 2` above
"E114", # Does not seem to honor `indent-width = 2` above
"E261",
"PERF203",
"PERF401",
"PLC0415",
"PLR0904",
"PLR0916",
"PLR0914",
"PLR1702",
"PLR1704",
"PLR5501",
"PLR6301",
"PLW0602",
"PLW0603",
"PLW1510",
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
coverage[toml]==6.5
mypy==1.14
psutil==7.0.0
ruff==0.14.1
ruff==0.15.7
types-requests==2.32.0.20241016
unittest-xml-reporting==3.2.0
deadcode==2.3.1
Expand Down
4 changes: 2 additions & 2 deletions site/source/get_api_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def addapiitems(matchobj):
filepath = api_reference_directory + file
print(file)
# open file
with open(filepath) as infile:
with open(filepath, encoding='utf-8') as infile:
for line in infile:
# parse line for API items
re.sub(r'^\.\.\s+((\w+)\:(\w+)\:\:(.*))', addapiitems, line)
Expand All @@ -74,7 +74,7 @@ def addapiitems(matchobj):
def exportItems():
"""Export the API items into form for use in another script.
"""
with open(api_item_filename, 'w') as infile:
with open(api_item_filename, 'w', encoding='utf-8') as infile:
# write function lead in
infile.write("# Auto-generated file (see get_api_items.py)\n\ndef get_mapped_items():\n mapped_wiki_inline_code = dict()\n")

Expand Down
14 changes: 7 additions & 7 deletions site/source/get_wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

wiki_checkout = 'emscripten.wiki/'
temp_set_of_codemarkup = set()
logfile = open(logfilename, 'w')
logfile = open(logfilename, 'w', encoding='utf-8')
# snapshot_version_information = '.. note:: This is a **snapshot** of the wiki: %s\n\n' % strftime("%a, %d %b %Y %H:%M", gmtime())
snapshot_version_information = '.. note:: This article was migrated from the wiki (%s) and is now the "master copy" (the version in the wiki will be deleted). It may not be a perfect rendering of the original but we hope to fix that soon!\n\n' % time.strftime("%a, %d %b %Y %H:%M", time.gmtime())

Expand Down Expand Up @@ -91,7 +91,7 @@ def ConvertFilesToRst():
continue

inputfilename = wiki_checkout + file
markdown = Path(inputfilename).read_text()
markdown = Path(inputfilename).read_text(encoding='utf-8')
if 'This article has moved from the wiki to the new site' in markdown:
continue
if 'This page has been migrated to the main site' in markdown:
Expand Down Expand Up @@ -127,16 +127,16 @@ def ConvertFilesToRst():

textinfile += snapshot_version_information

with open(outputfilename) as infile:
with open(outputfilename, encoding='utf-8') as infile:
for line in infile:
textinfile += line

# print textinfile
with open(outputfilename, 'w') as outfile:
with open(outputfilename, 'w', encoding='utf-8') as outfile:
outfile.write(textinfile)

# write the index
with open(output_dir + 'index.rst', 'w') as outfile:
with open(output_dir + 'index.rst', 'w', encoding='utf-8') as outfile:
outfile.write(indexfiletext)


Expand Down Expand Up @@ -184,7 +184,7 @@ def fixcodemarkuplinks(matchobj):
input_file = output_dir + file
# print input_file
textinfile = ''
with open(input_file) as infile:
with open(input_file, encoding='utf-8') as infile:
for line in infile:
textinfile += line

Expand All @@ -195,7 +195,7 @@ def fixcodemarkuplinks(matchobj):
# convert codemarkup to links if possible
textinfile = fixWikiCodeMarkupToCodeLinks(textinfile)

with open(input_file, 'w') as outfile:
with open(input_file, 'w', encoding='utf-8') as outfile:
outfile.write(textinfile)

logfile.write('\n\nCODE MARKUP THAT WONT BE LINKED (add entry to mapped_wiki_inline_code if one of these need to be linked. The tool get-api-items.py can be used to generate the list of the documented API items. \n')
Expand Down
6 changes: 3 additions & 3 deletions test/benchmark/benchmark_sse.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from tools.config import V8_ENGINE
from tools.shared import CLANG_CXX, EMCC
from tools.utils import WINDOWS, run_process
from tools.utils import WINDOWS, run_process, write_file

# System info
system_info = subprocess.check_output([EMRUN, '--system_info'], stderr=subprocess.STDOUT, text=True)
Expand Down Expand Up @@ -279,13 +279,13 @@ def format_comparison(a, b):

html += '</body></html>'

open(results_file, 'w').write(html)
write_file(results_file, html)
print('Wrote ' + str(len(html)) + ' bytes to file ' + results_file + '.')


if __name__ == '__main__':
suite = sys.argv[1].lower() if len(sys.argv) == 2 else None
if suite in ['sse', 'sse1']:
if suite in {'sse', 'sse1'}:
run_benchmark(test_file('benchmark/benchmark_sse1.cpp'), 'results_sse1.html', ['-msse'])
elif suite == 'sse2':
run_benchmark(test_file('benchmark/benchmark_sse2.cpp'), 'results_sse2.html', ['-msse2'])
Expand Down
17 changes: 8 additions & 9 deletions test/browser_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ def send_head(self):
ctype = self.guess_type(path)
self.send_header('Content-Type', ctype)
pieces = self.headers.get('Range').split('=')[1].split('-')
start = int(pieces[0]) if pieces[0] != '' else 0
end = int(pieces[1]) if pieces[1] != '' else fsize - 1
start = int(pieces[0]) if pieces[0] else 0
end = int(pieces[1]) if pieces[1] else fsize - 1
end = min(fsize - 1, end)
length = end - start + 1
self.send_header('Content-Range', f'bytes {start}-{end}/{fsize}')
Expand Down Expand Up @@ -404,7 +404,7 @@ def do_POST(self): # noqa: DC04
elif urlinfo.path.startswith('/status/'):
code_str = urlinfo.path[len('/status/'):]
code = int(code_str)
if code in (301, 302, 303, 307, 308):
if code in {301, 302, 303, 307, 308}:
self.send_response(code)
self.send_header('Location', '/status/200')
self.end_headers()
Expand All @@ -430,7 +430,7 @@ def do_GET(self):
elif info.path.startswith('/status/'):
code_str = info.path[len('/status/'):]
code = int(code_str)
if code in (301, 302, 303, 307, 308):
if code in {301, 302, 303, 307, 308}:
# Redirect to /status/200
self.send_response(code)
self.send_header('Location', '/status/200')
Expand Down Expand Up @@ -496,8 +496,8 @@ def do_GET(self):
ctype = self.guess_type(path)
self.send_header('Content-type', ctype)
pieces = self.headers.get('Range').split('=')[1].split('-')
start = int(pieces[0]) if pieces[0] != '' else 0
end = int(pieces[1]) if pieces[1] != '' else len(data) - 1
start = int(pieces[0]) if pieces[0] else 0
end = int(pieces[1]) if pieces[1] else len(data) - 1
end = min(len(data) - 1, end)
length = end - start + 1
self.send_header('Content-Length', str(length))
Expand Down Expand Up @@ -605,15 +605,14 @@ def __enter__(self):
time.sleep(0.1)
# Return the locking count number
try:
self.counter = int(open(f'{self.path}_counter').read())
self.counter = int(utils.read_file(f'{self.path}_counter'))
except Exception:
pass
return self.counter

def __exit__(self, *a):
# Increment locking count number before releasing the lock
with open(f'{self.path}_counter', 'w') as f:
f.write(str(self.counter + 1))
utils.write_file(f'{self.path}_counter', str(self.counter + 1))
# And release the lock
os.close(self.fd)
try:
Expand Down
Loading
Loading