Skip to content

Commit e0006f8

Browse files
committed
Fix python styling and flake8 issues
1 parent 1794ab3 commit e0006f8

File tree

11 files changed

+40
-47
lines changed

11 files changed

+40
-47
lines changed

.github/workflows/static_analysis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@ jobs:
2424
pip install --upgrade flake8
2525
- name: Run flake8
2626
run: flake8 benchmark scorep test
27-
continue-on-error: true # Not conformant yet

benchmark/benchmark.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010
tests = ["test_1.py", "test_2.py"]
1111
results = {}
1212

13-
reps_x={}
14-
reps_x["test_1.py"]=["1000000", "2000000", "3000000", "4000000", "5000000"]
15-
reps_x["test_2.py"]=["100000", "200000", "300000", "400000", "500000"]
16-
13+
reps_x = {}
14+
reps_x["test_1.py"] = ["1000000", "2000000", "3000000", "4000000", "5000000"]
15+
reps_x["test_2.py"] = ["100000", "200000", "300000", "400000", "500000"]
1716

1817
for test in tests:
1918
results[test] = {"profile": {}, "trace": {}, "dummy": {}, "None": {}}
2019
for instrumenter in results[test]:
21-
if instrumenter is "None":
20+
if instrumenter == "None":
2221
enable_scorep = False
2322
scorep_settings = []
2423
else:
@@ -29,11 +28,9 @@
2928
print("{}: {}".format(test, scorep_settings))
3029
print("#########")
3130
for reps in reps_x[test]:
32-
times = bench.call(
33-
test,
34-
[reps],
35-
enable_scorep,
36-
scorep_settings=scorep_settings)
31+
times = bench.call(test, [reps],
32+
enable_scorep,
33+
scorep_settings=scorep_settings)
3734
results[test][instrumenter][reps] = times
3835
print("{:<8}: {}".format(reps, times))
3936

benchmark/benchmark_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def call(self, script="", ops=[], enable_scorep=True, scorep_settings=[]):
4040
runtimes = []
4141
for i in range(self.repetitions):
4242
begin = time.time()
43-
print (arguments)
43+
print(arguments)
4444
out = subprocess.run(
4545
arguments,
4646
env=self.env,

scorep/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
import scorep.user
2-
import scorep.instrumenter
31
__all__ = ["user", "instrumenter"]

scorep/__main__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ def scorep_main(argv=None):
6666
os.environ["SCOREP_PYTHON_BINDINGS_INITALISED"] != "true"):
6767
scorep.subsystem.init_environment(scorep_config, keep_files)
6868
os.environ["SCOREP_PYTHON_BINDINGS_INITALISED"] = "true"
69-
7069
"""
7170
python -m starts the module as skript. i.e. sys.argv will loke like:
7271
['/home/gocht/Dokumente/code/scorep_python/scorep.py', '--mpi', 'mpi_test.py']
@@ -91,8 +90,9 @@ def scorep_main(argv=None):
9190
progname = prog_argv[0]
9291
sys.path[0] = os.path.split(progname)[0]
9392

94-
tracer = scorep.instrumenter.get_instrumenter(
95-
scorep_bindings, not no_instrumenter, instrumenter_type)
93+
tracer = scorep.instrumenter.get_instrumenter(scorep_bindings,
94+
not no_instrumenter,
95+
instrumenter_type)
9696
try:
9797
with open(progname) as fp:
9898
code = compile(fp.read(), progname, 'exec')
@@ -120,7 +120,8 @@ def main(argv=None):
120120
call_stack_string += elem
121121
_err_exit(
122122
"Someone called scorep.__main__.main(argv).\n"
123-
"This is not supposed to happen, but might be triggered, if your application calls \"sys.modules['__main__'].main\".\n"
123+
"This is not supposed to happen, but might be triggered, "
124+
"if your application calls \"sys.modules['__main__'].main\".\n"
124125
"This python stacktrace might be helpfull to find the reason:\n%s" %
125126
call_stack_string)
126127

scorep/instrumenter.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
global_instrumenter = None
99

1010

11-
def get_instrumenter(
12-
bindings=None,
13-
enable_instrumenter=False,
14-
instrumenter_type="dummy"):
11+
def get_instrumenter(bindings=None,
12+
enable_instrumenter=False,
13+
instrumenter_type="dummy"):
1514
"""
1615
returns an instrumenter
1716
1817
@param bindings the c/c++ scorep bindings
1918
@param enable_instrumenter True if the Instrumenter should be enabled when run is called
20-
@param instrumenter_type which python tracing interface to use. Currently available: `profile` (default), `trace` and `dummy`
19+
@param instrumenter_type which python tracing interface to use.
20+
Currently available: `profile` (default), `trace` and `dummy`
2121
"""
2222
global global_instrumenter
2323
if global_instrumenter is None:
@@ -47,7 +47,8 @@ def register():
4747
def unregister():
4848
"""
4949
Disables the python-tracing.
50-
Disabling the python-tracing is more efficient than disable_recording, as python does not longer call the tracing module.
50+
Disabling the python-tracing is more efficient than disable_recording,
51+
as python does not longer call the tracing module.
5152
However, all the other things that are traced by Score-P will still be recorded.
5253
Please call register() to enable tracing again.
5354
"""
@@ -62,14 +63,14 @@ class enable():
6263
do stuff
6364
```
6465
This overides --no-instrumenter (--nopython leagacy)
65-
@param region_name: if a region name is given, the region the contextmanager is active will be marked in the trace or profile
66+
If a region name is given, the region the contextmanager is active will be marked in the trace or profile
6667
"""
67-
6868
def __init__(self, region_name=None):
6969
self.region_name = region_name
7070

