Skip to content

Commit

Permalink
PEP8: Fix E302 expected 2 blank lines, found 1
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie committed Apr 14, 2013
1 parent 27044e7 commit b18d24a
Show file tree
Hide file tree
Showing 52 changed files with 250 additions and 0 deletions.
2 changes: 2 additions & 0 deletions _dumb_shelve.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import pickle


class DbfilenameShelf(Shelf):
"""Shelf implementation using the "anydbm" generic dbm interface.
Expand Down Expand Up @@ -39,6 +40,7 @@ def __setitem__(self, key, value):
#zlib doesn't exist, leave it uncompressed.
self.dict[key] = s


def open(filename, flag='c'):
"""Open a persistent dictionary for reading and writing.
Expand Down
1 change: 1 addition & 0 deletions _dumbdbm_patched.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

error = IOError # For anydbm


class _Database(object):

def __init__(self, file):
Expand Down
17 changes: 17 additions & 0 deletions accelerate_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from .bytecodecompiler import CXXCoder,Type_Descriptor,Function_Descriptor


def CStr(s):
"Hacky way to get legal C string from Python string"
if s is None:
Expand Down Expand Up @@ -67,6 +68,8 @@ def set_attribute(self,name):
##################################################################
# CLASS BASIC #
##################################################################


class Basic(Type_Descriptor):
owned = 1
def check(self,s):
Expand All @@ -76,25 +79,29 @@ def inbound(self,s):
def outbound(self,s):
return "%s(%s)" % (self.outbounder,s),self.owned


class Basic_Number(Basic):
def literalizer(self,s):
return str(s)
def binop(self,symbol,a,b):
assert_(symbol in ['+','-','*','/'], msg=symbol)
return '%s %s %s' % (a,symbol,b),self


class Integer(Basic_Number):
cxxtype = "long"
checker = "PyInt_Check"
inbounder = "PyInt_AsLong"
outbounder = "PyInt_FromLong"


class Double(Basic_Number):
cxxtype = "double"
checker = "PyFloat_Check"
inbounder = "PyFloat_AsDouble"
outbounder = "PyFloat_FromDouble"


class String(Basic):
cxxtype = "char*"
checker = "PyString_Check"
Expand All @@ -113,6 +120,7 @@ def literalizer(self,s):

import numpy as np


class Vector(Type_Descriptor):
cxxtype = 'PyArrayObject*'
refcount = 1
Expand Down Expand Up @@ -145,34 +153,41 @@ def getitem(self,A,v,t):
def setitem(self,A,v,t):
return self.getitem(A,v,t)


class matrix(Vector):
dims = 2


class IntegerVector(Vector):
typecode = 'PyArray_INT'
cxxbase = 'int'
pybase = Integer


class Integermatrix(matrix):
typecode = 'PyArray_INT'
cxxbase = 'int'
pybase = Integer


class LongVector(Vector):
typecode = 'PyArray_LONG'
cxxbase = 'long'
pybase = Integer


class Longmatrix(matrix):
typecode = 'PyArray_LONG'
cxxbase = 'long'
pybase = Integer


class DoubleVector(Vector):
typecode = 'PyArray_DOUBLE'
cxxbase = 'double'
pybase = Double


class Doublematrix(matrix):
typecode = 'PyArray_DOUBLE'
cxxbase = 'double'
Expand Down Expand Up @@ -271,6 +286,8 @@ def lookup_type(x):
##################################################################
# class ACCELERATE #
##################################################################


class accelerate(object):

def __init__(self, function, *args, **kw):
Expand Down
12 changes: 12 additions & 0 deletions ast_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import symbol
import parser


def issequence(t):
return isinstance(t, (list, tuple))


def int_to_symbol(i):
""" Convert numeric symbol or token to a desriptive name.
"""
Expand All @@ -15,6 +17,7 @@ def int_to_symbol(i):
except KeyError:
return token.tok_name[i]


