Skip to content

Commit

Permalink
Inverted option and envvar for controlling display of deprecation war…
Browse files Browse the repository at this point in the history
…nings

Details:

* Added a complementary --deprecation-warnings option to the
  --no-deprecation-warnings option and renamed the corresponding
  envvar to PYWBEMCLI_DEPRECATION_WARNINGS. The default remains
  the same, i.e. to display the warnings.

* For Windows, fixed the setting of the envvar in the Makefile
  by removing a trailing blank.

Signed-off-by: Andreas Maier <andreas.r.maier@gmx.de>
  • Loading branch information
andy-maier committed Jul 1, 2020
1 parent 9c7108b commit bad4a01
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 37 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -637,9 +637,9 @@ safety_$(pymn).done: develop_$(pymn).done Makefile minimum-constraints.txt
test: develop_$(pymn).done $(doc_utility_help_files)
@echo "makefile: Running unit and function tests"
ifeq ($(PLATFORM),Windows_native)
cmd /c "set PYWBEMCLI_TERMWIDTH=$(pywbemcli_termwidth) & set PYWBEMCLI_NO_DEPRECATION_WARNINGS=true& py.test --color=yes --cov $(pywbemcli_module_path) $(coverage_report) --cov-config coveragerc $(pytest_warning_opts) $(pytest_opts) tests/unit -s"
cmd /c "set PYWBEMCLI_TERMWIDTH=$(pywbemcli_termwidth) & set PYWBEMCLI_DEPRECATION_WARNINGS=false& py.test --color=yes --cov $(pywbemcli_module_path) $(coverage_report) --cov-config coveragerc $(pytest_warning_opts) $(pytest_opts) tests/unit -s"
else
PYWBEMCLI_TERMWIDTH=$(pywbemcli_termwidth) PYWBEMCLI_NO_DEPRECATION_WARNINGS=true py.test --color=yes --cov $(pywbemcli_module_path) $(coverage_report) --cov-config coveragerc $(pytest_warning_opts) $(pytest_opts) tests/unit -s
PYWBEMCLI_TERMWIDTH=$(pywbemcli_termwidth) PYWBEMCLI_DEPRECATION_WARNINGS=false py.test --color=yes --cov $(pywbemcli_module_path) $(coverage_report) --cov-config coveragerc $(pytest_warning_opts) $(pytest_opts) tests/unit -s
endif
@echo "makefile: Done running tests"

Expand Down
5 changes: 2 additions & 3 deletions docs/pywbemcli/cmdshelp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,8 @@ Help text for ``pywbemcli``:
[all|paths|summary], default: all. Default: EnvVar PYWBEMCLI_LOG, or all.

-v, --verbose / --no-verbose Display extra information about the processing.
--no-deprecation-warnings Suppress deprecation warnings (that otherwise are shown on stderr). Default: EnvVar
PYWBEMCLI_NO_DEPRECATION_WARNINGS, or false.

--deprecation-warnings / --no-deprecation-warnings
Enable deprecation warnings. Default: EnvVar PYWBEMCLI_DEPRECATION_WARNINGS, or true.
--pdb Pause execution in the built-in pdb debugger just before executing the command within
pywbemcli. Default: EnvVar PYWBEMCLI_PDB, or false.

Expand Down
19 changes: 10 additions & 9 deletions docs/pywbemcli/generaloptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ Other miscellaneous general options
The :ref:`--verbose general option` displays extra information about the
pywbemcli internal processing.

The :ref:`--no-deprecation-warnings general option` suppresses the display of
deprecation warnings, that are otherwise shown on the standard error stream.
The :ref:`--deprecation-warnings general option` controls the display of
deprecation warnings.

The :ref:`--version general option` displays pywbemcli version
information and the :ref:`--help general option` provides top level help
Expand Down Expand Up @@ -637,17 +637,18 @@ command completion.

.. index:: triple: --pdb; general options; pdb

.. _`--no-deprecation-warnings general option`:
.. _`--deprecation-warnings general option`:

``--no-deprecation-warnings`` general option
``--deprecation-warnings`` general option
""""""""""""""""""""""""""""""""""""""""""""

The ``--no-deprecation-warnings`` general option is a boolean option that
suppresses the display of deprecation warnings.
The ``--deprecation-warnings``/``--no-deprecation-warnings`` general option is
a boolean option that controls the display of deprecation warnings on the
standard error stream.

By default, deprecation warnings are displayed on the standard error stream.
By default, the display of deprecation warnings is enabled.

.. index:: triple: --no-deprecation-warnings; general options; deprecation warnings
.. index:: triple: --deprecation-warnings; --no-deprecation-warnings; general options; deprecation warnings

.. _`--pdb general option`:

Expand Down Expand Up @@ -713,7 +714,7 @@ PYWBEMCLI_STATS_ENABLED ``--timestats``
PYWBEMCLI_MOCK_SERVER (1) ``--mock-server``
PYWBEMCLI_LOG ``--log``
PYWBEMCLI_PDB ``--pdb``
PYWBEMCLI_NO_DEPRECATION_WARNINGS ``--no-deprecation-warnings``
PYWBEMCLI_DEPRECATION_WARNINGS ``--deprecation-warnings``
================================= =============================

Notes:
Expand Down
2 changes: 1 addition & 1 deletion pywbemtools/pywbemcli/_cmd_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ def cmd_connection_select(context, name, options):
context.log,
context.verbose,
context.pdb,
context.no_deprecation_warnings)
context.deprecation_warnings)

