Skip to content

Warn on command execution using custom styled format #652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 28, 2022
Merged

Warn on command execution using custom styled format #652

merged 2 commits into from
Jul 28, 2022

Conversation

sgillies
Copy link
Contributor

@sgillies sgillies commented Jul 28, 2022

Resolves #651.

Here's what the short warning looks like:

Screenshot from 2022-07-28 10-41-27

And here's what we see in planet --help:

$ planet --help
Usage: planet [OPTIONS] COMMAND [ARGS]...

  Planet API Client

  Attention!

  You are using version 1 of the Planet CLI. A pre-release of version 2 is
  available at https://pypi.org/project/planet/. Version 2 will not be
  backward compatible. Changes are planned for the arguments, options, and
  return values of subcommands. For more information about the new version,
  please join the discussion at https://github.com/planetlabs/planet-client-
  python/discussions.

Options:

@sgillies sgillies added the v1 label Jul 28, 2022
@sgillies sgillies added this to the 1.5.1 milestone Jul 28, 2022
@sgillies sgillies self-assigned this Jul 28, 2022
prev_formatwarning = warnings.formatwarning
warnings.formatwarning = lambda msg, *args, **kwargs: f"{msg}\n"
warnings.warn(warnmsg, UserWarning)
warnings.formatwarning = prev_formatwarning
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, the warning was sent to the terminal using click.echo, but this doesn't provide an easy way to disable the warning. Using Python's warning system, as above, lets us use PYTHONWARNINGS=ignore.

@@ -40,4 +40,5 @@ class ClientV1DeprecationWarning(FutureWarning):
"For more details please see the discussion at "
"https://github.com/planetlabs/planet-client-python/discussions.",
ClientV1DeprecationWarning,
stacklevel=2
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, the warning will point to the module that imports planet.api instead of to planet.api itself.

@sgillies sgillies marked this pull request as ready for review July 28, 2022 18:10
@sgillies sgillies merged commit 8c54b69 into v1 Jul 28, 2022
@jreiberkyle jreiberkyle deleted the issue651 branch June 28, 2023 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant