Skip to content

Commit

Permalink
Merge pull request pepkit#303 from vreuter/depr
Browse files Browse the repository at this point in the history
Better deprecation localization
  • Loading branch information
vreuter committed May 6, 2019
2 parents 7139d14 + aa8f43d commit fa5a1b1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
26 changes: 18 additions & 8 deletions peppy/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
from .exceptions import PeppyError
from .sample import merge_sample, Sample
from .utils import \
add_project_sample_constants, copy, fetch_samples, infer_delimiter, is_url, \
non_null_value, type_check_strict, warn_derived_cols, warn_implied_cols
add_project_sample_constants, copy, fetch_samples, get_name_depr_msg, \
infer_delimiter, is_url, non_null_value, type_check_strict


MAX_PROJECT_SAMPLES_REPR = 12
Expand All @@ -82,6 +82,8 @@
GENOMES_KEY = "genomes"
TRANSCRIPTOMES_KEY = "transcriptomes"
IDEALLY_IMPLIED = [GENOMES_KEY, TRANSCRIPTOMES_KEY]
_OLD_DERIVATIONS_KEY = "derived_columns"
_OLD_IMPLICATIONS_KEY = "implied_columns"


_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -264,11 +266,15 @@ def __setitem__(self, key, value):
:param str key: Key to map to given value
:param object value: Arbitrary value to bind to given key
"""
if key == "derived_columns":
warn_derived_cols()
if key == _OLD_DERIVATIONS_KEY:
warnings.warn(get_name_depr_msg(
_OLD_DERIVATIONS_KEY, "derived_attributes", self.__class__),
DeprecationWarning)
key = DERIVATIONS_DECLARATION
elif key == "implied_columns":
warn_implied_cols()
elif key == _OLD_IMPLICATIONS_KEY:
warnings.warn(get_name_depr_msg(
_OLD_IMPLICATIONS_KEY, "implied_attributes", self.__class__),
DeprecationWarning)
key = IMPLICATIONS_DECLARATION
elif key == METADATA_KEY:
value = _Metadata(value)
Expand All @@ -291,7 +297,9 @@ def derived_columns(self):
:return list[str]: sample attribute names for which value is derived
"""
warn_derived_cols()
msg = get_name_depr_msg(
_OLD_DERIVATIONS_KEY, "derived_attributes", self.__class__)
warnings.warn(msg, DeprecationWarning)
try:
return self.derived_attributes
except AttributeError:
Expand All @@ -304,7 +312,9 @@ def implied_columns(self):
:return list[str]: sample attribute names for which value is implied by other(s)
"""
warn_implied_cols()
msg = get_name_depr_msg(
_OLD_IMPLICATIONS_KEY, "implied_attributes", self.__class__)
warnings.warn(msg, DeprecationWarning)
try:
return self.implied_attributes
except AttributeError:
Expand Down
17 changes: 0 additions & 17 deletions peppy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from collections import Sized
else:
from collections.abc import Sized
import warnings
import yaml
from .const import SAMPLE_INDEPENDENT_PROJECT_SECTIONS
from ubiquerg import is_collection_like
Expand Down Expand Up @@ -398,16 +397,6 @@ def standard_stream_redirector(stream):
sys.stdout, sys.stderr = genuine_stdout, genuine_stderr


def warn_derived_cols():
""" Produce deprecation warning about derived columns. """
_warn_cols_to_attrs("derived")


def warn_implied_cols():
""" Produce deprecation warning about implied columns. """
_warn_cols_to_attrs("implied")


def get_name_depr_msg(old, new, cls=None):
"""
Warn of an attribute name deprecation.
Expand All @@ -420,12 +409,6 @@ def get_name_depr_msg(old, new, cls=None):
return msg if cls is None else "On {} ".format(cls.__name__) + msg


def _warn_cols_to_attrs(prefix):
""" Produce deprecation warning about 'columns' rather than 'attributes' """
warnings.warn("{pfx}_columns should be encoded and referenced "
"as {pfx}_attributes".format(pfx=prefix), DeprecationWarning)


class CommandChecker(object):
"""
Validate PATH availability of executables referenced by a config file.
Expand Down

0 comments on commit fa5a1b1

Please sign in to comment.