Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Xavier Thompson
cython
Commits
a0fff9f2
Commit
a0fff9f2
authored
Aug 05, 2011
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some Python 2.3 cleanup.
parent
5ace507f
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
49 additions
and
115 deletions
+49
-115
Cython/Build/Dependencies.py
Cython/Build/Dependencies.py
+7
-15
Cython/Build/Inline.py
Cython/Build/Inline.py
+0
-1
Cython/Compiler/Buffer.py
Cython/Compiler/Buffer.py
+0
-5
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+4
-4
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+0
-1
Cython/Compiler/FlowControl.py
Cython/Compiler/FlowControl.py
+4
-6
Cython/Compiler/Main.py
Cython/Compiler/Main.py
+0
-6
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+0
-1
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+0
-1
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+0
-1
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+8
-8
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+3
-3
Cython/Compiler/Scanning.py
Cython/Compiler/Scanning.py
+2
-2
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+0
-5
Cython/Compiler/TypeInference.py
Cython/Compiler/TypeInference.py
+0
-6
Cython/Shadow.py
Cython/Shadow.py
+0
-11
runtests.py
runtests.py
+21
-39
No files found.
Cython/Build/Dependencies.py
View file @
a0fff9f2
from
glob
import
glob
import
re
,
os
,
sys
from
cython
import
set
from
distutils.extension
import
Extension
...
...
@@ -8,7 +7,6 @@ from distutils.extension import Extension
from
Cython
import
Utils
from
Cython.Compiler.Main
import
Context
,
CompilationOptions
,
default_options
# Unfortunately, Python 2.3 doesn't support decorators.
def
cached_method
(
f
):
cache_name
=
'__%s_cache'
%
f
.
__name__
def
wrapper
(
self
,
*
args
):
...
...
@@ -254,12 +252,11 @@ class DependencyTree(object):
self
.
context
=
context
self
.
_transitive_cache
=
{}
#
@cached_method
@
cached_method
def
parse_dependencies
(
self
,
source_filename
):
return
parse_dependencies
(
source_filename
)
parse_dependencies
=
cached_method
(
parse_dependencies
)
#@cached_method
@
cached_method
def
cimports_and_externs
(
self
,
filename
):
cimports
,
includes
,
externs
=
self
.
parse_dependencies
(
filename
)[:
3
]
cimports
=
set
(
cimports
)
...
...
@@ -275,25 +272,22 @@ class DependencyTree(object):
else
:
print
(
"Unable to locate '%s' referenced from '%s'"
%
(
filename
,
include
))
return
tuple
(
cimports
),
tuple
(
externs
)
cimports_and_externs
=
cached_method
(
cimports_and_externs
)
def
cimports
(
self
,
filename
):
return
self
.
cimports_and_externs
(
filename
)[
0
]
#
@cached_method
@
cached_method
def
package
(
self
,
filename
):
dir
=
os
.
path
.
dirname
(
filename
)
if
os
.
path
.
exists
(
os
.
path
.
join
(
dir
,
'__init__.py'
)):
return
self
.
package
(
dir
)
+
(
os
.
path
.
basename
(
dir
),)
else
:
return
()
package
=
cached_method
(
package
)
#
@cached_method
@
cached_method
def
fully_qualifeid_name
(
self
,
filename
):
module
=
os
.
path
.
splitext
(
os
.
path
.
basename
(
filename
))[
0
]
return
'.'
.
join
(
self
.
package
(
filename
)
+
(
module
,))
fully_qualifeid_name
=
cached_method
(
fully_qualifeid_name
)
def
find_pxd
(
self
,
module
,
filename
=
None
):
if
module
[
0
]
==
'.'
:
...
...
@@ -306,7 +300,7 @@ class DependencyTree(object):
return
self
.
context
.
find_pxd_file
(
module
,
None
)
find_pxd
=
cached_method
(
find_pxd
)
#
@cached_method
@
cached_method
def
cimported_files
(
self
,
filename
):
if
filename
[
-
4
:]
==
'.pyx'
and
os
.
path
.
exists
(
filename
[:
-
4
]
+
'.pxd'
):
self_pxd
=
[
filename
[:
-
4
]
+
'.pxd'
]
...
...
@@ -319,7 +313,6 @@ class DependencyTree(object):
print
(
"
\
n
\
t
"
.
join
(
a
))
print
(
"
\
n
\
t
"
.
join
(
b
))
return
tuple
(
self_pxd
+
filter
(
None
,
[
self
.
find_pxd
(
m
,
filename
)
for
m
in
self
.
cimports
(
filename
)]))
cimported_files
=
cached_method
(
cimported_files
)
def
immediate_dependencies
(
self
,
filename
):
all
=
list
(
self
.
cimported_files
(
filename
))
...
...
@@ -327,10 +320,9 @@ class DependencyTree(object):
all
.
append
(
os
.
path
.
normpath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
filename
),
extern
)))
return
tuple
(
all
)
#
@cached_method
@
cached_method
def
timestamp
(
self
,
filename
):
return
os
.
path
.
getmtime
(
filename
)
timestamp
=
cached_method
(
timestamp
)
def
extract_timestamp
(
self
,
filename
):
# TODO: .h files from extern blocks
...
...
Cython/Build/Inline.py
View file @
a0fff9f2
import
tempfile
import
sys
,
os
,
re
,
inspect
from
cython
import
set
try
:
import
hashlib
...
...
Cython/Compiler/Buffer.py
View file @
a0fff9f2
...
...
@@ -10,11 +10,6 @@ import PyrexTypes
import
Naming
import
Symtab
try
:
set
except
NameError
:
from
sets
import
Set
as
set
import
textwrap
def
dedent
(
text
,
reindent
=
0
):
...
...
Cython/Compiler/Code.py
View file @
a0fff9f2
...
...
@@ -118,13 +118,13 @@ class FunctionState(object):
# exc_vars (string * 3) exception variables for reraise, or None
# Not used for now, perhaps later
def
__init__
(
self
,
owner
,
names_taken
=
cython
.
set
()):
def
__init__
(
self
,
owner
,
names_taken
=
set
()):
self
.
names_taken
=
names_taken
self
.
owner
=
owner
self
.
error_label
=
None
self
.
label_counter
=
0
self
.
labels_used
=
cython
.
set
()
self
.
labels_used
=
set
()
self
.
return_label
=
self
.
new_label
()
self
.
new_error_label
()
self
.
continue_label
=
None
...
...
@@ -309,7 +309,7 @@ class FunctionState(object):
"""
Useful to find out which temps were used in a code block
"""
self
.
collect_temps_stack
.
append
(
cython
.
set
())
self
.
collect_temps_stack
.
append
(
set
())
def
stop_collecting_temps
(
self
):
return
self
.
collect_temps_stack
.
pop
()
...
...
@@ -504,7 +504,7 @@ class GlobalState(object):
self.filename_table = {}
self.filename_list = []
self.input_file_contents = {}
self.utility_codes =
cython.
set()
self.utility_codes = set()
self.declared_cnames = {}
self.in_utility_code_generation = False
self.emit_linenums = emit_linenums
...
...
Cython/Compiler/ExprNodes.py
View file @
a0fff9f2
...
...
@@ -3,7 +3,6 @@
#
import
cython
from
cython
import
set
cython
.
declare
(
error
=
object
,
warning
=
object
,
warn_once
=
object
,
InternalError
=
object
,
CompileError
=
object
,
UtilityCode
=
object
,
StringEncoding
=
object
,
operator
=
object
,
Naming
=
object
,
Nodes
=
object
,
PyrexTypes
=
object
,
py_object_type
=
object
,
...
...
Cython/Compiler/FlowControl.py
View file @
a0fff9f2
...
...
@@ -13,8 +13,6 @@ from PyrexTypes import py_object_type, unspecified_type
from
Visitor
import
TreeVisitor
,
CythonTransform
from
Errors
import
error
,
warning
,
CompileError
,
InternalError
from
cython
import
set
class
TypedExprNode
(
ExprNodes
.
ExprNode
):
# Used for declaring assignments of a specified type whithout a known entry.
def
__init__
(
self
,
type
):
...
...
@@ -215,7 +213,7 @@ class ControlFlow(object):
offset
=
0
for
entry
in
self
.
entries
:
assmts
=
AssignmentList
()
assmts
.
bit
=
1
L
<<
offset
assmts
.
bit
=
1
<<
offset
assmts
.
mask
=
assmts
.
bit
self
.
assmts
[
entry
]
=
assmts
offset
+=
1
...
...
@@ -223,7 +221,7 @@ class ControlFlow(object):
for
block
in
self
.
blocks
:
for
stat
in
block
.
stats
:
if
isinstance
(
stat
,
NameAssignment
):
stat
.
bit
=
1
L
<<
offset
stat
.
bit
=
1
<<
offset
assmts
=
self
.
assmts
[
stat
.
entry
]
assmts
.
stats
.
append
(
stat
)
assmts
.
mask
|=
stat
.
bit
...
...
@@ -561,7 +559,7 @@ class CreateControlFlowGraph(CythonTransform):
self
.
gv_ctx
=
GVContext
()
# Set of NameNode reductions
self
.
reductions
=
cython
.
set
()
self
.
reductions
=
set
()
self
.
env_stack
=
[]
self
.
env
=
node
.
scope
...
...
@@ -857,7 +855,7 @@ class CreateControlFlowGraph(CythonTransform):
# if node.target is None or not a NameNode, an error will have
# been previously issued
if
hasattr
(
node
.
target
,
'entry'
):
self
.
reductions
=
cython
.
set
(
reductions
)
self
.
reductions
=
set
(
reductions
)
for
private_node
in
node
.
assigned_nodes
:
private_node
.
entry
.
error_on_uninitialized
=
True
...
...
Cython/Compiler/Main.py
View file @
a0fff9f2
...
...
@@ -7,12 +7,6 @@ if sys.version_info[:2] < (2, 3):
sys
.
stderr
.
write
(
"Sorry, Cython requires Python 2.3 or later
\
n
"
)
sys
.
exit
(
1
)
try
:
set
except
NameError
:
# Python 2.3
from
sets
import
Set
as
set
import
itertools
import
Code
...
...
Cython/Compiler/ModuleNode.py
View file @
a0fff9f2
...
...
@@ -3,7 +3,6 @@
#
import
cython
from
cython
import
set
cython
.
declare
(
Naming
=
object
,
Options
=
object
,
PyrexTypes
=
object
,
TypeSlots
=
object
,
error
=
object
,
warning
=
object
,
py_object_type
=
object
,
UtilityCode
=
object
,
EncodedString
=
object
)
...
...
Cython/Compiler/Nodes.py
View file @
a0fff9f2
...
...
@@ -3,7 +3,6 @@
# Pyrex - Parse tree nodes
#
import
cython
from
cython
import
set
cython
.
declare
(
sys
=
object
,
os
=
object
,
time
=
object
,
copy
=
object
,
Builtin
=
object
,
error
=
object
,
warning
=
object
,
Naming
=
object
,
PyrexTypes
=
object
,
py_object_type
=
object
,
ModuleScope
=
object
,
LocalScope
=
object
,
ClosureScope
=
object
,
\
...
...
Cython/Compiler/Optimize.py
View file @
a0fff9f2
import
cython
from
cython
import
set
cython
.
declare
(
UtilityCode
=
object
,
EncodedString
=
object
,
BytesLiteral
=
object
,
Nodes
=
object
,
ExprNodes
=
object
,
PyrexTypes
=
object
,
Builtin
=
object
,
UtilNodes
=
object
,
Naming
=
object
)
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
a0fff9f2
...
...
@@ -339,7 +339,7 @@ def eliminate_rhs_duplicates(expr_list_list, ref_node_sequence):
and appends them to ref_node_sequence. The input list is modified
in-place.
"""
seen_nodes
=
cython
.
set
()
seen_nodes
=
set
()
ref_nodes
=
{}
def
find_duplicates
(
node
):
if
node
.
is_literal
or
node
.
is_name
:
...
...
@@ -610,11 +610,11 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
'operator.comma'
:
ExprNodes
.
c_binop_constructor
(
','
),
}
special_methods
=
cython
.
set
([
'declare'
,
'union'
,
'struct'
,
'typedef'
,
'sizeof'
,
special_methods
=
set
([
'declare'
,
'union'
,
'struct'
,
'typedef'
,
'sizeof'
,
'cast'
,
'pointer'
,
'compiled'
,
'NULL'
,
'parallel'
])
special_methods
.
update
(
unop_method_nodes
.
keys
())
valid_parallel_directives
=
cython
.
set
([
valid_parallel_directives
=
set
([
"parallel"
,
"prange"
,
"threadid"
,
...
...
@@ -626,7 +626,7 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
self
.
compilation_directive_defaults
=
{}
for
key
,
value
in
compilation_directive_defaults
.
items
():
self
.
compilation_directive_defaults
[
unicode
(
key
)]
=
copy
.
deepcopy
(
value
)
self
.
cython_module_names
=
cython
.
set
()
self
.
cython_module_names
=
set
()
self
.
directive_names
=
{}
self
.
parallel_directives
=
{}
...
...
@@ -1380,7 +1380,7 @@ if VALUE is not None:
return
node
def
visit_ModuleNode
(
self
,
node
):
self
.
seen_vars_stack
.
append
(
cython
.
set
())
self
.
seen_vars_stack
.
append
(
set
())
node
.
analyse_declarations
(
self
.
env_stack
[
-
1
])
self
.
visitchildren
(
node
)
self
.
seen_vars_stack
.
pop
()
...
...
@@ -1412,7 +1412,7 @@ if VALUE is not None:
return
node
def
visit_FuncDefNode
(
self
,
node
):
self
.
seen_vars_stack
.
append
(
cython
.
set
())
self
.
seen_vars_stack
.
append
(
set
())
lenv
=
node
.
local_scope
node
.
declare_arguments
(
lenv
)
for
var
,
type_node
in
node
.
directive_locals
.
items
():
...
...
@@ -1446,7 +1446,7 @@ if VALUE is not None:
node
.
analyse_declarations
(
env
)
# the node may or may not have a local scope
if
node
.
has_local_scope
:
self
.
seen_vars_stack
.
append
(
cython
.
set
(
self
.
seen_vars_stack
[
-
1
]))
self
.
seen_vars_stack
.
append
(
set
(
self
.
seen_vars_stack
[
-
1
]))
self
.
env_stack
.
append
(
node
.
expr_scope
)
node
.
analyse_scoped_declarations
(
node
.
expr_scope
)
self
.
visitchildren
(
node
)
...
...
@@ -2345,7 +2345,7 @@ class DebugTransform(CythonTransform):
def
__init__
(
self
,
context
,
options
,
result
):
super
(
DebugTransform
,
self
).
__init__
(
context
)
self
.
visited
=
cython
.
set
()
self
.
visited
=
set
()
# our treebuilder and debug output writer
# (see Cython.Debugger.debug_output.CythonDebugWriter)
self
.
tb
=
self
.
context
.
gdb_debug_outputwriter
...
...
Cython/Compiler/Parsing.py
View file @
a0fff9f2
...
...
@@ -875,7 +875,7 @@ def p_comp_for(s, body):
pos
=
s
.
position
()
s
.
next
()
kw
=
p_for_bounds
(
s
,
allow_testlist
=
False
)
kw
.
update
(
dict
(
else_clause
=
None
,
body
=
p_comp_iter
(
s
,
body
)
))
kw
.
update
(
else_clause
=
None
,
body
=
p_comp_iter
(
s
,
body
))
return
Nodes
.
ForStatNode
(
pos
,
**
kw
)
def
p_comp_if
(
s
,
body
):
...
...
@@ -1404,7 +1404,7 @@ def p_for_statement(s):
kw
=
p_for_bounds
(
s
,
allow_testlist
=
True
)
body
=
p_suite
(
s
)
else_clause
=
p_else_clause
(
s
)
kw
.
update
(
dict
(
body
=
body
,
else_clause
=
else_clause
)
)
kw
.
update
(
body
=
body
,
else_clause
=
else_clause
)
return
Nodes
.
ForStatNode
(
pos
,
**
kw
)
def
p_for_bounds
(
s
,
allow_testlist
=
True
):
...
...
@@ -2187,7 +2187,7 @@ def p_c_func_declarator(s, pos, ctx, base, cmethod_flag):
exception_value
=
exc_val
,
exception_check
=
exc_check
,
nogil
=
nogil
or
ctx
.
nogil
or
with_gil
,
with_gil
=
with_gil
)
supported_overloaded_operators
=
cython
.
set
([
supported_overloaded_operators
=
set
([
'+'
,
'-'
,
'*'
,
'/'
,
'%'
,
'++'
,
'--'
,
'~'
,
'|'
,
'&'
,
'^'
,
'<<'
,
'>>'
,
','
,
'=='
,
'!='
,
'>='
,
'>'
,
'<='
,
'<'
,
...
...
Cython/Compiler/Scanning.py
View file @
a0fff9f2
...
...
@@ -282,10 +282,10 @@ class PyrexScanner(Scanner):
self
.
source_encoding
=
source_encoding
if
filename
.
is_python_file
():
self
.
in_python_file
=
True
self
.
keywords
=
cython
.
set
(
py_reserved_words
)
self
.
keywords
=
set
(
py_reserved_words
)
else
:
self
.
in_python_file
=
False
self
.
keywords
=
cython
.
set
(
pyx_reserved_words
)
self
.
keywords
=
set
(
pyx_reserved_words
)
self
.
trace
=
trace_scanner
self
.
indentation_stack
=
[
0
]
self
.
indentation_char
=
None
...
...
Cython/Compiler/Symtab.py
View file @
a0fff9f2
...
...
@@ -15,11 +15,6 @@ from TypeSlots import \
get_special_method_signature
,
get_property_accessor_signature
import
Code
import
__builtin__
as
builtins
try
:
set
except
NameError
:
from
sets
import
Set
as
set
import
copy
possible_identifier
=
re
.
compile
(
ur"(?![0-9])\
w+$
", re.U).match
nice_identifier = re.compile('^[a-zA-Z0-0_]+$').match
...
...
Cython/Compiler/TypeInference.py
View file @
a0fff9f2
...
...
@@ -7,12 +7,6 @@ from Cython import Utils
from
PyrexTypes
import
py_object_type
,
unspecified_type
from
Visitor
import
CythonTransform
try
:
set
except
NameError
:
# Python 2.3
from
sets
import
Set
as
set
class
TypedExprNode
(
ExprNodes
.
ExprNode
):
# Used for declaring assignments of a specified type whithout a known entry.
...
...
Cython/Shadow.py
View file @
a0fff9f2
...
...
@@ -239,17 +239,6 @@ py_float = float
py_complex
=
complex
try
:
# Python 3
from
builtins
import
set
,
frozenset
except
ImportError
:
try
:
# Python 2.4+
from
__builtin__
import
set
,
frozenset
except
ImportError
:
# Py 2.3
from
sets
import
Set
as
set
,
ImmutableSet
as
frozenset
# Predefined types
int_types
=
[
'char'
,
'short'
,
'Py_UNICODE'
,
'int'
,
'long'
,
'longlong'
,
'Py_ssize_t'
,
'size_t'
]
...
...
runtests.py
View file @
a0fff9f2
...
...
@@ -11,9 +11,11 @@ import time
import
unittest
import
doctest
import
operator
import
subprocess
import
tempfile
import
warnings
import
traceback
import
warnings
try
:
from
StringIO
import
StringIO
except
ImportError
:
...
...
@@ -116,24 +118,13 @@ def get_openmp_compiler_flags(language):
matcher
=
re
.
compile
(
r"gcc version (\
d+
\.\
d+)
").search
try:
import subprocess
except ImportError:
try:
in_, out_err = os.popen4([cc, "
-
v
"])
except EnvironmentError:
warnings.warn("
Unable
to
find
the
%
s
compiler
:
%
s
:
%
s
" %
(language, os.strerror(sys.exc_info()[1].errno), cc))
return None
output = out_err.read()
else:
try:
p = subprocess.Popen([cc, "
-
v
"], stderr=subprocess.PIPE)
except EnvironmentError:
# Be compatible with Python 3
warnings.warn("
Unable
to
find
the
%
s
compiler
:
%
s
:
%
s
" %
(language, os.strerror(sys.exc_info()[1].errno), cc))
return None
_, output = p.communicate()
p = subprocess.Popen([cc, "
-
v
"], stderr=subprocess.PIPE)
except EnvironmentError:
# Be compatible with Python 3
warnings.warn("
Unable
to
find
the
%
s
compiler
:
%
s
:
%
s
" %
(language, os.strerror(sys.exc_info()[1].errno), cc))
return None
_, output = p.communicate()
output = output.decode(locale.getpreferredencoding() or 'ASCII', 'replace')
...
...
@@ -1036,20 +1027,16 @@ class EndToEndTest(unittest.TestCase):
old_path = os.environ.get('PYTHONPATH')
os.environ['PYTHONPATH'] = self.cython_syspath + os.pathsep + os.path.join(self.cython_syspath, (old_path or ''))
for command in commands.split('
\
n
'):
if sys.version_info[:2] >= (2,4):
import subprocess
p = subprocess.Popen(commands,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
shell=True)
out, err = p.communicate()
res = p.returncode
if res != 0:
print(command)
print(out)
print(err)
else:
res = os.system(command)
p = subprocess.Popen(commands,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
shell=True)
out, err = p.communicate()
res = p.returncode
if res != 0:
print(command)
print(out)
print(err)
self.assertEqual(0, res, "
non
-
zero
exit
status
")
finally:
if old_path:
...
...
@@ -1238,12 +1225,7 @@ def check_thread_termination(ignore_seen=True):
def subprocess_output(cmd):
try:
try:
import subprocess
except:
return os.popen4(cmd)[1].read()
else:
return subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0]
return subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0]
except OSError:
return ''
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment