Skip to content

Commit

Permalink
enable and run isort fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfikl authored and inducer committed Mar 1, 2024
1 parent b5d848d commit 0e7a88a
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 26 deletions.
5 changes: 2 additions & 3 deletions codepy/bpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def expose_vector_type(self, name, py_name=None):
if py_name is None:
py_name = name

from cgen import (Block, Typedef, Line, Statement, Value)
from cgen import Block, Line, Statement, Typedef, Value

self.init_body.append(
Block([
Expand Down Expand Up @@ -134,8 +134,7 @@ def generate(self):
module line-by-line.
"""

from cgen import Block, Module, Include, Line, Define, \
PrivateNamespace
from cgen import Block, Define, Include, Line, Module, PrivateNamespace

body = []

Expand Down
5 changes: 3 additions & 2 deletions codepy/cuda.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import cgen


"""Convenience interface for using CodePy with CUDA"""


Expand Down Expand Up @@ -70,8 +72,7 @@ def compile(self, host_toolchain, nvcc_toolchain,
host_code = "{}\n".format(self.boost_module.generate())
device_code = "{}\n".format(self.generate())

from codepy.jit import compile_from_string
from codepy.jit import link_extension
from codepy.jit import compile_from_string, link_extension

local_host_kwargs = kwargs.copy()
local_host_kwargs.update(host_kwargs)
Expand Down
11 changes: 6 additions & 5 deletions codepy/elementwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
__copyright__ = "Copyright (C) 2009 Andreas Kloeckner"


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

from pytools import memoize


class Argument:
def __init__(self, dtype, name):
Expand Down Expand Up @@ -46,11 +47,11 @@ def struct_char(self):


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

from cgen import FunctionBody, FunctionDeclaration, \
Value, POD, Struct, For, Initializer, Include, Statement, \
Line, Block
from codepy.bpl import BoostPythonModule

S = Statement # noqa: N806

Expand Down
11 changes: 8 additions & 3 deletions codepy/jit.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@
THE SOFTWARE.
"""

from codepy import CompileError
import logging

from pytools import Record

import logging
from codepy import CompileError


logger = logging.getLogger(__name__)


def _erase_dir(dir):
from os import listdir, unlink, rmdir
from os import listdir, rmdir, unlink
from os.path import join
for name in listdir(dir):
unlink(join(dir, name))
Expand Down Expand Up @@ -479,6 +482,8 @@ def link_extension(toolchain, objects, mod_name, cache_dir=None,


from pytools import MovedFunctionDeprecationWrapper # noqa: E402

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


guess_toolchain = MovedFunctionDeprecationWrapper(_gtc)
4 changes: 2 additions & 2 deletions codepy/libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def search_on_path(filenames):
"""Find file on system path."""
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52224

from os.path import exists, join, abspath
from os import pathsep, environ
from os import environ, pathsep
from os.path import abspath, exists, join

search_path = environ["PATH"]

Expand Down
6 changes: 4 additions & 2 deletions codepy/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
"""


from codepy import CompileError
from pytools import Record

from codepy import CompileError


class Toolchain(Record):
"""Abstract base class for tools used to link dynamic Python modules."""
Expand Down Expand Up @@ -416,9 +417,10 @@ def _guess_toolchain_kwargs_from_python_config():


def call_capture_output(*args):
from pytools.prefork import call_capture_output
import sys

from pytools.prefork import call_capture_output

encoding = sys.getdefaultencoding()
result, stdout, stderr = call_capture_output(*args)
return result, stdout.decode(encoding), stderr.decode(encoding)
Expand Down
5 changes: 5 additions & 0 deletions examples/demo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import cgen as c

from codepy.bpl import BoostPythonModule


mod = BoostPythonModule()

mod.add_function(
Expand All @@ -9,6 +12,8 @@
))

from codepy.toolchain import guess_toolchain


cmod = mod.compile(guess_toolchain())

print(cmod.greet())
6 changes: 6 additions & 0 deletions examples/demo_plain.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@
"""

from codepy.toolchain import guess_toolchain


toolchain = guess_toolchain()

from codepy.libraries import add_boost_python


add_boost_python(toolchain)

from codepy.jit import extension_from_string


cmod = extension_from_string(toolchain, "module", MODULE_CODE)

print(cmod.greet())
13 changes: 9 additions & 4 deletions examples/nvcc-test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import cgen as c
from cgen.cuda import CudaGlobal

from codepy.bpl import BoostPythonModule
from codepy.cuda import CudaModule
from cgen.cuda import CudaGlobal


# This file tests the ability to use compile and link CUDA code into the
# Python interpreter. Running this test requires PyCUDA
Expand All @@ -11,9 +13,11 @@
# The host module should include a function which is callable from Python
host_mod = BoostPythonModule()

import math
# Are we on a 32 or 64 bit platform?
import sys
import math


bitness = math.log(sys.maxsize) + 1
ptr_sz_uint_conv = "K" if bitness > 32 else "I"

Expand Down Expand Up @@ -99,16 +103,17 @@
import codepy.jit
import codepy.toolchain


gcc_toolchain = codepy.toolchain.guess_toolchain()
nvcc_toolchain = codepy.toolchain.guess_nvcc_toolchain()

module = cuda_mod.compile(gcc_toolchain, nvcc_toolchain, debug=True)
import numpy as np
import pycuda.autoinit
import pycuda.driver
import pycuda.gpuarray


import pycuda.gpuarray
import numpy as np
length = 25
constant_value = 2
# This is a strange way to create a GPUArray, but is meant to illustrate
Expand Down
9 changes: 9 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,12 @@ docstring-quotes = """
multiline-quotes = """
# enable-flake8-bugbear
# enable-flake8-isort
[isort]
known_firstparty=pytools
known_local_folder=codepy
line_length = 85
lines_after_imports = 2
combine_as_imports = True
multi_line_output = 4
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python

from setuptools import setup, find_packages
from setuptools import find_packages, setup


setup(
name="codepy",
Expand Down
5 changes: 3 additions & 2 deletions test/test_identical_symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@


def make_greet_mod(greeting):
from cgen import FunctionBody, FunctionDeclaration, Block, \
Const, Pointer, Value, Statement
from cgen import (
Block, Const, FunctionBody, FunctionDeclaration, Pointer, Statement, Value)

from codepy.bpl import BoostPythonModule

mod = BoostPythonModule()
Expand Down
5 changes: 3 additions & 2 deletions test/test_two_stage_compile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from codepy.toolchain import guess_toolchain
from codepy.jit import compile_from_string
from ctypes import CDLL

from codepy.jit import compile_from_string
from codepy.toolchain import guess_toolchain


def test():
toolchain = guess_toolchain()
Expand Down

0 comments on commit 0e7a88a

Please sign in to comment.