Import error while trying to parse irrelevant command line arguments
See original GitHub issueSystem Information
- OS: Mac OS
- Python version: 3.7.7
- Python environment: pip
- Using jupyter: false
- Datapane version: 0.12.3
Bug / Issue
Hi there, we recently started to use datapane on our team to generate reports and we really like it.
We encountered an issue in our CI.
Whenever we import datapane in one of our tests, we get the following error:
click.exceptions.BadParameter: 'no:warnings', should be name=value
The reason is we run our tests using:
python -m pytest tests/ -p no:warnings
But datapane in its main init.py module tries to parse any command line parameter starting with ‘-p’, and in our case fails because this flag is for pytest’s use.
I’m not sure what the correct behavior should be, one option is to disable this override mechanism when datapane is used as a lib (and not an explicit datapane command), another option is to use more specific flag prefix instead of just ‘-p’, maybe ‘–datapane-p’ or something similar.
Hope this issue is not a duplicate, I didn’t find anything similar.
Full error stack:
/usr/local/lib/python3.7/site-packages/datapane/client/utils.py:104: in split_param
k, v = x.split("=", maxsplit=1)
E ValueError: not enough values to unpack (expected 2, got 1)
During handling of the above exception, another exception occurred:
tests/reporting/test_report_creator.py:8: in <module>
from reporting.serve_report.report_creator import _get_report_pages_block
reporting/serve_report/report_creator.py:4: in <module>
import datapane as dp
/usr/local/lib/python3.7/site-packages/datapane/__init__.py:87: in <module>
config = parse_command_line()
/usr/local/lib/python3.7/site-packages/datapane/client/utils.py:132: in parse_command_line
return process_cmd_param_vals(dp_args.parameter)
/usr/local/lib/python3.7/site-packages/datapane/client/utils.py:111: in process_cmd_param_vals
return {k: convert_param_val(v) for (k, v) in split_param(params)}
/usr/local/lib/python3.7/site-packages/datapane/client/utils.py:111: in <dictcomp>
return {k: convert_param_val(v) for (k, v) in split_param(params)}
/usr/local/lib/python3.7/site-packages/datapane/client/utils.py:106: in split_param
raise click.BadParameter(err_msg.format(x))
E click.exceptions.BadParameter: 'no:warnings', should be name=value
Issue Analytics
- State:
- Created 2 years ago
- Comments:14 (11 by maintainers)
Top GitHub Comments
Thank you for your support 🙏
Just to provide a bit more background information here on the intended use-case (pinging @shahinrostami and @spookylukey also)
The main code is in
parse_command_line
and is only used for parsing parameters that can then be loaded into thedp.Config
object as a way to paramterise your script as it runs (i.e. it’s not actually used by datapane itself, but a feature to help report writers pass data into their reports when running in batch mode, i.e. in a CI system or ML pipeline).I think there seems to be a bug in the handling here, but also we should use a more descriptive argument name, like
--dp-parameter
to avoid name-clashes.