hpcugent / vsc-base

Basic Python libraries used by UGent's HPC group
Other
14 stars 51 forks source link

Config values with --foo fails from config file #307

Closed wpoely86 closed 3 years ago

wpoely86 commented 3 years ago

In generatoptions, it works if you do --foo=--bar but if you have a config file with the same contents:

[MAIN]
foo=--bar

it will fail. You have to quote it but those don't get stripped.

stdweird commented 3 years ago

is that generaloption or configparser?

wpoely86 commented 3 years ago

Not sure what you mean? It's generaloption that complains about it but I don't yet fully understand how it works.

2021-02-24 09:48:19,300 DEBUG      TEST-OPTIONS    MainThread  add_group_parser: passed prefix None section_name None
2021-02-24 09:48:19,301 DEBUG      TEST-OPTIONS    MainThread  add_group_parser: auto_prefix None auto_section_name None
2021-02-24 09:48:19,301 DEBUG      TEST-OPTIONS    MainThread  add_group_parser: set prefix  section_name MAIN
2021-02-24 09:48:19,301 DEBUG      TEST-OPTIONS    MainThread  Added prefix  to list of sectionnames for MAIN
2021-02-24 09:48:19,301 DEBUG      TEST-OPTIONS    MainThread  Add debug and logging options descr ['Debug and logging options', ''] opts {'debug': ('Enable debug log mode', None, 'store_debuglog', False, 'd'), 'info': ('Enable info log mode', None, 'store_infolog', False), 'quiet': ('Enable quiet/warning log mode', None, 'store_warninglog', False)} (no prefix)
2021-02-24 09:48:19,301 DEBUG      TEST-OPTIONS    MainThread  add_group_parser: passed prefix None section_name None
2021-02-24 09:48:19,301 DEBUG      TEST-OPTIONS    MainThread  add_group_parser: auto_prefix None auto_section_name None
2021-02-24 09:48:19,301 DEBUG      TEST-OPTIONS    MainThread  add_group_parser: set prefix  section_name MAIN
2021-02-24 09:48:19,301 DEBUG      TEST-OPTIONS    MainThread  Add configfiles options descr ['Configfile options', ''] opts {'configfiles': ('Parse (additional) configfiles', 'strlist', 'add', None), 'ignoreconfigfiles': ('Ignore configfiles', 'strlist', 'add', None)} (no prefix)
2021-02-24 09:48:19,301 DEBUG      TEST-OPTIONS    MainThread  add_group_parser: passed prefix None section_name ('NO', 'SECTION')
2021-02-24 09:48:19,302 DEBUG      TEST-OPTIONS    MainThread  add_group_parser: auto_prefix None auto_section_name None
2021-02-24 09:48:19,302 DEBUG      TEST-OPTIONS    MainThread  add_group_parser: set prefix  section_name ('NO', 'SECTION')
2021-02-24 09:48:19,302 DEBUG      TEST-OPTIONS    MainThread  Added prefix  to list of sectionnames for ('NO', 'SECTION')
2021-02-24 09:48:19,302 DEBUG      TEST-OPTIONS    MainThread  setting autocomplete with args {}
2021-02-24 09:48:19,302 DEBUG      SimpleOptionParser MainThread  Environment variable TEST-OPTIONS_SHORTHELP is not set
2021-02-24 09:48:19,302 DEBUG      SimpleOptionParser MainThread  Environment variable TEST-OPTIONS_HELP is not set
2021-02-24 09:48:19,302 DEBUG      SimpleOptionParser MainThread  Environment variable TEST-OPTIONS_CONFIGHELP is not set
2021-02-24 09:48:19,302 DEBUG      SimpleOptionParser MainThread  Environment variable TEST-OPTIONS_FOO is not set
2021-02-24 09:48:19,302 DEBUG      SimpleOptionParser MainThread  Environment variable TEST-OPTIONS_DEBUG is not set
2021-02-24 09:48:19,302 DEBUG      SimpleOptionParser MainThread  Environment variable TEST-OPTIONS_ENABLE_DEBUG is not set
2021-02-24 09:48:19,303 DEBUG      SimpleOptionParser MainThread  Environment variable TEST-OPTIONS_DISABLE_DEBUG is not set
2021-02-24 09:48:19,303 DEBUG      SimpleOptionParser MainThread  Environment variable TEST-OPTIONS_INFO is not set
2021-02-24 09:48:19,303 DEBUG      SimpleOptionParser MainThread  Environment variable TEST-OPTIONS_ENABLE_INFO is not set
2021-02-24 09:48:19,303 DEBUG      SimpleOptionParser MainThread  Environment variable TEST-OPTIONS_DISABLE_INFO is not set
2021-02-24 09:48:19,303 DEBUG      SimpleOptionParser MainThread  Environment variable TEST-OPTIONS_QUIET is not set
2021-02-24 09:48:19,303 DEBUG      SimpleOptionParser MainThread  Environment variable TEST-OPTIONS_ENABLE_QUIET is not set
2021-02-24 09:48:19,303 DEBUG      SimpleOptionParser MainThread  Environment variable TEST-OPTIONS_DISABLE_QUIET is not set
2021-02-24 09:48:19,303 DEBUG      SimpleOptionParser MainThread  Environment variable TEST-OPTIONS_CONFIGFILES is not set
2021-02-24 09:48:19,303 DEBUG      SimpleOptionParser MainThread  Environment variable TEST-OPTIONS_IGNORECONFIGFILES is not set
2021-02-24 09:48:19,303 DEBUG      SimpleOptionParser MainThread  Environment variable options with prefix TEST-OPTIONS: []
2021-02-24 09:48:19,303 DEBUG      TEST-OPTIONS    MainThread  parseoptions: options from environment []
2021-02-24 09:48:19,303 DEBUG      TEST-OPTIONS    MainThread  parseoptions: options from commandline ['--configfiles', 'test.cfg']
2021-02-24 09:48:19,303 DEBUG      TEST-OPTIONS    MainThread  Found options {'help': None, 'foo': None, 'debug': False, 'info': False, 'quiet': False, 'configfiles': ['test.cfg'], 'ignoreconfigfiles': None} args []
2021-02-24 09:48:19,304 DEBUG      TEST-OPTIONS    MainThread  Initialise case sensitive configparser
2021-02-24 09:48:19,304 DEBUG      TEST-OPTIONS    MainThread  parseconfigfiles: configfiles initially set []
2021-02-24 09:48:19,304 DEBUG      TEST-OPTIONS    MainThread  parseconfigfiles: configfiles set through commandline ['test.cfg']
2021-02-24 09:48:19,304 DEBUG      TEST-OPTIONS    MainThread  parseconfigfiles: ignoreconfigfiles set through commandline None
2021-02-24 09:48:19,304 DEBUG      TEST-OPTIONS    MainThread  parseconfigfiles: following files were parsed ['test.cfg']
2021-02-24 09:48:19,304 DEBUG      TEST-OPTIONS    MainThread  parseconfigfiles: following files were NOT parsed []
2021-02-24 09:48:19,304 DEBUG      TEST-OPTIONS    MainThread  parseconfigfiles: sections (w/o DEFAULT) ['MAIN']
2021-02-24 09:48:19,304 DEBUG      TEST-OPTIONS    MainThread  parseconfigfiles: section MAIN option foo val --bar
2021-02-24 09:48:19,304 DEBUG      TEST-OPTIONS    MainThread  parseconfigfiles: no section ('NO', 'SECTION')
2021-02-24 09:48:19,304 DEBUG      TEST-OPTIONS    MainThread  parseconfigfiles: going to parse options through cmdline ['--foo', '--bar']
2021-02-24 09:48:19,304 DEBUG      SimpleOptionParser MainThread  Not processing environment for options
2021-02-24 09:48:19,304 WARNING    ExtOption       MainThread  Value '--bar' starts with a '-'. Use '--foo=--bar' if the value is correct.
Usage: test-options.py [options]

test.py: error: Value '--bar' starts with a '-'. Use '--foo=--bar' if the value is correct.
wpoely86 commented 3 years ago

I guess the issue is:

parseconfigfiles: going to parse options through cmdline ['--foo', '--bar']

vs

parseoptions: options from commandline ['--foo=--bar']

So I have to let the options from configparse be added to 'commandline' in a different way

stdweird commented 3 years ago

it probably misassembles the commandline to test. i can look at it if you don't find it