Skip to content

Commit

Permalink
Fix some code style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Bechberger committed Jul 22, 2020
1 parent b68f922 commit 0d5fe5d
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 61 deletions.
4 changes: 2 additions & 2 deletions temci/build/build_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BuildProcessor:
Build programs
"""

block_scheme = Dict({ # type: Dict
block_scheme = Dict({
"attributes": ATTRIBUTES_TYPE,
"run_config": Dict(unknown_keys=True) // Description("Run configuration for this program block"),
"build_config": Dict({
Expand All @@ -30,7 +30,7 @@ class BuildProcessor:
"base_dir": (DirName() | NonExistent()) // Default(".")
// Description("Base directory that contains everything to build an run the program")
}, unknown_keys=True) // Description("Build configuration for this program block")
})
}) # type: Dict
""" Type scheme of the program block configurations """

def __init__(self, build_blocks: t.Optional[t.List[t.Dict[str, t.Any]]] = None):
Expand Down
2 changes: 1 addition & 1 deletion temci/build/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, id: int, build_dir: str, build_cmd: str, revision: t.Union[st
""" Used version control system revision of the program """
self.number = number # type: int
""" Number of times to build this program """
self.vcs_driver = VCSDriver.get_suited_vcs(dir=self.build_dir, branch=None if branch is "" else branch)
self.vcs_driver = VCSDriver.get_suited_vcs(dir=self.build_dir, branch=None if branch == "" else branch)
""" Used version control system driver """
self.id = id

Expand Down
4 changes: 2 additions & 2 deletions temci/misc/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -1503,7 +1503,7 @@ def replace_run_with_build_cmd(config_dict: ConfigDict) -> ConfigDict:
BENCH_PATH = "/home/parttimenerd/benchmarksgame/bench"

# Inputs based on the ones used in the benchmarksgame
INPUTS_PER_CATEGORY = { # type: InputsPerCategory
INPUTS_PER_CATEGORY = {
"binarytrees": Input.list_from_numbers(12, 16, 20),
"binarytreesredux": Input.list_from_numbers(12, 16, 20),
"chameneosredux": Input.list_from_numbers(60000, 600000, 6000000),
Expand All @@ -1519,7 +1519,7 @@ def replace_run_with_build_cmd(config_dict: ConfigDict) -> ConfigDict:
"revcomp": prefix_inputs("$INPUT/revcomp-input.txt ", Input.list_from_numbers(250000, 2500000, 25000000)),
"spectralnorm": Input.list_from_numbers(500, 3000, 5500),
"threadring": Input.list_from_numbers(500000, 5000000, 50000000)
}
} # type: InputsPerCategory


def c_config(inputs_per_category: InputsPerCategory, optimisation: str = "-O2", clang_version = "3.7") -> ConfigDict:
Expand Down
8 changes: 4 additions & 4 deletions temci/report/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,10 +883,10 @@ def header_popover_func(elem, index: int, is_header_row: bool):
(geometric standard deviation is {std})</p>
""".format(po=_Popover(self, "Explanation", """
Geometric mean of the means of the first relative to the means of the second:
\\[\\sqrt[\|properties\|]{
\\prod_{p \in \\text{properties}}
\\[\\sqrt[\\|properties\\|]{
\\prod_{p \\in \\text{properties}}
\\frac{\\overline{\\text{first[p]}}}{
\\overline{\\text{second[p]}}}}\]
\\overline{\\text{second[p]}}}}\\]
Using the more widely known would be like
<a href='http://ece.uprm.edu/~nayda/Courses/Icom6115F06/Papers/paper4.pdf?origin=publication_detail'>
lying</a>.
Expand Down Expand Up @@ -1827,7 +1827,7 @@ def error():
if parts[1][:-1].split("|")[0] not in valid_csv_reporter_modifiers or \
len(parts[0]) < 1 or any(x not in FORMAT_OPTIONS for x in opt):
error()
return parts[0], prop, [x for x in opt if x is not " "]
return parts[0], prop, [x for x in opt if x != " "]


def _is_valid_csv_reporter_spec_list(specs: t.List[str]) -> bool:
Expand Down
6 changes: 3 additions & 3 deletions temci/report/rundata.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ def __init__(self, runs: t.List[RunData], tester: Tester = None, external_count:
:param errorneous_runs: runs that resulted in errors
:param included_blocks: include query
"""
self.tester = tester or TesterRegistry.get_for_name(TesterRegistry.get_used(), # type: Tester
Settings()["stats/uncertainty_range"])
self.tester = tester or TesterRegistry.get_for_name(TesterRegistry.get_used(),
Settings()["stats/uncertainty_range"]) # type: Tester
""" Used statistical tester """
typecheck(runs, List(T(RunData)))
self.runs = filter_runs(runs, included_blocks or Settings()["report/included_blocks"]) # type: t.List[RunData]
Expand Down Expand Up @@ -391,7 +391,7 @@ def get_description_clusters_and_single(self) -> t.Tuple[t.List['RunData'], t.Di
new_clusters = util.InsertionTimeOrderedDict()
single = []
for n, c in clusters.items():
if len(c) is 1:
if len(c) == 1:
single.extend(c)
else:
new_clusters[n] = c
Expand Down
4 changes: 2 additions & 2 deletions temci/report/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -1156,9 +1156,9 @@ def __init__(self, parent: TestedPair, first: Single, second: Single, property:
""" First of the two compared single property objects """
self.second = SingleProperty(second, second.rundata, property)
""" Second of the two compared single property objects """
self.tester = tester or TesterRegistry.get_for_name(TesterRegistry.get_used(), # type: Tester
self.tester = tester or TesterRegistry.get_for_name(TesterRegistry.get_used(),
Settings()["stats/tester"],
Settings()["stats/uncertainty_range"])
Settings()["stats/uncertainty_range"]) # type: Tester
""" Used statistical tester for the comparisons """
self.property = property
""" Regarded specific property """
Expand Down
45 changes: 23 additions & 22 deletions temci/run/run_driver.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
"""
This modules contains the base run driver, needed helper classes and registries.
"""
import os
import collections
import datetime
import gc
import logging
import os
import random
import re
import shlex
import shutil
import collections
import subprocess
import time
import typing as t
from collections import namedtuple
from copy import deepcopy

import humanfriendly
import yaml

from temci.build.build_processor import BuildProcessor
from ..setup import setup
from temci.utils.config_utils import ATTRIBUTES_TYPE
from temci.utils.settings import Settings
from temci.utils.sudo_utils import get_bench_user, bench_as_different_user, get_env_setting
from temci.utils.typecheck import NoInfo
from temci.utils.util import has_root_privileges, join_strs, does_command_succeed, sphinx_doc, on_apple_os, \
does_program_exist, document, proc_wait_with_rusage, rusage_header
from temci.utils.vcs import VCSDriver
from ..utils.typecheck import *
from ..utils.registry import AbstractRegistry, register
from .cpuset import CPUSet
from copy import deepcopy
import logging, time, random, subprocess
from collections import namedtuple
import gc
import typing as t
from ..setup import setup
from ..utils.registry import AbstractRegistry, register
from ..utils.typecheck import *

Number = t.Union[int, float]
""" Numeric value """
Expand Down Expand Up @@ -85,11 +88,11 @@ def parts(block) -> t.List[str]:
def match(block):
return ["all"] == included or any(p in included or any(re.fullmatch(i, p) for i in included)
for p in parts(block))
list = [block for block in blocks if match(block)]
for i, x in enumerate(list):
l = [block for block in blocks if match(block)]
for i, x in enumerate(l):
if isinstance(x, RunProgramBlock):
x.id = i
return list
return l


class RunProgramBlock:
Expand Down Expand Up @@ -303,8 +306,8 @@ def __init__(self, misc_settings: dict = None):
else:
self.used_plugins.append(self.get_for_name(used))
if miss_root_plugins:
logging.warning("The following plugins are disabled because they need root privileges (consider using `--sudo`): " +
join_strs(miss_root_plugins))
logging.warning("The following plugins are disabled because they need root privileges "
"(consider using `--sudo`): %s", join_strs(miss_root_plugins))
self.setup()

def setup(self):
Expand Down Expand Up @@ -562,13 +565,13 @@ def _eq_impl(self, other):
return True


_intel = ",disable_intel_turbo" if does_command_succeed("ls /sys/devices/system/cpu/intel_pstate/no_turbo") else ""
_INTEL = ",disable_intel_turbo" if does_command_succeed("ls /sys/devices/system/cpu/intel_pstate/no_turbo") else ""

PRESET_PLUGIN_MODES = {
"none": ("", "enable none by default"),
"all": ("cpu_governor,disable_swap,sync,stop_start,other_nice,nice,disable_aslr,disable_ht,cpuset" + _intel,
"all": ("cpu_governor,disable_swap,sync,stop_start,other_nice,nice,disable_aslr,disable_ht,cpuset" + _INTEL,
"enable all, might freeze your system"),
"usable": ("cpu_governor,disable_swap,sync,nice,disable_aslr,disable_ht,cpuset" + _intel,
"usable": ("cpu_governor,disable_swap,sync,nice,disable_aslr,disable_ht,cpuset" + _INTEL,
"like 'all' but doesn't affect other processes")
}

Expand Down Expand Up @@ -1473,7 +1476,7 @@ def parse_result_impl(self, exec_res: ExecRunDriver.ExecResult,
for (i, part) in enumerate(parts):
try:
m[self.misc["properties"][i]] = float(part)
except:
except BaseException:
pass
res.add_run_data(m)
return res
Expand All @@ -1494,9 +1497,6 @@ class OutputExecRunner(ExecRunner):
name = "output"
misc_options = Dict({})

def __init__(self, block: RunProgramBlock):
super().__init__(block)

def setup_block(self, block: RunProgramBlock, cpuset: CPUSet = None, set_id: int = 0):
pass

Expand Down Expand Up @@ -1554,6 +1554,7 @@ def __init__(self, recorded_error: 'RecordedProgramError'):


class TimeoutException(BenchmarkingProgramError):
""" Thrown whenever a benchmarked program timeouts """

def __init__(self, cmd: str, timeout: float, out: str, err: str, ret_code: int):
from temci.report.rundata import RecordedProgramError
Expand Down
2 changes: 1 addition & 1 deletion temci/run/run_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def build(self):
if self.no_build:
return
to_build = [(i, conf) for i, conf in enumerate(self.runs) if "build_config" in conf]
if len(to_build) is 0:
if len(to_build) == 0:
return
logging.info("Start building {} block(s)".format(len(to_build)))
for i, block in to_build:
Expand Down
6 changes: 3 additions & 3 deletions temci/utils/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __str__(self) -> str:
return str(self.number)
dev = self.deviation
parentheses = self.parentheses
if dev is None or dev is 0:
if dev is None or dev == 0:
dev = 0
parentheses = False
num = self.number
Expand Down Expand Up @@ -294,7 +294,7 @@ def _format_number(number: Number, deviation: float,
if last_sig >= 0: # decimal part is insignificant
if not omit_insignificant_decimal_places or force_min_decimal_places:
dec_part = "{{:.{}f}}".format(decimal_places).format(number - math.floor(number))[2:]
if max_decimal_places is not 0:
if max_decimal_places != 0:
num += "."
if parentheses:
num += "(" + dec_part + ")"
Expand All @@ -304,7 +304,7 @@ def _format_number(number: Number, deviation: float,
dec_digits = min_decimal_places
dec_part = "{{:.{}f}}".format(decimal_places)
dec_part = dec_part.format(number - math.floor(number))[2:]
if max_decimal_places is not 0:
if max_decimal_places != 0:
num += "."
if parentheses and len(dec_part[abs(last_sig):]) > 0:
num += dec_part[0:abs(last_sig)] + "(" + dec_part[abs(last_sig):] + ")"
Expand Down
6 changes: 3 additions & 3 deletions temci/utils/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Settings(metaclass=Singleton):

config_file_name = "temci.yaml" # type: str
""" Default name of the configuration files """
type_scheme = Dict({ # type: Dict
type_scheme = Dict({
"settings": Str() // Description("Additional settings file")
// Default(config_file_name if os.path.exists(config_file_name) else "")
// CompletionHint(zsh=YAML_FILE_COMPLETION_HINT),
Expand Down Expand Up @@ -160,7 +160,7 @@ class Settings(metaclass=Singleton):
"generated files"),
"sudo": Bool() // Default(False) // Description("Acquire sudo privileges and run benchmark programs with "
"non-sudo user. Only supported on the command line.")
}, unknown_keys=True)
}, unknown_keys=True) # type: Dict
""" Type scheme of the settings """

def __init__(self):
Expand Down Expand Up @@ -341,7 +341,7 @@ def _set(self, path: t.List[str], value):
tmp_pref[path[-1]] = value
if path[-1] not in tmp_type.data:
tmp_type[path[-1]] = Any() // Default(value)
if (path == ["config"] or path == ["settings"]) and value is not "":
if (path == ["config"] or path == ["settings"]) and value != "":
self.load_file(value)
self._update_doc()

Expand Down
26 changes: 13 additions & 13 deletions temci/utils/typecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def __init__(self, value_name: str = None, value = None, _app_str: str = None):
:param value_name: name of the value that is type checked
:param value: value that is type checked
"""
self.value_name = value_name # type: str
self.value_name = value_name # type: t.Optional[str]
""" Name of the value that is typechecked """
self._app_str = _app_str or "" # type: str
if value_name is None:
Expand Down Expand Up @@ -1269,12 +1269,12 @@ def __init__(self, constraint: t.Callable[[t.Any], bool] = None, range: range =
self.description = description # type: str
""" Description of the constraints """
if range is not None and len(range) <= 20:
self.completion_hints = { # type: t.Dict[str, t.Any]
self.completion_hints = {
"zsh": "({})".format(" ".join(str(x) for x in range)),
"fish": {
"hint": list(self.range)
}
}
} # type: t.Dict[str, t.Any]
""" Completion hints for supported shells for this type instance """

def _instancecheck_impl(self, value, info: Info) -> InfoMsg:
Expand Down Expand Up @@ -1406,12 +1406,12 @@ def __init__(self, constraint: t.Callable[[t.Any], bool] = None, allow_std: bool
super().__init__()
self.constraint = constraint # type: t.Optional[t.Callable[[t.Any], bool]]
""" Function that returns True if the user defined constraint is satisfied """
self.completion_hints = { # type: t.Dict[str, t.Any]
self.completion_hints = {
"zsh": "_files",
"fish": {
"files": True
}
}
} # type: t.Dict[str, t.Any]
""" Completion hints for supported shells for this type instance """
self.allow_std = allow_std # type: bool
""" Allow '-' as standard out or in """
Expand Down Expand Up @@ -1462,12 +1462,12 @@ def __init__(self, allow_non_existent: bool = False):
:param allow_non_existent: allow files that don't exist
"""
super().__init__()
self.completion_hints = { # type: t.Dict[str, t.Any]
self.completion_hints = {
"zsh": "_files",
"fish": {
"files": True
}
}
} # type: t.Dict[str, t.Any]
""" Completion hints for supported shells for this type instance """
self.allow_non_existent = allow_non_existent # type: bool
""" Allow files that don't exist """
Expand Down Expand Up @@ -1509,12 +1509,12 @@ def __init__(self, constraint: t.Callable[[t.Any], bool] = None):
super().__init__()
self.constraint = constraint # type: t.Optional[t.Callable[[t.Any], bool]]
""" Function that returns True if the user defined constraint is satisfied """
self.completion_hints = { # type: t.Dict[str, t.Any]
self.completion_hints = {
"zsh": "_directories",
"fish": {
"files": True
}
}
} # type: t.Dict[str, t.Any]
""" Completion hints for supported shells for this type instance """

def _instancecheck_impl(self, value, info: Info) -> InfoMsg:
Expand Down Expand Up @@ -1554,12 +1554,12 @@ class BoolOrNone(Type, click.ParamType):

def __init__(self):
super().__init__()
self.completion_hints = { # type: t.Dict[str, t.Any]
self.completion_hints = {
"zsh": "(true, false, none)",
"fish": {
"hint": ["true", "false", "none"]
}
}
} # type: t.Dict[str, t.Any]
""" Completion hints for supported shells for this type instance """
self.default = None # type: None
""" The default value of this instance """
Expand Down Expand Up @@ -1602,12 +1602,12 @@ class Bool(Type, click.ParamType):

def __init__(self):
super().__init__()
self.completion_hints = { # type: t.Dict[str, t.Any]
self.completion_hints = {
"zsh": "(true, false)",
"fish": {
"hint": ["true", "false"]
}
}
} # type: t.Dict[str, t.Any]
""" Completion hints for supported shells for this type instance """

def _instancecheck_impl(self, value, info: Info) -> InfoMsg:
Expand Down

0 comments on commit 0d5fe5d

Please sign in to comment.