Author: Ronan Lamy <ronan.l...@gmail.com> Branch: _py3k-cpyext-A Changeset: r87014:a0993b1fb7ba Date: 2016-09-12 01:29 +0100 http://bitbucket.org/pypy/pypy/changeset/a0993b1fb7ba/
Log: hack some more: one test passes! diff --git a/pypy/module/cpyext/test/test_cpyext.py b/pypy/module/cpyext/test/test_cpyext.py --- a/pypy/module/cpyext/test/test_cpyext.py +++ b/pypy/module/cpyext/test/test_cpyext.py @@ -7,7 +7,6 @@ from pypy import pypydir from pypy.interpreter import gateway from rpython.rtyper.lltypesystem import lltype, ll2ctypes -from rpython.translator.gensupp import uniquemodulename from rpython.tool.udir import udir from pypy.module.cpyext import api from pypy.module.cpyext.state import State @@ -16,7 +15,7 @@ from rpython.tool import leakfinder from rpython.rlib import rawrefcount -from .support import c_compile +from pypy.tool.cpyext.buildext import SystemCompilationInfo, get_sys_info_app only_pypy ="config.option.runappdirect and '__pypy__' not in sys.builtin_module_names" @@ -33,55 +32,6 @@ assert 'PyModule_Check' in api.FUNCTIONS assert api.FUNCTIONS['PyModule_Check'].argtypes == [api.PyObject] -def convert_sources_to_files(sources, dirname): - files = [] - for i, source in enumerate(sources): - filename = dirname / ('source_%d.c' % i) - with filename.open('w') as f: - f.write(str(source)) - files.append(filename) - return files - -class SystemCompilationInfo(object): - """Bundles all the generic information required to compile extensions. - - Note: here, 'system' means OS + target interpreter + test config + ... - """ - def __init__(self, include_extra=None, compile_extra=None, link_extra=None, - extra_libs=None, ext=None): - self.include_extra = include_extra or [] - self.compile_extra = compile_extra - self.link_extra = link_extra - self.extra_libs = extra_libs - self.ext = ext - - def compile_extension_module(self, name, include_dirs=[], - source_files=None, source_strings=None): - """ - Build an extension module and return the filename of the resulting - native code file. - - name is the name of the module, possibly including dots if it is a - module inside a package. - - Any extra keyword arguments are passed on to ExternalCompilationInfo to - build the module (so specify your source with one of those). - """ - modname = name.split('.')[-1] - dirname = (udir/uniquemodulename('module')).ensure(dir=1) - if source_strings: - assert not source_files - files = convert_sources_to_files(source_strings, dirname) - source_files = files - soname = c_compile(source_files, outputfilename=str(dirname/modname), - compile_extra=self.compile_extra, - link_extra=self.link_extra, - include_dirs=self.include_extra + include_dirs, - libraries=self.extra_libs) - pydname = soname.new(purebasename=modname, ext=self.ext) - soname.rename(pydname) - return str(pydname) - def get_cpyext_info(space): from pypy.module.imp.importing import get_so_extension state = space.fromcache(State) @@ -110,34 +60,6 @@ ext=get_so_extension(space)) -def get_so_suffix(): - from imp import get_suffixes, C_EXTENSION - for suffix, mode, typ in get_suffixes(): - if typ == C_EXTENSION: - return suffix - else: - raise RuntimeError("This interpreter does not define a filename " - "suffix for C extensions!") - -def get_sys_info_app(): - from distutils.sysconfig import get_python_inc - if sys.platform == 'win32': - compile_extra = ["/we4013"] - link_extra = ["/LIBPATH:" + os.path.join(sys.exec_prefix, 'libs')] - elif sys.platform == 'darwin': - compile_extra = link_extra = None - pass - elif sys.platform.startswith('linux'): - compile_extra = [ - "-O0", "-g", "-Werror=implicit-function-declaration", "-fPIC"] - link_extra = None - ext = get_so_suffix() - return SystemCompilationInfo( - include_extra=[get_python_inc()], - compile_extra=compile_extra, - link_extra=link_extra, - ext=get_so_suffix()) - def make_methods(functions, modname): methods_table = [] codes = [] @@ -329,7 +251,11 @@ cls.w_runappdirect = space.wrap(cls.runappdirect) else: def w_compile_module(self, name, source_files=None, source_strings=None): - return self.sys_info(name, source_files, source_strings) + from buildext import get_sys_info_app + sys_info = get_sys_info_app() + assert source_files or source_strings + return sys_info.compile_extension_module(name, + source_files=source_files, source_strings=source_strings) cls.w_compile_module = w_compile_module def record_imported_module(self, name): @@ -618,9 +544,9 @@ """ # Build the extensions. banana = self.compile_module( - "apple.banana", source_files=[self.here + b'banana.c']) + "apple.banana", source_files=[self.here.decode() + 'banana.c']) date = self.compile_module( - "cherry.date", source_files=[self.here + b'date.c']) + "cherry.date", source_files=[self.here.decode() + 'date.c']) # Set up some package state so that the extensions can actually be # imported. diff --git a/pypy/tool/pytest/apptest.py b/pypy/tool/pytest/apptest.py --- a/pypy/tool/pytest/apptest.py +++ b/pypy/tool/pytest/apptest.py @@ -76,8 +76,8 @@ def skip(message): print(message) raise SystemExit(0) - __builtins__.skip = skip - __builtins__.py3k_skip = skip + #__builtins__.skip = skip + #__builtins__.py3k_skip = skip class ExceptionWrapper: pass def raises(exc, func, *args, **kwargs): @@ -98,7 +98,7 @@ return res else: raise AssertionError("DID NOT RAISE") - __builtins__.raises = raises + #__builtins__.raises = raises class Test: pass self = Test() @@ -170,8 +170,11 @@ f.write('def %s():\n' % target_name) f.write('\n'.join(source)) f.write("\n%s()\n" % target_name) + helper_dir = os.path.join(pypydir, 'tool', 'cpyext') + env = os.environ.copy() + env['PYTHONPATH'] = helper_dir res, stdout, stderr = runsubprocess.run_subprocess( - python_, [str(pyfile)]) + python_, [str(pyfile)], env=env) print pyfile.read() print >> sys.stdout, stdout print >> sys.stderr, stderr @@ -325,4 +328,3 @@ space.newtuple([]), space.newdict()) self.w_class = w_class - diff --git a/rpython/tool/udir.py b/rpython/tool/udir.py --- a/rpython/tool/udir.py +++ b/rpython/tool/udir.py @@ -21,7 +21,11 @@ import sys from rpython.tool.version import get_repo_version_info -from py.path import local +from py.path import local +try: + unicode +except NameError: + class unicode: pass PYPY_KEEP = int(os.environ.get('PYPY_USESSION_KEEP', '3')) diff --git a/rpython/tool/version.py b/rpython/tool/version.py --- a/rpython/tool/version.py +++ b/rpython/tool/version.py @@ -16,6 +16,7 @@ def get_repo_version_info(hgexe=None, root=rpythonroot): '''Obtain version information by invoking the 'hg' or 'git' commands.''' + return default_retval # Try to see if we can get info from Git if hgexe is not specified. if not hgexe: @@ -137,4 +138,4 @@ if __name__ == '__main__': - print get_repo_version_info() + print(get_repo_version_info()) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit