提交 5e516c42 authored 作者: abalkin's avatar abalkin

Porting to py3k: use 'six'; import theano now works.

上级 e2749272
......@@ -177,7 +177,7 @@ def do_setup():
license=LICENSE,
platforms=PLATFORMS,
packages=find_packages(),
install_requires=['numpy>=1.5.0', 'scipy>=0.7.2'],
install_requires=['numpy>=1.5.0', 'scipy>=0.7.2', 'six>=1.2.0'],
package_data={
'': ['*.txt', '*.rst', '*.cu', '*.cuh', '*.c', '*.sh',
'ChangeLog'],
......
......@@ -10,6 +10,7 @@ from itertools import izip
from StringIO import StringIO
import numpy
import six
import theano
from theano import gof
......@@ -1563,8 +1564,8 @@ class _VariableEquivalenceTracker(object):
#List of default version of make thunk.
#This is needed to know if the user overrided it.
#The GpuOp will be added here when theano.sandbox.cuda is imported.
default_make_thunk = [theano.gof.Op.make_thunk.im_func,
theano.gof.OpenMPOp.make_thunk.im_func]
default_make_thunk = [six.get_unbound_function(theano.gof.Op.make_thunk),
six.get_unbound_function(theano.gof.OpenMPOp.make_thunk)]
class _Linker(gof.link.LocalLinker):
......
......@@ -6,7 +6,9 @@ import logging
import os
import sys
import warnings
import ConfigParser
from six.moves import configparser as ConfigParser
import StringIO
import theano
......
......@@ -13,6 +13,7 @@ import subprocess
import sys
import tempfile
import time
from six import b
import distutils.sysconfig
......@@ -1572,7 +1573,7 @@ class GCC_compiler(object):
lib_dirs.append(python_lib)
cppfilename = os.path.join(location, 'mod.cpp')
cppfile = file(cppfilename, 'w')
cppfile = open(cppfilename, 'w')
_logger.debug('Writing module C++ code to %s', cppfilename)
......@@ -1630,14 +1631,14 @@ class GCC_compiler(object):
# prints the exception, having '\n' in the text makes it more
# difficult to read.
raise Exception('Compilation failed (return status=%s): %s' %
(status, compile_stderr.replace('\n', '. ')))
(status, compile_stderr.replace(b('\n'), b('. '))))
elif config.cmodule.compilation_warning and compile_stderr:
# Print errors just below the command line.
print compile_stderr
if py_module:
#touch the __init__ file
file(os.path.join(location, "__init__.py"), 'w').close()
open(os.path.join(location, "__init__.py"), 'w').close()
return dlimport(lib_filename)
......
......@@ -27,7 +27,7 @@ try:
stdin=dummy_in.fileno(),
stderr=dummy_err.fileno())
p.wait()
gcc_version_str = p.stdout.readline().strip()
gcc_version_str = p.stdout.readline().strip().decode()
except OSError:
# Typically means gcc cannot be found.
gcc_version_str = 'GCC_NOT_FOUND'
......
......@@ -13,6 +13,17 @@ typedef int Py_ssize_t;
#define PyNumber_AsSsize_t(ob, exc) PyInt_AsLong(ob)
#endif
#if PY_VERSION_HEX >= 0x03000000
#include "numpy/npy_3kcompat.h"
#define PyCObject_AsVoidPtr NpyCapsule_AsVoidPtr
#define PyCObject_GetDesc NpyCapsule_GetDesc
#define PyCObject_Check NpyCapsule_Check
#endif
#ifndef Py_TYPE
#define Py_TYPE(obj) obj->ob_type
#endif
/**
TODO:
......@@ -172,7 +183,7 @@ CLazyLinker_dealloc(PyObject* _self)
Py_XDECREF(self->call_times);
Py_XDECREF(self->call_counts);
Py_XDECREF(self->pre_call_clear);
self->ob_type->tp_free((PyObject*)self);
Py_TYPE(self)->tp_free((PyObject*)self);
}
static PyObject *
CLazyLinker_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
......@@ -937,8 +948,12 @@ static PyMemberDef CLazyLinker_members[] = {
};
static PyTypeObject lazylinker_ext_CLazyLinkerType = {
#if defined(NPY_PY3K)
PyVarObject_HEAD_INIT(NULL, 0)
#else
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
#endif
"lazylinker_ext.CLazyLinker", /*tp_name*/
sizeof(CLazyLinker), /*tp_basicsize*/
0, /*tp_itemsize*/
......@@ -992,19 +1007,42 @@ static PyMethodDef lazylinker_ext_methods[] = {
#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
#define PyMODINIT_FUNC void
#endif
#if defined(NPY_PY3K)
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
"lazylinker_ext",
NULL,
-1,
lazylinker_ext_methods,
NULL,
NULL,
NULL,
NULL
};
#endif
#if defined(NPY_PY3K)
#define RETVAL m
PyObject *PyInit_lazylinker_ext(void) {
#else
PyMODINIT_FUNC
initlazylinker_ext(void)
{
#endif
PyObject* m;
lazylinker_ext_CLazyLinkerType.tp_new = PyType_GenericNew;
if (PyType_Ready(&lazylinker_ext_CLazyLinkerType) < 0)
return;
return RETVAL;
#if defined(NPY_PY3K)
m = PyModule_Create(&moduledef);
#else
m = Py_InitModule3("lazylinker_ext", lazylinker_ext_methods,
"Example module that creates an extension type.");
#endif
Py_INCREF(&lazylinker_ext_CLazyLinkerType);
PyModule_AddObject(m, "CLazyLinker", (PyObject *)&lazylinker_ext_CLazyLinkerType);
return RETVAL;
}
import errno
import os, logging, sys
from six.moves import reload_module as reload
import theano
from theano import config
......@@ -45,7 +46,7 @@ try:
assert os.path.isdir(location)
if not os.path.exists(os.path.join(location, '__init__.py')):
file(os.path.join(location, '__init__.py'), 'w').close()
open(os.path.join(location, '__init__.py'), 'w').close()
_need_reload = False
if force_compile:
......
......@@ -13,7 +13,9 @@ imported_scipy_special = False
try:
import scipy.special
imported_scipy_special = True
except ImportError:
# Importing scipy.special may raise ValueError.
# See http://projects.scipy.org/scipy/ticket/1739
except (ImportError, ValueError):
pass
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论