From 7991889a97695b6e7632af7214c57c558c55922e Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Fri, 7 Aug 2026 09:37:48 +0000 Subject: [PATCH] ruff UP022 (prefer `capture_output` over `stdout=PIPE, stderr=PIPE`) --- mmgen/daemon.py | 2 +- pyproject.toml | 1 - test/cmdtest_d/ethdev.py | 4 ++-- test/cmdtest_d/include/proxy.py | 4 ++-- test/cmdtest_d/input.py | 4 ++-- test/include/common.py | 2 +- test/modtest_d/dep.py | 6 +++--- test/scrambletest.py | 4 ++-- test/tooltest.py | 2 +- test/tooltest2.py | 2 +- 10 files changed, 15 insertions(+), 16 deletions(-) diff --git a/mmgen/daemon.py b/mmgen/daemon.py index d5566939..2a1a63eb 100755 --- a/mmgen/daemon.py +++ b/mmgen/daemon.py @@ -247,7 +247,7 @@ class Daemon(Lockable): @classmethod def get_exec_version_str(cls): try: - cp = run([cls.exec_fn, cls.version_info_arg], stdout=PIPE, stderr=PIPE, check=True, text=True) + cp = run([cls.exec_fn, cls.version_info_arg], capture_output=True, check=True, text=True) except Exception as e: die(2, f'{e}\nUnable to execute {cls.exec_fn}') diff --git a/pyproject.toml b/pyproject.toml index f7feefa9..2f09550a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,7 +36,6 @@ ignore = [ "SIM102", # Use a single `if` statement instead of nested `if` statements "SIM114", # Combine `if` branches using logical `or` operator "SIM905", # Consider using a list literal instead of `str.split` - "UP022", # Prefer `capture_output` over sending `stdout` and `stderr` to `PIPE` "UP030", # Use implicit references for positional format fields "UP031", # Use format specifiers instead of percent format "UP032", # Use f-string instead of `format` call diff --git a/test/cmdtest_d/ethdev.py b/test/cmdtest_d/ethdev.py index d1459453..1bc599bb 100755 --- a/test/cmdtest_d/ethdev.py +++ b/test/cmdtest_d/ethdev.py @@ -837,7 +837,7 @@ class CmdTestEthdev(CmdTestEthdevMethods, CmdTestBase, CmdTestShared): write_to_file(pwfile, '') run(['rm', '-rf', self.keystore_dir]) cmd = f'geth account new --password={pwfile} --lightkdf --keystore {self.keystore_dir}' - if (cp := run(cmd.split(), stdout=PIPE, stderr=PIPE, text=True)).returncode: + if (cp := run(cmd.split(), capture_output=True, text=True)).returncode: die(1, cp.stderr) def make_genesis(signer_addr, prealloc_addr): @@ -882,7 +882,7 @@ class CmdTestEthdev(CmdTestEthdevMethods, CmdTestBase, CmdTestShared): def init_genesis(fn): cmd = f'{d.exec_fn} init --datadir {d.datadir} {fn}' - if (cp := run(cmd.split(), stdout=PIPE, stderr=PIPE, text=True)).returncode: + if (cp := run(cmd.split(), capture_output=True, text=True)).returncode: die(1, cp.stderr) d.stop(quiet=True) diff --git a/test/cmdtest_d/include/proxy.py b/test/cmdtest_d/include/proxy.py index 318c3d6e..d3cf10e4 100755 --- a/test/cmdtest_d/include/proxy.py +++ b/test/cmdtest_d/include/proxy.py @@ -13,7 +13,7 @@ test.cmdtest_d.include.proxy: SSH SOCKS proxy runner for the cmdtest.py test sui """ import atexit -from subprocess import run, PIPE +from subprocess import run from mmgen.cfg import gc from mmgen.util import msg, die, fmt @@ -77,7 +77,7 @@ class TestProxy: if port_in_use(self.port): omsg(f'Port {self.port} already in use. Assuming SSH SOCKS server is running') else: - cp = run(a + b0 + b1, stdout=PIPE, stderr=PIPE, text=True) + cp = run(a + b0 + b1, capture_output=True, text=True) if cp.stderr: omsg(cp.stderr) if cp.returncode == 0: diff --git a/test/cmdtest_d/input.py b/test/cmdtest_d/input.py index e48a1be0..53646276 100755 --- a/test/cmdtest_d/input.py +++ b/test/cmdtest_d/input.py @@ -117,13 +117,13 @@ class CmdTestInput(CmdTestBase): def get_seed_from_stdin(self): self.spawn(msg_only=True) - from subprocess import run, PIPE + from subprocess import run cmd = ['python3', 'cmds/mmgen-walletconv', '--skip-cfg-file', '--in-fmt=words', '--out-fmt=words', '--outdir=test/trash'] mn = sample_mn['mmgen']['mn'] run_env = dict(os.environ) run_env['MMGEN_TEST_SUITE'] = '' - cp = run(cmd, input=mn.encode(), stdout=PIPE, stderr=PIPE, env=run_env) + cp = run(cmd, input=mn.encode(), capture_output=True, env=run_env) from mmgen.color import set_vt100 set_vt100() diff --git a/test/include/common.py b/test/include/common.py index 29ddc30d..347f5795 100755 --- a/test/include/common.py +++ b/test/include/common.py @@ -475,7 +475,7 @@ class VirtBlockDeviceMacOS(VirtBlockDeviceBase): self.size = size def _get_associations(self): - cp = run(['hdiutil', 'info'], stdout=PIPE, stderr=PIPE, text=True, check=False) + cp = run(['hdiutil', 'info'], capture_output=True, text=True, check=False) if cp.returncode == 0: lines = cp.stdout.splitlines() out = [re.sub('.* ', '', s.strip()) for s in lines if re.match(r'image-path|/dev/', s)] diff --git a/test/modtest_d/dep.py b/test/modtest_d/dep.py index b52c2c53..473490a8 100755 --- a/test/modtest_d/dep.py +++ b/test/modtest_d/dep.py @@ -9,7 +9,7 @@ test.modtest_d.dep: dependency unit tests for the MMGen suite import sys -from subprocess import run, PIPE +from subprocess import run from mmgen.util import msg, rmsg, ymsg, gmsg from mmgen.exception import NoLEDSupport @@ -29,7 +29,7 @@ class unit_tests: except ModuleNotFoundError as e: ymsg(f'{type(e).__name__}: {e}') msg('Installing secp256k1 module locally...') - run(['python3', './setup.py', 'build_ext', '--inplace'], stdout=PIPE, stderr=PIPE, check=True) + run(['python3', './setup.py', 'build_ext', '--inplace'], capture_output=True, check=True) ymsg('The module has been installed. Try re-running the test') sys.exit(1) return False @@ -148,7 +148,7 @@ class unit_tests: '--stdout', init_proto(cfg, 'eth').checksummed_addr('deadbeef'*5), ] - cp = run(cmd, stdout=PIPE, stderr=PIPE, text=True) + cp = run(cmd, capture_output=True, text=True) vmsg(cp.stderr) if cp.returncode: msg(cp.stderr) diff --git a/test/scrambletest.py b/test/scrambletest.py index 0fac93ec..44e0f706 100755 --- a/test/scrambletest.py +++ b/test/scrambletest.py @@ -22,7 +22,7 @@ test/scrambletest.py: seed scrambling and addrlist data generation tests for all """ import os, time -from subprocess import run, PIPE +from subprocess import run from collections import namedtuple try: @@ -107,7 +107,7 @@ def make_cmd(progname, opts, add_opts, args): return ['python3'] + cvrg_opts + [f'cmds/{progname}', '-qS'] + opts + add_opts + [words_file] + args + ['1'] def run_cmd(cmd): - cp = run(cmd, stdout=PIPE, stderr=PIPE, text=True, env=run_env) + cp = run(cmd, capture_output=True, text=True, env=run_env) if cp.returncode != 0: die(2, f'\nSpawned program exited with error code {cp.returncode}:\n{cp.stderr}') return cp.stdout.splitlines() diff --git a/test/tooltest.py b/test/tooltest.py index 4034003d..0a4cbbb3 100755 --- a/test/tooltest.py +++ b/test/tooltest.py @@ -266,7 +266,7 @@ class MMGenToolTestUtils: else: msg_r('Testing {:{w}}'.format(full_name+':', w=msg_w)) - cp = run(sys_cmd, stdout=PIPE, stderr=PIPE) + cp = run(sys_cmd, capture_output=True) out = cp.stdout err = cp.stderr if cfg.debug: diff --git a/test/tooltest2.py b/test/tooltest2.py index 26c93fbc..e8ec747e 100755 --- a/test/tooltest2.py +++ b/test/tooltest2.py @@ -89,7 +89,7 @@ def fork_cmd(cmd_name, args, opts, stdin_input): vmsg('{} {}'.format( green('Executing'), cyan(' '.join(cmd)))) - cp = run(cmd, input=stdin_input or None, stdout=PIPE, stderr=PIPE) + cp = run(cmd, input=stdin_input or None, capture_output=True) try: cmd_out = cp.stdout.decode() except: