Skip to content

Commit

Permalink
fix: lint code
Browse files Browse the repository at this point in the history
  • Loading branch information
altor committed Sep 28, 2021
1 parent 8587b9f commit d2039b2
Show file tree
Hide file tree
Showing 82 changed files with 564 additions and 680 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ disable=R0903, R0902, C0200,
C0114, C0103, R1705, R0913,
W0102, C0112, R1720, R0915,
W0237, R1732, W1514, R1718,
C0206, W0236, W0223,
C0206, W0236, W0223, W1201,
print-statement,
parameter-unpacking,
unpacking-in-except,
Expand Down
2 changes: 1 addition & 1 deletion powerapi/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def receiveMsg_StartMessage(self, message: StartMessage, sender: ActorAddress):
Actor.receiveMsg_StartMessage(self, message, sender)
self.wakeupAfter(self._time_interval)

def receiveMsg_WakeupMessage(self, message: WakeupMessage, _: ActorAddress):
def receiveMsg_WakeupMessage(self, _: WakeupMessage, __: ActorAddress):
"""
When receiving a WakeupMessage, launch the actor task
"""
Expand Down
4 changes: 2 additions & 2 deletions powerapi/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (c) 2018, INRIA
# Copyright (c) 2018, University of Lille
# Copyright (c) 2021, INRIA
# Copyright (c) 2021, University of Lille
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down
4 changes: 2 additions & 2 deletions powerapi/cli/config_validator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (c) 2018, INRIA
# Copyright (c) 2018, University of Lille
# Copyright (c) 2021, INRIA
# Copyright (c) 2021, University of Lille
# All rights reserved.

# Redistribution and use in source and binary forms, with or without
Expand Down
4 changes: 2 additions & 2 deletions powerapi/cli/parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (c) 2018, INRIA
# Copyright (c) 2018, University of Lille
# Copyright (c) 2021, INRIA
# Copyright (c) 2021, University of Lille
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down
7 changes: 3 additions & 4 deletions powerapi/database/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (c) 2018, INRIA
# Copyright (c) 2018, University of Lille
# Copyright (c) 2021, INRIA
# Copyright (c) 2021, University of Lille
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand All @@ -26,7 +26,6 @@
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from powerapi.database.base_db import BaseDB, IterDB, DBError
from powerapi.database.csvdb import CsvDB, CsvBadFilePathError
from powerapi.database.csvdb import CsvBadCommonKeysError, HeaderAreNotTheSameError
Expand All @@ -36,4 +35,4 @@
from powerapi.database.prometheus_db import PrometheusDB
from powerapi.database.virtiofs_db import VirtioFSDB
from powerapi.database.direct_prometheus_db import DirectPrometheusDB
from .socket_db import SocketDB
from powerapi.database.socket_db import SocketDB
9 changes: 2 additions & 7 deletions powerapi/database/base_db.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (c) 2018, INRIA
# Copyright (c) 2018, University of Lille
# Copyright (c) 2021, INRIA
# Copyright (c) 2021, University of Lille
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand All @@ -26,7 +26,6 @@
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from typing import List, Type
from powerapi.report import Report
from powerapi.exception import PowerAPIExceptionWithMessage
Expand Down Expand Up @@ -91,8 +90,6 @@ def connect(self):
def iter(self, stream_mode: bool) -> IterDB:
"""
Create the iterator for get the data
:param report_model: Object that herit from ReportModel and define
the type of Report
:param stream_mode: Define if we read in stream mode
"""
raise NotImplementedError()
Expand All @@ -102,7 +99,6 @@ def save(self, report: Report):
Allow to save a json input in the db
:param report: Report
:param report_model: ReportModel
"""
raise NotImplementedError()

Expand All @@ -111,6 +107,5 @@ def save_many(self, reports: List[Report]):
Allow to save a batch of data
:param reports: Batch of Serialized Report
:param report_model: ReportModel
"""
raise NotImplementedError()
13 changes: 5 additions & 8 deletions powerapi/database/csvdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import csv
import os

