diff --git a/contrib/fortran-to-opencl/setup.cfg b/contrib/fortran-to-opencl/setup.cfg index d3f13a0e64b79c00a957cb1369e335e0b8a00d76..6e9077bdac0dda5dbeface44a1612eb57519c695 100644 --- a/contrib/fortran-to-opencl/setup.cfg +++ b/contrib/fortran-to-opencl/setup.cfg @@ -1,3 +1,8 @@ [flake8] -ignore = E126,E127,E128,E123,E226,E241,E242,E265,N802 +ignore = E126,E127,E128,E123,E226,E241,E242,E265,N802,W503,N815 max-line-length=85 + +inline-quotes = " +docstring-quotes = """ +multiline-quotes = """ + diff --git a/contrib/fortran-to-opencl/translate.py b/contrib/fortran-to-opencl/translate.py index 371b012034300f7db6016468eeea0c9c3d448585..39611307c3ef903515c3555068ef6909e1f4e12e 100644 --- a/contrib/fortran-to-opencl/translate.py +++ b/contrib/fortran-to-opencl/translate.py @@ -1,5 +1,3 @@ -import six - __copyright__ = "Copyright (C) 2009 Andreas Kloeckner" __license__ = """ @@ -29,6 +27,7 @@ from pymbolic.parser import Parser as ExpressionParserBase from pymbolic.mapper import CombineMapper import pymbolic.primitives as p from pymbolic.mapper.c_code import CCodeMapper as CCodeMapperBase +from sys import intern from warnings import warn @@ -340,7 +339,7 @@ class ComplexCCodeMapper(CCodeMapperBase): def map_sum(self, expr, enclosing_prec): tgt_dtype = self.infer_type(expr) - is_complex = tgt_dtype.kind == 'c' + is_complex = tgt_dtype.kind == "c" if not is_complex: return CCodeMapperBase.map_sum(self, expr, enclosing_prec) @@ -348,9 +347,9 @@ class ComplexCCodeMapper(CCodeMapperBase): tgt_name = complex_type_name(tgt_dtype) reals = [child for child in expr.children - if 'c' != self.infer_type(child).kind] + if "c" != self.infer_type(child).kind] complexes = [child for child in expr.children - if 'c' == self.infer_type(child).kind] + if "c" == self.infer_type(child).kind] from pymbolic.mapper.stringifier import PREC_SUM, PREC_NONE real_sum = self.join_rec(" + ", reals, PREC_SUM) @@ -376,7 +375,7 @@ class ComplexCCodeMapper(CCodeMapperBase): def map_product(self, expr, enclosing_prec): tgt_dtype = self.infer_type(expr) - is_complex = 'c' == tgt_dtype.kind + is_complex = "c" == tgt_dtype.kind if not is_complex: return CCodeMapperBase.map_product(self, expr, enclosing_prec) @@ -384,9 +383,9 @@ class ComplexCCodeMapper(CCodeMapperBase): tgt_name = complex_type_name(tgt_dtype) reals = [child for child in expr.children - if 'c' != self.infer_type(child).kind] + if "c" != self.infer_type(child).kind] complexes = [child for child in expr.children - if 'c' == self.infer_type(child).kind] + if "c" == self.infer_type(child).kind] from pymbolic.mapper.stringifier import PREC_PRODUCT, PREC_NONE real_prd = self.join_rec("*", reals, PREC_PRODUCT) @@ -411,8 +410,8 @@ class ComplexCCodeMapper(CCodeMapperBase): def map_quotient(self, expr, enclosing_prec): from pymbolic.mapper.stringifier import PREC_NONE - n_complex = 'c' == self.infer_type(expr.numerator).kind - d_complex = 'c' == self.infer_type(expr.denominator).kind + n_complex = "c" == self.infer_type(expr.numerator).kind + d_complex = "c" == self.infer_type(expr.denominator).kind tgt_dtype = self.infer_type(expr) @@ -436,7 +435,7 @@ class ComplexCCodeMapper(CCodeMapperBase): def map_remainder(self, expr, enclosing_prec): tgt_dtype = self.infer_type(expr) - if 'c' == tgt_dtype.kind: + if "c" == tgt_dtype.kind: raise RuntimeError("complex remainder not defined") return CCodeMapperBase.map_remainder(self, expr, enclosing_prec) @@ -445,15 +444,15 @@ class ComplexCCodeMapper(CCodeMapperBase): from pymbolic.mapper.stringifier import PREC_NONE tgt_dtype = self.infer_type(expr) - if 'c' == tgt_dtype.kind: + if "c" == tgt_dtype.kind: if expr.exponent in [2, 3, 4]: value = expr.base for i in range(expr.exponent-1): value = value * expr.base return self.rec(value, enclosing_prec) else: - b_complex = 'c' == self.infer_type(expr.base).kind - e_complex = 'c' == self.infer_type(expr.exponent).kind + b_complex = "c" == self.infer_type(expr.base).kind + e_complex = "c" == self.infer_type(expr.exponent).kind if b_complex and not e_complex: return "{}_powr({}, {})".format( @@ -481,7 +480,7 @@ class CCodeMapper(ComplexCCodeMapper): def map_subscript(self, expr, enclosing_prec): idx_dtype = self.infer_type(expr.index) - if not 'i' == idx_dtype.kind or 'u' == idx_dtype.kind: + if not "i" == idx_dtype.kind or "u" == idx_dtype.kind: ind_prefix = "(int) " else: ind_prefix = "" @@ -505,10 +504,10 @@ class CCodeMapper(ComplexCCodeMapper): arg_dtypes = [self.infer_type(par) for par in expr.parameters] name = expr.function.name - if 'f' == tgt_dtype.kind and name == "abs": + if "f" == tgt_dtype.kind and name == "abs": name = "fabs" - elif 'c' == tgt_dtype.kind: + elif "c" == tgt_dtype.kind: if name in ["conjg", "dconjg"]: name = "conj" @@ -532,7 +531,7 @@ class CCodeMapper(ComplexCCodeMapper): complex_type_name(arg_dtype), name) - elif 'c' == tgt_dtype.kind and name == "abs": + elif "c" == tgt_dtype.kind and name == "abs": arg_dtype, = arg_dtypes name = "%s_abs" % ( @@ -712,7 +711,7 @@ class ArgumentAnalayzer(FTreeWalkerBase): FTreeWalkerBase.__init__(self) # map (func, arg_nr) to - # 'w' for 'needs pointer' + # "w" for "needs pointer" # [] for no obstacle to de-pointerification known # [(func_name, arg_nr), ...] # depends on how this arg is used @@ -945,12 +944,12 @@ class F2CLTranslator(FTreeWalkerBase): if shape is not None: dim_stmt = cgen.Statement( - "dimension \"fortran\" {}[{}]".format( + 'dimension \"fortran\" {}[{}]'.format( scope.translate_var_name(name), ", ".join(gen_shape(s) for s in shape) )) - # cannot omit 'dimension' decl even for rank-1 args: + # cannot omit "dimension" decl even for rank-1 args: result.append(dim_stmt) if name in scope.data: @@ -1088,7 +1087,7 @@ class F2CLTranslator(FTreeWalkerBase): ("integer", ""): np.int32, ("integer", "4"): np.int32, - ("complex", "8"): np.int64, + ("integer", "8"): np.int64, } def dtype_from_stmt(self, stmt): @@ -1182,11 +1181,11 @@ class F2CLTranslator(FTreeWalkerBase): rhs_dtype = infer_type(rhs) # check for silent truncation of complex - if lhs_dtype.kind != 'c' and rhs_dtype.kind == 'c': + if lhs_dtype.kind != "c" and rhs_dtype.kind == "c": from pymbolic import var rhs = var("real")(rhs) # check for silent widening of real - if lhs_dtype.kind == 'c' and rhs_dtype.kind != 'c': + if lhs_dtype.kind == "c" and rhs_dtype.kind != "c": from pymbolic import var rhs = var("fromreal")(rhs) @@ -1414,9 +1413,9 @@ if __name__ == "__main__": import logging console = logging.StreamHandler() console.setLevel(logging.DEBUG) - formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') + formatter = logging.Formatter("%(name)-12s: %(levelname)-8s %(message)s") console.setFormatter(formatter) - logging.getLogger('fparser').addHandler(console) + logging.getLogger("fparser").addHandler(console) from cgen.opencl import CLConstant diff --git a/examples/demo_elementwise.py b/examples/demo_elementwise.py index 21646c4f42a8cce495c02aef7beae5d4a2ceaffe..3521089210a6dcde9d957443cc909049f39b61c8 100644 --- a/examples/demo_elementwise.py +++ b/examples/demo_elementwise.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- import numpy as np import pyopencl as cl diff --git a/examples/demo_mandelbrot.py b/examples/demo_mandelbrot.py index 9753b3ad5d9287f1968bf1d182bf22c50fe9bb79..6ca51347d53b239cebeda3063179c3d4db82d814 100644 --- a/examples/demo_mandelbrot.py +++ b/examples/demo_mandelbrot.py @@ -107,11 +107,7 @@ calc_fractal = calc_fractal_opencl # calc_fractal = calc_fractal_numpy if __name__ == '__main__': - try: - import six.moves.tkinter as tk - except ImportError: - # Python 3 - import tkinter as tk + import tkinter as tk from PIL import Image, ImageTk class Mandelbrot: diff --git a/examples/download-examples-from-wiki.py b/examples/download-examples-from-wiki.py deleted file mode 100755 index 13fd8fb7a09ecbd4d18f8055377047bc1a00ac4c..0000000000000000000000000000000000000000 --- a/examples/download-examples-from-wiki.py +++ /dev/null @@ -1,57 +0,0 @@ -#! /usr/bin/env python - - -import six.moves.xmlrpc_client -destwiki = six.moves.xmlrpc_client.ServerProxy("http://wiki.tiker.net?action=xmlrpc2") - -import os -try: - os.mkdir("wiki-examples") -except OSError: - pass - -print("downloading wiki examples to wiki-examples/...") -print("fetching page list...") -all_pages = destwiki.getAllPages() - - -from os.path import exists - -for page in all_pages: - if not page.startswith("PyOpenCL/Examples/"): - continue - - print(page) - try: - content = destwiki.getPage(page) - - import re - match = re.search(r"\{\{\{\#\!python(.*)\}\}\}", content, re.DOTALL) - code = match.group(1) - - match = re.search("([^/]+)$", page) - fname = match.group(1) - - outfname = os.path.join("wiki-examples", fname+".py") - if exists(outfname): - print("%s exists, refusing to overwrite." % outfname) - else: - outf = open(outfname, "w") - outf.write(code) - outf.close() - - for att_name in destwiki.listAttachments(page): - content = destwiki.getAttachment(page, att_name) - - outfname = os.path.join("wiki-examples", att_name) - if exists(outfname): - print("%s exists, refusing to overwrite." % outfname) - else: - outf = open(outfname, "w") - outf.write(str(content)) - outf.close() - - except Exception as e: - print(f"Error when processing {page}: {e}") - from traceback import print_exc - print_exc() diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py index 0f4709d12b8d4d6c4086a0aa3e0d94fdd4d49e64..6e0268dc1f5ba748d85af0586e773cf17182eb38 100644 --- a/pyopencl/__init__.py +++ b/pyopencl/__init__.py @@ -20,8 +20,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -import six -from six.moves import intern +from sys import intern from pyopencl.version import VERSION, VERSION_STATUS, VERSION_TEXT # noqa @@ -304,14 +303,9 @@ def _find_pyopencl_include_path(): def _split_options_if_necessary(options): if isinstance(options, str): import shlex - if six.PY2: - # shlex.split takes bytes (py2 str) on py2 - if isinstance(options, str): - options = options.encode("utf-8") - else: - # shlex.split takes unicode (py3 str) on py3 - if isinstance(options, bytes): - options = options.decode("utf-8") + # shlex.split takes unicode (py3 str) on py3 + if isinstance(options, bytes): + options = options.decode("utf-8") options = shlex.split(options) diff --git a/pyopencl/array.py b/pyopencl/array.py index 2562192c5dea1d254eb794c1a86f03cbb4750a3a..297b4eff86f478c111ec31b9a5fb0c8e69eb9a12 100644 --- a/pyopencl/array.py +++ b/pyopencl/array.py @@ -111,7 +111,7 @@ def splay(queue, n, kernel_specific_max_wg_size=None): max_work_items = _builtin_min(128, dev.max_work_group_size) if kernel_specific_max_wg_size is not None: - from six.moves.builtins import min + from builtins import min max_work_items = min(max_work_items, kernel_specific_max_wg_size) min_work_items = _builtin_min(32, max_work_items) diff --git a/pyopencl/cache.py b/pyopencl/cache.py index adae470b2a58f96db11f22d38a8e374712ee259f..ecab64a131a6222f519f979f6f1b319098c01663 100644 --- a/pyopencl/cache.py +++ b/pyopencl/cache.py @@ -268,7 +268,7 @@ def retrieve_from_cache(cache_dir, cache_key): # {{{ load info file try: - from six.moves.cPickle import load + from pickle import load try: info_file = open(info_path, "rb") @@ -445,7 +445,7 @@ def _create_built_program_from_source_cached(ctx, src, options_bytes, outf.write(binary) outf.close() - from six.moves.cPickle import dump + from pickle import dump info_file = open(info_path, "wb") dump(_SourceInfo( dependencies=get_dependencies(src, include_path), diff --git a/setup.cfg b/setup.cfg index ad68ea236494ef28401610d829b2463349b45b36..845fb8c484af1df89a79136b4bd54f97d89de4c1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,7 +3,6 @@ ignore = E126,E127,E128,E123,E226,E241,E242,E265,W503,E402 max-line-length=85 exclude=pyopencl/compyte/ndarray,pyopencl/compyte/array.py - inline-quotes = " docstring-quotes = """ multiline-quotes = """