def translate_symbols(ast_tuple):
""" Translate numeric grammar symbols in an ast_tuple descriptive names.
Expand All @@ -34,6 +37,7 @@ def translate_symbols(ast_tuple):
else:
return new_list


def ast_to_string(ast_seq):
"""* Traverse an ast tree sequence, printing out all leaf nodes.
Expand All @@ -50,6 +54,7 @@ def ast_to_string(ast_seq):
output = output + ast_to_string(item)
return output


def build_atom(expr_string):
""" Build an ast for an atom from the given expr string.
Expand All @@ -68,12 +73,15 @@ def build_atom(expr_string):
ast = parser.expr(repr(expr_string)).totuple()[1][1]
return ast


def atom_tuple(expr_string):
return build_atom(expr_string)


def atom_list(expr_string):
return tuples_to_lists(build_atom(expr_string))


def find_first_pattern(ast_tuple,pattern_list):
"""* Find the first occurence of a pattern one of a list of patterns
in ast_tuple.
Expand Down Expand Up @@ -113,6 +121,7 @@ def find_first_pattern(ast_tuple,pattern_list):

name_pattern = (token.NAME, ['var'])


def remove_duplicates(lst):
output = []
for item in lst:
Expand All @@ -122,6 +131,7 @@ def remove_duplicates(lst):

reserved_names = ['sin']


def remove_reserved_names(lst):
""" These are functions names -- don't create variables for them
There is a more reobust approach, but this ought to work pretty
Expand All @@ -133,6 +143,7 @@ def remove_reserved_names(lst):
output.append(item)
return output


def harvest_variables(ast_list):
""" Retreive all the variables that need to be defined.
"""
Expand All @@ -148,6 +159,7 @@ def harvest_variables(ast_list):
variables = remove_reserved_names(variables)
return variables


def match(pattern, data, vars=None):
"""match `data' to `pattern', with variable extraction.
Expand Down
4 changes: 4 additions & 0 deletions base_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import UserList


class base_info(object):
_warnings = []
_headers = []
Expand Down Expand Up @@ -60,6 +61,7 @@ def extra_compile_args(self):
def extra_link_args(self):
return self._extra_link_args


class custom_info(base_info):
def __init__(self):
self._warnings = []
Expand Down Expand Up @@ -100,6 +102,7 @@ def add_extra_compile_arg(self,compile_arg):
def add_extra_link_arg(self,link_arg):
return self._extra_link_args.append(link_arg)


class info_list(UserList.UserList):
def get_unique_values(self,attribute):
all_values = []
Expand Down Expand Up @@ -133,6 +136,7 @@ def support_code(self):
def module_init_code(self):
return self.get_unique_values('module_init_code')


def unique_values(lst):
all_values = []
for value in lst:
Expand Down
2 changes: 2 additions & 0 deletions base_spec.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import absolute_import, print_function