Expand Down Expand Up @@ -65,10 +64,10 @@ class CsvIterDB(IterDB):
This class allows to browse a database as an iterable
"""

def __init__(self, db, filenames, report_model, stream_mode):
def __init__(self, db, filenames, report_type, stream_mode):
"""
"""
super().__init__(db, report_model, stream_mode)
super().__init__(db, report_type, stream_mode)

self.filenames = filenames

Expand Down Expand Up @@ -160,15 +159,15 @@ def __next__(self) -> Report:
if row_timestamp > current_timestamp:
if path_file == self.filenames[-1]:
self.saved_timestamp = row_timestamp
break # move to next file
break # move to next file

if row_timestamp < current_timestamp:
self.tmp_read[path_file]['next_line'] = self._next(path_file)
continue

if previous_target is not None:
if row['target'] != previous_target:
break # move to next file
break # move to next file
else:
previous_target = row['target']

Expand All @@ -191,7 +190,7 @@ class CsvDB(BaseDB):
CsvDB class herited from BaseDB
This class define the behaviour for reading some csv file.
a CsvDB instance can be define by his ReportModel and its current path
a CsvDB instance can be define by its current path
"""

def __init__(self, report_type: Type[Report], tags: List[str], current_path="/tmp/csvdbtest", files=[]):
Expand Down Expand Up @@ -265,7 +264,6 @@ def save(self, report: Report):
Allow to save a serialized_report in the db
:param report: Report
:param report_model: ReportModel
"""
csv_header, data = self.report_type.to_csv_lines(report, self.tags)

Expand Down Expand Up @@ -308,7 +306,6 @@ def save_many(self, reports: List[Report]):
Allow to save a batch of report
:param reports: Batch of report.
:param report_model: ReportModel
"""
for report in reports:
self.save(report)
2 changes: 1 addition & 1 deletion powerapi/database/direct_prometheus_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
except ImportError:
logging.getLogger().info("prometheus-client is not installed.")

from powerapi.database import BaseDB
from powerapi.report import Report
from .base_db import BaseDB


class DirectPrometheusDB(BaseDB):
Expand Down
10 changes: 2 additions & 8 deletions powerapi/database/influxdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,16 @@
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


import logging
from typing import List, Type
try:
from influxdb import InfluxDBClient
from requests.exceptions import ConnectionError as InfluxConnectionError
except ImportError:
logging.getLogger().info("influx-client is not installed.")

from typing import List, Type


from powerapi.database import BaseDB, DBError

from powerapi.report import Report
from .base_db import BaseDB, DBError


class CantConnectToInfluxDBException(DBError):
Expand Down Expand Up @@ -126,7 +121,6 @@ def save_many(self, reports: List[Report]):
Save a batch of data
:param reports: Batch of data.
:param report_model: ReportModel
"""

data_list = list(map(lambda r: self.report_type.to_influxdb(r, self.tags), reports))
Expand Down
3 changes: 1 addition & 2 deletions powerapi/database/opentsdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from typing import List, Type

from powerapi.report import PowerReport, Report
from powerapi.database import BaseDB, DBError
from .base_db import BaseDB, DBError


class CantConnectToOpenTSDBException(DBError):
Expand Down Expand Up @@ -105,7 +105,6 @@ def save_many(self, reports: List[Report]):
Save a batch of data
:param reports: Batch of data.
:param report_model: ReportModel
"""

for report in reports:
Expand Down
6 changes: 2 additions & 4 deletions powerapi/database/prometheus_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,15 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import logging
from typing import List, Type
try:
from prometheus_client import start_http_server, Gauge
except ImportError:
logging.getLogger().info("prometheus-client is not installed.")

from typing import List, Type

from powerapi.database import BaseDB

from powerapi.report import Report
from powerapi.utils import StatBuffer
from .base_db import BaseDB


class PrometheusDB(BaseDB):
Expand Down
9 changes: 5 additions & 4 deletions powerapi/database/socket_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
from typing import Type, List
import json

