-
Notifications
You must be signed in to change notification settings - Fork 96
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,14 @@ | |
import click | ||
import logging | ||
import sys | ||
import textwrap | ||
import warnings | ||
|
||
# Importing planet.api triggers a deprecation warning. In the planet | ||
# command and its sub-commands we will intercept and ignore the | ||
# warning and instead show users a detailed warning in the command | ||
# usage text, and a short warning on command execution. | ||
warnings.filterwarnings("ignore", module="planet.api") | ||
|
||
from planet import api | ||
from planet.api.__version__ import __version__ | ||
|
@@ -64,7 +72,35 @@ def configure_logging(verbosity): | |
' - Default https://api.planet.com/') | ||
@click.version_option(version=__version__, message='%(version)s') | ||
def cli(context, verbose, api_key, base_url, workers): | ||
'''Planet API Client''' | ||
"""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. | ||
|
||
""" | ||
warnmsg = click.style( | ||
"\n".join( | ||
textwrap.wrap( | ||
"Attention! You are using version 1 of the Planet CLI. " | ||
"Version 2 will not be backward compatible. " | ||
"Please see `planet --help` for details. " | ||
"This warning may be disabled by setting " | ||
"`PYTHONWARNINGS=ignore` in your environment.", | ||
width=80, | ||
) | ||
), | ||
fg="yellow", | ||
) | ||
prev_formatwarning = warnings.formatwarning | ||
warnings.formatwarning = lambda msg, *args, **kwargs: "{}\n".format(msg) | ||
warnings.warn(warnmsg, UserWarning) | ||
warnings.formatwarning = prev_formatwarning | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously, the warning was sent to the terminal using |
||
|
||
configure_logging(verbose) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.