Skip to content

Commit

Permalink
Backward-compatible proxy versions of modules moved from executor/
Browse files Browse the repository at this point in the history
  • Loading branch information
azawlocki committed Jun 7, 2021
1 parent b00c610 commit 4daf411
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 2 deletions.
4 changes: 2 additions & 2 deletions yapapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pathlib import Path
from pkg_resources import get_distribution

from yapapi.ctx import CaptureContext, ExecOptions, WorkContext
from yapapi.ctx import ExecOptions, Work, WorkContext
from yapapi.engine import NoPaymentAccountError, WorkItem
from yapapi.executor import Executor, Task
from yapapi.golem import Golem
Expand Down Expand Up @@ -51,9 +51,9 @@ class _WindowsEventPolicy(asyncio.events.BaseDefaultEventLoopPolicy):
"storage",
"Task",
"WorkContext",
"CaptureContext",
"ExecOptions",
"Golem",
"NoPaymentAccountError",
"Work",
"WorkItem",
]
31 changes: 31 additions & 0 deletions yapapi/executor/ctx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from deprecated import deprecated # type: ignore

import yapapi.ctx
from yapapi.utils import show_module_deprecation_warning


_deprecation_version = "0.6.0"
_deprecation_reason = "Please use the class with the same name defined in yapapi.ctx instead"


show_module_deprecation_warning("yapapi.executor.ctx", "yapapi.ctx", _deprecation_version)


@deprecated(version=_deprecation_version, reason=_deprecation_reason)
class CommandContainer(yapapi.ctx.CommandContainer):
pass


@deprecated(version=_deprecation_version, reason=_deprecation_reason)
class ExecOptions(yapapi.ctx.ExecOptions):
pass


@deprecated(version=_deprecation_version, reason=_deprecation_reason)
class Work(yapapi.ctx.Work):
pass


@deprecated(version=_deprecation_version, reason=_deprecation_reason)
class WorkContext(yapapi.ctx.WorkContext):
pass
21 changes: 21 additions & 0 deletions yapapi/executor/events.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from deprecated.classic import ClassicAdapter # type: ignore

import yapapi.events
from yapapi.utils import show_module_deprecation_warning


_deprecation_version = "0.6.0"
_deprecation_reason = "Please use the class with the same name defined in yapapi.events instead"


show_module_deprecation_warning("yapapi.executor.events", "yapapi.events", _deprecation_version)


for id, item in yapapi.events.__dict__.items():
# For each subclass `E` of `yapapi.events.Event`, produce a subclass `yapapi.executor.events.E`
# decorated with @deprecated(_deprecation_version, _deprecation_reason)
if isinstance(item, type) and issubclass(item, yapapi.events.Event):
_subclass = type(id, (item,), {})
_adapter = ClassicAdapter(version=_deprecation_version, reason=_deprecation_reason)
_wrapped = _adapter(_subclass)
globals()[id] = _wrapped
32 changes: 32 additions & 0 deletions yapapi/executor/strategy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from deprecated import deprecated # type: ignore

import yapapi.strategy
from yapapi.strategy import SCORE_NEUTRAL, SCORE_REJECTED, SCORE_TRUSTED
from yapapi.utils import show_module_deprecation_warning


_deprecation_version = "0.6.0"
_deprecation_reason = "Please use the class with the same name defined in yapapi.strategy instead"


show_module_deprecation_warning("yapapi.executor.strategy", "yapapi.strategy", _deprecation_version)


@deprecated(version=_deprecation_version, reason=_deprecation_reason)
class MarketStrategy(yapapi.strategy.MarketStrategy):
pass


@deprecated(version=_deprecation_version, reason=_deprecation_reason)
class DummyMS(yapapi.strategy.DummyMS):
pass


@deprecated(version=_deprecation_version, reason=_deprecation_reason)
class LeastExpensiveLinearPayuMS(yapapi.strategy.LeastExpensiveLinearPayuMS):
pass


@deprecated(version=_deprecation_version, reason=_deprecation_reason)
class DecreaseScoreForUnconfirmedAgreement(yapapi.strategy.DecreaseScoreForUnconfirmedAgreement):
pass
12 changes: 12 additions & 0 deletions yapapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import asyncio
import logging
from typing import AsyncContextManager, Callable, Optional
import warnings


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -75,3 +76,14 @@ def async_call(self, *args, **kwargs) -> None:
if not self._task or self._task.done():
raise RuntimeError("AsyncWrapper is closed")
self._args_buffer.put_nowait((args, kwargs))


def show_module_deprecation_warning(old_module: str, new_module: str, since_version: str) -> None:

warnings.filterwarnings("default", category=DeprecationWarning, module=old_module)
warnings.warn(
f"Module `{old_module}` is deprecated since version {since_version}, "
f"please use module `{new_module}` instead",
category=DeprecationWarning,
stacklevel=2,
)

0 comments on commit 4daf411

Please sign in to comment.