Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI cleanup and general maintenance #121

Merged
merged 8 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[flake8]
statistics = True
max-line-length = 80
ignore = E501, B008, B011, W503
ignore = E501, B008, B011, W503, B905
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

select = C,E,F,W,B,B9
exclude = docs,.svn,CVS,.bzr,.hg,.git,__pycache__,.tox,.eggs,*.egg
6 changes: 5 additions & 1 deletion .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Unit Tests

on: [push, pull_request]
on:
push:
pull_request:
schedule:
- cron: '0 10 * * 3'

jobs:
build:
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/verification.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Static Checks

on: [push, pull_request]
on:
push:
pull_request:
schedule:
- cron: '0 10 * * 3'

jobs:
build:
Expand Down
12 changes: 4 additions & 8 deletions cobald_tests/controller/test_relative_supply.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,15 @@


class TestRelativeSupplyController(object):
def test_low_scale(self):
def test_parameter_verification(self):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I combined these three test cases into one as before reading all of them it wasn't clear to me what each one tested. The new name hopefully makes this clearer.

pool = MockPool()
with pytest.raises(Exception):
with pytest.raises(AssertionError):
RelativeSupplyController(pool, low_scale=0.9, high_scale=1.0)

def test_high_scale(self):
pool = MockPool()
with pytest.raises(Exception):
with pytest.raises(AssertionError):
RelativeSupplyController(pool, low_scale=0.5, high_scale=0.9)

def test_both_scales(self):
pool = MockPool()
with pytest.raises(Exception):
with pytest.raises(AssertionError):
RelativeSupplyController(pool, low_scale=1.1, high_scale=0.9)

def test_adjustment(self):
Expand Down
1 change: 0 additions & 1 deletion src/cobald/controller/relative_supply.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def __init__(
assert low_utilisation <= high_allocation
self.low_utilisation = low_utilisation
self.high_allocation = high_allocation
assert low_scale <= high_scale
assert low_scale < 1
assert high_scale > 1
self.low_scale = low_scale
Expand Down
4 changes: 2 additions & 2 deletions src/cobald/controller/stepwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ def continuous(pool: Pool, interval):

def __init__(self, base: ControlRule):
self.base = base
self.rules = [] # type: List[Tuple[float, ControlRule]]
self._thresholds = set() # type: Set[float]
self.rules: List[Tuple[float, ControlRule]] = []
self._thresholds: Set[float] = set()

@overload # noqa: F811
def add(self, rule: ControlRule, *, supply: float) -> ControlRule:
Expand Down
2 changes: 1 addition & 1 deletion src/cobald/daemon/config/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def load(cls, entry_point: EntryPoint) -> "SectionPlugin":
requirements = getattr(digest, "__requirements__", PluginRequirements())
if entry_point.extras:
raise ValueError(
f"SectionPlugin entry point '{entry_point.name}':"
f"SectionPlugin entry point {entry_point.name!r}:"
f" extras are no longer supported"
)
return cls(section=entry_point.name, digest=digest, requirements=requirements)
Expand Down
6 changes: 3 additions & 3 deletions src/cobald/daemon/runners/asyncio_runner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable, Awaitable, Coroutine
from typing import Callable, Awaitable, Coroutine, Set
import asyncio

from .base_runner import BaseRunner, OrphanedReturn
Expand All @@ -21,7 +21,7 @@ class AsyncioRunner(BaseRunner):
# takes care of adding/removing tasks.
def __init__(self, asyncio_loop: asyncio.AbstractEventLoop):
super().__init__(asyncio_loop)
self._tasks = set()
self._tasks: Set[asyncio.Task] = set()
self._payload_failure = asyncio_loop.create_future()

def register_payload(self, payload: Callable[[], Awaitable]):
Expand Down Expand Up @@ -60,7 +60,7 @@ async def aclose(self):
if not self._payload_failure.done():
self._payload_failure.set_result(None)
while self._tasks:
for task in self._tasks.copy(): # type: asyncio.Task
for task in self._tasks.copy():
if task.done():
self._tasks.discard(task)
# monitored tasks only propagate cancellation and KeyboardInterrupt
Expand Down
2 changes: 1 addition & 1 deletion src/cobald/daemon/runners/base_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class BaseRunner(metaclass=ABCMeta):
"""Concurrency backend on top of `asyncio`"""

flavour = None # type: Any
flavour: Any

def __init__(self, asyncio_loop: asyncio.AbstractEventLoop):
self.asyncio_loop = asyncio_loop
Expand Down
3 changes: 2 additions & 1 deletion src/cobald/daemon/runners/meta_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def runners(self):
DeprecationWarning(
"Accessing 'MetaRunner.runners' directly is deprecated. "
"Use register_payload or run_payload with the correct flavour instead."
)
),
stacklevel=2,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed according to flake8-bugbear:

