From d1db9317fc3708a2bdca43df11baaee67578068d Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sun, 13 Sep 2026 15:50:14 +0000 Subject: [PATCH] opts.py: new `--ignore-env` global cmdline option --- mmgen/opts.py | 3 ++- scripts/create-token.py | 5 ++++- test/clean.py | 3 ++- test/cmdtest_d/base.py | 2 +- test/cmdtest_d/input.py | 26 ++++++++++++++++---------- test/include/coin_daemon_control.py | 3 ++- 6 files changed, 27 insertions(+), 15 deletions(-) diff --git a/mmgen/opts.py b/mmgen/opts.py index 7ca62a91..2e60c9d9 100755 --- a/mmgen/opts.py +++ b/mmgen/opts.py @@ -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 diff --git a/scripts/create-token.py b/scripts/create-token.py index aa9fd725..d662d6c7 100755 --- a/scripts/create-token.py +++ b/scripts/create-token.py @@ -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) diff --git a/test/clean.py b/test/clean.py index 451729ce..4b6392dc 100755 --- a/test/clean.py +++ b/test/clean.py @@ -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) diff --git a/test/cmdtest_d/base.py b/test/cmdtest_d/base.py index c4b9808b..fe32d049 100755 --- a/test/cmdtest_d/base.py +++ b/test/cmdtest_d/base.py @@ -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 diff --git a/test/cmdtest_d/input.py b/test/cmdtest_d/input.py index 3da38cee..3aca6fac 100755 --- a/test/cmdtest_d/input.py +++ b/test/cmdtest_d/input.py @@ -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') diff --git a/test/include/coin_daemon_control.py b/test/include/coin_daemon_control.py index fd7f1590..1051b1ed 100755 --- a/test/include/coin_daemon_control.py +++ b/test/include/coin_daemon_control.py @@ -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})