opts.py: new --ignore-env global cmdline option

This commit is contained in:
The MMGen Project 2026-09-13 15:50:14 +00:00
commit d1db9317fc
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
6 changed files with 27 additions and 15 deletions

View file

@ -261,7 +261,7 @@ class Opts:
cfg._opts = self
cfg._parsed_opts = po
cfg._use_env = True
cfg._use_env = not 'ignore_env' in uopts
cfg._use_cfg_file = not 'skip_cfg_file' in uopts
# Make these available to usage():
@ -300,6 +300,7 @@ class UserOpts(Opts):
rr --daemon-data-dir=path Specify coin daemon data directory location
Rr --daemon-id=ID Specify the coin daemon ID
rr --ignore-daemon-version Ignore coin daemon version check
-- --ignore-env Do not process MMGen environment variables
Rr --list-daemon-ids List all available daemon IDs
xr --http-timeout=t Set HTTP timeout in seconds for JSON-RPC connections
-- --no-license Suppress the GPL license prompt

View file

@ -151,7 +151,10 @@ def compile_code(cfg, code):
def main():
cfg = Config(
opts_data = opts_data)
opts_data = opts_data,
init_opts = {
'skip_cfg_file': True,
'ignore_env': True})
if cfg.check_solc_version:
sys.exit(0 if check_solc_version() else 1)

View file

@ -35,7 +35,8 @@ cfg = Config(
opts_data = opts_data,
need_proto = False,
init_opts = {
'skip_cfg_file': True})
'skip_cfg_file': True,
'ignore_env': True})
from test.overlay import get_overlay_tree_dir
overlay_tree_dir = get_overlay_tree_dir(repo_root)

View file

@ -31,7 +31,7 @@ from .include.common import get_file_with_ext
class CmdTestBase:
'initializer class for the cmdtest.py test suite'
base_passthru_opts = ('data_dir', 'skip_cfg_file')
base_passthru_opts = ('data_dir', 'skip_cfg_file', 'ignore_env')
passthru_opts = ()
networks = ()
segwit_opts_ok = False

View file

@ -107,6 +107,15 @@ class CmdTestInput(CmdTestBase):
)
}
def clean_env_spawn(self, cmd, cmd_args, *args, **kwargs):
return self.spawn(
cmd,
['--skip-cfg-file', '--ignore-env'] + cmd_args,
*args,
no_exec_wrapper = True,
cmd_dir = '.',
**kwargs)
def skip_no_readline_insert(self, extra_msg=None):
return self.skip_on_condition(
gc.platform == 'darwin' or self.cfg.threaded_python,
@ -141,7 +150,7 @@ class CmdTestInput(CmdTestBase):
return 'ok' if b'written to file' in cp.stderr else 'error'
def get_passphrase_ui(self):
t = self.spawn('test/misc/get_passphrase.py', ['--usr-randchars=0', 'seed'], cmd_dir='.')
t = self.clean_env_spawn('test/misc/get_passphrase.py', ['--usr-randchars=0', 'seed'])
# 1 - new wallet, default hp, label;empty pw
t.expect('accept the default.*: ', '\n', regex=True)
@ -212,20 +221,19 @@ class CmdTestInput(CmdTestBase):
def get_passphrase_cmdline(self):
with open(os.path.join(trash_dir, 'pwfile'), 'w') as fp:
fp.write('reference password\n')
t = self.spawn('test/misc/get_passphrase.py', [
t = self.clean_env_spawn('test/misc/get_passphrase.py', [
'--usr-randchars=0',
'--label=MyLabel',
'--passwd-file={}'.format(os.path.join(trash_dir, 'pwfile')),
'--hash-preset=1',
'seed'],
cmd_dir = '.')
'seed'])
for _ in range(4):
t.expect('[reference password][1][MyLabel]')
return t
def get_passphrase_crypto(self):
t = self.spawn('test/misc/get_passphrase.py', ['--usr-randchars=0', 'crypto'], cmd_dir='.')
t = self.clean_env_spawn('test/misc/get_passphrase.py', ['--usr-randchars=0', 'crypto'])
# new passwd
t.expect('passphrase for .*: ', 'x\n', regex=True)
@ -256,11 +264,9 @@ class CmdTestInput(CmdTestBase):
if term and gc.platform == 'win32':
return ('skip_warn', 'pexpect_spawn not supported on Windows platform')
func_args = dict(zip(arg_dfls.keys(), func_args))
t = self.spawn(
'test/misc/input_func.py',
t = self.clean_env_spawn('test/misc/input_func.py',
[func_name, repr(func_args)],
cmd_dir='.',
pexpect_spawn=term)
pexpect_spawn = term)
imsg('Parameters:')
imsg(f' pexpect_spawn: {term}')
imsg(f' sending: {text!r}')
@ -404,7 +410,7 @@ class CmdTestInput(CmdTestBase):
def _password_entry(self, prompt, opts=[], term=False):
if term and gc.platform == 'win32':
return ('skip_warn', 'pexpect_spawn not supported on Windows platform')
t = self.spawn('test/misc/input_func.py', opts + ['passphrase'], cmd_dir='.', pexpect_spawn=term)
t = self.clean_env_spawn('test/misc/input_func.py', opts + ['passphrase'], pexpect_spawn=term)
imsg(f'Terminal: {term}')
pw = 'abc-α'
t.expect(prompt, pw+'\n')

View file

@ -154,4 +154,5 @@ def main():
cfg = Config(
opts_data = opts_data,
init_opts = {
'skip_cfg_file': True})
'skip_cfg_file': True,
'ignore_env': True})