Skip to content

Commit

Permalink
Addressing some nits
Browse files Browse the repository at this point in the history
  • Loading branch information
piannucci authored and zanellia committed Apr 4, 2020
1 parent 7cdd6d3 commit 25915e7
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 101 deletions.
2 changes: 1 addition & 1 deletion examples/binary_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def py_int_search(seq, t):
while 1:
if max < min:
return -1
m = int((min + max) / 2)
m = (min + max) // 2
if seq[m] < t:
min = m + 1
elif seq[m] > t:
Expand Down
4 changes: 2 additions & 2 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def main(argv):
else:
test = sys.modules[modname].test
except (ImportError, KeyError, AttributeError) as e:
print(("Cannot run tests for %s (%s)" % (modname, e)))
print("Cannot run tests for %s (%s)" % (modname, e))
sys.exit(2)
elif args.tests:
def fix_test_path(x):
Expand Down Expand Up @@ -317,7 +317,7 @@ def build_project(args):
else:
if not args.show_build_log:
with open(log_filename, 'r') as f:
print((f.read()))
print(f.read())
print("Build failed!")
sys.exit(1)

Expand Down
5 changes: 0 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,6 @@ def setup_package():
url = "http://www.github.com/scipy/weave",
download_url = "https://pypi.python.org/pypi/weave",
license = 'BSD',
# packages = find_packages(),
# install_requires=[
# 'numpy',
# 'nose',
# ],
cmdclass=cmdclass,
classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f],
platforms = ["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"],
Expand Down
6 changes: 0 additions & 6 deletions weave/_dumbdbm_patched.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@
import collections


PY3 = sys.version_info[0] == 3
if PY3:
string_types = str,
else:
string_types = str,

_open = open

__all__ = ["error", "open"]
Expand Down
2 changes: 1 addition & 1 deletion weave/blitz_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def blitz(expr,local_dict=None, global_dict=None,check_size=1,verbose=0,**kw):
arg_names,local_dict,
global_dict,module_dir,
compiler='gcc',auto_downcast=1,
verbose=2,
verbose=verbose,
type_converters=converters.blitz,**kw)

function_catalog.add_function(expr,func,module_dir)
Expand Down
1 change: 0 additions & 1 deletion weave/build_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ def build_extension(module_path,compiler_name='',build_dir=None,
success = 0
from numpy.distutils.log import set_verbosity
set_verbosity(-1)
verbose = 2

# get the name of the module and the extension directory it lives in.
module_dir,cpp_name = os.path.split(os.path.abspath(module_path))
Expand Down
2 changes: 1 addition & 1 deletion weave/bytecodecompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def __init__(self,code,return_type,support=''):
# Build one in the reverse sense
# -----------------------------------------------
byOpcode = {}
for name, op in list(byName.items()):
for name, op in byName.items():
byOpcode[op] = name
del name
del op
Expand Down
2 changes: 0 additions & 2 deletions weave/c_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import types
from .base_spec import base_converter
from . import base_info
import io

import io
import sys
Expand Down Expand Up @@ -351,7 +350,6 @@ class scxx_converter(common_base_converter):
def init_info(self):
super().init_info()
self.headers = ['"scxx/object.h"','"scxx/list.h"','"scxx/tuple.h"',
# self.headers = ['"py3c/include/py3c.h"', '"scxx/object.h"','"scxx/list.h"','"scxx/tuple.h"',
'"scxx/dict.h"','<iostream>']
self.include_dirs = [local_dir,scxx_dir]
self.sources = [os.path.join(scxx_dir,'weave_imp.cpp'),]
Expand Down
6 changes: 3 additions & 3 deletions weave/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def getmodule(object):
value = inspect.getmodule(object)
if value is None:
# walk trough all modules looking for function
for name,mod in list(sys.modules.items()):
for name,mod in sys.modules.items():
# try except used because of some comparison failures
# in wxPoint code. Need to review this.
# Moreover, when mod = coverage.debug.DebugOutputFile.the_one,
Expand Down Expand Up @@ -635,9 +635,9 @@ def file_test(x):
from os import access, F_OK, W_OK
return (access(x,F_OK) and access(x,W_OK) or
access(os.path.dirname(x),W_OK))
writable = iter(list(filter(file_test,files)))
writable = list(filter(file_test,files))
if writable:
file = next(writable)
file = writable[0]
else:
file = None
return file
Expand Down
20 changes: 0 additions & 20 deletions weave/common_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,6 @@
object None = object(Py_None);
}
//const char* find_type(PyObject* py_obj)
//{
// if(py_obj == NULL) return "C NULL value";
// if(PyCallable_Check(py_obj)) return "callable";
// if(PyUnicode_Check(py_obj)) return "string";
// if(PyInt_Check(py_obj)) return "int";
// if(PyFloat_Check(py_obj)) return "float";
// if(PyDict_Check(py_obj)) return "dict";
// if(PyList_Check(py_obj)) return "list";
// if(PyTuple_Check(py_obj)) return "tuple";
// if(PyFile_Check(py_obj)) return "file";
// if(PyModule_Check(py_obj)) return "module";
//
// //should probably do more intergation (and thinking) on these.
// if(PyCallable_Check(py_obj) && PyInstance_Check(py_obj)) return "callable";
// if(PyInstance_Check(py_obj)) return "instance";
// if(PyCallable_Check(py_obj)) return "callable";
// return "unknown type";
//}
const char* find_type(PyObject* py_obj)
{
if(py_obj == NULL) return "C NULL value";
Expand Down
79 changes: 28 additions & 51 deletions weave/ext_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ def module_code(self):
self.support_code(),
self.function_code(),
self.python_function_definition_code(),
self.python_module_definition_code(),
self.module_init_code(),
])
return code
Expand Down Expand Up @@ -289,54 +288,35 @@ def python_function_definition_code(self):
'};\n'
return code % (all_definition_code)