from powerapi.database import IterDB, BaseDB

from powerapi.utils import JsonStream
from powerapi.report import Report
from .base_db import IterDB, BaseDB, DBError

BUFFER_SIZE = 4096
SOCKET_TIMEOUT = 0.5
Expand Down Expand Up @@ -77,13 +78,13 @@ async def callback(stream_reader, _):
return callback

def __iter__(self):
raise NotImplementedError()
raise DBError('Socket db don\'t support __iter__ method')

def save(self, report: Report):
raise NotImplementedError()
raise DBError('Socket db don\'t support save method')

def save_many(self, reports: List[Report]):
raise NotImplementedError()
raise DBError('Socket db don\'t support save_many method')


class IterSocketDB(IterDB):
Expand Down
14 changes: 8 additions & 6 deletions powerapi/database/virtiofs_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

from typing import List, Type

from powerapi.database import BaseDB, DBError
from powerapi.report import Report
from .base_db import BaseDB, DBError


class DirectoryDoesNotExistForVirtioFS(DBError):
Expand All @@ -47,18 +47,20 @@ class VirtioFSDB(BaseDB):
"""
write power consumption of virtual machine in a file shared with the virtual machine
The File will be written in a directory created by the VM manager.
The File will be written in a directory created by the VM manager.
A regular expression must be given by the VM manager to extract vm name from target name. VM name is used to find directory that contains the output file.
"""
def __init__(self, report_type: Type[Report], vm_name_regexp: str, root_directory_name: str, vm_directory_name_prefix : str = '', vm_directory_name_suffix : str = ''):
def __init__(self, report_type: Type[Report], vm_name_regexp: str, root_directory_name: str,
vm_directory_name_prefix: str = '', vm_directory_name_suffix: str = ''):
"""
:param vm_name_regexp: regexp used to extract vm name from report. The regexp must match the name of the target in the HWPC-report and a group must
:param vm_name_regexp: regexp used to extract vm name from report. The regexp must match the name of the target
in the HWPC-report and a group must
:param root_directory_name: directory where VM directory will be stored
:param vm_directory_name_prefix: first part of the VM directory name
:param vm_directory_name_suffix: last part of the VM directory name
"""
BaseDB.__init__(self)
BaseDB.__init__(self, report_type)

self.vm_name_regexp = re.compile(vm_name_regexp)
self.root_directory_name = root_directory_name
Expand All @@ -82,7 +84,7 @@ def save(self, report: Report):
return

vm_filename, power = self.report_type.to_virtiofs_db(report)
vm_filename_path =self.root_directory_name + '/' + directory_name + '/'
vm_filename_path = self.root_directory_name + '/' + directory_name + '/'
if not os.path.exists(vm_filename_path):
raise DirectoryDoesNotExistForVirtioFS(vm_filename_path)

Expand Down
4 changes: 2 additions & 2 deletions powerapi/dispatch_rule/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (c) 2018, INRIA
# Copyright (c) 2018, University of Lille
# Copyright (c) 2021, INRIA
# Copyright (c) 2021, University of Lille
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down
4 changes: 2 additions & 2 deletions powerapi/dispatch_rule/dispatch_rule.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (c) 2018, INRIA
# Copyright (c) 2018, University of Lille
# Copyright (c) 2021, INRIA
# Copyright (c) 2021, University of Lille
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down
6 changes: 3 additions & 3 deletions powerapi/dispatch_rule/hwpc_dispatch_rule.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (c) 2018, INRIA
# Copyright (c) 2018, University of Lille
# Copyright (c) 2021, INRIA
# Copyright (c) 2021, University of Lille
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -29,7 +29,7 @@

from enum import IntEnum

from powerapi.dispatch_rule import DispatchRule
from .dispatch_rule import DispatchRule


class HWPCDepthLevel(IntEnum):
Expand Down
Loading

0 comments on commit d2039b2

Please sign in to comment.