ruff: various

This commit is contained in:
The MMGen Project 2026-10-24 15:56:46 +00:00
commit 5a765caed0
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
8 changed files with 20 additions and 21 deletions

View file

@ -170,11 +170,10 @@ class BlocksInfo:
(rf'\+{cspat}\-{cspat}$', lambda g: (dfl_set_lc | g[0]) - g[1]),
(rf'\-{cspat}\+{cspat}$', lambda g: (dfl_set_lc - g[0]) | g[1]),
(rf'all\-{cspat}$', lambda g: full_set_lc - g[0])):
m = re.match(pat, uarg, re.ASCII|re.IGNORECASE)
if m:
if m := re.match(pat, uarg, re.ASCII|re.IGNORECASE):
return make_list(m, func)
else:
die(1, f'{uarg}: invalid parameter')
die(1, f'{uarg}: invalid parameter')
def __init__(self, cfg, cmd_args, rpc):
@ -490,7 +489,7 @@ class BlocksInfo:
case _:
assert False, f'{d}: invalid stats data'
foo, data = await res
_, data = await res
indent = '' if sname in self.noindent_stats else ' '
Msg('\n'.join(gen(data)))

View file

@ -32,7 +32,7 @@ def timespec2secs(ts):
pat = r'^([0-9]+)([smhd]*)$'
m = re.match(pat, ts)
if m is None:
die(2,"'%s': invalid time specifier" % ts)
die(2, f"'{ts}': invalid time specifier")
a, b = m.groups()
return int(a) * (mul[b] if b else 1)
@ -53,17 +53,17 @@ def play_sound(fn, vol, repeat_spec='', remote_host='', kill_flg=None, testing=F
if not remote_host:
do_system('sudo alsactl store -f ' + _alsa_config_file)
for k in 'Master', 'Speaker', 'Headphone':
do_system(('sudo amixer -q set %s on' % k), testing)
do_system(f'sudo amixer -q set {k} on', testing)
# do_system('amixer -q set Headphone off')
vols = dict([(k, int(_dvols[k] * float(vol) / 100)) for k in _dvols])
vols = {k: int(_dvols[k] * float(vol) / 100) for k in _dvols}
for k, v in vols.items():
do_system(f'sudo amixer -q set {k} {v}', testing)
fn = os.path.expanduser(fn)
cmd = (
'aplay -q %s' % fn,
'ssh %s mmnode-play-sound -v%d %s' % (remote_host, vol, fn)
f'aplay -q {fn}',
f'ssh {remote_host} mmnode-play-sound -v{vol} {fn}'
)[bool(remote_host)]
if repeat_spec and kill_flg:

View file

@ -490,7 +490,7 @@ def gen_data(data):
wants = {k: rows_want[k] | usr_wants[k] for k in ('id', 'symbol')}
btcusd = Decimal('1') # dummy
btcusd = Decimal(1) # dummy
hist_close = {}
parse_fail = False
@ -940,7 +940,7 @@ class Ticker:
sort_dfl = sort_params[code].sort_dfl
sort_func = lambda row: data.get(row.id, {key: sort_dfl})[key]
pf_sort_func = lambda row: data.get(row, {key: sort_dfl})[key]
for group in self.rows.keys():
for group in self.rows.keys(): # noqa SIM118
if group not in self.hidden_groups:
self.rows[group] = sorted(self.rows[group], key=sort_func, reverse=reverse)
if cfg.portfolio:

View file

@ -135,7 +135,7 @@ async def main(req_addrs):
if 'desc' in res['unspents'][0]:
import re
for unspent in sorted(res['unspents'], key=lambda x: x['height']):
addr = re.match('addr\((.*?)\)', unspent['desc'])[1]
addr = re.match(r'addr\((.*?)\)', unspent['desc'])[1]
addr_data[addr].append(unspent)
else:
from mmgen.proto.btc.tx.base import decodeScriptPubKey

View file

@ -18,7 +18,7 @@
mmnode-netrate: Bitcoin daemon network rate monitor
"""
import sys, time
import sys, asyncio
from mmgen.cfg import Config
from mmgen.util import async_run
@ -56,7 +56,7 @@ async def main():
(r-rs)/(t-ts),
(s-ss)/(t-ts)))
time.sleep(2)
await asyncio.sleep(2)
if rs is not None:
sys.stderr.write('{}{}{}'.format(ERASE_LINE, CUR_UP, ERASE_LINE))

View file

@ -115,7 +115,7 @@ class CmdTestScripts(CmdTestBase):
self.dests = {
'nt_datadir': os.path.join(cfg.data_dir_root, 'node_tools'),
'cache': self.tmpdir}
return super().__init__(cfg, trunner, cfgs, spawn)
super().__init__(cfg, trunner, cfgs, spawn)
def rm_file(self, fn, dest='nt_datadir'):
os.unlink(os.path.join(self.dests[dest], fn))
@ -485,7 +485,7 @@ class CmdTestScripts(CmdTestBase):
t = self.ticker(
[],
[
'BITCOIN 23,250.77 1.00000000 \+0.00',
r'BITCOIN 23,250.77 1.00000000 \+0.00',
'US DOLLAR 1.00 0.00004301 -15.93',
],
add_opts = ['--widest', '--pchg-unit=btc', f'--sort={sort}'])

View file

@ -12,10 +12,10 @@
test.cmdtest_d.regtest: Regtest tests for the cmdtest.py test suite
"""
import sys, os
import sys
from decimal import Decimal
from mmgen.util import msg_r, die, gmsg
from mmgen.util import msg_r, die
from mmgen.protocol import init_proto
from mmgen.proto.btc.regtest import MMGenRegtest

View file

@ -7,14 +7,14 @@ test.unit_tests_d.ut_dep: dependency unit tests for the MMGen Node Tools
No data verification is performed.
"""
from ..include.common import vmsg,imsg
from ..include.common import imsg
from mmgen.color import yellow
class unit_tests:
def yahooquery(self,name,ut):
try:
from yahooquery import Ticker
from yahooquery import Ticker # noqa F401
return True
except ImportError:
imsg(yellow('Unable to import Ticker from yahooquery'))