def python_module_definition_code(self):
module_name = self.name
code = 'static struct PyModuleDef %s = \n' \
'{\n' \
' PyModuleDef_HEAD_INIT,\n' \
' "%s",\n' \
' NULL,' \
' -1,\n' \
' compiled_methods\n' \
'};\n'
return code % (module_name, module_name)

def module_init_code(self):
init_code_list = self.build_information().module_init_code()
init_code = indent(''.join(init_code_list),4)
if sys.version_info.major < 3:
code = 'PyMODINIT_FUNC init%s(void)\n' \
'{\n' \
'%s' \
' (void) Py_InitModule("%s", compiled_methods);\n' \
'}\n' % (self.name,init_code,self.name)
else:
code = 'static int traverse(PyObject *m, visitproc visit, void *arg) {\n' \
' return 0;\n' \
'}\n' \
'\n' \
'static int clear(PyObject *m) {\n' \
' return 0;\n' \
'}\n' \
'\n' \
'static struct PyModuleDef moduledef = {\n' \
' PyModuleDef_HEAD_INIT,\n' \
' "%s", NULL,\n' \
' 0,\n' \
' compiled_methods,\n' \
' NULL,\n' \
' traverse,\n' \
' clear,\n' \
' NULL\n' \
'};\n' \
'\n' \
'extern "C"\n' \
'PyObject *PyInit_%s(void)\n' \
'{\n' \
' PyObject *module = PyModule_Create(&moduledef);\n' \
'%s' \
' return module;\n' \
'}\n' % (self.name,self.name,init_code)
code = 'static int traverse(PyObject *m, visitproc visit, void *arg) {\n' \
' return 0;\n' \
'}\n' \
'\n' \
'static int clear(PyObject *m) {\n' \
' return 0;\n' \
'}\n' \
'\n' \
'static struct PyModuleDef moduledef = {\n' \
' PyModuleDef_HEAD_INIT,\n' \
' "%s", NULL,\n' \
' 0,\n' \
' compiled_methods,\n' \
' NULL,\n' \
' traverse,\n' \
' clear,\n' \
' NULL\n' \
'};\n' \
'\n' \
'extern "C"\n' \
'PyObject *PyInit_%s(void)\n' \
'{\n' \
' PyObject *module = PyModule_Create(&moduledef);\n' \
'%s' \
' return module;\n' \
'}\n' % (self.name,self.name,init_code)

return code

Expand All @@ -363,10 +343,7 @@ def build_kw_and_file(self,location,kw):
info = self.build_information()
_source_files = info.sources()
# remove duplicates
source_files = {}
for i in _source_files:
source_files[i] = None
source_files = list(source_files.keys())
source_files = list({i:None for i in _source_files})

# add internally specified macros, includes, etc. to the key words
# values of the same names so that distutils will use them.
Expand All @@ -379,7 +356,7 @@ def build_kw_and_file(self,location,kw):
info.extra_compile_args()
kw['extra_link_args'] = kw.get('extra_link_args',[]) + \
info.extra_link_args()
kw['sources'] = kw.get('sources',[]) + list(source_files)
kw['sources'] = kw.get('sources',[]) + source_files
file = self.generate_file(location=location)
return kw,file

Expand Down
2 changes: 0 additions & 2 deletions weave/scxx/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#include <limits.h>
#include <string>
#include <complex>
// #include "../py3c/include/py3c.h"


// for debugging
#include <iostream>
Expand Down
4 changes: 2 additions & 2 deletions weave/size_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ def check_expr(expr,local_vars,global_vars={}):
values = {}

# first handle the globals
for var,val in list(global_vars.items()):
for var,val in global_vars.items():
if isinstance(val, ndarray):
values[var] = dummy_array(val,name=var)
elif isnumeric(val):
values[var] = val
# now handle the locals
for var,val in list(local_vars.items()):
for var,val in local_vars.items():
if isinstance(val, ndarray):
values[var] = dummy_array(val,name=var)
if isnumeric(val):
Expand Down
1 change: 0 additions & 1 deletion weave/standard_array_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ class numpy_size_handler

numeric_init_code = \
"""
// Py_Initialize();
import_array();
PyImport_ImportModule("numpy");
"""
Expand Down
3 changes: 1 addition & 2 deletions weave/swigptr2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3741,11 +3741,10 @@
#endif
/* A crude _PyUnicode_AsStringAndSize implementation for old Pythons */
/* A crude PyString_AsStringAndSize implementation for old Pythons */
#if PY_VERSION_HEX < 0x02010000
# ifndef PyString_AsStringAndSize
# define PyString_AsStringAndSize(obj, s, len) {*s = PyUnicode_AsUTF8(obj); *len = *s ? strlen(*s) : 0;}
>>>>>>> piannucci/python3
# endif
#endif
Expand Down
2 changes: 1 addition & 1 deletion weave/tests/weave_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def cleanup_temp_dir(d):
This should probably catch some errors.
"""
files = list(map(lambda x,d=d: os.path.join(d,x),os.listdir(d)))
files = [os.path.join(d,x) for x in os.listdir(d)]
for i in files:
try:
if os.path.isdir(i):
Expand Down

0 comments on commit 25915e7

Please sign in to comment.