question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Import error while trying to parse irrelevant command line arguments

See original GitHub issue

System 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:closed
  • Created 2 years ago
  • Comments:14 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
mzedaydacommented, Sep 25, 2022

Thank you for your support 🙏

1reaction
mandscommented, Sep 5, 2022

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 the dp.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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Environment variables trigger errors for irrelevant commands ...
No, the environment var error with build doesn't happen like that (since env() is never invoked). However, such a configuration doesn't seem ...
Read more >
Dealing with backslash as a command line argument in Python
So I am trying to concatenate all argv[] arguments except the first element into a string to then parse.
Read more >
Python argparse and command line arguments - YouTube
In this Python Programming Tutorial for Beginners video I am going to show you How to use argparse to parse python scripts parameters....
Read more >
optparse — Parser for command line options — Python 3.11.1 ...
optparse uses a more declarative style of command-line parsing: you create an instance of OptionParser , populate it with options, and parse the...
Read more >
jsonargparse — jsonargparse documentation
from jsonargparse import ArgumentParser parser = ArgumentParser( prog='app', ... In command line arguments, config files and environment variables, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found