Closed aisbergde closed 3 years ago
I tried to comment out some parts. The following works:
import configargparse
p = configargparse.ArgParser(default_config_files=['/etc/app/conf.d/*.conf', '~/.my_settings'])
# p.add('-c', '--my-config', required=True, is_config_file=True, help='config file path')
# p.add('--genome', required=True, help='path to genome file') # this option can be set in a config file because it starts with '--'
p.add('-v', help='verbose', action='store_true')
p.add('-d', '--dbsnp', help='known variants .vcf', env_var='DBSNP_PATH') # this option can be set in a config file because it starts with '--'
# p.add('vcf', nargs='+', help='variant file(s)')
options = p.parse_args()
print(options)
print("----------")
print(p.format_help())
print("----------")
print(p.format_values()) # useful for logging where different settings came from
Some more comments in the example would be helpful. for example it looks like required=True
has some meaning and if a required parameter is missing the script will create an error (whithout some information about the reason)
it is also not clear why p.add('vcf', nargs='+', help='variant file(s)')
causes an error.
It would be fine to extend the example to make it executable without errors or some additional comments in the example would be helpful why some content will cause an error in some situations.
I think I got the idea: the errors are by intention and the error message is in the output of the program. But anyway the documentation is not 100% clear. What about this:
DBSNP_PATH=/data/dbsnp/variants_v2.vcf python config_test.py --my-config config.txt f1.vcf f2.vcf
What is the meaning of this DBSNP_PATH=/data/dbsnp/variants_v2.vcf
?
Or should this be the environment?
Maybe my questions are stupid, but I try to use Python as I can, but it looks like I have some deficites :-)
You mostly figured it out.. by convention, environment variables are written in all capital letters and
DBSNP_PATH=/data/dbsnp/variants_v2.vcf
is meant to be an environment variable.
Are you running your python code inside a code editor or an interactive console like ipython?
If yes, this is why you're seeing long error messages that don't make sense.
configargparse is meant to be used in stand-alone python scripts that you run non-interactively (by passing them to python.exe).
I tried to use the example as it is, but it doesn't work out of the box and the error message is not helpful I get an error on this line:
options = p.parse_args()
I am not an experienced python programmer, but I use Python when it has some functions which I need as a database developer. That's why I have no idea where to look and what to do.
some version info, if this could help