Commit a96882e1 authored by Stefan Behnel's avatar Stefan Behnel

use explicit relative imports everywhere and enable absolute imports by default

parent 3b9f95ef
......@@ -7,12 +7,15 @@ Basic usage:
python cythonrun somefile.py [ARGS]
"""
from __future__ import absolute_import
DEBUG = True
import sys
import os
from distutils import sysconfig
def get_config_var(name, default=''):
return sysconfig.get_config_var(name) or default
......@@ -81,7 +84,7 @@ def ccompile(basename):
runcmd([CC, '-c', '-o', basename+'.o', basename+'.c', '-I' + INCDIR] + CFLAGS.split())
def cycompile(input_file, options=()):
from Cython.Compiler import Version, CmdLine, Main
from ..Compiler import Version, CmdLine, Main
options, sources = CmdLine.parse_command_line(list(options or ()) + ['--embed', input_file])
_debug('Using Cython %s to compile %s', Version.version, input_file)
result = Main.compile(sources, options)
......
#!/usr/bin/env python
from __future__ import absolute_import
import os
import shutil
import tempfile
from distutils.core import setup
from Cython.Build.Dependencies import cythonize, extended_iglob
from Cython.Utils import is_package_dir
from Cython.Compiler import Options
from .Dependencies import cythonize, extended_iglob
from ..Utils import is_package_dir
from ..Compiler import Options
try:
import multiprocessing
......
from __future__ import absolute_import
import cython
from Cython import __version__
from .. import __version__
import re, os, sys, time
from glob import iglob
......@@ -42,9 +44,9 @@ except ImportError:
from distutils.extension import Extension
from Cython import Utils
from Cython.Utils import cached_function, cached_method, path_exists, find_root_package_dir
from Cython.Compiler.Main import Context, CompilationOptions, default_options
from .. import Utils
from ..Utils import cached_function, cached_method, path_exists, find_root_package_dir
from ..Compiler.Main import Context, CompilationOptions, default_options
join_path = cached_function(os.path.join)
......@@ -871,8 +873,8 @@ else:
# TODO: Share context? Issue: pyx processing leaks into pxd module
@record_results
def cythonize_one(pyx_file, c_file, fingerprint, quiet, options=None, raise_on_failure=True):
from Cython.Compiler.Main import compile, default_options
from Cython.Compiler.Errors import CompileError, PyrexError
from ..Compiler.Main import compile, default_options
from ..Compiler.Errors import CompileError, PyrexError
if fingerprint:
if not os.path.exists(options.cache):
......
from __future__ import absolute_import
import sys, os, re, inspect
import imp
......@@ -10,14 +12,14 @@ from distutils.core import Distribution, Extension
from distutils.command.build_ext import build_ext
import Cython
from Cython.Compiler.Main import Context, CompilationOptions, default_options
from ..Compiler.Main import Context, CompilationOptions, default_options
from Cython.Compiler.ParseTreeTransforms import (CythonTransform,
from ..Compiler.ParseTreeTransforms import (CythonTransform,
SkipDeclarations, AnalyseDeclarationsTransform, EnvTransform)
from Cython.Compiler.TreeFragment import parse_from_strings
from Cython.Build.Dependencies import strip_string_literals, cythonize, cached_function
from Cython.Compiler import Pipeline, Nodes
from Cython.Utils import get_cython_cache_dir
from ..Compiler.TreeFragment import parse_from_strings
from .Dependencies import strip_string_literals, cythonize, cached_function
from ..Compiler import Pipeline, Nodes
from ..Utils import get_cython_cache_dir
import cython as cython_module
# A utility function to convert user-supplied ASCII strings to unicode.
......@@ -48,7 +50,7 @@ def unbound_symbols(code, context=None):
code = to_unicode(code)
if context is None:
context = Context([], default_options)
from Cython.Compiler.ParseTreeTransforms import AnalyseDeclarationsTransform
from ..Compiler.ParseTreeTransforms import AnalyseDeclarationsTransform
tree = parse_from_strings('(tree fragment)', code)
for phase in Pipeline.create_pipeline(context, 'pyx'):
if phase is None:
......
......@@ -44,7 +44,7 @@ Parts of this code were taken from Cython.inline.
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
from __future__ import print_function
from __future__ import absolute_import, print_function
import imp
import io
......@@ -74,8 +74,8 @@ from IPython.utils.path import get_ipython_cache_dir
from IPython.utils.text import dedent
import Cython
from Cython.Compiler.Errors import CompileError
from Cython.Build.Dependencies import cythonize
from ..Compiler.Errors import CompileError
from .Dependencies import cythonize
@magics_class
......
from Dependencies import cythonize
from .Dependencies import cythonize
from Visitor import ScopeTrackingTransform
from Nodes import StatListNode, SingleAssignmentNode, CFuncDefNode, DefNode
from ExprNodes import DictNode, DictItemNode, NameNode, UnicodeNode
from PyrexTypes import py_object_type
from StringEncoding import EncodedString
import Symtab
from __future__ import absolute_import
from .Visitor import ScopeTrackingTransform
from .Nodes import StatListNode, SingleAssignmentNode, CFuncDefNode, DefNode
from .ExprNodes import DictNode, DictItemNode, NameNode, UnicodeNode
from .PyrexTypes import py_object_type
from .StringEncoding import EncodedString
from . import Symtab
class AutoTestDictTransform(ScopeTrackingTransform):
# Handles autotestdict directive
......
# Note: Work in progress
from __future__ import absolute_import
import os
import re
import codecs
......@@ -7,9 +9,9 @@ import textwrap
from xml.sax.saxutils import escape as html_escape
from StringIO import StringIO
import Version
from Code import CCodeWriter
from Cython import Utils
from . import Version
from .Code import CCodeWriter
from .. import Utils
class AnnotationCCodeWriter(CCodeWriter):
......
from Cython.Compiler.Visitor import CythonTransform
from Cython.Compiler.StringEncoding import EncodedString
from Cython.Compiler import Options
from Cython.Compiler import PyrexTypes, ExprNodes
from __future__ import absolute_import
from .Visitor import CythonTransform
from .StringEncoding import EncodedString
from . import Options
from . import PyrexTypes, ExprNodes
class EmbedSignature(CythonTransform):
......
from Cython.Compiler.Visitor import CythonTransform
from Cython.Compiler.ModuleNode import ModuleNode
from Cython.Compiler.Errors import CompileError
from Cython.Compiler.UtilityCode import CythonUtilityCode
from Cython.Compiler.Code import UtilityCode, TempitaUtilityCode
from Cython.Compiler import Options
from Cython.Compiler import Interpreter
from Cython.Compiler import PyrexTypes
from Cython.Compiler import Naming
from Cython.Compiler import Symtab
from __future__ import absolute_import
from .Visitor import CythonTransform
from .ModuleNode import ModuleNode
from .Errors import CompileError
from .UtilityCode import CythonUtilityCode
from .Code import UtilityCode, TempitaUtilityCode
from . import Options
from . import Interpreter
from . import PyrexTypes
from . import Naming
from . import Symtab
def dedent(text, reindent=0):
......
......@@ -2,11 +2,13 @@
# Builtin Definitions
#
from Symtab import BuiltinScope, StructOrUnionScope
from Code import UtilityCode
from TypeSlots import Signature
import PyrexTypes
import Options
from __future__ import absolute_import
from .Symtab import BuiltinScope, StructOrUnionScope
from .Code import UtilityCode
from .TypeSlots import Signature
from . import PyrexTypes
from . import Options
# C-level implementations of builtin types, functions and methods
......
......@@ -2,9 +2,11 @@
# Cython - Command Line Parsing
#
from __future__ import absolute_import
import os
import sys
import Options
from . import Options
usage = """\
Cython (http://cython.org) is a compiler for code written in the
......@@ -46,6 +48,7 @@ Options:
-X, --directive <name>=<value>[,<name=value,...] Overrides a compiler directive
"""
#The following experimental options are supported only on MacOSX:
# -C, --compile Compile generated .c file to .o file
# --link Link .o file to produce extension module (implies -C)
......@@ -56,10 +59,9 @@ def bad_usage():
sys.stderr.write(usage)
sys.exit(1)
def parse_command_line(args):
from Cython.Compiler.Main import \
CompilationOptions, default_options
def parse_command_line(args):
from .Main import CompilationOptions, default_options
def pop_arg():
if args:
......@@ -156,7 +158,7 @@ def parse_command_line(args):
sys.exit(1)
elif option.startswith('--debug'):
option = option[2:].replace('-', '_')
import DebugFlags
from . import DebugFlags
if option in dir(DebugFlags):
setattr(DebugFlags, option, True)
else:
......
from __future__ import absolute_import
cimport cython
#cdef class UtilityCodeBase(object):
......
......@@ -3,6 +3,8 @@
# Code output module
#
from __future__ import absolute_import
import cython
cython.declare(os=object, re=object, operator=object,
Naming=object, Options=object, StringEncoding=object,
......@@ -21,13 +23,13 @@ try:
except ImportError:
import md5 as hashlib
import Naming
import Options
import StringEncoding
from Cython import Utils
from Scanning import SourceDescriptor
from Cython.StringIOTree import StringIOTree
import DebugFlags
from . import Naming
from . import Options
from . import DebugFlags
from . import StringEncoding
from .. import Utils
from .Scanning import SourceDescriptor
from ..StringIOTree import StringIOTree
try:
from __builtin__ import basestring
......@@ -452,7 +454,7 @@ def sub_tempita(s, context, file=None, name=None):
elif name:
context['__name'] = name
from Cython.Tempita import sub
from ..Tempita import sub
return sub(s, **context)
class TempitaUtilityCode(UtilityCode):
......@@ -1621,11 +1623,11 @@ class CCodeWriter(object):
self.level += 1
def putln_tempita(self, code, **context):
from Cython.Tempita import sub
from ..Tempita import sub
self.putln(sub(code, **context))
def put_tempita(self, code, **context):
from Cython.Tempita import sub
from ..Tempita import sub
self.put(sub(code, **context))
def increase_indent(self):
......@@ -1701,7 +1703,7 @@ class CCodeWriter(object):
if type.is_pyobject:
self.putln("%s = NULL;" % decl)
elif type.is_memoryviewslice:
import MemoryView
from . import MemoryView
self.putln("%s = %s;" % (decl, MemoryView.memslice_entry_init))
else:
self.putln("%s%s;" % (static and "static " or "", decl))
......@@ -1742,7 +1744,7 @@ class CCodeWriter(object):
return entry.cname
def as_pyobject(self, cname, type):
from PyrexTypes import py_object_type, typecast
from .PyrexTypes import py_object_type, typecast
return typecast(py_object_type, type, cname)
def put_gotref(self, cname):
......@@ -1870,12 +1872,12 @@ class CCodeWriter(object):
self.put_var_xdecref_clear(entry)
def put_incref_memoryviewslice(self, slice_cname, have_gil=False):
import MemoryView
from . import MemoryView
self.globalstate.use_utility_code(MemoryView.memviewslice_init_code)
self.putln("__PYX_INC_MEMVIEW(&%s, %d);" % (slice_cname, int(have_gil)))
def put_xdecref_memoryviewslice(self, slice_cname, have_gil=False):
import MemoryView
from . import MemoryView
self.globalstate.use_utility_code(MemoryView.memviewslice_init_code)
self.putln("__PYX_XDEC_MEMVIEW(&%s, %d);" % (slice_cname, int(have_gil)))
......@@ -1883,7 +1885,7 @@ class CCodeWriter(object):
self.put_xgiveref("%s.memview" % slice_cname)
def put_init_to_py_none(self, cname, type, nanny=True):
from PyrexTypes import py_object_type, typecast
from .PyrexTypes import py_object_type, typecast
py_none = typecast(type, py_object_type, "Py_None")
if nanny:
self.putln("%s = %s; __Pyx_INCREF(Py_None);" % (cname, py_none))
......@@ -1908,7 +1910,7 @@ class CCodeWriter(object):
# that's better than ours.
elif allow_skip:
return
from TypeSlots import method_coexist
from .TypeSlots import method_coexist
if entry.doc:
doc_code = entry.doc_cname
else:
......@@ -1986,7 +1988,7 @@ class CCodeWriter(object):
return self.putln("if (%s < 0) %s" % (value, self.error_goto(pos)))
def put_error_if_unbound(self, pos, entry, in_nogil_context=False):
import ExprNodes
from . import ExprNodes
if entry.from_closure:
func = '__Pyx_RaiseClosureNameError'
self.globalstate.use_utility_code(
......
from Cython.Compiler.Visitor import VisitorTransform
from Cython.Compiler.Nodes import StatListNode
from __future__ import absolute_import
from .Visitor import VisitorTransform
from .Nodes import StatListNode
class ExtractPxdCode(VisitorTransform):
"""
......
from Symtab import ModuleScope
from PyrexTypes import *
from UtilityCode import CythonUtilityCode
from Errors import error
from Scanning import StringSourceDescriptor
import MemoryView
from __future__ import absolute_import
from .Symtab import ModuleScope
from .PyrexTypes import *
from .UtilityCode import CythonUtilityCode
from .Errors import error
from .Scanning import StringSourceDescriptor
from . import MemoryView
class CythonScope(ModuleScope):
is_cython_builtin = 1
......
......@@ -2,15 +2,19 @@
# Errors
#
from __future__ import absolute_import
import sys
from Cython.Utils import open_new_file
import DebugFlags
import Options
from ..Utils import open_new_file
from . import DebugFlags
from . import Options
class PyrexError(Exception):
pass
class PyrexWarning(Exception):
pass
......
......@@ -2,6 +2,8 @@
# Parse tree nodes for expressions
#
from __future__ import absolute_import
import cython
cython.declare(error=object, warning=object, warn_once=object, InternalError=object,
CompileError=object, UtilityCode=object, TempitaUtilityCode=object,
......@@ -17,26 +19,26 @@ import sys
import copy
import operator
from Errors import error, warning, warn_once, InternalError, CompileError
from Errors import hold_errors, release_errors, held_errors, report_error
from Code import UtilityCode, TempitaUtilityCode
import StringEncoding
import Naming
import Nodes
from Nodes import Node
import PyrexTypes
from PyrexTypes import py_object_type, c_long_type, typecast, error_type, \
from .Errors import error, warning, warn_once, InternalError, CompileError
from .Errors import hold_errors, release_errors, held_errors, report_error
from .Code import UtilityCode, TempitaUtilityCode
from . import StringEncoding
from . import Naming
from . import Nodes
from .Nodes import Node
from . import PyrexTypes
from .PyrexTypes import py_object_type, c_long_type, typecast, error_type, \
unspecified_type
import TypeSlots
from Builtin import list_type, tuple_type, set_type, dict_type, type_type, \
from . import TypeSlots
from .Builtin import list_type, tuple_type, set_type, dict_type, type_type, \
unicode_type, str_type, bytes_type, bytearray_type, basestring_type, slice_type
import Builtin
import Symtab
from Cython import Utils
from Annotate import AnnotationItem
from Cython.Compiler import Future
from Cython.Debugging import print_call_chain
from DebugFlags import debug_disposal_code, debug_temp_alloc, \
from . import Builtin
from . import Symtab
from .. import Utils
from .Annotate import AnnotationItem
from . import Future
from ..Debugging import print_call_chain
from .DebugFlags import debug_disposal_code, debug_temp_alloc, \
debug_coercion
try:
......@@ -726,7 +728,7 @@ class ExprNode(Node):
node.coerce_to(dst_type, env)
if dst_type.is_memoryviewslice:
import MemoryView
from . import MemoryView
if not src.type.is_memoryviewslice:
if src.type.is_pyobject:
src = CoerceToMemViewSliceNode(src, dst_type, env)
......@@ -1180,7 +1182,7 @@ def _analyse_name_as_type(name, pos, env):
if type is not None:
return type
hold_errors()
from TreeFragment import TreeFragment
from .TreeFragment import TreeFragment
pos = (pos[0], pos[1], pos[2]-7)
try:
declaration = TreeFragment(u"sizeof(%s)" % name, name=pos[0].filename, initial_pos=pos)
......@@ -1702,7 +1704,7 @@ class NameNode(AtomicExprNode):
if entry:
entry.used = 1
if entry.type.is_buffer:
import Buffer
from . import Buffer
Buffer.used_buffer_aux_vars(entry)
self.analyse_rvalue_entry(env)
return self
......@@ -1726,7 +1728,7 @@ class NameNode(AtomicExprNode):
self.type = PyrexTypes.error_type
self.entry.used = 1
if self.entry.type.is_buffer:
import Buffer
from . import Buffer
Buffer.used_buffer_aux_vars(self.entry)
return self
......@@ -1763,7 +1765,7 @@ class NameNode(AtomicExprNode):
self.gil_error()
elif self.entry.type.is_memoryviewslice:
if self.cf_is_null or self.cf_maybe_null:
import MemoryView
from . import MemoryView
MemoryView.err_if_nogil_initialized_check(self.pos, env)
gil_message = "Accessing Python global or builtin"
......@@ -2051,7 +2053,7 @@ class NameNode(AtomicExprNode):
Slices, coercions from objects, return values etc are new references.
We have a borrowed reference in case of dst = src
"""
import MemoryView
from . import MemoryView
MemoryView.put_acquire_memoryviewslice(
lhs_cname=self.result(),
......@@ -2073,7 +2075,7 @@ class NameNode(AtomicExprNode):
rhstmp = code.funcstate.allocate_temp(self.entry.type, manage_ref=False)
code.putln('%s = %s;' % (rhstmp, rhs.result_as(self.ctype())))
import Buffer
from . import Buffer
Buffer.put_assign_to_buffer(self.result(), rhstmp, self.entry,
is_initialized=not self.lhs_of_first_assignment,
pos=self.pos, code=code)
......@@ -2829,7 +2831,6 @@ class IndexNode(ExprNode):
template_values = self.index.args
else:
template_values = [self.index]
import Nodes
type_node = Nodes.TemplatedTypeNode(
pos = self.pos,
positional_args = template_values,
......@@ -2989,7 +2990,7 @@ class IndexNode(ExprNode):
elif is_memslice:
# memoryviewslice indexing or slicing
import MemoryView
from . import MemoryView
skip_child_analysis = True
newaxes = [newaxis for newaxis in indices if newaxis.is_none]
......@@ -3682,7 +3683,7 @@ class IndexNode(ExprNode):
self.free_subexpr_temps(code)
def buffer_entry(self):
import Buffer, MemoryView
from . import Buffer, MemoryView
base = self.base
if self.base.is_nonecheck:
......@@ -3713,7 +3714,7 @@ class IndexNode(ExprNode):
code.putln("%s = %s;" % (temp, index.result()))
# Generate buffer access code using these temps
import Buffer
from . import Buffer
buffer_entry = self.buffer_entry()
if buffer_entry.type.is_buffer:
negative_indices = buffer_entry.type.negative_indices
......@@ -3759,12 +3760,12 @@ class IndexNode(ExprNode):
def generate_memoryviewslice_setslice_code(self, rhs, code):
"memslice1[...] = memslice2 or memslice1[:] = memslice2"
import MemoryView
from . import MemoryView
MemoryView.copy_broadcast_memview_src_to_dst(rhs, self, code)
def generate_memoryviewslice_assign_scalar_code(self, rhs, code):
"memslice1[...] = 0.0 or memslice1[:] = 0.0"
import MemoryView
from . import MemoryView
MemoryView.assign_scalar(self, rhs, code)
......@@ -5027,7 +5028,7 @@ class GeneralCallNode(CallNode):
# match keyword arguments that are passed out-of-order, but keep
# the evaluation of non-simple arguments in order by moving them
# into temps
from Cython.Compiler.UtilNodes import EvalWithTempExprNode, LetRefNode
from .UtilNodes import EvalWithTempExprNode, LetRefNode
temps = []
if len(kwargs.key_value_pairs) > matched_kwargs_count:
unmatched_args = declared_args[len(args):]
......@@ -5489,7 +5490,7 @@ class AttributeNode(ExprNode):
if self.is_py_attr:
self.gil_error()
elif self.type.is_memoryviewslice:
import MemoryView
from . import MemoryView
MemoryView.err_if_nogil_initialized_check(self.pos, env, 'attribute')
gil_message = "Accessing Python attribute"
......@@ -5634,7 +5635,7 @@ class AttributeNode(ExprNode):
code.put_gotref(select_code)
code.put_decref(select_code, self.ctype())
elif self.type.is_memoryviewslice:
import MemoryView
from . import MemoryView
MemoryView.put_assign_to_memviewslice(
select_code, rhs, rhs.result(), self.type, code)
......@@ -8536,7 +8537,7 @@ class CythonArrayNode(ExprNode):
shape_type = PyrexTypes.c_py_ssize_t_type
def analyse_types(self, env):
import MemoryView
from . import MemoryView
self.operand = self.operand.analyse_types(env)
if self.array_dtype:
......@@ -8653,7 +8654,7 @@ class CythonArrayNode(ExprNode):
return env.global_scope().context.cython_scope.viewscope.lookup("array").type
def generate_result_code(self, code):
import Buffer
from . import Buffer
shapes = [self.shape_type.cast_code(shape.result())
for shape in self.shapes]
......
from __future__ import absolute_import
cimport cython
from Cython.Compiler.Visitor cimport CythonTransform, TreeVisitor
from .Visitor cimport CythonTransform, TreeVisitor
cdef class ControlBlock:
cdef public set children
......
from __future__ import absolute_import
import cython
cython.declare(PyrexTypes=object, ExprNodes=object, Nodes=object,
Builtin=object, InternalError=object,
......@@ -6,15 +8,15 @@ cython.declare(PyrexTypes=object, ExprNodes=object, Nodes=object,
object_expr=object, object_expr_not_none=object,
fake_rhs_expr=object, TypedExprNode=object)
import Builtin
import ExprNodes
import Nodes
import Options
from PyrexTypes import py_object_type, unspecified_type
import PyrexTypes
from . import Builtin
from . import ExprNodes
from . import Nodes
from . import Options
from .PyrexTypes import py_object_type, unspecified_type
from . import PyrexTypes
from Visitor import TreeVisitor, CythonTransform
from Errors import error, warning, InternalError
from .Visitor import TreeVisitor, CythonTransform
from .Errors import error, warning, InternalError
class TypedExprNode(ExprNodes.ExprNode):
# Used for declaring assignments of a specified type without a known entry.
......
from __future__ import absolute_import
import copy
from Cython.Compiler import (ExprNodes, PyrexTypes, MemoryView,
ParseTreeTransforms, StringEncoding,
Errors)
from Cython.Compiler.ExprNodes import CloneNode, ProxyNode, TupleNode
from Cython.Compiler.Nodes import (FuncDefNode, CFuncDefNode, StatListNode,
DefNode)
from . import (ExprNodes, PyrexTypes, MemoryView,
ParseTreeTransforms, StringEncoding, Errors)
from .ExprNodes import CloneNode, ProxyNode, TupleNode
from .Nodes import FuncDefNode, CFuncDefNode, StatListNode, DefNode
class FusedCFuncDefNode(StatListNode):
"""
......@@ -384,7 +385,6 @@ class FusedCFuncDefNode(StatListNode):
to each specialization, which obtains the buffer each time and tries
to match the format string.
"""
from Cython.Compiler import ExprNodes
if buffer_types:
if pyx_code.indenter(u"else:"):
# The first thing to find a match in this loop breaks out of the loop
......@@ -520,7 +520,7 @@ class FusedCFuncDefNode(StatListNode):
arg tuple and kwargs dict (or None) and the defaults tuple
as arguments from the Binding Fused Function's tp_call.
"""
from Cython.Compiler import TreeFragment, Code, MemoryView, UtilityCode
from . import TreeFragment, Code, UtilityCode
# { (arg_pos, FusedType) : specialized_type }
seen_fused_types = set()
......
......@@ -6,9 +6,11 @@ For now this only covers parse tree to value conversion of
compile-time values.
"""
from Nodes import *
from ExprNodes import *
from Errors import CompileError
from __future__ import absolute_import
from .Nodes import *
from .ExprNodes import *
from .Errors import CompileError
class EmptyScope(object):
......
......@@ -3,6 +3,8 @@
# Cython Scanner - Lexical Definitions
#
from __future__ import absolute_import
raw_prefixes = "rR"
bytes_prefixes = "bB"
string_prefixes = "uU" + bytes_prefixes
......@@ -12,10 +14,10 @@ IDENT = 'IDENT'
def make_lexicon():
from Cython.Plex import \
from ..Plex import \
Str, Any, AnyBut, AnyChar, Rep, Rep1, Opt, Bol, Eol, Eof, \
TEXT, IGNORE, State, Lexicon
from Scanning import Method
from .Scanning import Method
letter = Any("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_")
digit = Any("0123456789")
......
......@@ -2,23 +2,29 @@
# Cython Top Level
#
import os, sys, re, codecs
from __future__ import absolute_import
import os
import re
import sys
import codecs
if sys.version_info[:2] < (2, 6) or (3, 0) <= sys.version_info[:2] < (3, 2):
sys.stderr.write("Sorry, Cython requires Python 2.6+ or 3.2+, found %d.%d\n" % tuple(sys.version_info[:2]))
sys.exit(1)
import Errors
from . import Errors
# Do not import Parsing here, import it when needed, because Parsing imports
# Nodes, which globally needs debug command line options initialized to set a
# conditional metaclass. These options are processed by CmdLine called from
# main() in this file.
# import Parsing
import Version
from Scanning import PyrexScanner, FileSourceDescriptor
from Errors import PyrexError, CompileError, error, warning
from Symtab import ModuleScope
from Cython import Utils
import Options
from .Scanning import PyrexScanner, FileSourceDescriptor
from .Errors import PyrexError, CompileError, error, warning
from .Symtab import ModuleScope
from .. import __version__ as version
from .. import Utils
from . import Options
module_name_pattern = re.compile(r"[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*$")
......@@ -58,7 +64,7 @@ class Context(object):
# an infinite loop.
# Better code organization would fix it.
import Builtin, CythonScope
from . import Builtin, CythonScope
self.modules = {"__builtin__" : Builtin.builtin_scope}
self.cython_scope = CythonScope.create_cython_scope(self)
self.modules["cython"] = self.cython_scope
......@@ -81,14 +87,14 @@ class Context(object):
def set_language_level(self, level):
self.language_level = level
if level >= 3:
from Future import print_function, unicode_literals, absolute_import
from .Future import print_function, unicode_literals, absolute_import
self.future_directives.update([print_function, unicode_literals, absolute_import])
self.modules['builtins'] = self.modules['__builtin__']
# pipeline creation functions can now be found in Pipeline.py
def process_pxd(self, source_desc, scope, module_name):
import Pipeline
from . import Pipeline
if isinstance(source_desc, FileSourceDescriptor) and source_desc._file_type == 'pyx':
source = CompilationSource(source_desc, module_name, os.getcwd())
result_sink = create_default_resultobj(source, self.options)
......@@ -294,7 +300,7 @@ class Context(object):
try:
f = Utils.open_source_file(source_filename, "rU")
try:
import Parsing
from . import Parsing
s = PyrexScanner(f, source_desc, source_encoding = f.encoding,
scope = scope, context = self)
tree = Parsing.p_module(s, pxd, full_module_name)
......@@ -391,7 +397,7 @@ def create_default_resultobj(compilation_source, options):
return result
def run_pipeline(source, options, full_module_name=None, context=None):
import Pipeline
from . import Pipeline
source_ext = os.path.splitext(source)[1]
options.configure_language_defaults(source_ext[1:]) # py/pyx
......@@ -619,14 +625,14 @@ def main(command_line = 0):
args = sys.argv[1:]
any_failures = 0
if command_line:
from CmdLine import parse_command_line
from .CmdLine import parse_command_line
options, sources = parse_command_line(args)
else:
options = CompilationOptions(default_options)
sources = args
if options.show_version:
sys.stderr.write("Cython version %s\n" % Version.version)
sys.stderr.write("Cython version %s\n" % version)
if options.working_path!="":
os.chdir(options.working_path)
try:
......
from Errors import CompileError, error
import ExprNodes
from ExprNodes import IntNode, NameNode, AttributeNode
import Options
from Code import UtilityCode, TempitaUtilityCode
from UtilityCode import CythonUtilityCode
import Buffer
import PyrexTypes
import ModuleNode
from __future__ import absolute_import
from .Errors import CompileError, error
from . import ExprNodes
from .ExprNodes import IntNode, NameNode, AttributeNode
from . import Options
from .Code import UtilityCode, TempitaUtilityCode
from .UtilityCode import CythonUtilityCode
from . import Buffer
from . import PyrexTypes
from . import ModuleNode
START_ERR = "Start must not be given."
STOP_ERR = "Axis specification only allowed in the 'step' slot."
......@@ -75,7 +77,7 @@ def put_init_entry(mv_cname, code):
def mangle_dtype_name(dtype):
# a dumb wrapper for now; move Buffer.mangle_dtype_name in here later?
import Buffer
from . import Buffer
return Buffer.mangle_dtype_name(dtype)
#def axes_to_str(axes):
......
......@@ -2,6 +2,8 @@
# Module parse tree node
#
from __future__ import absolute_import
import cython
cython.declare(Naming=object, Options=object, PyrexTypes=object, TypeSlots=object,
error=object, warning=object, py_object_type=object, UtilityCode=object,
......@@ -9,23 +11,23 @@ cython.declare(Naming=object, Options=object, PyrexTypes=object, TypeSlots=objec
import os
import operator
from PyrexTypes import CPtrType
import Future
from .PyrexTypes import CPtrType
from . import Future
import Annotate
import Code
import Naming
import Nodes
import Options
import TypeSlots
import Version
import PyrexTypes
from . import Annotate
from . import Code
from . import Naming
from . import Nodes
from . import Options
from . import TypeSlots
from . import Version
from . import PyrexTypes
from Errors import error, warning
from PyrexTypes import py_object_type
from Cython.Utils import open_new_file, replace_suffix, decode_filename
from Code import UtilityCode
from StringEncoding import EncodedString
from .Errors import error, warning
from .PyrexTypes import py_object_type
from ..Utils import open_new_file, replace_suffix, decode_filename
from .Code import UtilityCode
from .StringEncoding import EncodedString
......@@ -455,7 +457,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
if key in vtab_dict:
# FIXME: this should *never* happen, but apparently it does
# for Cython generated utility code
from Cython.Compiler.UtilityCode import NonManglingModuleScope
from .UtilityCode import NonManglingModuleScope
assert isinstance(entry.scope, NonManglingModuleScope), str(entry.scope)
assert isinstance(vtab_dict[key].scope, NonManglingModuleScope), str(vtab_dict[key].scope)
else:
......@@ -577,7 +579,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln("#else")
code.globalstate["end"].putln("#endif /* Py_PYTHON_H */")
from Cython import __version__
from .. import __version__
code.putln('#define CYTHON_ABI "%s"' % __version__.replace('.', '_'))
code.put(UtilityCode.load_as_string("CModulePreamble", "ModuleSetupCode.c")[1])
......
This diff is collapsed.
from Cython.Compiler import TypeSlots
from Cython.Compiler.ExprNodes import not_a_constant
from __future__ import absolute_import
from . import TypeSlots
from .ExprNodes import not_a_constant
import cython
cython.declare(UtilityCode=object, EncodedString=object, BytesLiteral=object,
Nodes=object, ExprNodes=object, PyrexTypes=object, Builtin=object,
UtilNodes=object, Naming=object)
import Nodes
import ExprNodes
import PyrexTypes
import Visitor
import Builtin
import UtilNodes
import Options
import Naming
from Code import UtilityCode
from StringEncoding import EncodedString, BytesLiteral
from Errors import error
from ParseTreeTransforms import SkipDeclarations
UtilNodes=object)
from . import Nodes
from . import ExprNodes
from . import PyrexTypes
from . import Visitor
from . import Builtin
from . import UtilNodes
from . import Options
from .Code import UtilityCode
from .StringEncoding import EncodedString, BytesLiteral
from .Errors import error
from .ParseTreeTransforms import SkipDeclarations
import copy
import codecs
......
......@@ -2,6 +2,8 @@
# Cython - Compilation-wide options and pragma declarations
#
from __future__ import absolute_import
# Perform lookups on builtin names only once, at module initialisation
# time. This will prevent the module from getting imported if a
# builtin name that it uses cannot be found during initialisation.
......
from __future__ import absolute_import
cimport cython
from Cython.Compiler.Visitor cimport (
from .Visitor cimport (
CythonTransform, VisitorTransform, TreeVisitor,
ScopeTrackingTransform, EnvTransform)
......
from __future__ import absolute_import
import copy
import cython
cython.declare(PyrexTypes=object, Naming=object, ExprNodes=object, Nodes=object,
Options=object, UtilNodes=object, LetNode=object,
LetRefNode=object, TreeFragment=object, EncodedString=object,
error=object, warning=object, copy=object)
import PyrexTypes
import Naming
import ExprNodes
import Nodes
import Options
import Builtin
from Cython.Compiler.Visitor import VisitorTransform, TreeVisitor
from Cython.Compiler.Visitor import CythonTransform, EnvTransform, ScopeTrackingTransform
from Cython.Compiler.UtilNodes import LetNode, LetRefNode, ResultRefNode
from Cython.Compiler.TreeFragment import TreeFragment
from Cython.Compiler.StringEncoding import EncodedString
from Cython.Compiler.Errors import error, warning, CompileError, InternalError
from Cython.Compiler.Code import UtilityCode
from . import PyrexTypes
from . import Naming
from . import ExprNodes
from . import Nodes
from . import Options
from . import Builtin
import copy
from .Visitor import VisitorTransform, TreeVisitor
from .Visitor import CythonTransform, EnvTransform, ScopeTrackingTransform
from .UtilNodes import LetNode, LetRefNode, ResultRefNode
from .TreeFragment import TreeFragment
from .StringEncoding import EncodedString
from .Errors import error, warning, CompileError, InternalError
from .Code import UtilityCode
class NameNodeCollector(TreeVisitor):
......@@ -1526,7 +1528,7 @@ if VALUE is not None:
def _create_fused_function(self, env, node):
"Create a fused function for a DefNode with fused arguments"
from Cython.Compiler import FusedNode
from . import FusedNode
if self.fused_function or self.in_lambda:
if self.fused_function not in self.fused_error_funcs:
......@@ -2540,8 +2542,8 @@ class TransformBuiltinMethods(EnvTransform):
if attribute == u'compiled':
node = ExprNodes.BoolNode(node.pos, value=True)
elif attribute == u'__version__':
import Cython
node = ExprNodes.StringNode(node.pos, value=EncodedString(Cython.__version__))
from .. import __version__ as version
node = ExprNodes.StringNode(node.pos, value=EncodedString(version))
elif attribute == u'NULL':
node = ExprNodes.NullNode(node.pos)
elif attribute in (u'set', u'frozenset'):
......@@ -2740,8 +2742,8 @@ class ReplaceFusedTypeChecks(VisitorTransform):
super(ReplaceFusedTypeChecks, self).__init__()
self.local_scope = local_scope
# defer the import until now to avoid circular import time dependencies
from Cython.Compiler import Optimize
self.transform = Optimize.ConstantFolding(reevaluate=True)
from .Optimize import ConstantFolding
self.transform = ConstantFolding(reevaluate=True)
def visit_IfStatNode(self, node):
"""
......
# We declare all of these here to type the first argument.
from __future__ import absolute_import
cimport cython
from Cython.Compiler.Scanning cimport PyrexScanner
from .Scanning cimport PyrexScanner
ctypedef object (*p_sub_expr_func)(PyrexScanner obj)
......
......@@ -3,6 +3,8 @@
# Parser
#
from __future__ import absolute_import
# This should be done automatically
import cython
cython.declare(Nodes=object, ExprNodes=object, EncodedString=object,
......@@ -15,17 +17,18 @@ cython.declare(Nodes=object, ExprNodes=object, EncodedString=object,
import re
from unicodedata import lookup as lookup_unicodechar
from Cython.Compiler.Scanning import PyrexScanner, FileSourceDescriptor
import Nodes
import ExprNodes
import Builtin
import StringEncoding
from StringEncoding import EncodedString, BytesLiteral, _unicode, _bytes
from ModuleNode import ModuleNode
from Errors import error, warning
from Cython import Utils
import Future
import Options
from .Scanning import PyrexScanner, FileSourceDescriptor
from . import Nodes
from . import ExprNodes
from . import Builtin
from . import StringEncoding
from .StringEncoding import EncodedString, BytesLiteral, _unicode, _bytes
from .ModuleNode import ModuleNode
from .Errors import error, warning
from .. import Utils
from . import Future
from . import Options
class Ctx(object):
# Parsing context
......@@ -3249,7 +3252,6 @@ def p_cpp_class_definition(s, pos, ctx):
templates = templates)
#----------------------------------------------
#
# Debugging
......@@ -3257,8 +3259,6 @@ def p_cpp_class_definition(s, pos, ctx):
#----------------------------------------------
def print_parse_tree(f, node, level, key = None):
from types import ListType, TupleType
from Nodes import Node
ind = " " * level
if node:
f.write(ind)
......@@ -3271,7 +3271,7 @@ def print_parse_tree(f, node, level, key = None):
print_parse_tree(f, node[i], level+1)
f.write("%s)\n" % ind)
return
elif isinstance(node, Node):
elif isinstance(node, Nodes.Node):
try:
tag = node.tag
except AttributeError:
......
from __future__ import absolute_import
import itertools
from time import time
import Errors
import DebugFlags
import Options
from Visitor import CythonTransform
from Errors import CompileError, InternalError, AbortError
import Naming
from . import Errors
from . import DebugFlags
from . import Options
from .Visitor import CythonTransform
from .Errors import CompileError, InternalError, AbortError
from . import Naming
#
# Really small pipeline stages
......@@ -56,8 +58,6 @@ def generate_pyx_code_stage_factory(options, result):
def inject_pxd_code_stage_factory(context):
def inject_pxd_code_stage(module_node):
from textwrap import dedent
stats = module_node.body.stats
for name, (statlistnode, scope) in context.pxds.iteritems():
module_node.merge_in(statlistnode, scope)
return module_node
......@@ -127,28 +127,28 @@ class UseUtilityCodeDefinitions(CythonTransform):
def create_pipeline(context, mode, exclude_classes=()):
assert mode in ('pyx', 'py', 'pxd')
from Visitor import PrintTree
from ParseTreeTransforms import WithTransform, NormalizeTree, PostParse, PxdPostParse
from ParseTreeTransforms import ForwardDeclareTypes, AnalyseDeclarationsTransform
from ParseTreeTransforms import AnalyseExpressionsTransform, FindInvalidUseOfFusedTypes
from ParseTreeTransforms import CreateClosureClasses, MarkClosureVisitor, DecoratorTransform
from ParseTreeTransforms import InterpretCompilerDirectives, TransformBuiltinMethods
from ParseTreeTransforms import ExpandInplaceOperators, ParallelRangeTransform
from ParseTreeTransforms import CalculateQualifiedNamesTransform
from TypeInference import MarkParallelAssignments, MarkOverflowingArithmetic
from ParseTreeTransforms import AdjustDefByDirectives, AlignFunctionDefinitions
from ParseTreeTransforms import RemoveUnreachableCode, GilCheck
from FlowControl import ControlFlowAnalysis
from AnalysedTreeTransforms import AutoTestDictTransform
from AutoDocTransforms import EmbedSignature
from Optimize import FlattenInListTransform, SwitchTransform, IterationTransform
from Optimize import EarlyReplaceBuiltinCalls, OptimizeBuiltinCalls
from Optimize import InlineDefNodeCalls
from Optimize import ConstantFolding, FinalOptimizePhase
from Optimize import DropRefcountingTransform
from Optimize import ConsolidateOverflowCheck
from Buffer import IntroduceBufferAuxiliaryVars
from ModuleNode import check_c_declarations, check_c_declarations_pxd
from .Visitor import PrintTree
from .ParseTreeTransforms import WithTransform, NormalizeTree, PostParse, PxdPostParse
from .ParseTreeTransforms import ForwardDeclareTypes, AnalyseDeclarationsTransform
from .ParseTreeTransforms import AnalyseExpressionsTransform, FindInvalidUseOfFusedTypes
from .ParseTreeTransforms import CreateClosureClasses, MarkClosureVisitor, DecoratorTransform
from .ParseTreeTransforms import InterpretCompilerDirectives, TransformBuiltinMethods
from .ParseTreeTransforms import ExpandInplaceOperators, ParallelRangeTransform
from .ParseTreeTransforms import CalculateQualifiedNamesTransform
from .TypeInference import MarkParallelAssignments, MarkOverflowingArithmetic
from .ParseTreeTransforms import AdjustDefByDirectives, AlignFunctionDefinitions
from .ParseTreeTransforms import RemoveUnreachableCode, GilCheck
from .FlowControl import ControlFlowAnalysis
from .AnalysedTreeTransforms import AutoTestDictTransform
from .AutoDocTransforms import EmbedSignature
from .Optimize import FlattenInListTransform, SwitchTransform, IterationTransform
from .Optimize import EarlyReplaceBuiltinCalls, OptimizeBuiltinCalls
from .Optimize import InlineDefNodeCalls
from .Optimize import ConstantFolding, FinalOptimizePhase
from .Optimize import DropRefcountingTransform
from .Optimize import ConsolidateOverflowCheck
from .Buffer import IntroduceBufferAuxiliaryVars
from .ModuleNode import check_c_declarations, check_c_declarations_pxd
if mode == 'pxd':
......@@ -221,12 +221,12 @@ def create_pyx_pipeline(context, options, result, py=False, exclude_classes=()):
mode = 'pyx'
test_support = []
if options.evaluate_tree_assertions:
from Cython.TestUtils import TreeAssertVisitor
from ..TestUtils import TreeAssertVisitor
test_support.append(TreeAssertVisitor())
if options.gdb_debug:
from Cython.Debugger import DebugWriter # requires Py2.5+
from ParseTreeTransforms import DebugTransform
from ..Debugger import DebugWriter # requires Py2.5+
from .ParseTreeTransforms import DebugTransform
context.gdb_debug_outputwriter = DebugWriter.CythonDebugWriter(
options.output_dir)
debug_transform = [DebugTransform(context, options, result)]
......@@ -244,7 +244,7 @@ def create_pyx_pipeline(context, options, result, py=False, exclude_classes=()):
[generate_pyx_code_stage_factory(options, result)]))
def create_pxd_pipeline(context, scope, module_name):
from CodeGeneration import ExtractPxdCode
from .CodeGeneration import ExtractPxdCode
# The pxd pipeline ends up with a CCodeWriter containing the
# code of the pxd, as well as a pxd scope.
......@@ -258,10 +258,10 @@ def create_py_pipeline(context, options, result):
return create_pyx_pipeline(context, options, result, py=True)
def create_pyx_as_pxd_pipeline(context, result):
from ParseTreeTransforms import AlignFunctionDefinitions, \
from .ParseTreeTransforms import AlignFunctionDefinitions, \
MarkClosureVisitor, WithTransform, AnalyseDeclarationsTransform
from Optimize import ConstantFolding, FlattenInListTransform
from Nodes import StatListNode
from .Optimize import ConstantFolding, FlattenInListTransform
from .Nodes import StatListNode
pipeline = []
pyx_pipeline = create_pyx_pipeline(context, context.options, result,
exclude_classes=[
......@@ -312,7 +312,7 @@ def insert_into_pipeline(pipeline, transform, before=None, after=None):
#
def run_pipeline(pipeline, source, printtree=True):
from Cython.Compiler.Visitor import PrintTree
from .Visitor import PrintTree
error = None
data = source
......
......@@ -2,11 +2,16 @@
# Cython/Python language types
#
from Code import UtilityCode, LazyUtilityCode, TempitaUtilityCode
import StringEncoding
import Naming
from __future__ import absolute_import
import copy
from Errors import error
from .Code import UtilityCode, LazyUtilityCode, TempitaUtilityCode
from . import StringEncoding
from . import Naming
from .Errors import error
class BaseType(object):
#
......@@ -508,7 +513,7 @@ class MemoryViewSliceType(PyrexType):
the *first* axis' packing spec and 'follow' for all other packing
specs.
"""
import MemoryView
from . import MemoryView
self.dtype = base_dtype
self.axes = axes
......@@ -542,14 +547,14 @@ class MemoryViewSliceType(PyrexType):
# XXX: we put these guards in for now...
assert not pyrex
assert not dll_linkage
import MemoryView
from . import MemoryView
return self.base_declaration_code(
MemoryView.memviewslice_cname,
entity_code)
def attributes_known(self):
if self.scope is None:
import Symtab
from . import Symtab
self.scope = scope = Symtab.CClassScope(
'mvs_class_'+self.specialization_suffix(),
......@@ -565,7 +570,7 @@ class MemoryViewSliceType(PyrexType):
return True
def declare_attribute(self, attribute, env, pos):
import MemoryView, Options
from . import MemoryView, Options
scope = self.scope
......@@ -652,7 +657,7 @@ class MemoryViewSliceType(PyrexType):
return cname + '.memview'
def create_from_py_utility_code(self, env):
import MemoryView, Buffer
from . import MemoryView, Buffer
# We don't have 'code', so use a LazyUtilityCode with a callback.
def lazy_utility_callback(code):
......@@ -741,13 +746,13 @@ class MemoryViewSliceType(PyrexType):
def axes_to_code(self):
"""Return a list of code constants for each axis"""
import MemoryView
from . import MemoryView
d = MemoryView._spec_to_const
return ["(%s | %s)" % (d[a], d[p]) for a, p in self.axes]
def axes_to_name(self):
"""Return an abbreviated name for our axes"""
import MemoryView
from . import MemoryView
d = MemoryView._spec_to_abbrev
return "".join(["%s%s" % (d[a], d[p]) for a, p in self.axes])
......@@ -755,7 +760,7 @@ class MemoryViewSliceType(PyrexType):
return "!%s.memview" % result_code
def __str__(self):
import MemoryView
from . import MemoryView
axes_code_list = []
for idx, (access, packing) in enumerate(self.axes):
......@@ -1220,7 +1225,7 @@ class CConstType(BaseType):
def __init__(self, const_base_type):
self.const_base_type = const_base_type
if const_base_type.has_attributes and const_base_type.scope is not None:
import Symtab
from . import Symtab
self.scope = Symtab.CConstScope(const_base_type.scope)
def __repr__(self):
......@@ -1366,7 +1371,7 @@ class CNumericType(CType):
def attributes_known(self):
if self.scope is None:
import Symtab
from . import Symtab
self.scope = scope = Symtab.CClassScope(
'',
None,
......@@ -1720,7 +1725,7 @@ class CComplexType(CNumericType):
def attributes_known(self):
if self.scope is None:
import Symtab
from . import Symtab
self.scope = scope = Symtab.CClassScope(
'',
None,
......@@ -3035,7 +3040,7 @@ class CppClassType(CType):
'cname': cname,
'maybe_unordered': self.maybe_unordered(),
}
from UtilityCode import CythonUtilityCode
from .UtilityCode import CythonUtilityCode
env.use_utility_code(CythonUtilityCode.load(cls.replace('unordered_', '') + ".from_py", "CppConvert.pyx", context=context))
self.from_py_function = cname
return True
......@@ -3064,7 +3069,7 @@ class CppClassType(CType):
'cname': cname,
'maybe_unordered': self.maybe_unordered(),
}
from UtilityCode import CythonUtilityCode
from .UtilityCode import CythonUtilityCode
env.use_utility_code(CythonUtilityCode.load(cls.replace('unordered_', '') + ".to_py", "CppConvert.pyx", context=context))
self.to_py_function = cname
return True
......@@ -3544,7 +3549,7 @@ def best_match(args, functions, pos=None, env=None):
", ".join([param.name for param in set(func_type.templates) - set(deductions.keys())]))))
else:
type_list = [deductions[param] for param in func_type.templates]
from Symtab import Entry
from .Symtab import Entry
specialization = Entry(
name = func.name + "[%s]" % ",".join([str(t) for t in type_list]),
cname = func.cname + "<%s>" % ",".join([t.declaration_code("") for t in type_list]),
......
from __future__ import absolute_import
import cython
from Cython.Plex.Scanners cimport Scanner
from ..Plex.Scanners cimport Scanner
cdef class Method:
cdef object name
......
......@@ -3,6 +3,8 @@
# Cython Scanner
#
from __future__ import absolute_import
import os
import platform
......@@ -10,14 +12,14 @@ import cython
cython.declare(EncodedString=object, any_string_prefix=unicode, IDENT=unicode,
print_function=object)
from Cython import Utils
from Cython.Plex.Scanners import Scanner
from Cython.Plex.Errors import UnrecognizedInput
from Errors import error
from Lexicon import any_string_prefix, make_lexicon, IDENT
from Future import print_function
from .. import Utils
from ..Plex.Scanners import Scanner
from ..Plex.Errors import UnrecognizedInput
from .Errors import error
from .Lexicon import any_string_prefix, make_lexicon, IDENT
from .Future import print_function
from StringEncoding import EncodedString
from .StringEncoding import EncodedString
debug_scanner = 0
trace_scanner = 0
......
......@@ -2,6 +2,8 @@
# Cython -- encoding related tools
#
from __future__ import absolute_import
import re
import sys
......@@ -17,6 +19,7 @@ empty_unicode = _unicode()
join_bytes = empty_bytes.join
class UnicodeLiteralBuilder(object):
"""Assemble a unicode string.
"""
......
......@@ -2,17 +2,19 @@
# Symbol Table
#
from __future__ import absolute_import
import copy
import re
from Errors import warning, error, InternalError
from StringEncoding import EncodedString
import Options, Naming
import PyrexTypes
from PyrexTypes import py_object_type, unspecified_type
from TypeSlots import \
from .Errors import warning, error, InternalError
from .StringEncoding import EncodedString
from . import Options, Naming
from . import PyrexTypes
from .PyrexTypes import py_object_type, unspecified_type
from .TypeSlots import \
pyfunction_signature, pymethod_signature, \
get_special_method_signature, get_property_accessor_signature
import Code
from . import Code
import __builtin__ as builtins
iso_c99_keywords = set(
......@@ -23,6 +25,7 @@ iso_c99_keywords = set(
'volatile', 'while',
'_Bool', '_Complex'', _Imaginary', 'inline', 'restrict'])
def c_safe_identifier(cname):
# There are some C limitations on struct entry names.
if ((cname[:2] == '__'
......@@ -431,7 +434,7 @@ class Scope(object):
entries[name] = entry
if type.is_memoryviewslice:
import MemoryView
from . import MemoryView
entry.init = MemoryView.memslice_entry_init
entry.scope = self
......@@ -801,7 +804,7 @@ class Scope(object):
return PyrexTypes.best_match(operands, function.all_alternatives())
def lookup_operator_for_types(self, pos, operator, types):
from Nodes import Node
from .Nodes import Node
class FakeOperand(Node):
pass
operands = [FakeOperand(pos, type=type) for type in types]
......@@ -823,7 +826,7 @@ class Scope(object):
return 0
def infer_types(self):
from TypeInference import get_type_inferer
from .TypeInference import get_type_inferer
get_type_inferer().infer_types(self)
def is_cpp(self):
......@@ -995,7 +998,7 @@ class ModuleScope(Scope):
is_cython_builtin = 0
def __init__(self, name, parent_module, context):
import Builtin
from . import Builtin
self.parent_module = parent_module
outer_scope = Builtin.builtin_scope
Scope.__init__(self, name, outer_scope, parent_module)
......@@ -1461,7 +1464,7 @@ class ModuleScope(Scope):
# variable entry attached to it. For the variable entry,
# we use a read-only C global variable whose name is an
# expression that refers to the type object.
import Builtin
from . import Builtin
var_entry = Entry(name = entry.name,
type = Builtin.type_type,
pos = entry.pos,
......@@ -1475,7 +1478,7 @@ class ModuleScope(Scope):
return self.cpp
def infer_types(self):
from TypeInference import PyObjectTypeInferer
from .TypeInference import PyObjectTypeInferer
PyObjectTypeInferer().infer_types(self)
......
......@@ -2,22 +2,26 @@
# TreeFragments - parsing of strings to trees
#
import re
from StringIO import StringIO
from Scanning import PyrexScanner, StringSourceDescriptor
from Symtab import ModuleScope
import PyrexTypes
from Visitor import VisitorTransform
from Nodes import Node, StatListNode
from ExprNodes import NameNode
import Parsing
import Main
import UtilNodes
"""
Support for parsing strings into code trees.
"""
from __future__ import absolute_import
import re
from StringIO import StringIO
from .Scanning import PyrexScanner, StringSourceDescriptor
from .Symtab import ModuleScope
from . import PyrexTypes
from .Visitor import VisitorTransform
from .Nodes import Node, StatListNode
from .ExprNodes import NameNode
from . import Parsing
from . import Main
from . import UtilNodes
class StringParseContext(Main.Context):
def __init__(self, name, include_directories=None):
if include_directories is None: include_directories = []
......@@ -30,6 +34,7 @@ class StringParseContext(Main.Context):
raise AssertionError("Not yet supporting any cimports/includes from string code snippets")
return ModuleScope(module_name, parent_module = None, context = self)
def parse_from_strings(name, code, pxds={}, level=None, initial_pos=None,
context=None, allow_struct_enum_decorator=False):
"""
......
......@@ -6,6 +6,8 @@ function selects a part of the expression, e.g. a child node, a
specific descendant or a node that holds an attribute.
"""
from __future__ import absolute_import
import re
import operator
......
from Errors import error, message
import ExprNodes
import Nodes
import Builtin
import PyrexTypes
from Cython import Utils
from PyrexTypes import py_object_type, unspecified_type
from Visitor import CythonTransform, EnvTransform
from __future__ import absolute_import
from .Errors import error, message
from . import ExprNodes
from . import Nodes
from . import Builtin
from . import PyrexTypes
from .. import Utils
from .PyrexTypes import py_object_type, unspecified_type
from .Visitor import CythonTransform, EnvTransform
class TypedExprNode(ExprNodes.ExprNode):
......
......@@ -3,13 +3,16 @@
# and associated know-how.
#
import Naming
import PyrexTypes
import StringEncoding
from __future__ import absolute_import
from . import Naming
from . import PyrexTypes
from . import StringEncoding
invisible = ['__cinit__', '__dealloc__', '__richcmp__',
'__nonzero__', '__bool__']
class Signature(object):
# Method slot signature descriptor.
#
......
......@@ -4,11 +4,14 @@
# so it is convenient to have them in a seperate module.
#
import Nodes
import ExprNodes
from Nodes import Node
from ExprNodes import AtomicExprNode
from PyrexTypes import c_ptr_type
from __future__ import absolute_import
from . import Nodes
from . import ExprNodes
from .Nodes import Node
from .ExprNodes import AtomicExprNode
from .PyrexTypes import c_ptr_type
class TempHandle(object):
# THIS IS DEPRECATED, USE LetRefNode instead
......
from TreeFragment import parse_from_strings, StringParseContext
import Symtab
import Naming
import Code
from __future__ import absolute_import
from .TreeFragment import parse_from_strings, StringParseContext
from . import Symtab
from . import Naming
from . import Code
class NonManglingModuleScope(Symtab.ModuleScope):
......@@ -83,13 +86,13 @@ class CythonUtilityCode(Code.UtilityCodeBase):
self.from_scope = from_scope
def get_tree(self, entries_only=False, cython_scope=None):
from AnalysedTreeTransforms import AutoTestDictTransform
from .AnalysedTreeTransforms import AutoTestDictTransform
# The AutoTestDictTransform creates the statement "__test__ = {}",
# which when copied into the main ModuleNode overwrites
# any __test__ in user code; not desired
excludes = [AutoTestDictTransform]
import Pipeline, ParseTreeTransforms
from . import Pipeline, ParseTreeTransforms
context = CythonUtilityCodeContext(self.name)
context.prefix = self.prefix
context.cython_scope = cython_scope
......
# for backwards compatibility
from Cython import __version__ as version
from __future__ import absolute_import
from .. import __version__ as version
# For generated by string.
......
from __future__ import absolute_import
cimport cython
cdef class TreeVisitor:
......
......@@ -3,14 +3,17 @@
#
# Tree visitor and transform framework
#
from __future__ import absolute_import
import inspect
from Cython.Compiler import TypeSlots
from Cython.Compiler import Builtin
from Cython.Compiler import Nodes
from Cython.Compiler import ExprNodes
from Cython.Compiler import Errors
from Cython.Compiler import DebugFlags
from . import TypeSlots
from . import Builtin
from . import Nodes
from . import ExprNodes
from . import Errors
from . import DebugFlags
import cython
......@@ -270,7 +273,7 @@ class CythonTransform(VisitorTransform):
self.context = context
def __call__(self, node):
import ModuleNode
from . import ModuleNode
if isinstance(node, ModuleNode.ModuleNode):
self.current_directives = node.directives
return super(CythonTransform, self).__call__(node)
......
......@@ -6,9 +6,12 @@
#
#=======================================================================
import Machines
from Machines import LOWEST_PRIORITY
from Transitions import TransitionMap
from __future__ import absolute_import
from . import Machines
from .Machines import LOWEST_PRIORITY
from .Transitions import TransitionMap
def nfa_to_dfa(old_machine, debug = None):
"""
......@@ -147,7 +150,7 @@ class StateMap(object):
return tuple(lst)
def dump(self, file):
from Transitions import state_set_str
from .Transitions import state_set_str
for new_state in self.new_machine.states:
old_state_set = self.new_to_old_dict[id(new_state)]
file.write(" State %s <-- %s\n" % (
......
......@@ -6,18 +6,21 @@
#
#=======================================================================
from __future__ import absolute_import
import types
import Actions
import DFA
import Errors
import Machines
import Regexps
from . import Actions
from . import DFA
from . import Errors
from . import Machines
from . import Regexps
# debug_flags for Lexicon constructor
DUMP_NFA = 1
DUMP_DFA = 2
class State(object):
"""
This class is used as part of a Plex.Lexicon specification to
......@@ -114,7 +117,7 @@ class Lexicon(object):
if type(specifications) != types.ListType:
raise Errors.InvalidScanner("Scanner definition is not a list")
if timings:
from Timing import time
from .Timing import time
total_time = 0.0
time1 = time()
nfa = Machines.Machine()
......
......@@ -6,12 +6,15 @@
#
#=======================================================================
from __future__ import absolute_import
import sys
from Transitions import TransitionMap
from .Transitions import TransitionMap
LOWEST_PRIORITY = -sys.maxint
class Machine(object):
"""A collection of Nodes representing an NFA or DFA."""
states = None # [Node]
......
......@@ -6,10 +6,12 @@
#
#=======================================================================
from __future__ import absolute_import
import types
from sys import maxint as maxint
import Errors
from . import Errors
#
# Constants
......@@ -21,6 +23,7 @@ EOF = 'eof'
nl_code = ord('\n')
#
# Helper functions
#
......
from __future__ import absolute_import
import cython
from Cython.Plex.Actions cimport Action
......
......@@ -7,14 +7,17 @@
#
#=======================================================================
from __future__ import absolute_import
import cython
cython.declare(BOL=object, EOL=object, EOF=object, NOT_FOUND=object)
import Errors
from Regexps import BOL, EOL, EOF
from . import Errors
from .Regexps import BOL, EOL, EOF
NOT_FOUND = object()
class Scanner(object):
"""
A Scanner is used to read tokens from a stream of characters
......
......@@ -2,6 +2,8 @@
# Get time in platform-dependent way
#
from __future__ import absolute_import
import os
from sys import platform, exit, stderr
......@@ -19,4 +21,3 @@ else:
stderr.write(
"Don't know how to get time on platform %s\n" % repr(platform))
exit(1)
......@@ -6,12 +6,16 @@
#
#=======================================================================
from Regexps import Alt, Seq, Rep, Rep1, Opt, Any, AnyBut, Bol, Eol, Char
from Errors import PlexError
from __future__ import absolute_import
from .Regexps import Alt, Seq, Rep, Rep1, Opt, Any, AnyBut, Bol, Eol, Char
from .Errors import PlexError
class RegexpSyntaxError(PlexError):
pass
def re(s):
"""
Convert traditional string representation of regular expression |s|
......@@ -19,6 +23,7 @@ def re(s):
"""
return REParser(s).parse_re()
class REParser(object):
def __init__(self, s):
......
#
# Plex - Transition Maps
#
# This version represents state sets direcly as dicts
# for speed.
# This version represents state sets directly as dicts for speed.
#
from __future__ import absolute_import
from sys import maxint as maxint
class TransitionMap(object):
"""
A TransitionMap maps an input event to a set of states.
......@@ -242,6 +244,3 @@ class TransitionMap(object):
def state_set_str(set):
return "[%s]" % ','.join(["S%d" % state.number for state in set])
......@@ -30,11 +30,10 @@ see the attached docstrings for more information.
creating a Lexicon.
"""
from Actions import TEXT, IGNORE, Begin
from Lexicons import Lexicon, State
from Regexps import RE, Seq, Alt, Rep1, Empty, Str, Any, AnyBut, AnyChar, Range
from Regexps import Opt, Rep, Bol, Eol, Eof, Case, NoCase
from Scanners import Scanner
from __future__ import absolute_import
from .Actions import TEXT, IGNORE, Begin
from .Lexicons import Lexicon, State
from .Regexps import RE, Seq, Alt, Rep1, Empty, Str, Any, AnyBut, AnyChar, Range
from .Regexps import Opt, Rep, Bol, Eol, Eof, Case, NoCase
from .Scanners import Scanner
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment