Skip to content

Commit

Permalink
multiple: explicitly set attr.s cmp parameter
Browse files Browse the repository at this point in the history
We mostly don't need the compare functionality of attrs. Disable it to fall back
to object id hashes (similar to python standard classes). The only exception is
the ResourceMatch class, since we collect these into a list and need to remove
them later on. The list remove function requires the implementation of the
compare functions, explicitly enable it for the ResourceMatch class.

Fixes #106

Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
  • Loading branch information
Emantor committed Aug 1, 2017
1 parent 9d4e2a3 commit 9516871
Show file tree
Hide file tree
Showing 45 changed files with 93 additions and 91 deletions.
6 changes: 3 additions & 3 deletions labgrid/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import attr


@attr.s
@attr.s(cmp=False)
class StateError(Exception):
msg = attr.ib(validator=attr.validators.instance_of(str))


@attr.s
@attr.s(cmp=False)
class BindingError(Exception):
msg = attr.ib(validator=attr.validators.instance_of(str))

Expand All @@ -22,7 +22,7 @@ class BindingState(enum.Enum):
active = 2


@attr.s
@attr.s(cmp=False)
class BindingMixin:
"""
Handles the binding and activation of drivers and their supplying resources
Expand Down
2 changes: 1 addition & 1 deletion labgrid/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .util.yaml import load


@attr.s
@attr.s(cmp=False)
class Config:
filename = attr.ib(validator=attr.validators.instance_of(str))

Expand Down
2 changes: 1 addition & 1 deletion labgrid/driver/bareboxdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


@target_factory.reg_driver
@attr.s
@attr.s(cmp=False)
class BareboxDriver(CommandMixin, Driver, CommandProtocol, LinuxBootProtocol):
"""BareboxDriver - Driver to control barebox via the console.
BareboxDriver binds on top of a ConsoleProtocol.
Expand Down
2 changes: 1 addition & 1 deletion labgrid/driver/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .exception import ExecutionError


@attr.s
@attr.s(cmp=False)
class Driver(BindingMixin):
"""
Represents a driver which is used externally or by other drivers. It
Expand Down
4 changes: 2 additions & 2 deletions labgrid/driver/exception.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import attr


@attr.s
@attr.s(cmp=False)
class ExecutionError(Exception):
msg = attr.ib(validator=attr.validators.instance_of(str))


@attr.s
@attr.s(cmp=False)
class CleanUpError(Exception):
msg = attr.ib(validator=attr.validators.instance_of(str))
2 changes: 1 addition & 1 deletion labgrid/driver/externalconsoledriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


@target_factory.reg_driver
@attr.s
@attr.s(cmp=False)
class ExternalConsoleDriver(ConsoleExpectMixin, Driver, ConsoleProtocol):
"""
Driver implementing the ConsoleProtocol interface using a subprocess
Expand Down
8 changes: 4 additions & 4 deletions labgrid/driver/fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


@target_factory.reg_driver
@attr.s
@attr.s(cmp=False)
class FakeConsoleDriver(ConsoleExpectMixin, Driver, ConsoleProtocol):
txdelay = attr.ib(default=0.0, validator=attr.validators.instance_of(float))

Expand All @@ -32,7 +32,7 @@ def close(self):


@target_factory.reg_driver
@attr.s
@attr.s(cmp=False)
class FakeCommandDriver(CommandMixin, Driver, CommandProtocol):
@Driver.check_active
def run(self, *args):
Expand All @@ -48,7 +48,7 @@ def get_status(self):


@target_factory.reg_driver
@attr.s
@attr.s(cmp=False)
class FakeFileTransferDriver(Driver, FileTransferProtocol):
@Driver.check_active
def get(self, *args):
Expand All @@ -59,7 +59,7 @@ def put(self, *args):
pass

@target_factory.reg_driver
@attr.s
@attr.s(cmp=False)
class FakePowerDriver(Driver, PowerProtocol):
@Driver.check_active
def on(self, *args):
Expand Down
2 changes: 1 addition & 1 deletion labgrid/driver/fastbootdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


