Add more ruff checks (#1709)
This caught as few bugs form the f-string conversion.
diff --git a/bazel/emscripten_toolchain/link_wrapper.py b/bazel/emscripten_toolchain/link_wrapper.py
index 75cd3fa..470ea27 100644
--- a/bazel/emscripten_toolchain/link_wrapper.py
+++ b/bazel/emscripten_toolchain/link_wrapper.py
@@ -38,7 +38,7 @@
sys.argv[1] = '@' + new_param_filename
emcc_py = os.path.join(os.environ['EMSCRIPTEN'], 'emcc.py')
-rtn = subprocess.call([sys.executable, emcc_py] + sys.argv[1:])
+rtn = subprocess.call([sys.executable, emcc_py, *sys.argv[1:]])
if rtn != 0:
sys.exit(1)
@@ -157,7 +157,7 @@
sys.exit(1)
# cc_binary must output exactly one file; put all the output files in a tarball.
-cmd = ['tar', 'cf', base_name + '.tar'] + files
+cmd = ['tar', 'cf', base_name + '.tar', *files]
subprocess.check_call(cmd, cwd=outdir)
os.replace(os.path.join(outdir, base_name + '.tar'), output_file)
diff --git a/emsdk.py b/emsdk.py
index 4e05b7d..06f9864 100644
--- a/emsdk.py
+++ b/emsdk.py
@@ -745,7 +745,7 @@
gits = ['git/1.9.4/bin/git.exe', shutil.which('git')]
for git in gits:
try:
- ret, stdout, stderr = run_get_output([git, '--version'])
+ ret, _stdout, _stderr = run_get_output([git, '--version'])
if ret == 0:
cached_git_executable = git
return git
@@ -766,7 +766,7 @@
def git_repo_version(repo_path):
- returncode, stdout, stderr = run_get_output([GIT(), 'log', '-n', '1', '--pretty="%aD %H"'], cwd=repo_path)
+ returncode, stdout, _stderr = run_get_output([GIT(), 'log', '-n', '1', '--pretty="%aD %H"'], cwd=repo_path)
if returncode == 0:
return stdout.strip()
else:
@@ -774,7 +774,7 @@
def git_recent_commits(repo_path, n=20):
- returncode, stdout, stderr = run_get_output([GIT(), 'log', '-n', str(n), '--pretty="%H"'], cwd=repo_path)
+ returncode, stdout, _stderr = run_get_output([GIT(), 'log', '-n', str(n), '--pretty="%H"'], cwd=repo_path)
if returncode == 0:
return stdout.strip().replace('\r', '').replace('"', '').split('\n')
else:
@@ -805,7 +805,7 @@
if GIT_CLONE_SHALLOW:
git_clone_args += ['--depth', '1']
print(f'Cloning from {url}...')
- return run([GIT(), 'clone', '-o', remote_name] + git_clone_args + [url, dstpath]) == 0
+ return run([GIT(), 'clone', '-o', remote_name, *git_clone_args, url, dstpath]) == 0
def git_pull(repo_path, branch_or_tag, remote_name='origin'):
@@ -986,7 +986,7 @@
print('Running build: ' + str(make))
ret = subprocess.check_call(make, cwd=build_root, env=build_env())
if ret != 0:
- errlog('Build failed with exit code {ret}!')
+ errlog(f'Build failed with exit code {ret}!')
errlog('Working directory: ' + build_root)
return False
except Exception as e:
@@ -1011,9 +1011,9 @@
# Target macOS 11.0 Big Sur at minimum, to support older Mac devices.
# See https://en.wikipedia.org/wiki/MacOS#Hardware_compatibility for min-spec details.
cmdline += ['-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0']
- cmdline += extra_cmake_args + [src_root]
+ cmdline += [*extra_cmake_args, src_root]
- print('Running CMake: ' + str(cmdline))
+ print(f'Running CMake: {cmdline}')
# Specify the deployment target also as an env. var, since some Xcode versions
# read this instead of the CMake field.
@@ -1030,8 +1030,8 @@
open(os.path.join(build_root, 'recmake.' + ('bat' if WINDOWS else 'sh')), 'w').write(' '.join(map(quote_parens, cmdline)))
ret = subprocess.check_call(cmdline, cwd=build_root, env=build_env())
if ret != 0:
- errlog('CMake invocation failed with exit code {ret}!')
- errlog('Working directory: ' + build_root)
+ errlog(f'CMake invocation failed with exit code {ret}')
+ errlog(f'Working directory: {build_root}')
return False
except OSError as e:
if e.errno == errno.ENOENT:
@@ -1046,8 +1046,8 @@
return False
raise
except Exception as e:
- errlog('CMake invocation failed due to exception!')
- errlog('Working directory: ' + build_root)
+ errlog('CMake invocation failed due to exception')
+ errlog(f'Working directory: {build_root}')
errlog(str(e))
return False
@@ -1528,7 +1528,7 @@
def download_and_extract(archive, dest_dir, filename_prefix='', clobber=True):
- debug_print('download_and_extract(archive={archive}, dest_dir={dest_dir})')
+ debug_print(f'download_and_extract(archive={archive}, dest_dir={dest_dir})')
url = urljoin(emsdk_packages_url, archive)
@@ -2902,7 +2902,7 @@
return name
-def main(args): # noqa: C901, PLR0911, PLR0912, PLR0915
+def main(args): # noqa: C901, PLR0911, PLR0912
if not args:
errlog("Missing command; Type 'emsdk help' to get a list of commands.")
return 1
@@ -3087,7 +3087,7 @@
tool_name, url_and_refspec = forked_url.split('@')
t = find_tool(tool_name)
if not t:
- errlog('Failed to find tool {tool_name}!')
+ errlog(f'Failed to find tool {tool_name}')
return False
else:
t.url, t.git_branch, t.remote_name = parse_github_url_and_refspec(url_and_refspec)
diff --git a/pyproject.toml b/pyproject.toml
index 383d526..94cfdcb 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,4 +1,5 @@
[project]
+name = 'emsdk'
requires-python = ">=3.2"
[tool.ruff]
@@ -24,6 +25,7 @@
"PL",
"UP",
"W",
+ "RUF",
"YTT",
]
lint.external = [ "D" ]
@@ -53,6 +55,7 @@
"PLW1510",
"PLW1514",
"PLW2901",
+ "RUF039", # https://docs.astral.sh/ruff/rules/unraw-re-pattern/
"UP030", # TODO
"UP031", # TODO
"UP032", # TODO
diff --git a/scripts/create_release.py b/scripts/create_release.py
index 425f7d7..64eccaf 100755
--- a/scripts/create_release.py
+++ b/scripts/create_release.py
@@ -12,7 +12,7 @@
root_dir = os.path.dirname(script_dir)
sys.path.append(root_dir)
-import emsdk # noqa
+import emsdk
def version_key(version_string):
diff --git a/scripts/update_node.py b/scripts/update_node.py
index 257bb74..d3babd1 100755
--- a/scripts/update_node.py
+++ b/scripts/update_node.py
@@ -44,13 +44,13 @@
urllib.request.urlretrieve(download_url, filename)
if '-win-' in suffix:
- subprocess.check_call(unzip_cmd() + [filename])
+ subprocess.check_call([*unzip_cmd(), filename])
dirname = os.path.splitext(os.path.basename(filename))[0]
shutil.move(dirname, 'bin')
os.mkdir(dirname)
shutil.move('bin', dirname)
os.remove(filename)
- subprocess.check_call(zip_cmd() + [filename, dirname])
+ subprocess.check_call([*zip_cmd(), filename, dirname])
shutil.rmtree(dirname)
if '--upload' in sys.argv:
diff --git a/scripts/update_python.py b/scripts/update_python.py
index a9d9d60..7aa6cfe 100755
--- a/scripts/update_python.py
+++ b/scripts/update_python.py
@@ -68,7 +68,7 @@
urllib.request.urlretrieve(download_url, filename)
os.mkdir('python-nuget')
- check_call(unzip_cmd() + [os.path.abspath(filename)], cwd='python-nuget')
+ check_call([*unzip_cmd(), os.path.abspath(filename)], cwd='python-nuget')
os.remove(filename)
src_dir = os.path.join('python-nuget', 'tools')
@@ -77,7 +77,7 @@
check_call([python_exe, '-m', 'pip', 'install', 'pywin32==310', '--no-warn-script-location'])
check_call([python_exe, '-m', 'pip', 'install', PSUTIL])
- check_call(zip_cmd() + [os.path.join('..', '..', out_filename), '.'], cwd=src_dir)
+ check_call([*zip_cmd(), os.path.join('..', '..', out_filename), '.'], cwd=src_dir)
print('Created: %s' % out_filename)
# cleanup if everything went fine
@@ -137,7 +137,7 @@
configure_args = ['CFLAGS=' + build_flags, 'CXXFLAGS=' + build_flags, 'LDFLAGS=' + min_macos_version_line]
else:
configure_args = []
- check_call(['./configure'] + configure_args, cwd=src_dir, env=env)
+ check_call(['./configure', *configure_args], cwd=src_dir, env=env)
check_call(['make', '-j', str(multiprocessing.cpu_count())], cwd=src_dir, env=env)
check_call(['make', 'install', 'DESTDIR=install'], cwd=src_dir, env=env)
diff --git a/test/test.py b/test/test.py
index 330fde1..f8b96d5 100755
--- a/test/test.py
+++ b/test/test.py
@@ -133,7 +133,7 @@
def run_emsdk(cmd):
if type(cmd) is not list:
cmd = cmd.split()
- check_call([emsdk] + cmd)
+ check_call([emsdk, *cmd])
class Emsdk(unittest.TestCase):