Skip to content

Commit

Permalink
add and fix ruff UP errors
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfikl committed Jul 1, 2024
1 parent 72001f4 commit fe37ffe
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion contrib/cldis.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def main(ctx, tmp_dir, cl_str, output=None, build_options=()):
import pyopencl as cl
ctx = cl.create_some_context()
cl_file = sys.argv[1]
with open(cl_file, "r") as f:
with open(cl_file) as f:
cl_str = f.read()
output = sys.argv[2] if len(sys.argv) >= 3 else None
build_options = sys.argv[3:] if len(sys.argv) >= 4 else []
Expand Down
2 changes: 1 addition & 1 deletion examples/n-body.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
NBody Demonstrator implemented in OpenCL, rendering OpenGL
Expand Down
4 changes: 2 additions & 2 deletions pyopencl/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -3157,8 +3157,8 @@ def _logical_op(x1, x2, out, operator, queue=None):
else:
out[:] = np.logical_or(x1, x2)
elif np.isscalar(x1) or np.isscalar(x2):
scalar_arg, = [x for x in (x1, x2) if np.isscalar(x)]
ary_arg, = [x for x in (x1, x2) if not np.isscalar(x)]
scalar_arg, = (x for x in (x1, x2) if np.isscalar(x))
ary_arg, = (x for x in (x1, x2) if not np.isscalar(x))
queue = queue or ary_arg.queue
allocator = ary_arg.allocator

Expand Down
10 changes: 4 additions & 6 deletions pyopencl/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,13 +462,11 @@ def _create_built_program_from_source_cached(ctx, src, options_bytes,
binary_path = mod_cache_dir_m.sub("binary")
source_path = mod_cache_dir_m.sub("source.cl")

outf = open(source_path, "wt")
outf.write(src)
outf.close()
with open(source_path, "w") as outf:
outf.write(src)

outf = open(binary_path, "wb")
outf.write(binary)
outf.close()
with open(binary_path, "wb") as outf:
outf.write(binary)

from pickle import dump
info_file = open(info_path, "wb")
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ extend-select = [
"NPY", # numpy
"Q", # flake8-quotes
"RUF", # ruff
"UP", # pyupgrade
"W", # pycodestyle
]
extend-ignore = [
Expand All @@ -99,6 +100,8 @@ extend-ignore = [
"E402", # module level import not at the top of file
"D", # pydocstyle
"C90", # McCabe complexity
"UP031", # use f-strings instead of %
"UP032", # use f-strings instead of .format
]
exclude = [
"examples/gl_interop_demo.py",
Expand Down
2 changes: 1 addition & 1 deletion test/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -2336,7 +2336,7 @@ def test_logical_not(ctx_factory):
cl_array.logical_not(cl_array.zeros(cq, 10, np.float64)).get(),
np.logical_not(np.zeros(10)))
np.testing.assert_array_equal(
cl_array.logical_not((cl_array.zeros(cq, 10, np.float64) + 1)).get(),
cl_array.logical_not(cl_array.zeros(cq, 10, np.float64) + 1).get(),
np.logical_not(np.ones(10)))


Expand Down
2 changes: 1 addition & 1 deletion test/test_clmath.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def test_fmod(ctx_factory):
b = clmath.fmod(a, a2)

# https://salsa.debian.org/opencl-team/python-pyopencl/-/merge_requests/3#note_383761
assert np.max(np.abs((np.fmod(a.get(), a2.get()) - b.get()))) < 1e-4
assert np.max(np.abs(np.fmod(a.get(), a2.get()) - b.get())) < 1e-4


def test_ldexp(ctx_factory):
Expand Down

0 comments on commit fe37ffe

Please # to comment.