Ejemplo n.º 1
0
def _version_ok(ver, preferred):
    if preferred == LATEST_VERSION:
        return False

    pref_ver = preferred.lstrip("<=>").strip()
    cond = preferred.rstrip(pref_ver).strip()
    check = {
        "==": lambda x, y: x == y,
        ">=": lambda x, y: x >= y,
        ">": lambda x, y: x > y,
        "<=": lambda x, y: x <= y,
        "<": lambda x, y: x < y,
    }[cond]
    return check(mod_util.version(ver), mod_util.version(pref_ver))
Ejemplo n.º 2
0
def warn_deprecated(name, use_instead, remove_in, module_name=None):
    if config.INTERNAL_CORRECTNESS_CHECKS and version(
            polygraphy.__version__) >= version(remove_in):
        G_LOGGER.internal_error(
            "{:} should have been removed in version: {:}".format(
                name, remove_in))

    full_obj_name = "{:}.{:}".format(module_name,
                                     name) if module_name else name
    warnings.warn(
        "{:} is deprecated and will be removed in Polygraphy {:}. "
        "Use {:} instead.".format(full_obj_name, remove_in, use_instead),
        DeprecationWarning,
        stacklevel=3,
    )
Ejemplo n.º 3
0
    def deprecate_impl(obj):
        if config.INTERNAL_CORRECTNESS_CHECKS and version(
                polygraphy.__version__) >= version(remove_in):
            G_LOGGER.internal_error(
                "{:} should have been removed in version: {:}".format(
                    obj, remove_in))

        nonlocal name
        name = name or obj.__name__

        if inspect.ismodule(obj):

            class DeprecatedModule(object):
                def __getattr__(self, attr_name):
                    warn_deprecated(name, use_instead, remove_in, module_name)
                    self = obj
                    return getattr(self, attr_name)

                def __setattr__(self, attr_name, value):
                    warn_deprecated(name, use_instead, remove_in, module_name)
                    self = obj
                    return setattr(self, attr_name, value)

            DeprecatedModule.__doc__ = "Deprecated: Use {:} instead".format(
                use_instead)
            return DeprecatedModule()
        elif inspect.isclass(obj):

            class Deprecated(obj):
                def __init__(self, *args, **kwargs):
                    warn_deprecated(name, use_instead, remove_in, module_name)
                    super().__init__(*args, **kwargs)

            Deprecated.__doc__ = "Deprecated: Use {:} instead".format(
                use_instead)
            return Deprecated
        elif inspect.isfunction(obj):

            def wrapped(*args, **kwargs):
                warn_deprecated(name, use_instead, remove_in, module_name)
                return obj(*args, **kwargs)

            wrapped.__doc__ = "Deprecated: Use {:} instead".format(use_instead)
            return wrapped
        else:
            G_LOGGER.internal_error(
                "deprecate is not implemented for: {:}".format(obj))