diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6e7cbc519368f8d9ff68aaed01a5aaeab30be3e5..690ab13b88de72e26406aee205e64a425d69d330 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,7 +35,7 @@ jobs: python-version: '3.x' - name: "Main Script" run: | - EXTRA_INSTALL="pymbolic matplotlib" + EXTRA_INSTALL="pymbolic" curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/prepare-and-run-pylint.sh . ./prepare-and-run-pylint.sh "$(basename $GITHUB_REPOSITORY)" test/test_*.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 82757f6676ad244edeb609d1db01d693c22fd143..463450507fc68b074a22f5b4016c4826244f5ebd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -44,7 +44,7 @@ Mypy: Pylint: script: - - EXTRA_INSTALL="pymbolic matplotlib" + - EXTRA_INSTALL="pymbolic" - py_version=3 - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/prepare-and-run-pylint.sh - . ./prepare-and-run-pylint.sh "$CI_PROJECT_NAME" test/test_*.py diff --git a/.pylintrc-local.yml b/.pylintrc-local.yml index a78cc33c4ad038785444eb92fa3f23a125bf72d4..8cb3aa72495ee15c342e82f9c340807bbd2c18c2 100644 --- a/.pylintrc-local.yml +++ b/.pylintrc-local.yml @@ -1,3 +1,6 @@ - arg: ignore val: - mpiwrap.py +- arg: ignored-modules + val: + - matplotlib diff --git a/pytools/__init__.py b/pytools/__init__.py index 950e0014d0c66fe433a756a45288de575bac1a55..7f88a5e95ce7a73dad339eb984a7baba23341051 100644 --- a/pytools/__init__.py +++ b/pytools/__init__.py @@ -26,7 +26,7 @@ THE SOFTWARE. """ -from functools import reduce +from functools import reduce, wraps import operator import sys import logging @@ -120,6 +120,11 @@ Name generation .. autofunction:: generate_numbered_unique_names .. autoclass:: UniqueNameGenerator +Deprecation Warnings +-------------------- + +.. autofunction:: deprecate_keyword + Functions for dealing with (large) auxiliary files -------------------------------------------------- @@ -174,6 +179,69 @@ F = TypeVar("F", bound=Callable[..., Any]) # }}} +# {{{ code maintenance + +class MovedFunctionDeprecationWrapper: + def __init__(self, f, deadline=None): + if deadline is None: + deadline = "the future" + + self.f = f + self.deadline = deadline + + def __call__(self, *args, **kwargs): + from warnings import warn + warn(f"This function is deprecated and will go away in {self.deadline}. " + f"Use {self.f.__module}.{self.f.__name__} instead.", + DeprecationWarning, stacklevel=2) + + return self.f(*args, **kwargs) + + +def deprecate_keyword(oldkey: str, + newkey: Optional[str] = None, *, + deadline: Optional[str] = None): + """Decorator used to deprecate function keyword arguments. + + :arg oldkey: deprecated argument name. + :arg newkey: new argument name that serves the same purpose, if any. + :arg deadline: expected time frame for the removal of the deprecated argument. + """ + from warnings import warn + + if deadline is None: + deadline = "the future" + + def wrapper(func): + @wraps(func) + def inner_wrapper(*args, **kwargs): + if oldkey in kwargs: + if newkey is None: + warn(f"The '{oldkey}' keyword is deprecated and will " + f"go away in {deadline}.", + DeprecationWarning, stacklevel=2) + else: + warn(f"The '{oldkey}' keyword is deprecated and will " + f"go away in {deadline}. " + f"Use '{newkey}' instead.", + DeprecationWarning, stacklevel=2) + + if newkey in kwargs: + raise ValueError(f"Cannot use '{oldkey}' " + f"and '{newkey}' in the same call.") + + kwargs[newkey] = kwargs[oldkey] + del kwargs[oldkey] + + return func(*args, **kwargs) + + return inner_wrapper + + return wrapper + +# }}} + + # {{{ math -------------------------------------------------------------------- def delta(x, y): @@ -778,7 +846,6 @@ def memoize_method_nested(inner): "Use @memoize_in(self, 'identifier') instead", DeprecationWarning, stacklevel=2) - from functools import wraps cache_dict_name = intern("_memoize_inner_dic_%s_%s_%d" % (inner.__name__, inner.__code__.co_filename, inner.__code__.co_firstlineno)) @@ -827,8 +894,6 @@ class memoize_in(object): # noqa self.cache_dict = memoize_in_dict.setdefault(identifier, {}) def __call__(self, inner): - from functools import wraps - @wraps(inner) def new_inner(*args): try: @@ -1465,23 +1530,6 @@ def get_write_to_map_from_permutation(original, permuted): # }}} -# {{{ code maintenance - -class MovedFunctionDeprecationWrapper: - def __init__(self, f): - self.f = f - - def __call__(self, *args, **kwargs): - from warnings import warn - warn("This function is deprecated. Use %s.%s instead." % ( - self.f.__module__, self.f.__name__), - DeprecationWarning, stacklevel=2) - - return self.f(*args, **kwargs) - -# }}} - - # {{{ graph algorithms from pytools.graph import a_star as a_star_moved