@target_factory.reg_driver
@attr.s
@attr.s(cmp=False)
class AndroidFastbootDriver(Driver):
bindings = {
"fastboot": {AndroidFastboot, NetworkAndroidFastboot},
Expand Down
2 changes: 1 addition & 1 deletion labgrid/driver/infodriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .common import Driver

@target_factory.reg_driver
@attr.s
@attr.s(cmp=False)
class InfoDriver(Driver, InfoProtocol):
"""
InfoDriver implementing the InfoProtocol on top of CommandProtocol drivers
Expand Down
2 changes: 1 addition & 1 deletion labgrid/driver/onewiredriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .common import Driver

@target_factory.reg_driver
@attr.s
@attr.s(cmp=False)
class OneWirePIODriver(Driver, DigitalOutputProtocol):

bindings = {"port": OneWirePIO, }
Expand Down
2 changes: 1 addition & 1 deletion labgrid/driver/openocddriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


@target_factory.reg_driver
@attr.s
@attr.s(cmp=False)
class OpenOCDDriver(Driver, BootstrapProtocol):
bindings = {
"interface": {AlteraUSBBlaster, NetworkAlteraUSBBlaster},
Expand Down
8 changes: 4 additions & 4 deletions labgrid/driver/powerdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


@target_factory.reg_driver
@attr.s
@attr.s(cmp=False)
class ManualPowerDriver(Driver, PowerProtocol):
"""ManualPowerDriver - Driver to tell the user to control a target's power"""
name = attr.ib(validator=attr.validators.instance_of(str))
Expand Down Expand Up @@ -43,7 +43,7 @@ def cycle(self):


@target_factory.reg_driver
@attr.s
@attr.s(cmp=False)
class ExternalPowerDriver(Driver, PowerProtocol):
"""ExternalPowerDriver - Driver using an external command to control a target's power"""
cmd_on = attr.ib(validator=attr.validators.instance_of(str))
Expand Down Expand Up @@ -78,7 +78,7 @@ def cycle(self):
self.on()

@target_factory.reg_driver
@attr.s
@attr.s(cmp=False)
class NetworkPowerDriver(Driver, PowerProtocol):
"""NetworkPowerDriver - Driver using a networked power switch to control a target's power"""
bindings = {"port": NetworkPowerPort, }
Expand Down Expand Up @@ -115,7 +115,7 @@ def get(self):
return self.backend.get(self.port.host, self.port.index)

@target_factory.reg_driver
@attr.s
@attr.s(cmp=False)
class DigitalOutputPowerDriver(Driver, PowerProtocol):
"""DigitalOutputPowerDriver - Driver using a DigitalOutput to reset the target and
subprocesses to turn it on and off"""
Expand Down
2 changes: 1 addition & 1 deletion labgrid/driver/qemudriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


@target_factory.reg_driver
@attr.s
@attr.s(cmp=False)
class QEMUDriver(ConsoleExpectMixin, Driver, PowerProtocol, ConsoleProtocol):
"""
The QEMUDriver implements an interface to start targets as qemu instances.
Expand Down
2 changes: 1 addition & 1 deletion labgrid/driver/serialdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


@target_factory.reg_driver
@attr.s
@attr.s(cmp=False)
class SerialDriver(ConsoleExpectMixin, Driver, ConsoleProtocol):
"""
Driver implementing the ConsoleProtocol interface over a SerialPort connection
Expand Down
2 changes: 1 addition & 1 deletion labgrid/driver/shelldriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


@target_factory.reg_driver
@attr.s
@attr.s(cmp=False)
class ShellDriver(CommandMixin, Driver, CommandProtocol, FileTransferProtocol):
"""ShellDriver - Driver to execute commands on the shell
ShellDriver binds on top of a ConsoleProtocol.
Expand Down
2 changes: 1 addition & 1 deletion labgrid/driver/sshdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


@target_factory.reg_driver
@attr.s
@attr.s(cmp=False)
class SSHDriver(CommandMixin, Driver, CommandProtocol, FileTransferProtocol):
"""SSHDriver - Driver to execute commands via SSH"""
bindings = {"networkservice": NetworkService, }
Expand Down
2 changes: 1 addition & 1 deletion labgrid/driver/ubootdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


@target_factory.reg_driver
@attr.s
@attr.s(cmp=False)
class UBootDriver(CommandMixin, Driver, CommandProtocol, LinuxBootProtocol):
"""UBootDriver - Driver to control uboot via the console.
UBootDriver binds on top of a ConsoleProtocol.
Expand Down
4 changes: 2 additions & 2 deletions labgrid/driver/usbloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


@target_factory.reg_driver
@attr.s
@attr.s(cmp=False)
class MXSUSBDriver(Driver, BootstrapProtocol):
bindings = {
"loader": {MXSUSBLoader, NetworkMXSUSBLoader},
Expand Down Expand Up @@ -48,7 +48,7 @@ def load(self, filename=None):


@target_factory.reg_driver
@attr.s
@attr.s(cmp=False)
class IMXUSBDriver(Driver, BootstrapProtocol):
bindings = {
"loader": {IMXUSBLoader, NetworkIMXUSBLoader},
Expand Down
2 changes: 1 addition & 1 deletion labgrid/driver/usbstorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


@target_factory.reg_driver
@attr.s
@attr.s(cmp=False)
class USBStorageDriver(Driver):
bindings = {"storage": USBMassStorage, }

Expand Down
2 changes: 1 addition & 1 deletion labgrid/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .config import Config


@attr.s
@attr.s(cmp=False)
class Environment:
"""An environment encapsulates targets."""
config_file = attr.ib(
Expand Down
8 changes: 4 additions & 4 deletions labgrid/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import attr


@attr.s
@attr.s(cmp=False)
class NoConfigFoundError(Exception):
msg = attr.ib(validator=attr.validators.instance_of(str))


@attr.s
@attr.s(cmp=False)
class NoSupplierFoundError(Exception):
msg = attr.ib(validator=attr.validators.instance_of(str))


@attr.s
@attr.s(cmp=False)
class NoDriverFoundError(NoSupplierFoundError):
pass


@attr.s
@attr.s(cmp=False)
class NoResourceFoundError(NoSupplierFoundError):
pass
4 changes: 2 additions & 2 deletions labgrid/external/hawkbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import attr
import requests as r

@attr.s
@attr.s(cmp=False)
class HawkbitTestClient:
host = attr.ib(validator=attr.validators.instance_of(str))
port = attr.ib(validator=attr.validators.instance_of(str))
Expand Down Expand Up @@ -126,6 +126,6 @@ def get_endpoint(self, endpoint: str):
return req.json()


@attr.s
@attr.s(cmp=False)
class HawkbiError(Exception):
msg = attr.ib()
4 changes: 2 additions & 2 deletions labgrid/external/usbstick.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class USBStatus(enum.Enum):
mounted = 2


@attr.s
@attr.s(cmp=False)
class USBStick(object):
"""The USBStick class provides an easy to use interface to describe a
target as an USB Stick."""
Expand Down Expand Up @@ -140,7 +140,7 @@ def switch_image(self, image_name):
self.image_name = image_name


@attr.s
@attr.s(cmp=False)
class StateError(Exception):
"""Exception which indicates a error in the state handling of the test"""
msg = attr.ib()
2 changes: 1 addition & 1 deletion labgrid/provider/mediafileprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .fileprovider import FileProvider


@attr.s
@attr.s(cmp=False)
class MediaFileProvider(FileProvider):
groups = attr.ib(default={}, validator=attr.validators.instance_of(dict))

Expand Down
8 changes: 5 additions & 3 deletions labgrid/remote/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import attr


@attr.s
@attr.s(cmp=False)
class ResourceEntry:
data = attr.ib() # cls, params
acquired = attr.ib(default=None)
Expand Down Expand Up @@ -47,7 +47,9 @@ def asdict(self):
}


@attr.s
@attr.s(cmp=True)
# This class requires cmp=True, since we put the matches into a list and require
# the cmp functions to be able to remove the matches from the list later on.
class ResourceMatch:
exporter = attr.ib()
group = attr.ib()
Expand Down Expand Up @@ -84,7 +86,7 @@ def ismatch(self, resource_path):
return True


@attr.s
@attr.s(cmp=False)
class Place:
name = attr.ib()
aliases = attr.ib(default=attr.Factory(set), convert=set)
Expand Down
2 changes: 1 addition & 1 deletion labgrid/remote/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ..exceptions import NoConfigFoundError


@attr.s
@attr.s(cmp=False)
class ResourceConfig:
filename = attr.ib(validator=attr.validators.instance_of(str))

Expand Down
6 changes: 3 additions & 3 deletions labgrid/remote/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Action(Enum):
UPD = 2


@attr.s(init=False)
@attr.s(init=False, cmp=False)
class RemoteSession:
"""class encapsulating a session, used by ExporterSession and ClientSession"""
coordinator = attr.ib()
Expand All @@ -39,7 +39,7 @@ def name(self):
return self.authid.split('/', 1)[1]


@attr.s
@attr.s(cmp=False)
class ExporterSession(RemoteSession):
"""An ExporterSession is opened for each Exporter connecting to the
coordinator, allowing the Exporter to get and set resources"""
Expand Down Expand Up @@ -86,7 +86,7 @@ def get_resources(self):
return result


@attr.s
@attr.s(cmp=False)
class ClientSession(RemoteSession):
acquired = attr.ib(default=attr.Factory(list), init=False)

Expand Down
Loading

0 comments on commit 9516871

Please sign in to comment.