Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,16 @@ on:
- cron: '17 3 * * 0'

jobs:
flake8:
name: Flake8
ruff:
name: Ruff
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
-
uses: actions/setup-python@v5
with:
# matches compat target in setup.py
python-version: '3.8'
- uses: actions/setup-python@v5
- name: "Main Script"
run: |
curl -L -O https://gitlab.tiker.net/inducer/ci-support/raw/main/prepare-and-run-flake8.sh
. ./prepare-and-run-flake8.sh "$(basename $GITHUB_REPOSITORY)" ./test

pip install ruff
ruff check

pytest:
name: Pytest on Py${{ matrix.python-version }}
Expand Down
10 changes: 5 additions & 5 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Flake8:
script:
- curl -L -O https://gitlab.tiker.net/inducer/ci-support/raw/main/prepare-and-run-flake8.sh
- ". ./prepare-and-run-flake8.sh codepy test"
Ruff:
script: |
pipx install ruff
ruff check
tags:
- python3
- docker-runner
except:
- tags

Expand Down
14 changes: 6 additions & 8 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
include test/*.py

include doc/source/*.rst
include doc/*.rst
include doc/Makefile
include doc/source/conf.py
include doc/source/_static/*.css
include doc/source/_templates/*.html

include LICENSE
include README.rst
include codepy/include/codepy/bpl.hpp

include Makefile.in
include codepy/include/codepy/*.hpp
prune .github
exclude .gitlab-ci.yml
exclude .gitignore
16 changes: 10 additions & 6 deletions codepy/bpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def add_struct(self,
member_defs = []
for f in struct.fields:
py_f_name = py_member_name_transform(f.name)
tp_lines, declarator = f.get_decl_pair()
tp_lines, _ = f.get_decl_pair()
if f.name in by_value_members or tp_lines[0].startswith("numpy_"):
member_defs.append(
".def(pyublas::by_value_rw_member"
Expand Down Expand Up @@ -146,11 +146,15 @@ def generate(self):
else:
mod_body = self.mod_body

body += ([Include("boost/python.hpp")]
+ self.preamble + [Line()]
+ mod_body
+ [Line(), Line(f"BOOST_PYTHON_MODULE({self.name})")]
+ [Block(self.init_body)])
body += [
Include("boost/python.hpp"),
*self.preamble,
Line(),
*mod_body,
Line(),
Line(f"BOOST_PYTHON_MODULE({self.name})"),
Block(self.init_body),
]

return Module(body)

Expand Down
8 changes: 4 additions & 4 deletions codepy/cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def generate(self):
module line-by-line.
"""
body = []
body += (self.preamble + [cgen.Line()] + self.body)
body += [*self.preamble, cgen.Line(), *self.body]
return cgen.Module(body)

def compile(self, host_toolchain, nvcc_toolchain,
Expand Down Expand Up @@ -81,11 +81,11 @@ def compile(self, host_toolchain, nvcc_toolchain,

# Don't compile shared objects, just normal objects
# (on some platforms, they're different)
host_checksum, host_mod_name, host_object, host_compiled = \
host_checksum, _host_mod_name, host_object, host_compiled = \
compile_from_string(
host_toolchain, self.boost_module.name, host_code,
object=True, **local_host_kwargs)
device_checksum, device_mod_name, device_object, device_compiled = \
device_checksum, _device_mod_name, device_object, device_compiled = \
compile_from_string(
nvcc_toolchain, "gpu", device_code, "gpu.cu",
object=True, **local_nvcc_kwargs)
Expand All @@ -101,7 +101,7 @@ def compile(self, host_toolchain, nvcc_toolchain,
else:
import os.path

destination_base, first_object = os.path.split(host_object)
destination_base, _ = os.path.split(host_object)
module_path = os.path.join(destination_base, mod_name
+ host_toolchain.so_ext)
try:
Expand Down
37 changes: 26 additions & 11 deletions codepy/elementwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@


import numpy
from cgen import POD, Value, dtype_to_ctype

from cgen import POD, Value, dtype_to_ctype
from pytools import memoize


Expand Down Expand Up @@ -48,8 +48,18 @@ def struct_char(self):

def get_elwise_module_descriptor(arguments, operation, name="kernel"):
from cgen import (
POD, Block, For, FunctionBody, FunctionDeclaration, Include, Initializer,
Line, Statement, Struct, Value)
POD,
Block,
For,
FunctionBody,
FunctionDeclaration,
Include,
Initializer,
Line,
Statement,
Struct,
Value,
)

from codepy.bpl import BoostPythonModule

Expand Down Expand Up @@ -161,15 +171,20 @@ def __call__(self, *args):
@memoize
def make_linear_comb_kernel_with_result_dtype(
result_dtype, scalar_dtypes, vector_dtypes):
comp_count = len(vector_dtypes)
from pytools import flatten
return ElementwiseKernel([VectorArg(result_dtype, "result")] + list(flatten(
(ScalarArg(scalar_dtypes[i], f"a{i}_fac"),
VectorArg(vector_dtypes[i], f"a{i}"))
for i in range(comp_count))),
"result[i] = " + " + ".join(
f"a{i}_fac*a{i}[i]" for i in range(comp_count)
))

comp_count = len(vector_dtypes)

args = flatten(
(ScalarArg(scalar_dtypes[i], f"a{i}_fac"),
VectorArg(vector_dtypes[i], f"a{i}"))
for i in range(comp_count)
)
return ElementwiseKernel(
[VectorArg(result_dtype, "result"), *args],
"result[i] = " + " + ".join(
f"a{i}_fac*a{i}[i]" for i in range(comp_count)
))


@memoize
Expand Down
31 changes: 16 additions & 15 deletions codepy/jit.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ def __init__(self, cleanup_m, cache_dir, sleep_delay=1):

if attempts > 10:
from warnings import warn
warn("could not obtain lock -- "
f"delete '{self.lock_file}' if necessary")
warn(f"could not obtain lock -- delete '{self.lock_file}' "
"if necessary", stacklevel=2)

cleanup_m.register(self)

Expand Down Expand Up @@ -201,16 +201,17 @@ def extension_from_string(toolchain, name, source_string,
If *debug_recompile*, messages are printed indicating whether a
recompilation is taking place.
"""
checksum, mod_name, ext_file, recompiled = \
_checksum, mod_name, ext_file, _recompiled = (
compile_from_string(toolchain, name, source_string, source_name,
cache_dir, debug, wait_on_error, debug_recompile,
False, sleep_delay=sleep_delay)
False, sleep_delay=sleep_delay))

# try loading it
from codepy.tools import load_dynamic
return load_dynamic(mod_name, ext_file)


class _InvalidInfoFile(RuntimeError):
class _InvalidInfoFileError(RuntimeError):
pass


Expand Down Expand Up @@ -280,7 +281,7 @@ def compile_from_string(toolchain, name, source_string,
if wait_on_error is not None:
from warnings import warn
warn("wait_on_error is deprecated and has no effect",
DeprecationWarning)
DeprecationWarning, stacklevel=2)

import os

Expand Down Expand Up @@ -351,13 +352,13 @@ def load_info(info_path):

try:
info_file = open(info_path, "rb")
except OSError:
raise _InvalidInfoFile()
except OSError as exc:
raise _InvalidInfoFileError() from exc

try:
return pickle.load(info_file)
except EOFError:
raise _InvalidInfoFile()
except EOFError as exc:
raise _InvalidInfoFileError() from exc
finally:
info_file.close()

Expand Down Expand Up @@ -399,7 +400,7 @@ def check_source(source_path):

if not valid:
from warnings import warn
warn("hash collision in compiler cache")
warn("hash collision in compiler cache", stacklevel=2)
return valid

cleanup_m = CleanupManager()
Expand All @@ -424,7 +425,7 @@ def check_source(source_path):
if mod_cache_dir_m.existed:
try:
info = load_info(info_path)
except _InvalidInfoFile:
except _InvalidInfoFileError:
mod_cache_dir_m.reset()

if debug_recompile:
Expand Down Expand Up @@ -472,7 +473,7 @@ def link_extension(toolchain, objects, mod_name, cache_dir=None,
destination = os.path.join(cache_dir, mod_name + toolchain.so_ext)
else:
# put the linked object in the same directory as the first object
destination_base, first_object = os.path.split(objects[0])
destination_base, _ = os.path.split(objects[0])
destination = os.path.join(
destination_base,
mod_name + toolchain.so_ext)
Expand All @@ -488,9 +489,9 @@ def link_extension(toolchain, objects, mod_name, cache_dir=None,
return load_dynamic(mod_name, destination)


from pytools import MovedFunctionDeprecationWrapper # noqa: E402
from pytools import MovedFunctionDeprecationWrapper

from codepy.toolchain import guess_toolchain as _gtc # noqa: E402
from codepy.toolchain import guess_toolchain as _gtc


guess_toolchain = MovedFunctionDeprecationWrapper(_gtc)
12 changes: 7 additions & 5 deletions codepy/libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,13 @@ def add_boost_python(toolchain):
"boost-python",
aksetup.get("BOOST_INC_DIR", []),
aksetup.get("BOOST_LIB_DIR", []),
get_boost_libname("python-py{}{}".format(*sys.version_info[:2]), aksetup)
+ ["python{}.{}{}".format(
*sys.version_info[:2],
"m" if sys.version_info[0] >= 3 else "")]
)
[
*get_boost_libname("python-py{}{}".format(*sys.version_info[:2]),
aksetup),
"python{}.{}{}".format(
*sys.version_info[:2],
"m" if sys.version_info[0] >= 3 else "")
])


def add_boost_numeric_bindings(toolchain):
Expand Down
24 changes: 6 additions & 18 deletions codepy/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,7 @@ def get_dependencies(self, source_files):
line.split()[2:] for line in lines))

def build_object(self, ext_file, source_files, debug=False):
cc_cmdline = (
self._cmdline(source_files, True)
+ ["-o", ext_file]
)
cc_cmdline = [*self._cmdline(source_files, True), "-o", ext_file]

from pytools.prefork import call
if debug:
Expand All @@ -212,10 +209,7 @@ def build_object(self, ext_file, source_files, debug=False):
raise CompileError("module compilation failed")

def build_extension(self, ext_file, source_files, debug=False):
cc_cmdline = (
self._cmdline(source_files, False)
+ ["-o", ext_file]
)
cc_cmdline = [*self._cmdline(source_files, False), "-o", ext_file]

from pytools.prefork import call
if debug:
Expand All @@ -230,10 +224,7 @@ def build_extension(self, ext_file, source_files, debug=False):
raise CompileError("module compilation failed")

def link_extension(self, ext_file, object_files, debug=False):
cc_cmdline = (
self._cmdline(object_files, False)
+ ["-o", ext_file]
)
cc_cmdline = [*self._cmdline(object_files, False), "-o", ext_file]

from pytools.prefork import call
if debug:
Expand Down Expand Up @@ -290,7 +281,7 @@ def _cmdline(self, files, object=False):
)

def abi_id(self):
return Toolchain.abi_id(self) + [self._cmdline([])]
return [*Toolchain.abi_id(self), self._cmdline([])]

def with_optimization_level(self, level, debug=False, **extra):
def remove_prefix(flags, prefix):
Expand Down Expand Up @@ -353,13 +344,10 @@ def _cmdline(self, files, object=False):
)

def abi_id(self):
return Toolchain.abi_id(self) + [self._cmdline([])]
return [*Toolchain.abi_id(self), self._cmdline([])]

def build_object(self, ext_file, source_files, debug=False):
cc_cmdline = (
self._cmdline(source_files, True)
+ ["-o", ext_file]
)
cc_cmdline = [*self._cmdline(source_files, True), "-o", ext_file]

if debug:
print(" ".join(cc_cmdline))
Expand Down
2 changes: 1 addition & 1 deletion codepy/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def join_continued_lines(lines):
except StopIteration:
if append_line:
from warnings import warn
warn("line continuation at end of file")
warn("line continuation at end of file", stacklevel=2)

return result

Expand Down
15 changes: 5 additions & 10 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
from importlib import metadata
from urllib.request import urlopen


_conf_url = \
"https://raw.githubusercontent.com/inducer/sphinxconfig/main/sphinxconfig.py"
with urlopen(_conf_url) as _inf:
exec(compile(_inf.read(), _conf_url, "exec"), globals())

copyright = "2009-21, Andreas Kloeckner"

# The short X.Y version.
import re
ver_re = re.compile(r'version\s*=\s*"([0-9a-z.]+)"')
version = [ver_re.search(line).group(1)
for line in open("../setup.py").readlines()
if ver_re.search(line)][0]
# The full version, including alpha/beta/rc tags.
release = version
copyright = "2009-2024, Andreas Kloeckner"
release = metadata.version("codepy")
version = ".".join(release.split(".")[:2])

intersphinx_mapping = {
"python": ("https://docs.python.org/dev", None),
Expand Down
Loading