From 72c1db62c909e43851c67158bf863035a0168692 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 5 Dec 2016 19:04:06 -0600 Subject: [PATCH 1/2] Prep for Flake8 during CI --- .gitlab-ci.yml | 11 +++++++++++ pytools/batchjob.py | 27 +++++++-------------------- pytools/debug.py | 1 + pytools/log.py | 4 ++-- pytools/mpi.py | 2 ++ pytools/mpiwrap.py | 13 +++++++------ pytools/obj_array.py | 4 ++++ pytools/prefork.py | 2 +- pytools/stopwatch.py | 18 +++--------------- setup.cfg | 3 ++- test/test_math_stuff.py | 5 +---- 11 files changed, 41 insertions(+), 49 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 43b36f9..ae39fb4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,6 +7,7 @@ Python 2.7: - python2.7 except: - tags + Python 3.5: script: - py_version=3.5 @@ -16,6 +17,7 @@ Python 3.5: - python3.5 except: - tags + Python 2.6: script: - py_version=2.6 @@ -26,3 +28,12 @@ Python 2.6: - python2.6 except: - tags + +Flake8: + script: + - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/prepare-and-run-flake8.sh + - ". ./prepare-and-run-flake8.sh pyopencl test" + tags: + - python3.5 + except: + - tags diff --git a/pytools/batchjob.py b/pytools/batchjob.py index 4a190a4..2afde16 100644 --- a/pytools/batchjob.py +++ b/pytools/batchjob.py @@ -1,5 +1,7 @@ from __future__ import absolute_import import six + + def _cp(src, dest): from pytools import assert_not_a_file assert_not_a_file(dest) @@ -15,16 +17,11 @@ def _cp(src, dest): inf.close() - - - def get_timestamp(): from datetime import datetime return datetime.now().strftime("%Y-%m-%d-%H%M%S") - - class BatchJob(object): def __init__(self, moniker, main_file, aux_files=[], timestamp=None): import os @@ -49,7 +46,7 @@ class BatchJob(object): runscript = open("%s/run.sh" % self.path, "w") import sys - runscript.write("%s %s setup.cpy" + runscript.write("%s %s setup.cpy" % (sys.executable, main_file)) runscript.close() @@ -68,14 +65,10 @@ class BatchJob(object): setup.close() - - -class INHERIT(object): +class INHERIT(object): # noqa pass - - class GridEngineJob(BatchJob): def submit(self, env={"LD_LIBRARY_PATH": INHERIT, "PYTHONPATH": INHERIT}, memory_megs=None, extra_args=[]): @@ -103,8 +96,6 @@ class GridEngineJob(BatchJob): raise RuntimeError("Process submission of %s failed" % self.moniker) - - class PBSJob(BatchJob): def submit(self, env={"LD_LIBRARY_PATH": INHERIT, "PYTHONPATH": INHERIT}, memory_megs=None, extra_args=[]): @@ -132,11 +123,9 @@ class PBSJob(BatchJob): raise RuntimeError("Process submission of %s failed" % self.moniker) - - def guess_job_class(): from subprocess import Popen, PIPE, STDOUT - qstat_helplines = Popen(["qstat", "--help"], + qstat_helplines = Popen(["qstat", "--help"], stdout=PIPE, stderr=STDOUT).communicate()[0].split("\n") if qstat_helplines[0].startswith("GE"): return GridEngineJob @@ -144,8 +133,6 @@ def guess_job_class(): return PBSJob - - class ConstructorPlaceholder: def __init__(self, classname, *args, **kwargs): self.classname = classname @@ -162,8 +149,8 @@ class ConstructorPlaceholder: return "%s(%s)" % (self.classname, ",".join( [str(arg) for arg in self.args] - + ["%s=%s" % (kw, repr(val)) for kw, val in six.iteritems(self.kwargs)] + + ["%s=%s" % (kw, repr(val)) + for kw, val in six.iteritems(self.kwargs)] ) ) __repr__ = __str__ - diff --git a/pytools/debug.py b/pytools/debug.py index 6ddb171..98b73de 100644 --- a/pytools/debug.py +++ b/pytools/debug.py @@ -163,6 +163,7 @@ def setup_readline(): readline.parse_and_bind("tab: complete") + try: import readline import rlcompleter diff --git a/pytools/log.py b/pytools/log.py index d7f1f95..13301fc 100644 --- a/pytools/log.py +++ b/pytools/log.py @@ -538,7 +538,7 @@ class LogManager(object): self.constants[name] = value from pickle import dumps - value = buffer(dumps(value)) + value = bytes(dumps(value)) if existed: self.db_conn.execute("update constants set value = ? where name = ?", @@ -662,7 +662,7 @@ class LogManager(object): from pickle import dumps self.db_conn.execute("""insert into quantities values (?,?,?,?)""", ( name, unit, description, - buffer(dumps(def_agg)))) + bytes(dumps(def_agg)))) self.db_conn.execute("""create table %s (step integer, rank integer, value real)""" % name) diff --git a/pytools/mpi.py b/pytools/mpi.py index 5d9c931..8f4b2bb 100644 --- a/pytools/mpi.py +++ b/pytools/mpi.py @@ -1,4 +1,6 @@ from __future__ import absolute_import + + def check_for_mpi_relaunch(argv): if argv[1] != "--mpi-relaunch": return diff --git a/pytools/mpiwrap.py b/pytools/mpiwrap.py index 0090e88..5c5ed24 100644 --- a/pytools/mpiwrap.py +++ b/pytools/mpiwrap.py @@ -8,14 +8,15 @@ mpi4py.rc.initialize = False import pytools.prefork pytools.prefork.enable_prefork() -from mpi4py.MPI import * +from mpi4py.MPI import * # noqa -if Is_initialized(): + +if Is_initialized(): # noqa raise RuntimeError("MPI already initialized before MPI wrapper import") -def InitWithAutoFinalize(*args, **kwargs): - result = Init(*args, **kwargs) + +def InitWithAutoFinalize(*args, **kwargs): # noqa + result = Init(*args, **kwargs) # noqa import atexit - atexit.register(Finalize) + atexit.register(Finalize) # noqa return result - diff --git a/pytools/obj_array.py b/pytools/obj_array.py index 597d212..e425e70 100644 --- a/pytools/obj_array.py +++ b/pytools/obj_array.py @@ -66,6 +66,7 @@ def obj_array_to_hashable(f): else: return f + hashable_field = MovedFunctionDeprecationWrapper(obj_array_to_hashable) @@ -78,6 +79,7 @@ def obj_array_equal(a, b): else: return a == b + field_equal = MovedFunctionDeprecationWrapper(obj_array_equal) @@ -129,6 +131,7 @@ def with_object_array_or_scalar(f, field, obj_array_only=False): else: return f(field) + as_oarray_func = decorator(with_object_array_or_scalar) @@ -158,6 +161,7 @@ def with_object_array_or_scalar_n_args(f, *args): else: return f(*args) + as_oarray_func_n_args = decorator(with_object_array_or_scalar_n_args) diff --git a/pytools/prefork.py b/pytools/prefork.py index 6932bc9..68a46d8 100644 --- a/pytools/prefork.py +++ b/pytools/prefork.py @@ -37,7 +37,7 @@ class DirectForker(object): return self.count except OSError as e: - raise ExecError("error invoking '%s': %s" + raise ExecError("error invoking '%s': %s" % (" ".join(cmdline), e)) def call_capture_output(self, cmdline, cwd=None, error_on_nonzero=True): diff --git a/pytools/stopwatch.py b/pytools/stopwatch.py index 231b4c6..e34bb9f 100644 --- a/pytools/stopwatch.py +++ b/pytools/stopwatch.py @@ -1,12 +1,8 @@ -from __future__ import division -from __future__ import absolute_import -from __future__ import print_function +from __future__ import division, absolute_import, print_function import time import pytools - - class StopWatch: def __init__(self): self.Elapsed = 0. @@ -42,16 +38,14 @@ class Job: JOB_TIMES[self.Name] += elapsed if self.is_visible(): print(" " * (len(self.Name) + 2), elapsed, "seconds") - + def is_visible(self): if PRINT_JOBS.get(): - return not self.Name in HIDDEN_JOBS + return self.Name not in HIDDEN_JOBS else: return self.Name in VISIBLE_JOBS - - class EtaEstimator: def __init__(self, total_steps): self.stopwatch = StopWatch().start() @@ -67,17 +61,11 @@ class EtaEstimator: return None - - def print_job_summary(): for key in JOB_TIMES: print(key, " " * (50-len(key)), JOB_TIMES[key]) - - - - HIDDEN_JOBS = [] VISIBLE_JOBS = [] JOB_TIMES = pytools.DictionaryWithDefault(lambda x: 0) diff --git a/setup.cfg b/setup.cfg index 9c207b0..4f28d74 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,6 @@ [flake8] -ignore = E126,E127,E128,E123,E226,E241,E242,E265,E402,W503 +ignore = E126,E127,E128,E123,E226,E241,E242,E265,E402,W503,E731 max-line-length=85 +exclude=pytools/arithmetic_container.py,pytools/decorator.py [wheel] universal = 1 diff --git a/test/test_math_stuff.py b/test/test_math_stuff.py index 7450e53..5204008 100644 --- a/test/test_math_stuff.py +++ b/test/test_math_stuff.py @@ -2,8 +2,6 @@ from __future__ import division from __future__ import absolute_import - - def test_variance(): data = [4, 7, 13, 16] @@ -12,7 +10,7 @@ def test_variance(): return (( sum(di**2 for di in data) - sum(data)**2/n) - /(n-1)) + / (n-1)) from pytools import variance orig_variance = variance(data, entire_pop=False) @@ -21,4 +19,3 @@ def test_variance(): data = [1e9 + x for x in data] assert abs(variance(data, entire_pop=False) - orig_variance) < 1e-15 - -- GitLab From 744c6b7b4abe91b39ffd95abe6c69b987e392e38 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 5 Dec 2016 19:06:22 -0600 Subject: [PATCH 2/2] Fix flake8 invocation --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ae39fb4..028b535 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -32,7 +32,7 @@ Python 2.6: Flake8: script: - curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/prepare-and-run-flake8.sh - - ". ./prepare-and-run-flake8.sh pyopencl test" + - ". ./prepare-and-run-flake8.sh pytools test" tags: - python3.5 except: -- GitLab