7171
def __enter__(self):
72-
self.tracer_registered = scorep.instrumenter.get_instrumenter().get_registered()
72+
self.tracer_registered = scorep.instrumenter.get_instrumenter(
73+
).get_registered()
7374
if not self.tracer_registered:
7475
if self.region_name:
7576
self.module_name = "user_instrumenter"
@@ -82,7 +83,8 @@ def __enter__(self):
8283
full_file_name = "None"
8384

8485
scorep.instrumenter.get_instrumenter().region_begin(
85-
self.module_name, self.region_name, full_file_name, line_number)
86+
self.module_name, self.region_name, full_file_name,
87+
line_number)
8688

8789
scorep.instrumenter.get_instrumenter().register()
8890

@@ -103,14 +105,14 @@ class disable():
103105
do stuff
104106
```
105107
This overides --no-instrumenter (--nopython leagacy)
106-
@param region_name: if a region name is given, the region the contextmanager is active will be marked in the trace or profile
108+
If a region name is given, the region the contextmanager is active will be marked in the trace or profile
107109
"""
108-
109110
def __init__(self, region_name=None):
110111
self.region_name = region_name
111112

112113
def __enter__(self):
113-
self.tracer_registered = scorep.instrumenter.get_instrumenter().get_registered()
114+
self.tracer_registered = scorep.instrumenter.get_instrumenter(
115+
).get_registered()
114116
if self.tracer_registered:
115117
scorep.instrumenter.get_instrumenter().unregister()
116118

@@ -125,7 +127,8 @@ def __enter__(self):
125127
full_file_name = "None"
126128

127129
scorep.instrumenter.get_instrumenter().region_begin(
128-
self.module_name, self.region_name, full_file_name, line_number)
130+
self.module_name, self.region_name, full_file_name,
131+
line_number)
129132

130133
def __exit__(self, exc_type, exc_value, traceback):
131134
if self.tracer_registered:

scorep/instrumenters/dummy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import scorep.instrumenters.base_instrumenter as base_instrumenter
44

5+
56
class ScorepDummy(base_instrumenter.BaseInstrumenter):
67
def __init__(self, scorep_bindings=None, enable_instrumenter=True):
78
pass

test/test.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ def test_mpi(self):
298298

299299
env = self.env
300300
env["SCOREP_EXPERIMENT_DIRECTORY"] += "/test_mpi"
301-
trace_path = env["SCOREP_EXPERIMENT_DIRECTORY"] + "/traces.otf2"
302301
out = call(["mpirun",
303302
"-n",
304303
"2",
@@ -316,19 +315,15 @@ def test_mpi(self):
316315
std_out = out[1]
317316
std_err = out[2]
318317

319-
expected_std_err = ""
320-
expected_std_out = u"\[0[0-9]\] \[0. 1. 2. 3. 4.\]\\n\[0[0-9]] \[0. 1. 2. 3. 4.\]\\n"
318+
expected_std_out = r"\[0[0-9]\] \[0. 1. 2. 3. 4.\]\n\[0[0-9]] \[0. 1. 2. 3. 4.\]\n"
321319

322320
self.assertRegex(std_err,
323-
'\[Score-P\] [\w/.: ]*MPI_THREAD_FUNNELED')
321+
r'\[Score-P\] [\w/.: ]*MPI_THREAD_FUNNELED')
324322
self.assertRegex(std_out, expected_std_out)
325323

326-
expected_std_out
327-
328324
def test_call_main(self):
329325
env = self.env
330326
env["SCOREP_EXPERIMENT_DIRECTORY"] += "/test_call_main"
331-
trace_path = env["SCOREP_EXPERIMENT_DIRECTORY"] + "/traces.otf2"
332327
out = call([self.python,
333328
"-m",
334329
"scorep",
@@ -346,7 +341,6 @@ def test_call_main(self):
346341
def test_dummy(self):
347342
env = self.env
348343
env["SCOREP_EXPERIMENT_DIRECTORY"] += "/test_dummy"
349-
trace_path = env["SCOREP_EXPERIMENT_DIRECTORY"] + "/traces.otf2"
350344

351345
out = call([self.python,
352346
"-m",
@@ -382,7 +376,6 @@ def test_numpy_dot(self):
382376

383377
self.assertEqual(std_out, "[[ 7 10]\n [15 22]]\n")
384378
self.assertEqual(std_err, self.expected_std_err)
385-
386379

387380
out = call(["otf2-print", trace_path])
388381
std_out = out[1]
@@ -394,7 +387,6 @@ def test_numpy_dot(self):
394387
self.assertRegex(std_out,
395388
'LEAVE[ ]*[0-9 ]*[0-9 ]*Region: "numpy.__array_function__:dot"')
396389

397-
398390
def tearDown(self):
399391
# pass
400392
shutil.rmtree(

test/test_instrumentation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ def foo():
66
test_instrumentation2.baz()
77
test_instrumentation2.bar()
88

9+
910
foo()

test/test_numpy_dot.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import scorep.instrumenter
33

44
with scorep.instrumenter.enable():
5-
a = [[1, 2],[3, 4]]
6-
b = [[1, 2],[3, 4]]
7-
8-
c = numpy.dot(a,b)
9-
print(c)
5+
a = [[1, 2], [3, 4]]
6+
b = [[1, 2], [3, 4]]
7+
8+
c = numpy.dot(a, b)
9+
print(c)

0 commit comments

Comments
 (0)