|
15 | 15 | import click
|
16 | 16 | import logging
|
17 | 17 | import sys
|
| 18 | +import textwrap |
| 19 | +import warnings |
| 20 | + |
| 21 | +# Importing planet.api triggers a deprecation warning. In the planet |
| 22 | +# command and its sub-commands we will intercept and ignore the |
| 23 | +# warning and instead show users a detailed warning in the command |
| 24 | +# usage text, and a short warning on command execution. |
| 25 | +warnings.filterwarnings("ignore", module="planet.api") |
18 | 26 |
|
19 | 27 | from planet import api
|
20 | 28 | from planet.api.__version__ import __version__
|
@@ -64,7 +72,35 @@ def configure_logging(verbosity):
|
64 | 72 | ' - Default https://api.planet.com/')
|
65 | 73 | @click.version_option(version=__version__, message='%(version)s')
|
66 | 74 | def cli(context, verbose, api_key, base_url, workers):
|
67 |
| - '''Planet API Client''' |
| 75 | + """Planet API Client |
| 76 | +
|
| 77 | + Attention! |
| 78 | +
|
| 79 | + You are using version 1 of the Planet CLI. A pre-release of version |
| 80 | + 2 is available at https://pypi.org/project/planet/. Version 2 will |
| 81 | + not be backward compatible. Changes are planned for the arguments, |
| 82 | + options, and return values of subcommands. For more information |
| 83 | + about the new version, please join the discussion at |
| 84 | + https://github.com/planetlabs/planet-client- python/discussions. |
| 85 | +
|
| 86 | + """ |
| 87 | + warnmsg = click.style( |
| 88 | + "\n".join( |
| 89 | + textwrap.wrap( |
| 90 | + "Attention! You are using version 1 of the Planet CLI. " |
| 91 | + "Version 2 will not be backward compatible. " |
| 92 | + "Please see `planet --help` for details. " |
| 93 | + "This warning may be disabled by setting " |
| 94 | + "`PYTHONWARNINGS=ignore` in your environment.", |
| 95 | + width=80, |
| 96 | + ) |
| 97 | + ), |
| 98 | + fg="yellow", |
| 99 | + ) |
| 100 | + prev_formatwarning = warnings.formatwarning |
| 101 | + warnings.formatwarning = lambda msg, *args, **kwargs: "{}\n".format(msg) |
| 102 | + warnings.warn(warnmsg, UserWarning) |
| 103 | + warnings.formatwarning = prev_formatwarning |
68 | 104 |
|
69 | 105 | configure_logging(verbose)
|
70 | 106 |
|
|
0 commit comments