Skip to content

Commit 4ab2998

Browse files
committed
cleaned up and tested extensions lecture and examples
1 parent 9bb9b27 commit 4ab2998

File tree

7 files changed

+1029
-43
lines changed

7 files changed

+1029
-43
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#!/usr/bin/env python
22

3-
from distutils.core import setup, Extension
3+
from setuptools import setup, Extension
44

55
setup(
66
name='Cdiv',
77
version='1.0',
88
description='sample method that does exceptions',
99
ext_modules=[Extension('divide', sources=['divide.c'])],
1010
)
11-
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
#!/usr/bin/env python
22

3-
from distutils.core import setup
4-
from distutils.extension import Extension
3+
from setuptools import setup
54
from Cython.Build import cythonize
65

7-
setup(name = "cython_example",
8-
ext_modules = cythonize(['cy_integrate1.pyx',
9-
'cy_integrate2.pyx',
10-
'cy_integrate3.pyx',
11-
'cy_integrate4.pyx',
12-
'cy_integrate5.pyx',
13-
'cy_integrate6.pyx',
14-
'cy_integrate7.pyx',
15-
])
6+
setup(name="cython_example",
7+
ext_modules=cythonize(['cy_integrate1.pyx',
8+
'cy_integrate2.pyx',
9+
'cy_integrate3.pyx',
10+
'cy_integrate4.pyx',
11+
'cy_integrate5.pyx',
12+
'cy_integrate6.pyx',
13+
'cy_integrate7.pyx',
14+
])
1615
)
17-
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#!/usr/bin/env python
22

3-
from distutils.core import setup
3+
from setuptools import setup
44
from Cython.Build import cythonize
55

6-
setup(name = "cython_example",
7-
ext_modules = cythonize(['cy_add_c.pyx',
8-
'cy_add1.pyx',
9-
'cy_add2.pyx',
10-
] )
6+
setup(name="cython_example",
7+
ext_modules=cythonize(['cy_add_c.pyx',
8+
'cy_add1.pyx',
9+
'cy_add2.pyx',
10+
])
1111

1212
)
13-

Examples/week-08-extensions/distutils/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from distutils.core import setup, Extension
1+
from setuptools import setup
22

33
setup(
44
name='add',

Examples/week-08-extensions/swig/add.py

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This file was automatically generated by SWIG (http://www.swig.org).
2-
# Version 3.0.0
2+
# Version 3.0.5
33
#
44
# Do not make changes to this file unless you know what you are doing--modify
55
# the SWIG interface file instead.
@@ -9,7 +9,7 @@
99

1010

1111
from sys import version_info
12-
if version_info >= (2,6,0):
12+
if version_info >= (2, 6, 0):
1313
def swig_import_helper():
1414
from os.path import dirname
1515
import imp
@@ -33,45 +33,66 @@ def swig_import_helper():
3333
try:
3434
_swig_property = property
3535
except NameError:
36-
pass # Python < 2.2 doesn't have 'property'.
37-
def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
38-
if (name == "thisown"): return self.this.own(value)
36+
pass # Python < 2.2 doesn't have 'property'.
37+
38+
39+
def _swig_setattr_nondynamic(self, class_type, name, value, static=1):
40+
if (name == "thisown"):
41+
return self.this.own(value)
3942
if (name == "this"):
4043
if type(value).__name__ == 'SwigPyObject':
4144
self.__dict__[name] = value
4245
return
43-
method = class_type.__swig_setmethods__.get(name,None)
44-
if method: return method(self,value)
46+
method = class_type.__swig_setmethods__.get(name, None)
47+
if method:
48+
return method(self, value)
4549
if (not static):
46-
self.__dict__[name] = value
50+
if _newclass:
51+
object.__setattr__(self, name, value)
52+
else:
53+
self.__dict__[name] = value
4754
else:
4855
raise AttributeError("You cannot add attributes to %s" % self)
4956

50-
def _swig_setattr(self,class_type,name,value):
51-
return _swig_setattr_nondynamic(self,class_type,name,value,0)
5257

53-
def _swig_getattr(self,class_type,name):
54-
if (name == "thisown"): return self.this.own()
55-
method = class_type.__swig_getmethods__.get(name,None)
56-
if method: return method(self)
57-
raise AttributeError(name)
58+
def _swig_setattr(self, class_type, name, value):
59+
return _swig_setattr_nondynamic(self, class_type, name, value, 0)
60+
61+
62+
def _swig_getattr_nondynamic(self, class_type, name, static=1):
63+
if (name == "thisown"):
64+
return self.this.own()
65+
method = class_type.__swig_getmethods__.get(name, None)
66+
if method:
67+
return method(self)
68+
if (not static):
69+
return object.__getattr__(self, name)
70+
else:
71+
raise AttributeError(name)
72+
73+
def _swig_getattr(self, class_type, name):
74+
return _swig_getattr_nondynamic(self, class_type, name, 0)
75+
5876

5977
def _swig_repr(self):
60-
try: strthis = "proxy of " + self.this.__repr__()
61-
except: strthis = ""
78+
try:
79+
strthis = "proxy of " + self.this.__repr__()
80+
except:
81+
strthis = ""
6282
return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
6383

6484
try:
6585
_object = object
6686
_newclass = 1
6787
except AttributeError:
68-
class _object : pass
88+
class _object:
89+
pass
6990
_newclass = 0
7091

7192

7293

73-
def add(*args):
74-
return _add.add(*args)
94+
def add(x, y):
95+
return _add.add(x, y)
7596
add = _add.add
7697
# This file is compatible with both classic and new-style classes.
7798

Examples/week-08-extensions/swig/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
from distutils.core import setup, Extension
3+
from setuptools import setup, Extension
44

55
setup(
66
name='add',

0 commit comments

Comments
 (0)