class base_converter(object):
"""
Properties:
Expand Down Expand Up @@ -73,6 +74,7 @@ def variable_as_string(self):
import UserList
from . import base_info


class arg_spec_list(UserList.UserList):
def build_information(self):
all_info = base_info.info_list()
Expand Down
1 change: 1 addition & 0 deletions blitz_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
# The spec/info unification needs to continue so that this can
# incorporated into the spec somehow.


class array_info(base_info.custom_info):
# throw error if trying to use msvc compiler

Expand Down
3 changes: 3 additions & 0 deletions blitz_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
function_catalog = inline_tools.function_catalog
function_cache = inline_tools.function_cache


def blitz(expr,local_dict=None, global_dict=None,check_size=1,verbose=0,**kw):
# this could call inline, but making a copy of the
# code here is more efficient for several reasons.
Expand Down Expand Up @@ -69,6 +70,7 @@ def blitz(expr,local_dict=None, global_dict=None,check_size=1,verbose=0,**kw):
print('warning: compilation failed. Executing as python code')
exec(expr, global_dict, local_dict)


def ast_to_blitz_expr(ast_seq):
""" Convert an ast_sequence to a blitz expression.
"""
Expand Down Expand Up @@ -107,6 +109,7 @@ def ast_to_blitz_expr(ast_seq):

return expr + ';\n'


def test_function():
expr = "ex[:,1:,1:] = k + ca_x[:,1:,1:] * ex[:,1:,1:]" \
"+ cb_y_x[:,1:,1:] * (hz[:,1:,1:] - hz[:,:-1,1:])"\
Expand Down
10 changes: 10 additions & 0 deletions build_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

old_init_posix = distutils.sysconfig._init_posix


def _init_posix():
old_init_posix()
ld = distutils.sysconfig._config_vars['LDSHARED']
Expand Down Expand Up @@ -125,6 +126,7 @@ def create_extension(module_path, **kw):
ext = Extension(module_name, **kw)
return ext


def build_extension(module_path,compiler_name='',build_dir=None,
temp_dir=None, verbose=0, **kw):
""" Build the file given by module_path into a Python extension module.
Expand Down Expand Up @@ -290,6 +292,8 @@ def build_extension(module_path,compiler_name='',build_dir=None,
return success

old_argv = []


def configure_sys_argv(compiler_name,temp_dir,build_dir):
# We're gonna play some tricks with argv here to pass info to distutils
# which is really built for command line use. better way??
Expand All @@ -302,9 +306,11 @@ def configure_sys_argv(compiler_name,temp_dir,build_dir):
elif compiler_name:
sys.argv.insert(2,'--compiler='+compiler_name)


def restore_sys_argv():
sys.argv = old_argv


def configure_python_path(build_dir):
#make sure the module lives in a directory on the python path.
python_paths = [os.path.abspath(x) for x in sys.path]
Expand All @@ -313,6 +319,7 @@ def configure_python_path(build_dir):
# " It has been appended to the path."
sys.path.append(os.path.abspath(build_dir))


def choose_compiler(compiler_name=''):
""" Try and figure out which compiler is gonna be used on windows.
On other platforms, it just returns whatever value it is given.
Expand All @@ -336,6 +343,7 @@ def choose_compiler(compiler_name=''):
compiler_name = 'unix'
return compiler_name


def gcc_exists(name='gcc'):
""" Test to make sure gcc is found."""
result = 0
Expand All @@ -358,6 +366,7 @@ def gcc_exists(name='gcc'):
result = not os.system(" ".join(cmd))
return result


def msvc_exists():
""" Determine whether MSVC is available on the machine.
"""
Expand Down Expand Up @@ -410,6 +419,7 @@ def configure_temp_dir(temp_dir=None):
raise ValueError(msg)
return temp_dir


def configure_build_dir(build_dir=None):
# make sure build_dir exists and is writable
if build_dir and (not os.path.exists(build_dir) or
Expand Down
8 changes: 8 additions & 0 deletions bytecodecompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
##################################################################
# CLASS __DESCRIPTOR #
##################################################################


class __Descriptor(object):
prerequisites = []
refcount = 0
Expand All @@ -26,12 +28,16 @@ def __repr__(self):
##################################################################
# CLASS TYPE_DESCRIPTOR #
##################################################################


class Type_Descriptor(__Descriptor):
module_init_code = ''

##################################################################
# CLASS FUNCTION_DESCRIPTOR #
##################################################################


class Function_Descriptor(__Descriptor):
def __init__(self,code,return_type,support=''):
self.code = code
Expand Down Expand Up @@ -212,6 +218,8 @@ def listing(f):
##################################################################
# CLASS BYTECODEMEANING #
##################################################################


class ByteCodeMeaning(object):
def fetch(self, pc,code):
opcode = ord(code[pc])
Expand Down
Loading

0 comments on commit b18d24a

Please sign in to comment.