Skip to content

Commit 49b189e

Browse files
PEP8 standards (#72)
* PEP8 and formatting standards compliant code ( including ci checkers as well ) * Bumping version from 0.1.59 to 0.1.60
1 parent 3781fd0 commit 49b189e

28 files changed

+320
-224
lines changed

.flake8

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[flake8]
2+
max-line-length = 120
3+
max-complexity = 10
4+
select = C,E,F,W,B,B950
5+
ignore = E203,E501,W503,E722,B001,C901
6+
exclude =
7+
.git,
8+
test_*,
9+
__pycache__,
10+
*.egg-info,
11+
.nox,
12+
.pytest_cache,
13+
.mypy_cache

.github/workflows/poetry-pytest.yml renamed to .github/workflows/poetry-ci-test-lint.yml

+7-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77

88
jobs:
99
pytest:
10-
name: pytest
10+
name: Linting, testing, and compliance
1111
runs-on: ubuntu-latest
1212
env:
1313
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
@@ -39,10 +39,13 @@ jobs:
3939
run: poetry install
4040
if: steps.cache.outputs.cache-hit != 'true'
4141

42+
- name: Check formatting compliance with black
43+
run: poetry run black --check .
44+
45+
- name: Check PEP8 compliance with flake
46+
run: poetry run flake8
47+
4248
- name: Test with pytest
43-
env:
44-
DJANGO_SETTINGS_MODULE: project.settings
45-
SECRETS_FILE: .confidential/ci.json
4649
run: poetry run pytest --cov redisbench_admin
4750

4851
- name: Upload coverage

poetry.lock

+55-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "redisbench-admin"
3-
version = "0.1.59"
3+
version = "0.1.60"
44
description = "Redis benchmark run helper. A wrapper around Redis and Redis Modules benchmark tools ( ftsb_redisearch, memtier_benchmark, redis-benchmark, aibench, etc... )."
55
authors = ["filipecosta90 <[email protected]>"]
66
readme = "README.md"
@@ -32,6 +32,7 @@ pytest = "^4.6"
3232
pytest-cov = "^2.9.0"
3333
codecov = "^2.1.4"
3434
black = "^20.8b1"
35+
flake8 = "^3.9.1"
3536

3637
[build-system]
3738
requires = ["poetry>=0.12"]

redisbench_admin/cli.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ def populate_with_poetry_data():
3939

4040

4141
def main():
42-
tool = None
4342
if len(sys.argv) < 2:
4443
print(
45-
"A minimum of 2 arguments is required: redisbench-admin <tool> <arguments>. Use redisbench-admin --help if you need further assistance."
44+
"A minimum of 2 arguments is required: redisbench-admin <tool> <arguments>."
45+
" Use redisbench-admin --help if you need further assistance."
4646
)
4747
sys.exit(1)
4848
requested_tool = sys.argv[1]

redisbench_admin/export/args.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def create_export_arguments(parser):
2121
"--results-format",
2222
type=str,
2323
default="redis-benchmark",
24-
help="results format of the the benchmark results files to read results from ( either memtier_benchmark, redis-benchmark, or ftsb_redisearch )",
24+
help="results format of the the benchmark results files to read "
25+
"results from ( either memtier_benchmark, redis-benchmark, or ftsb_redisearch )",
2526
)
2627
parser.add_argument(
2728
"--use-result",

redisbench_admin/export/common/common.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ def split_tags_string(extra_tags):
5656
def split_key_metrics_by_step(key_metrics_specs):
5757
key_metrics_by_step = {}
5858
for key_metric_spec in key_metrics_specs:
59-
step = None
6059
if "step" in key_metric_spec and "metric-name" in key_metric_spec:
6160
step = key_metric_spec["step"]
6261
metric_name = key_metric_spec["metric-name"]
@@ -66,10 +65,10 @@ def split_key_metrics_by_step(key_metrics_specs):
6665
return key_metrics_by_step
6766

6867

69-
def get_or_none(dict, property):
68+
def get_or_none(dictionary, prop: str):
7069
result = None
71-
if property in dict:
72-
result = dict[property]
70+
if prop in dictionary:
71+
result = dictionary[prop]
7372
return result
7473

7574

redisbench_admin/export/export.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ def export_command_logic(args):
1616
benchmark_files = args.benchmark_result_files
1717
local_path = os.path.abspath(args.local_dir)
1818
results_format = args.results_format
19-
use_result = args.use_result
20-
included_steps = args.steps.split(",")
2119
input_tags_json = args.input_tags_json
22-
start_time_ms = None
2320
extra_tags_array = split_tags_string(args.extra_tags)
2421

2522
if input_tags_json != "":
@@ -37,13 +34,9 @@ def export_command_logic(args):
3734
benchmark_results = retrieve_local_or_remote_input_json(
3835
benchmark_files, local_path, "--benchmark-result-files", "csv"
3936
)
40-
for filename, benchmark_result in benchmark_results.items():
37+
for _, benchmark_result in benchmark_results.items():
4138
ok, time_series_dict = redis_benchmark_export_logic(
42-
benchmark_result,
43-
extra_tags_array,
44-
results_type,
45-
time_series_dict,
46-
use_result,
39+
benchmark_result, extra_tags_array, results_type, time_series_dict
4740
)
4841

4942
elif results_format == "memtier_benchmark":
@@ -58,7 +51,7 @@ def export_command_logic(args):
5851
for timeseries_name, time_series in time_series_dict.items():
5952
try:
6053
rts.create(timeseries_name, labels=time_series["tags"])
61-
except redis.exceptions.ResponseError as e:
54+
except redis.exceptions.ResponseError:
6255
# if ts already exists continue
6356
pass
6457
for pos, timestamp in enumerate(time_series["index"]):

redisbench_admin/export/redis_benchmark/redis_benchmark_csv_format.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,22 @@
1111
)
1212