B028: No explicit stacklevel keyword argument found. The warn method from the warnings module uses a stacklevel of 1 by default. This will only show a stack trace for the line on which the warn method is called. It is therefore recommended to use a stacklevel of 2 or greater to provide more information to the user.

)
return self._runners

Expand Down
4 changes: 2 additions & 2 deletions src/cobald/daemon/runners/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ServiceUnit(object):
:param flavour: runner flavour to use for running the service
"""

__active_units__ = weakref.WeakSet() # type: weakref.WeakSet[ServiceUnit]
__active_units__: "weakref.WeakSet[ServiceUnit]" = weakref.WeakSet()

def __init__(self, service, flavour):
assert hasattr(service, "run"), "service must implement a 'run' method"
Expand Down Expand Up @@ -193,7 +193,7 @@ async def _accept_services(self):
self._is_shutdown.set()

def _adopt_services(self):
for unit in ServiceUnit.units(): # type: ServiceUnit
for unit in ServiceUnit.units():
if unit.running:
continue
self._logger.info("%s adopts %s", self.__class__.__name__, NameRepr(unit))
Expand Down
11 changes: 6 additions & 5 deletions src/cobald/decorator/logger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import NamedTuple, Any
from typing import NamedTuple, Any, Optional
import logging
import warnings

Expand Down Expand Up @@ -107,15 +107,15 @@ def name(self) -> str:
return self._logger.name

@name.setter
def name(self, value: str):
def name(self, value: Optional[str]):
if value is None:
value = self.target.__class__.__qualname__
self._logger = logging.getLogger(value)

def __init__(
self,
target: Pool,
name: str = None,
name: Optional[str] = None,
message: str = _DEFAULT_MESSAGE,
level: int = logging.INFO,
):
Expand All @@ -127,7 +127,8 @@ def __init__(
raise RuntimeError(
f"invalid {type(self).__name__} message field: {e}"
) from None
self._logger = None # type: logging.Logger
self.message = message
# set properly by self.name setter immediately afterwards
self._logger: logging.Logger = None # type: ignore
maxfischer2781 marked this conversation as resolved.
Show resolved Hide resolved
self.name = name
self.message = message
self.level = level
3 changes: 1 addition & 2 deletions src/cobald/interfaces/_composite.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import abc
from typing import List

import abc

from ._pool import Pool

Expand Down
4 changes: 2 additions & 2 deletions src/cobald/interfaces/_controller.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import abc
from typing import TypeVar, Type
import abc

from ._pool import Pool
from ._partial import Partial
Expand All @@ -8,7 +8,7 @@
C = TypeVar("C", bound="Controller")


class Controller(metaclass=abc.ABCMeta):
class Controller(metaclass=abc.ABCMeta): # noqa: B024
"""
Controller adjusting the demand in a :py:class:`~.Pool`

Expand Down
6 changes: 2 additions & 4 deletions src/cobald/interfaces/_partial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from inspect import Signature, BoundArguments
from inspect import Signature
from typing import Type, Generic, TypeVar, TYPE_CHECKING, Union, overload

from . import _pool
Expand Down Expand Up @@ -58,9 +58,7 @@ def _check_signature(self):
try:
if not self.leaf:
args = None, *args
_ = Signature.from_callable(self.ctor).bind_partial(
*args, **kwargs
) # type: BoundArguments
Signature.from_callable(self.ctor).bind_partial(*args, **kwargs)
except TypeError as err:
message = err.args[0]
raise TypeError(
Expand Down
2 changes: 1 addition & 1 deletion src/cobald/interfaces/_pool.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import abc
from typing import TypeVar, Type, TYPE_CHECKING
import abc

from ._partial import Partial

Expand Down
1 change: 0 additions & 1 deletion src/cobald/interfaces/_proxy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from ._pool import Pool
from typing import TypeVar, Type


from ._partial import Partial


Expand Down