# Update the root context making this context the basis for future
# commands in the current interactive session
Expand Down
10 changes: 5 additions & 5 deletions pywbemtools/pywbemcli/_context_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ContextObj(object): # pylint: disable=useless-object-inheritance
# pylint: disable=unused-argument
def __init__(self, pywbem_server, output_format, use_pull,
pull_max_cnt, timestats, log, verbose, pdb,
no_deprecation_warnings):
deprecation_warnings):

self._pywbem_server = pywbem_server
self._output_format = output_format
Expand All @@ -54,7 +54,7 @@ def __init__(self, pywbem_server, output_format, use_pull,
self._log = log
self._verbose = verbose
self._pdb = pdb
self._no_deprecation_warnings = no_deprecation_warnings
self._deprecation_warnings = deprecation_warnings

self._spinner_enabled = None # Deferred init in getter
self._spinner_obj = click_spinner.Spinner()
Expand Down Expand Up @@ -116,11 +116,11 @@ def pdb(self):
return self._pdb

@property
def no_deprecation_warnings(self):
def deprecation_warnings(self):
"""
bool: Indicates whether to suppress deprecation warnings.
bool: Indicates whether to enable deprecation warnings.
"""
return self._no_deprecation_warnings
return self._deprecation_warnings

@property
def conn(self):
Expand Down
2 changes: 1 addition & 1 deletion pywbemtools/pywbemcli/_pywbem_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class PywbemServer(object):
mock_server_envvar = 'PYWBEMCLI_MOCK_SERVER'
log_envvar = 'PYWBEMCLI_LOG'
pdb_envvar = 'PYWBEMCLI_PDB'
no_deprecation_warnings_envvar = 'PYWBEMCLI_NO_DEPRECATION_WARNINGS'
deprecation_warnings_envvar = 'PYWBEMCLI_DEPRECATION_WARNINGS'
termwidth_envvar = 'PYWBEMCLI_TERMWIDTH'

def __init__(self, server=None, default_namespace=DEFAULT_NAMESPACE,
Expand Down
6 changes: 3 additions & 3 deletions pywbemtools/pywbemcli/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def _eq_name(name1, name2):

def deprecation_warning(msg, ctx_obj):
"""
Display a deprecation warning on stderr, unless suppressed via
ctx_obj.no_deprecation_warnings.
Display a deprecation warning on stderr, unless disabled via
ctx_obj.deprecation_warnings.
"""
if not ctx_obj.no_deprecation_warnings:
if ctx_obj.deprecation_warnings:
click.echo(msg, err=True)
20 changes: 10 additions & 10 deletions pywbemtools/pywbemcli/pywbemcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,12 @@
@click.option('-v', '--verbose/--no-verbose',
default=None,
help='Display extra information about the processing.')
@click.option('--no-deprecation-warnings', is_flag=True,
default=False,
envvar=PywbemServer.no_deprecation_warnings_envvar,
help='Suppress deprecation warnings (that otherwise are shown on '
'stderr). Default: EnvVar {ev}, or false.'.
format(ev=PywbemServer.no_deprecation_warnings_envvar))
@click.option('--deprecation-warnings/--no-deprecation-warnings', is_flag=True,
default=True,
envvar=PywbemServer.deprecation_warnings_envvar,
help='Enable deprecation warnings. '
'Default: EnvVar {ev}, or true.'.
format(ev=PywbemServer.deprecation_warnings_envvar))
@click.option('--pdb', is_flag=True,
# defaulted in code
envvar=PywbemServer.pdb_envvar,
Expand All @@ -260,7 +260,7 @@
def cli(ctx, server, svr_name, default_namespace, user, password, timeout,
verify, certfile, keyfile, ca_certs, output_format, use_pull,
pull_max_cnt, mock_server, verbose=None, timestats=None, log=None,
pdb=None, no_deprecation_warnings=None):
pdb=None, deprecation_warnings=None):
"""
Pywbemcli is a command line WBEM client that uses the DMTF CIM-XML protocol
to communicate with WBEM servers. Pywbemcli can:
Expand Down Expand Up @@ -585,8 +585,8 @@ def create_server_instance(svr_name):
verbose = ctx.obj.verbose
if pdb is None:
pdb = ctx.obj.pdb
if no_deprecation_warnings is None:
no_deprecation_warnings = ctx.obj.no_deprecation_warnings
if deprecation_warnings is None:
deprecation_warnings = ctx.obj.deprecation_warnings

# Create a command context for each command: An interactive command has
# its own command context as a child of the command context for the
Expand All @@ -595,7 +595,7 @@ def create_server_instance(svr_name):
resolved_use_pull,
resolved_pull_max_cnt,
resolved_timestats,
log, verbose, pdb, no_deprecation_warnings)
log, verbose, pdb, deprecation_warnings)
if verbose and os.getenv('PYWBEMCLI_DIAGNOSTICS'):
print('CONTEXT_OBJ {!r}'.format(ctx.obj))
print('CLICK CTX {}'.format(ctx))
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_general_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@
-v, --verbose / --no-verbose Display extra information about the
processing.
--no-deprecation-warnings Suppress deprecation warnings (that otherwise
are shown on stderr). Default: EnvVar
PYWBEMCLI_NO_DEPRECATION_WARNINGS, or false.
--deprecation-warnings / --no-deprecation-warnings
Enable deprecation warnings. Default: EnvVar
PYWBEMCLI_DEPRECATION_WARNINGS, or true.
--pdb Pause execution in the built-in pdb debugger
just before executing the command within
Expand Down

0 comments on commit bad4a01

Please sign in to comment.