1313

14-
def warn_if_tag_none(tagName, tagValue, tool, level="Warning"):
15-
if tagValue is None:
14+
def warn_if_tag_none(tag_name, tag_value, tool, level="Warning"):
15+
if tag_value is None:
1616
print(
17-
'{}! The tag "{}" is None. Given that {} cannot infer it you should pass it via --extra-tags {}=<value>'.format(
18-
level, tagName, tool, tagName
17+
'{}! The tag "{}" is None. Given that {} cannot infer'
18+
" it you should pass it via --extra-tags {}=<value>".format(
19+
level, tag_name, tool, tag_name
1920
)
2021
)
2122

2223

23-
def get_tag_fromextra_tags_array(array, tagName):
24+
def get_tag_fromextra_tags_array(array, tag_name):
2425
result = None
25-
for innerDict in array:
26-
inneResult = get_or_none(innerDict, tagName)
27-
if inneResult is not None:
28-
result = inneResult
26+
for inner_dict in array:
27+
inne_result = get_or_none(inner_dict, tag_name)
28+
if inne_result is not None:
29+
result = inne_result
2930
return result
3031

3132

@@ -50,7 +51,7 @@ def fill_tags_from_passed_array(extra_tags_array):
5051

5152

5253
def redis_benchmark_export_logic(
53-
benchmark_result, extra_tags_array, results_type, time_series_dict, use_result
54+
benchmark_result, extra_tags_array, results_type, time_series_dict
5455
):
5556
ok = True
5657
start_time_ms = get_tag_fromextra_tags_array(extra_tags_array, "start_time_ms")
@@ -75,7 +76,6 @@ def redis_benchmark_export_logic(
7576
step,
7677
) = fill_tags_from_passed_array(extra_tags_array)
7778

78-
metrics = {}
7979
col0_row0 = benchmark_result["col_0"][0]
8080
# new format
8181
# "test","rps","avg_latency_ms","min_latency_ms","p50_latency_ms","p95_latency_ms","p99_latency_ms","max_latency_ms"

redisbench_admin/extract/args.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def create_extract_arguments(parser):
2121
"--upload-results-s3",
2222
default=False,
2323
action="store_true",
24-
help="uploads the result files and configuration file to public benchmarks.redislabs bucket. Proper credentials are required",
24+
help="uploads the result files and configuration file to public "
25+
"'benchmarks.redislabs' bucket. Proper credentials are required",
2526
)
2627
parser.add_argument(
2728
"--cluster-mode",

0 commit comments

Comments
 (0)