ConfigArgParse
ConfigArgParse copied to clipboard
env vars not loaded when a "nargs=REMAINDER" argument is used
Example Script (tmp.py)
import configargparse
parser = configargparse.ArgumentParser()
parser.add_argument('--rawr', required=True, env_var='RAWR')
parser.add_argument(
'--leftovers',
default=[],
nargs=configargparse.REMAINDER,
)
args = parser.parse_args()
print(args)
run tmp.py using bash shell
command
RAWR=rawr python tmp.py --leftovers x
output
usage: tmp.py [-h] --rawr RAWR [--leftovers ...]
tmp.py: error: the following arguments are required: --rawr
command
RAWR=rawr python tmp.py
output
Namespace(leftovers=[], rawr='rawr')
System Info
- python 3.6.7
- ConfigArgParse 0.14.0
The problem is caused by this line, which appends the env var arg values to the list of CLI args, causing them to be consumed by the nargs=REMAINDER
argument.
https://github.com/bw2/ConfigArgParse/blob/8bbc7de67f884184068d62af7f78e723d01c0081/configargparse.py#L448
A simple solution would be to change this to:
args = env_var_args + args
However, I'm not clear if this would affect other parts of the code.