Show More
@@ -1,23 +1,24 | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 | """The IPython1 kernel. |
|
2 | """The IPython1 kernel. | |
3 |
|
3 | |||
4 | The IPython kernel actually refers to three things: |
|
4 | The IPython kernel actually refers to three things: | |
5 |
|
5 | |||
6 | * The IPython Engine |
|
6 | * The IPython Engine | |
7 | * The IPython Controller |
|
7 | * The IPython Controller | |
8 | * Clients to the IPython Controller |
|
8 | * Clients to the IPython Controller | |
9 |
|
9 | |||
10 | The kernel module implements the engine, controller and client and all the |
|
10 | The kernel module implements the engine, controller and client and all the | |
11 | network protocols needed for the various entities to talk to each other. |
|
11 | network protocols needed for the various entities to talk to each other. | |
12 |
|
12 | |||
13 | An end user should probably begin by looking at the `client.py` module |
|
13 | An end user should probably begin by looking at the `client.py` module | |
14 | if they need blocking clients or in `asyncclient.py` if they want asynchronous, |
|
14 | if they need blocking clients or in `asyncclient.py` if they want asynchronous, | |
15 | deferred/Twisted using clients. |
|
15 | deferred/Twisted using clients. | |
16 | """ |
|
16 | """ | |
17 | __docformat__ = "restructuredtext en" |
|
17 | __docformat__ = "restructuredtext en" | |
18 | #------------------------------------------------------------------------------- |
|
18 | #------------------------------------------------------------------------------- | |
19 | # Copyright (C) 2008 The IPython Development Team |
|
19 | # Copyright (C) 2008 The IPython Development Team | |
20 | # |
|
20 | # | |
21 | # Distributed under the terms of the BSD License. The full license is in |
|
21 | # Distributed under the terms of the BSD License. The full license is in | |
22 | # the file COPYING, distributed as part of this software. |
|
22 | # the file COPYING, distributed as part of this software. | |
23 | #------------------------------------------------------------------------------- |
|
23 | #------------------------------------------------------------------------------- | |
|
24 | No newline at end of file |
@@ -1,40 +1,43 | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 |
|
2 | |||
3 | """This file contains unittests for the kernel.engineservice.py module. |
|
3 | """This file contains unittests for the kernel.engineservice.py module. | |
4 |
|
4 | |||
5 | Things that should be tested: |
|
5 | Things that should be tested: | |
6 |
|
6 | |||
7 | - Should the EngineService return Deferred objects? |
|
7 | - Should the EngineService return Deferred objects? | |
8 | - Run the same tests that are run in shell.py. |
|
8 | - Run the same tests that are run in shell.py. | |
9 | - Make sure that the Interface is really implemented. |
|
9 | - Make sure that the Interface is really implemented. | |
10 | - The startService and stopService methods. |
|
10 | - The startService and stopService methods. | |
11 | """ |
|
11 | """ | |
12 |
|
12 | |||
13 | __docformat__ = "restructuredtext en" |
|
13 | __docformat__ = "restructuredtext en" | |
14 |
|
14 | |||
15 | #------------------------------------------------------------------------------- |
|
15 | #------------------------------------------------------------------------------- | |
16 | # Copyright (C) 2008 The IPython Development Team |
|
16 | # Copyright (C) 2008 The IPython Development Team | |
17 | # |
|
17 | # | |
18 | # Distributed under the terms of the BSD License. The full license is in |
|
18 | # Distributed under the terms of the BSD License. The full license is in | |
19 | # the file COPYING, distributed as part of this software. |
|
19 | # the file COPYING, distributed as part of this software. | |
20 | #------------------------------------------------------------------------------- |
|
20 | #------------------------------------------------------------------------------- | |
21 |
|
21 | |||
22 | #------------------------------------------------------------------------------- |
|
22 | #------------------------------------------------------------------------------- | |
23 | # Imports |
|
23 | # Imports | |
24 | #------------------------------------------------------------------------------- |
|
24 | #------------------------------------------------------------------------------- | |
25 |
|
25 | |||
|
26 | try: | |||
26 | from twisted.application.service import IService |
|
27 | from twisted.application.service import IService | |
27 | from IPython.kernel.controllerservice import ControllerService |
|
28 | from IPython.kernel.controllerservice import ControllerService | |
28 | from IPython.kernel.tests import multienginetest as met |
|
29 | from IPython.kernel.tests import multienginetest as met | |
29 | from controllertest import IControllerCoreTestCase |
|
30 | from controllertest import IControllerCoreTestCase | |
30 | from IPython.testing.util import DeferredTestCase |
|
31 | from IPython.testing.util import DeferredTestCase | |
31 |
|
32 | except ImportError: | ||
|
33 | pass | |||
|
34 | else: | |||
32 | class BasicControllerServiceTest(DeferredTestCase, |
|
35 | class BasicControllerServiceTest(DeferredTestCase, | |
33 | IControllerCoreTestCase): |
|
36 | IControllerCoreTestCase): | |
34 |
|
37 | |||
35 | def setUp(self): |
|
38 | def setUp(self): | |
36 | self.controller = ControllerService() |
|
39 | self.controller = ControllerService() | |
37 | self.controller.startService() |
|
40 | self.controller.startService() | |
38 |
|
41 | |||
39 | def tearDown(self): |
|
42 | def tearDown(self): | |
40 | self.controller.stopService() |
|
43 | self.controller.stopService() |
@@ -1,89 +1,92 | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 |
|
2 | |||
3 | """This file contains unittests for the enginepb.py module.""" |
|
3 | """This file contains unittests for the enginepb.py module.""" | |
4 |
|
4 | |||
5 | __docformat__ = "restructuredtext en" |
|
5 | __docformat__ = "restructuredtext en" | |
6 |
|
6 | |||
7 | #------------------------------------------------------------------------------- |
|
7 | #------------------------------------------------------------------------------- | |
8 | # Copyright (C) 2008 The IPython Development Team |
|
8 | # Copyright (C) 2008 The IPython Development Team | |
9 | # |
|
9 | # | |
10 | # Distributed under the terms of the BSD License. The full license is in |
|
10 | # Distributed under the terms of the BSD License. The full license is in | |
11 | # the file COPYING, distributed as part of this software. |
|
11 | # the file COPYING, distributed as part of this software. | |
12 | #------------------------------------------------------------------------------- |
|
12 | #------------------------------------------------------------------------------- | |
13 |
|
13 | |||
14 | #------------------------------------------------------------------------------- |
|
14 | #------------------------------------------------------------------------------- | |
15 | # Imports |
|
15 | # Imports | |
16 | #------------------------------------------------------------------------------- |
|
16 | #------------------------------------------------------------------------------- | |
17 |
|
17 | |||
18 |
|
18 | try: | ||
19 | from twisted.python import components |
|
19 | from twisted.python import components | |
20 | from twisted.internet import reactor, defer |
|
20 | from twisted.internet import reactor, defer | |
21 | from twisted.spread import pb |
|
21 | from twisted.spread import pb | |
22 | from twisted.internet.base import DelayedCall |
|
22 | from twisted.internet.base import DelayedCall | |
23 | DelayedCall.debug = True |
|
23 | DelayedCall.debug = True | |
24 |
|
24 | |||
25 | import zope.interface as zi |
|
25 | import zope.interface as zi | |
26 |
|
26 | |||
27 | from IPython.kernel.fcutil import Tub, UnauthenticatedTub |
|
27 | from IPython.kernel.fcutil import Tub, UnauthenticatedTub | |
28 | from IPython.kernel import engineservice as es |
|
28 | from IPython.kernel import engineservice as es | |
29 | from IPython.testing.util import DeferredTestCase |
|
29 | from IPython.testing.util import DeferredTestCase | |
30 | from IPython.kernel.controllerservice import IControllerBase |
|
30 | from IPython.kernel.controllerservice import IControllerBase | |
31 | from IPython.kernel.enginefc import FCRemoteEngineRefFromService, IEngineBase |
|
31 | from IPython.kernel.enginefc import FCRemoteEngineRefFromService, IEngineBase | |
32 | from IPython.kernel.engineservice import IEngineQueued |
|
32 | from IPython.kernel.engineservice import IEngineQueued | |
33 | from IPython.kernel.engineconnector import EngineConnector |
|
33 | from IPython.kernel.engineconnector import EngineConnector | |
34 |
|
34 | |||
35 | from IPython.kernel.tests.engineservicetest import \ |
|
35 | from IPython.kernel.tests.engineservicetest import \ | |
36 | IEngineCoreTestCase, \ |
|
36 | IEngineCoreTestCase, \ | |
37 | IEngineSerializedTestCase, \ |
|
37 | IEngineSerializedTestCase, \ | |
38 | IEngineQueuedTestCase |
|
38 | IEngineQueuedTestCase | |
39 |
|
39 | except ImportError: | ||
|
40 | print "we got an error!!!" | |||
|
41 | pass | |||
|
42 | else: | |||
40 | class EngineFCTest(DeferredTestCase, |
|
43 | class EngineFCTest(DeferredTestCase, | |
41 | IEngineCoreTestCase, |
|
44 | IEngineCoreTestCase, | |
42 | IEngineSerializedTestCase, |
|
45 | IEngineSerializedTestCase, | |
43 | IEngineQueuedTestCase |
|
46 | IEngineQueuedTestCase | |
44 | ): |
|
47 | ): | |
45 |
|
48 | |||
46 | zi.implements(IControllerBase) |
|
49 | zi.implements(IControllerBase) | |
47 |
|
50 | |||
48 | def setUp(self): |
|
51 | def setUp(self): | |
49 |
|
52 | |||
50 | # Start a server and append to self.servers |
|
53 | # Start a server and append to self.servers | |
51 | self.controller_reference = FCRemoteEngineRefFromService(self) |
|
54 | self.controller_reference = FCRemoteEngineRefFromService(self) | |
52 | self.controller_tub = Tub() |
|
55 | self.controller_tub = Tub() | |
53 | self.controller_tub.listenOn('tcp:10105:interface=127.0.0.1') |
|
56 | self.controller_tub.listenOn('tcp:10105:interface=127.0.0.1') | |
54 | self.controller_tub.setLocation('127.0.0.1:10105') |
|
57 | self.controller_tub.setLocation('127.0.0.1:10105') | |
55 |
|
58 | |||
56 | furl = self.controller_tub.registerReference(self.controller_reference) |
|
59 | furl = self.controller_tub.registerReference(self.controller_reference) | |
57 | self.controller_tub.startService() |
|
60 | self.controller_tub.startService() | |
58 |
|
61 | |||
59 | # Start an EngineService and append to services/client |
|
62 | # Start an EngineService and append to services/client | |
60 | self.engine_service = es.EngineService() |
|
63 | self.engine_service = es.EngineService() | |
61 | self.engine_service.startService() |
|
64 | self.engine_service.startService() | |
62 | self.engine_tub = Tub() |
|
65 | self.engine_tub = Tub() | |
63 | self.engine_tub.startService() |
|
66 | self.engine_tub.startService() | |
64 | engine_connector = EngineConnector(self.engine_tub) |
|
67 | engine_connector = EngineConnector(self.engine_tub) | |
65 | d = engine_connector.connect_to_controller(self.engine_service, furl) |
|
68 | d = engine_connector.connect_to_controller(self.engine_service, furl) | |
66 | # This deferred doesn't fire until after register_engine has returned and |
|
69 | # This deferred doesn't fire until after register_engine has returned and | |
67 | # thus, self.engine has been defined and the tets can proceed. |
|
70 | # thus, self.engine has been defined and the tets can proceed. | |
68 | return d |
|
71 | return d | |
69 |
|
72 | |||
70 | def tearDown(self): |
|
73 | def tearDown(self): | |
71 | dlist = [] |
|
74 | dlist = [] | |
72 | # Shut down the engine |
|
75 | # Shut down the engine | |
73 | d = self.engine_tub.stopService() |
|
76 | d = self.engine_tub.stopService() | |
74 | dlist.append(d) |
|
77 | dlist.append(d) | |
75 | # Shut down the controller |
|
78 | # Shut down the controller | |
76 | d = self.controller_tub.stopService() |
|
79 | d = self.controller_tub.stopService() | |
77 | dlist.append(d) |
|
80 | dlist.append(d) | |
78 | return defer.DeferredList(dlist) |
|
81 | return defer.DeferredList(dlist) | |
79 |
|
82 | |||
80 | #--------------------------------------------------------------------------- |
|
83 | #--------------------------------------------------------------------------- | |
81 | # Make me look like a basic controller |
|
84 | # Make me look like a basic controller | |
82 | #--------------------------------------------------------------------------- |
|
85 | #--------------------------------------------------------------------------- | |
83 |
|
86 | |||
84 | def register_engine(self, engine_ref, id=None, ip=None, port=None, pid=None): |
|
87 | def register_engine(self, engine_ref, id=None, ip=None, port=None, pid=None): | |
85 | self.engine = IEngineQueued(IEngineBase(engine_ref)) |
|
88 | self.engine = IEngineQueued(IEngineBase(engine_ref)) | |
86 | return {'id':id} |
|
89 | return {'id':id} | |
87 |
|
90 | |||
88 | def unregister_engine(self, id): |
|
91 | def unregister_engine(self, id): | |
89 | pass No newline at end of file |
|
92 | pass |
@@ -1,64 +1,66 | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 |
|
2 | |||
3 | """This file contains unittests for the kernel.engineservice.py module. |
|
3 | """This file contains unittests for the kernel.engineservice.py module. | |
4 |
|
4 | |||
5 | Things that should be tested: |
|
5 | Things that should be tested: | |
6 |
|
6 | |||
7 | - Should the EngineService return Deferred objects? |
|
7 | - Should the EngineService return Deferred objects? | |
8 | - Run the same tests that are run in shell.py. |
|
8 | - Run the same tests that are run in shell.py. | |
9 | - Make sure that the Interface is really implemented. |
|
9 | - Make sure that the Interface is really implemented. | |
10 | - The startService and stopService methods. |
|
10 | - The startService and stopService methods. | |
11 | """ |
|
11 | """ | |
12 |
|
12 | |||
13 | __docformat__ = "restructuredtext en" |
|
13 | __docformat__ = "restructuredtext en" | |
14 |
|
14 | |||
15 | #------------------------------------------------------------------------------- |
|
15 | #------------------------------------------------------------------------------- | |
16 | # Copyright (C) 2008 The IPython Development Team |
|
16 | # Copyright (C) 2008 The IPython Development Team | |
17 | # |
|
17 | # | |
18 | # Distributed under the terms of the BSD License. The full license is in |
|
18 | # Distributed under the terms of the BSD License. The full license is in | |
19 | # the file COPYING, distributed as part of this software. |
|
19 | # the file COPYING, distributed as part of this software. | |
20 | #------------------------------------------------------------------------------- |
|
20 | #------------------------------------------------------------------------------- | |
21 |
|
21 | |||
22 | #------------------------------------------------------------------------------- |
|
22 | #------------------------------------------------------------------------------- | |
23 | # Imports |
|
23 | # Imports | |
24 | #------------------------------------------------------------------------------- |
|
24 | #------------------------------------------------------------------------------- | |
25 |
|
25 | |||
|
26 | try: | |||
26 | from twisted.internet import defer |
|
27 | from twisted.internet import defer | |
27 | from twisted.application.service import IService |
|
28 | from twisted.application.service import IService | |
28 |
|
29 | |||
29 | from IPython.kernel import engineservice as es |
|
30 | from IPython.kernel import engineservice as es | |
30 | from IPython.testing.util import DeferredTestCase |
|
31 | from IPython.testing.util import DeferredTestCase | |
31 | from IPython.kernel.tests.engineservicetest import \ |
|
32 | from IPython.kernel.tests.engineservicetest import \ | |
32 | IEngineCoreTestCase, \ |
|
33 | IEngineCoreTestCase, \ | |
33 | IEngineSerializedTestCase, \ |
|
34 | IEngineSerializedTestCase, \ | |
34 | IEngineQueuedTestCase, \ |
|
35 | IEngineQueuedTestCase, \ | |
35 | IEnginePropertiesTestCase |
|
36 | IEnginePropertiesTestCase | |
36 |
|
37 | except ImportError: | ||
37 |
|
38 | pass | ||
|
39 | else: | |||
38 | class BasicEngineServiceTest(DeferredTestCase, |
|
40 | class BasicEngineServiceTest(DeferredTestCase, | |
39 | IEngineCoreTestCase, |
|
41 | IEngineCoreTestCase, | |
40 | IEngineSerializedTestCase, |
|
42 | IEngineSerializedTestCase, | |
41 | IEnginePropertiesTestCase): |
|
43 | IEnginePropertiesTestCase): | |
42 |
|
44 | |||
43 | def setUp(self): |
|
45 | def setUp(self): | |
44 | self.engine = es.EngineService() |
|
46 | self.engine = es.EngineService() | |
45 | self.engine.startService() |
|
47 | self.engine.startService() | |
46 |
|
48 | |||
47 | def tearDown(self): |
|
49 | def tearDown(self): | |
48 | return self.engine.stopService() |
|
50 | return self.engine.stopService() | |
49 |
|
51 | |||
50 | class QueuedEngineServiceTest(DeferredTestCase, |
|
52 | class QueuedEngineServiceTest(DeferredTestCase, | |
51 | IEngineCoreTestCase, |
|
53 | IEngineCoreTestCase, | |
52 | IEngineSerializedTestCase, |
|
54 | IEngineSerializedTestCase, | |
53 | IEnginePropertiesTestCase, |
|
55 | IEnginePropertiesTestCase, | |
54 | IEngineQueuedTestCase): |
|
56 | IEngineQueuedTestCase): | |
55 |
|
57 | |||
56 | def setUp(self): |
|
58 | def setUp(self): | |
57 | self.rawEngine = es.EngineService() |
|
59 | self.rawEngine = es.EngineService() | |
58 | self.rawEngine.startService() |
|
60 | self.rawEngine.startService() | |
59 | self.engine = es.IEngineQueued(self.rawEngine) |
|
61 | self.engine = es.IEngineQueued(self.rawEngine) | |
60 |
|
62 | |||
61 | def tearDown(self): |
|
63 | def tearDown(self): | |
62 | return self.rawEngine.stopService() |
|
64 | return self.rawEngine.stopService() | |
63 |
|
65 | |||
64 |
|
66 |
@@ -1,52 +1,54 | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 |
|
2 | |||
3 | """""" |
|
3 | """""" | |
4 |
|
4 | |||
5 | __docformat__ = "restructuredtext en" |
|
5 | __docformat__ = "restructuredtext en" | |
6 |
|
6 | |||
7 | #------------------------------------------------------------------------------- |
|
7 | #------------------------------------------------------------------------------- | |
8 | # Copyright (C) 2008 The IPython Development Team |
|
8 | # Copyright (C) 2008 The IPython Development Team | |
9 | # |
|
9 | # | |
10 | # Distributed under the terms of the BSD License. The full license is in |
|
10 | # Distributed under the terms of the BSD License. The full license is in | |
11 | # the file COPYING, distributed as part of this software. |
|
11 | # the file COPYING, distributed as part of this software. | |
12 | #------------------------------------------------------------------------------- |
|
12 | #------------------------------------------------------------------------------- | |
13 |
|
13 | |||
14 | #------------------------------------------------------------------------------- |
|
14 | #------------------------------------------------------------------------------- | |
15 | # Imports |
|
15 | # Imports | |
16 | #------------------------------------------------------------------------------- |
|
16 | #------------------------------------------------------------------------------- | |
17 |
|
17 | |||
|
18 | try: | |||
18 | from twisted.internet import defer |
|
19 | from twisted.internet import defer | |
19 | from IPython.testing.util import DeferredTestCase |
|
20 | from IPython.testing.util import DeferredTestCase | |
20 | from IPython.kernel.controllerservice import ControllerService |
|
21 | from IPython.kernel.controllerservice import ControllerService | |
21 | from IPython.kernel import multiengine as me |
|
22 | from IPython.kernel import multiengine as me | |
22 | from IPython.kernel.tests.multienginetest import (IMultiEngineTestCase, |
|
23 | from IPython.kernel.tests.multienginetest import (IMultiEngineTestCase, | |
23 | ISynchronousMultiEngineTestCase) |
|
24 | ISynchronousMultiEngineTestCase) | |
24 |
|
25 | except ImportError: | ||
25 |
|
26 | pass | ||
|
27 | else: | |||
26 | class BasicMultiEngineTestCase(DeferredTestCase, IMultiEngineTestCase): |
|
28 | class BasicMultiEngineTestCase(DeferredTestCase, IMultiEngineTestCase): | |
27 |
|
29 | |||
28 | def setUp(self): |
|
30 | def setUp(self): | |
29 | self.controller = ControllerService() |
|
31 | self.controller = ControllerService() | |
30 | self.controller.startService() |
|
32 | self.controller.startService() | |
31 | self.multiengine = me.IMultiEngine(self.controller) |
|
33 | self.multiengine = me.IMultiEngine(self.controller) | |
32 | self.engines = [] |
|
34 | self.engines = [] | |
33 |
|
35 | |||
34 | def tearDown(self): |
|
36 | def tearDown(self): | |
35 | self.controller.stopService() |
|
37 | self.controller.stopService() | |
36 | for e in self.engines: |
|
38 | for e in self.engines: | |
37 | e.stopService() |
|
39 | e.stopService() | |
38 |
|
40 | |||
39 |
|
41 | |||
40 | class SynchronousMultiEngineTestCase(DeferredTestCase, ISynchronousMultiEngineTestCase): |
|
42 | class SynchronousMultiEngineTestCase(DeferredTestCase, ISynchronousMultiEngineTestCase): | |
41 |
|
43 | |||
42 | def setUp(self): |
|
44 | def setUp(self): | |
43 | self.controller = ControllerService() |
|
45 | self.controller = ControllerService() | |
44 | self.controller.startService() |
|
46 | self.controller.startService() | |
45 | self.multiengine = me.ISynchronousMultiEngine(me.IMultiEngine(self.controller)) |
|
47 | self.multiengine = me.ISynchronousMultiEngine(me.IMultiEngine(self.controller)) | |
46 | self.engines = [] |
|
48 | self.engines = [] | |
47 |
|
49 | |||
48 | def tearDown(self): |
|
50 | def tearDown(self): | |
49 | self.controller.stopService() |
|
51 | self.controller.stopService() | |
50 | for e in self.engines: |
|
52 | for e in self.engines: | |
51 | e.stopService() |
|
53 | e.stopService() | |
52 |
|
54 |
@@ -1,68 +1,70 | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 | # encoding: utf-8 |
|
2 | # encoding: utf-8 | |
3 |
|
3 | |||
4 | __docformat__ = "restructuredtext en" |
|
4 | __docformat__ = "restructuredtext en" | |
5 |
|
5 | |||
6 | #------------------------------------------------------------------------------- |
|
6 | #------------------------------------------------------------------------------- | |
7 | # Copyright (C) 2008 The IPython Development Team |
|
7 | # Copyright (C) 2008 The IPython Development Team | |
8 | # |
|
8 | # | |
9 | # Distributed under the terms of the BSD License. The full license is in |
|
9 | # Distributed under the terms of the BSD License. The full license is in | |
10 | # the file COPYING, distributed as part of this software. |
|
10 | # the file COPYING, distributed as part of this software. | |
11 | #------------------------------------------------------------------------------- |
|
11 | #------------------------------------------------------------------------------- | |
12 |
|
12 | |||
13 | #------------------------------------------------------------------------------- |
|
13 | #------------------------------------------------------------------------------- | |
14 | # Imports |
|
14 | # Imports | |
15 | #------------------------------------------------------------------------------- |
|
15 | #------------------------------------------------------------------------------- | |
16 |
|
16 | |||
|
17 | try: | |||
17 | from twisted.internet import defer, reactor |
|
18 | from twisted.internet import defer, reactor | |
18 |
|
19 | |||
19 | from IPython.kernel.fcutil import Tub, UnauthenticatedTub |
|
20 | from IPython.kernel.fcutil import Tub, UnauthenticatedTub | |
20 |
|
21 | |||
21 | from IPython.testing.util import DeferredTestCase |
|
22 | from IPython.testing.util import DeferredTestCase | |
22 | from IPython.kernel.controllerservice import ControllerService |
|
23 | from IPython.kernel.controllerservice import ControllerService | |
23 | from IPython.kernel.multiengine import IMultiEngine |
|
24 | from IPython.kernel.multiengine import IMultiEngine | |
24 | from IPython.kernel.tests.multienginetest import IFullSynchronousMultiEngineTestCase |
|
25 | from IPython.kernel.tests.multienginetest import IFullSynchronousMultiEngineTestCase | |
25 | from IPython.kernel.multienginefc import IFCSynchronousMultiEngine |
|
26 | from IPython.kernel.multienginefc import IFCSynchronousMultiEngine | |
26 | from IPython.kernel import multiengine as me |
|
27 | from IPython.kernel import multiengine as me | |
27 | from IPython.kernel.clientconnector import ClientConnector |
|
28 | from IPython.kernel.clientconnector import ClientConnector | |
28 |
|
29 | except ImportError: | ||
29 |
|
30 | pass | ||
|
31 | else: | |||
30 | class FullSynchronousMultiEngineTestCase(DeferredTestCase, IFullSynchronousMultiEngineTestCase): |
|
32 | class FullSynchronousMultiEngineTestCase(DeferredTestCase, IFullSynchronousMultiEngineTestCase): | |
31 |
|
33 | |||
32 | def setUp(self): |
|
34 | def setUp(self): | |
33 |
|
35 | |||
34 | self.engines = [] |
|
36 | self.engines = [] | |
35 |
|
37 | |||
36 | self.controller = ControllerService() |
|
38 | self.controller = ControllerService() | |
37 | self.controller.startService() |
|
39 | self.controller.startService() | |
38 | self.imultiengine = IMultiEngine(self.controller) |
|
40 | self.imultiengine = IMultiEngine(self.controller) | |
39 | self.mec_referenceable = IFCSynchronousMultiEngine(self.imultiengine) |
|
41 | self.mec_referenceable = IFCSynchronousMultiEngine(self.imultiengine) | |
40 |
|
42 | |||
41 | self.controller_tub = Tub() |
|
43 | self.controller_tub = Tub() | |
42 | self.controller_tub.listenOn('tcp:10105:interface=127.0.0.1') |
|
44 | self.controller_tub.listenOn('tcp:10105:interface=127.0.0.1') | |
43 | self.controller_tub.setLocation('127.0.0.1:10105') |
|
45 | self.controller_tub.setLocation('127.0.0.1:10105') | |
44 |
|
46 | |||
45 | furl = self.controller_tub.registerReference(self.mec_referenceable) |
|
47 | furl = self.controller_tub.registerReference(self.mec_referenceable) | |
46 | self.controller_tub.startService() |
|
48 | self.controller_tub.startService() | |
47 |
|
49 | |||
48 | self.client_tub = ClientConnector() |
|
50 | self.client_tub = ClientConnector() | |
49 | d = self.client_tub.get_multiengine_client(furl) |
|
51 | d = self.client_tub.get_multiengine_client(furl) | |
50 | d.addCallback(self.handle_got_client) |
|
52 | d.addCallback(self.handle_got_client) | |
51 | return d |
|
53 | return d | |
52 |
|
54 | |||
53 | def handle_got_client(self, client): |
|
55 | def handle_got_client(self, client): | |
54 | self.multiengine = client |
|
56 | self.multiengine = client | |
55 |
|
57 | |||
56 | def tearDown(self): |
|
58 | def tearDown(self): | |
57 | dlist = [] |
|
59 | dlist = [] | |
58 | # Shut down the multiengine client |
|
60 | # Shut down the multiengine client | |
59 | d = self.client_tub.tub.stopService() |
|
61 | d = self.client_tub.tub.stopService() | |
60 | dlist.append(d) |
|
62 | dlist.append(d) | |
61 | # Shut down the engines |
|
63 | # Shut down the engines | |
62 | for e in self.engines: |
|
64 | for e in self.engines: | |
63 | e.stopService() |
|
65 | e.stopService() | |
64 | # Shut down the controller |
|
66 | # Shut down the controller | |
65 | d = self.controller_tub.stopService() |
|
67 | d = self.controller_tub.stopService() | |
66 | d.addBoth(lambda _: self.controller.stopService()) |
|
68 | d.addBoth(lambda _: self.controller.stopService()) | |
67 | dlist.append(d) |
|
69 | dlist.append(d) | |
68 | return defer.DeferredList(dlist) |
|
70 | return defer.DeferredList(dlist) |
@@ -1,99 +1,102 | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 |
|
2 | |||
3 | """This file contains unittests for the shell.py module.""" |
|
3 | """This file contains unittests for the shell.py module.""" | |
4 |
|
4 | |||
5 | __docformat__ = "restructuredtext en" |
|
5 | __docformat__ = "restructuredtext en" | |
6 |
|
6 | |||
7 | #------------------------------------------------------------------------------- |
|
7 | #------------------------------------------------------------------------------- | |
8 | # Copyright (C) 2008 The IPython Development Team |
|
8 | # Copyright (C) 2008 The IPython Development Team | |
9 | # |
|
9 | # | |
10 | # Distributed under the terms of the BSD License. The full license is in |
|
10 | # Distributed under the terms of the BSD License. The full license is in | |
11 | # the file COPYING, distributed as part of this software. |
|
11 | # the file COPYING, distributed as part of this software. | |
12 | #------------------------------------------------------------------------------- |
|
12 | #------------------------------------------------------------------------------- | |
13 |
|
13 | |||
14 | #------------------------------------------------------------------------------- |
|
14 | #------------------------------------------------------------------------------- | |
15 | # Imports |
|
15 | # Imports | |
16 | #------------------------------------------------------------------------------- |
|
16 | #------------------------------------------------------------------------------- | |
17 |
|
17 | |||
|
18 | try: | |||
18 | import zope.interface as zi |
|
19 | import zope.interface as zi | |
19 | from twisted.trial import unittest |
|
20 | from twisted.trial import unittest | |
20 | from IPython.testing.util import DeferredTestCase |
|
21 | from IPython.testing.util import DeferredTestCase | |
21 |
|
22 | |||
22 | from IPython.kernel.newserialized import \ |
|
23 | from IPython.kernel.newserialized import \ | |
23 | ISerialized, \ |
|
24 | ISerialized, \ | |
24 | IUnSerialized, \ |
|
25 | IUnSerialized, \ | |
25 | Serialized, \ |
|
26 | Serialized, \ | |
26 | UnSerialized, \ |
|
27 | UnSerialized, \ | |
27 | SerializeIt, \ |
|
28 | SerializeIt, \ | |
28 | UnSerializeIt |
|
29 | UnSerializeIt | |
29 |
|
30 | except ImportError: | ||
|
31 | pass | |||
|
32 | else: | |||
30 | #------------------------------------------------------------------------------- |
|
33 | #------------------------------------------------------------------------------- | |
31 | # Tests |
|
34 | # Tests | |
32 | #------------------------------------------------------------------------------- |
|
35 | #------------------------------------------------------------------------------- | |
33 |
|
36 | |||
34 | class SerializedTestCase(unittest.TestCase): |
|
37 | class SerializedTestCase(unittest.TestCase): | |
35 |
|
38 | |||
36 | def setUp(self): |
|
39 | def setUp(self): | |
37 | pass |
|
40 | pass | |
38 |
|
41 | |||
39 | def tearDown(self): |
|
42 | def tearDown(self): | |
40 | pass |
|
43 | pass | |
41 |
|
44 | |||
42 | def testSerializedInterfaces(self): |
|
45 | def testSerializedInterfaces(self): | |
43 |
|
46 | |||
44 | us = UnSerialized({'a':10, 'b':range(10)}) |
|
47 | us = UnSerialized({'a':10, 'b':range(10)}) | |
45 | s = ISerialized(us) |
|
48 | s = ISerialized(us) | |
46 | uss = IUnSerialized(s) |
|
49 | uss = IUnSerialized(s) | |
47 | self.assert_(ISerialized.providedBy(s)) |
|
50 | self.assert_(ISerialized.providedBy(s)) | |
48 | self.assert_(IUnSerialized.providedBy(us)) |
|
51 | self.assert_(IUnSerialized.providedBy(us)) | |
49 | self.assert_(IUnSerialized.providedBy(uss)) |
|
52 | self.assert_(IUnSerialized.providedBy(uss)) | |
50 | for m in list(ISerialized): |
|
53 | for m in list(ISerialized): | |
51 | self.assert_(hasattr(s, m)) |
|
54 | self.assert_(hasattr(s, m)) | |
52 | for m in list(IUnSerialized): |
|
55 | for m in list(IUnSerialized): | |
53 | self.assert_(hasattr(us, m)) |
|
56 | self.assert_(hasattr(us, m)) | |
54 | for m in list(IUnSerialized): |
|
57 | for m in list(IUnSerialized): | |
55 | self.assert_(hasattr(uss, m)) |
|
58 | self.assert_(hasattr(uss, m)) | |
56 |
|
59 | |||
57 | def testPickleSerialized(self): |
|
60 | def testPickleSerialized(self): | |
58 | obj = {'a':1.45345, 'b':'asdfsdf', 'c':10000L} |
|
61 | obj = {'a':1.45345, 'b':'asdfsdf', 'c':10000L} | |
59 | original = UnSerialized(obj) |
|
62 | original = UnSerialized(obj) | |
60 | originalSer = ISerialized(original) |
|
63 | originalSer = ISerialized(original) | |
61 | firstData = originalSer.getData() |
|
64 | firstData = originalSer.getData() | |
62 | firstTD = originalSer.getTypeDescriptor() |
|
65 | firstTD = originalSer.getTypeDescriptor() | |
63 | firstMD = originalSer.getMetadata() |
|
66 | firstMD = originalSer.getMetadata() | |
64 | self.assert_(firstTD == 'pickle') |
|
67 | self.assert_(firstTD == 'pickle') | |
65 | self.assert_(firstMD == {}) |
|
68 | self.assert_(firstMD == {}) | |
66 | unSerialized = IUnSerialized(originalSer) |
|
69 | unSerialized = IUnSerialized(originalSer) | |
67 | secondObj = unSerialized.getObject() |
|
70 | secondObj = unSerialized.getObject() | |
68 | for k, v in secondObj.iteritems(): |
|
71 | for k, v in secondObj.iteritems(): | |
69 | self.assert_(obj[k] == v) |
|
72 | self.assert_(obj[k] == v) | |
70 | secondSer = ISerialized(UnSerialized(secondObj)) |
|
73 | secondSer = ISerialized(UnSerialized(secondObj)) | |
71 | self.assert_(firstData == secondSer.getData()) |
|
74 | self.assert_(firstData == secondSer.getData()) | |
72 | self.assert_(firstTD == secondSer.getTypeDescriptor() ) |
|
75 | self.assert_(firstTD == secondSer.getTypeDescriptor() ) | |
73 | self.assert_(firstMD == secondSer.getMetadata()) |
|
76 | self.assert_(firstMD == secondSer.getMetadata()) | |
74 |
|
77 | |||
75 | def testNDArraySerialized(self): |
|
78 | def testNDArraySerialized(self): | |
76 | try: |
|
79 | try: | |
77 | import numpy |
|
80 | import numpy | |
78 | except ImportError: |
|
81 | except ImportError: | |
79 | pass |
|
82 | pass | |
80 | else: |
|
83 | else: | |
81 | a = numpy.linspace(0.0, 1.0, 1000) |
|
84 | a = numpy.linspace(0.0, 1.0, 1000) | |
82 | unSer1 = UnSerialized(a) |
|
85 | unSer1 = UnSerialized(a) | |
83 | ser1 = ISerialized(unSer1) |
|
86 | ser1 = ISerialized(unSer1) | |
84 | td = ser1.getTypeDescriptor() |
|
87 | td = ser1.getTypeDescriptor() | |
85 | self.assert_(td == 'ndarray') |
|
88 | self.assert_(td == 'ndarray') | |
86 | md = ser1.getMetadata() |
|
89 | md = ser1.getMetadata() | |
87 | self.assert_(md['shape'] == a.shape) |
|
90 | self.assert_(md['shape'] == a.shape) | |
88 | self.assert_(md['dtype'] == a.dtype.str) |
|
91 | self.assert_(md['dtype'] == a.dtype.str) | |
89 | buff = ser1.getData() |
|
92 | buff = ser1.getData() | |
90 | self.assert_(buff == numpy.getbuffer(a)) |
|
93 | self.assert_(buff == numpy.getbuffer(a)) | |
91 | s = Serialized(buff, td, md) |
|
94 | s = Serialized(buff, td, md) | |
92 | us = IUnSerialized(s) |
|
95 | us = IUnSerialized(s) | |
93 | final = us.getObject() |
|
96 | final = us.getObject() | |
94 | self.assert_(numpy.getbuffer(a) == numpy.getbuffer(final)) |
|
97 | self.assert_(numpy.getbuffer(a) == numpy.getbuffer(final)) | |
95 | self.assert_(a.dtype.str == final.dtype.str) |
|
98 | self.assert_(a.dtype.str == final.dtype.str) | |
96 | self.assert_(a.shape == final.shape) |
|
99 | self.assert_(a.shape == final.shape) | |
97 |
|
100 | |||
98 |
|
101 | |||
99 | No newline at end of file |
|
102 |
@@ -1,215 +1,218 | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 | # encoding: utf-8 |
|
2 | # encoding: utf-8 | |
3 |
|
3 | |||
4 | """Tests for pendingdeferred.py""" |
|
4 | """Tests for pendingdeferred.py""" | |
5 |
|
5 | |||
6 | __docformat__ = "restructuredtext en" |
|
6 | __docformat__ = "restructuredtext en" | |
7 |
|
7 | |||
8 | #------------------------------------------------------------------------------- |
|
8 | #------------------------------------------------------------------------------- | |
9 | # Copyright (C) 2008 The IPython Development Team |
|
9 | # Copyright (C) 2008 The IPython Development Team | |
10 | # |
|
10 | # | |
11 | # Distributed under the terms of the BSD License. The full license is in |
|
11 | # Distributed under the terms of the BSD License. The full license is in | |
12 | # the file COPYING, distributed as part of this software. |
|
12 | # the file COPYING, distributed as part of this software. | |
13 | #------------------------------------------------------------------------------- |
|
13 | #------------------------------------------------------------------------------- | |
14 |
|
14 | |||
15 | #------------------------------------------------------------------------------- |
|
15 | #------------------------------------------------------------------------------- | |
16 | # Imports |
|
16 | # Imports | |
17 | #------------------------------------------------------------------------------- |
|
17 | #------------------------------------------------------------------------------- | |
18 |
|
18 | |||
|
19 | try: | |||
19 | from twisted.internet import defer |
|
20 | from twisted.internet import defer | |
20 | from twisted.python import failure |
|
21 | from twisted.python import failure | |
21 |
|
22 | |||
22 | from IPython.testing import tcommon |
|
23 | from IPython.testing import tcommon | |
23 | from IPython.testing.tcommon import * |
|
24 | from IPython.testing.tcommon import * | |
24 | from IPython.testing.util import DeferredTestCase |
|
25 | from IPython.testing.util import DeferredTestCase | |
25 | import IPython.kernel.pendingdeferred as pd |
|
26 | import IPython.kernel.pendingdeferred as pd | |
26 | from IPython.kernel import error |
|
27 | from IPython.kernel import error | |
27 | from IPython.kernel.util import printer |
|
28 | from IPython.kernel.util import printer | |
28 |
|
29 | except ImportError: | ||
|
30 | pass | |||
|
31 | else: | |||
29 |
|
32 | |||
30 | #------------------------------------------------------------------------------- |
|
33 | #------------------------------------------------------------------------------- | |
31 | # Setup for inline and standalone doctests |
|
34 | # Setup for inline and standalone doctests | |
32 | #------------------------------------------------------------------------------- |
|
35 | #------------------------------------------------------------------------------- | |
33 |
|
36 | |||
34 |
|
37 | |||
35 | # If you have standalone doctests in a separate file, set their names in the |
|
38 | # If you have standalone doctests in a separate file, set their names in the | |
36 | # dt_files variable (as a single string or a list thereof): |
|
39 | # dt_files variable (as a single string or a list thereof): | |
37 | dt_files = [] |
|
40 | dt_files = [] | |
38 |
|
41 | |||
39 | # If you have any modules whose docstrings should be scanned for embedded tests |
|
42 | # If you have any modules whose docstrings should be scanned for embedded tests | |
40 | # as examples accorging to standard doctest practice, set them here (as a |
|
43 | # as examples accorging to standard doctest practice, set them here (as a | |
41 | # single string or a list thereof): |
|
44 | # single string or a list thereof): | |
42 | dt_modules = [] |
|
45 | dt_modules = [] | |
43 |
|
46 | |||
44 | #------------------------------------------------------------------------------- |
|
47 | #------------------------------------------------------------------------------- | |
45 | # Regular Unittests |
|
48 | # Regular Unittests | |
46 | #------------------------------------------------------------------------------- |
|
49 | #------------------------------------------------------------------------------- | |
47 |
|
50 | |||
48 |
|
51 | |||
49 | class Foo(object): |
|
52 | class Foo(object): | |
50 |
|
53 | |||
51 | def bar(self, bahz): |
|
54 | def bar(self, bahz): | |
52 | return defer.succeed('blahblah: %s' % bahz) |
|
55 | return defer.succeed('blahblah: %s' % bahz) | |
53 |
|
56 | |||
54 | class TwoPhaseFoo(pd.PendingDeferredManager): |
|
57 | class TwoPhaseFoo(pd.PendingDeferredManager): | |
55 |
|
58 | |||
56 | def __init__(self, foo): |
|
59 | def __init__(self, foo): | |
57 | self.foo = foo |
|
60 | self.foo = foo | |
58 | pd.PendingDeferredManager.__init__(self) |
|
61 | pd.PendingDeferredManager.__init__(self) | |
59 |
|
62 | |||
60 | @pd.two_phase |
|
63 | @pd.two_phase | |
61 | def bar(self, bahz): |
|
64 | def bar(self, bahz): | |
62 | return self.foo.bar(bahz) |
|
65 | return self.foo.bar(bahz) | |
63 |
|
66 | |||
64 | class PendingDeferredManagerTest(DeferredTestCase): |
|
67 | class PendingDeferredManagerTest(DeferredTestCase): | |
65 |
|
68 | |||
66 | def setUp(self): |
|
69 | def setUp(self): | |
67 | self.pdm = pd.PendingDeferredManager() |
|
70 | self.pdm = pd.PendingDeferredManager() | |
68 |
|
71 | |||
69 | def tearDown(self): |
|
72 | def tearDown(self): | |
70 | pass |
|
73 | pass | |
71 |
|
74 | |||
72 | def testBasic(self): |
|
75 | def testBasic(self): | |
73 | dDict = {} |
|
76 | dDict = {} | |
74 | # Create 10 deferreds and save them |
|
77 | # Create 10 deferreds and save them | |
75 | for i in range(10): |
|
78 | for i in range(10): | |
76 | d = defer.Deferred() |
|
79 | d = defer.Deferred() | |
77 | did = self.pdm.save_pending_deferred(d) |
|
80 | did = self.pdm.save_pending_deferred(d) | |
78 | dDict[did] = d |
|
81 | dDict[did] = d | |
79 | # Make sure they are begin saved |
|
82 | # Make sure they are begin saved | |
80 | for k in dDict.keys(): |
|
83 | for k in dDict.keys(): | |
81 | self.assert_(self.pdm.quick_has_id(k)) |
|
84 | self.assert_(self.pdm.quick_has_id(k)) | |
82 | # Get the pending deferred (block=True), then callback with 'foo' and compare |
|
85 | # Get the pending deferred (block=True), then callback with 'foo' and compare | |
83 | for did in dDict.keys()[0:5]: |
|
86 | for did in dDict.keys()[0:5]: | |
84 | d = self.pdm.get_pending_deferred(did,block=True) |
|
87 | d = self.pdm.get_pending_deferred(did,block=True) | |
85 | dDict[did].callback('foo') |
|
88 | dDict[did].callback('foo') | |
86 | d.addCallback(lambda r: self.assert_(r=='foo')) |
|
89 | d.addCallback(lambda r: self.assert_(r=='foo')) | |
87 | # Get the pending deferreds with (block=False) and make sure ResultNotCompleted is raised |
|
90 | # Get the pending deferreds with (block=False) and make sure ResultNotCompleted is raised | |
88 | for did in dDict.keys()[5:10]: |
|
91 | for did in dDict.keys()[5:10]: | |
89 | d = self.pdm.get_pending_deferred(did,block=False) |
|
92 | d = self.pdm.get_pending_deferred(did,block=False) | |
90 | d.addErrback(lambda f: self.assertRaises(error.ResultNotCompleted, f.raiseException)) |
|
93 | d.addErrback(lambda f: self.assertRaises(error.ResultNotCompleted, f.raiseException)) | |
91 | # Now callback the last 5, get them and compare. |
|
94 | # Now callback the last 5, get them and compare. | |
92 | for did in dDict.keys()[5:10]: |
|
95 | for did in dDict.keys()[5:10]: | |
93 | dDict[did].callback('foo') |
|
96 | dDict[did].callback('foo') | |
94 | d = self.pdm.get_pending_deferred(did,block=False) |
|
97 | d = self.pdm.get_pending_deferred(did,block=False) | |
95 | d.addCallback(lambda r: self.assert_(r=='foo')) |
|
98 | d.addCallback(lambda r: self.assert_(r=='foo')) | |
96 |
|
99 | |||
97 | def test_save_then_delete(self): |
|
100 | def test_save_then_delete(self): | |
98 | d = defer.Deferred() |
|
101 | d = defer.Deferred() | |
99 | did = self.pdm.save_pending_deferred(d) |
|
102 | did = self.pdm.save_pending_deferred(d) | |
100 | self.assert_(self.pdm.quick_has_id(did)) |
|
103 | self.assert_(self.pdm.quick_has_id(did)) | |
101 | self.pdm.delete_pending_deferred(did) |
|
104 | self.pdm.delete_pending_deferred(did) | |
102 | self.assert_(not self.pdm.quick_has_id(did)) |
|
105 | self.assert_(not self.pdm.quick_has_id(did)) | |
103 |
|
106 | |||
104 | def test_save_get_delete(self): |
|
107 | def test_save_get_delete(self): | |
105 | d = defer.Deferred() |
|
108 | d = defer.Deferred() | |
106 | did = self.pdm.save_pending_deferred(d) |
|
109 | did = self.pdm.save_pending_deferred(d) | |
107 | d2 = self.pdm.get_pending_deferred(did,True) |
|
110 | d2 = self.pdm.get_pending_deferred(did,True) | |
108 | d2.addErrback(lambda f: self.assertRaises(error.AbortedPendingDeferredError, f.raiseException)) |
|
111 | d2.addErrback(lambda f: self.assertRaises(error.AbortedPendingDeferredError, f.raiseException)) | |
109 | self.pdm.delete_pending_deferred(did) |
|
112 | self.pdm.delete_pending_deferred(did) | |
110 | return d2 |
|
113 | return d2 | |
111 |
|
114 | |||
112 | def test_double_get(self): |
|
115 | def test_double_get(self): | |
113 | d = defer.Deferred() |
|
116 | d = defer.Deferred() | |
114 | did = self.pdm.save_pending_deferred(d) |
|
117 | did = self.pdm.save_pending_deferred(d) | |
115 | d2 = self.pdm.get_pending_deferred(did,True) |
|
118 | d2 = self.pdm.get_pending_deferred(did,True) | |
116 | d3 = self.pdm.get_pending_deferred(did,True) |
|
119 | d3 = self.pdm.get_pending_deferred(did,True) | |
117 | d3.addErrback(lambda f: self.assertRaises(error.InvalidDeferredID, f.raiseException)) |
|
120 | d3.addErrback(lambda f: self.assertRaises(error.InvalidDeferredID, f.raiseException)) | |
118 |
|
121 | |||
119 | def test_get_after_callback(self): |
|
122 | def test_get_after_callback(self): | |
120 | d = defer.Deferred() |
|
123 | d = defer.Deferred() | |
121 | did = self.pdm.save_pending_deferred(d) |
|
124 | did = self.pdm.save_pending_deferred(d) | |
122 | d.callback('foo') |
|
125 | d.callback('foo') | |
123 | d2 = self.pdm.get_pending_deferred(did,True) |
|
126 | d2 = self.pdm.get_pending_deferred(did,True) | |
124 | d2.addCallback(lambda r: self.assertEquals(r,'foo')) |
|
127 | d2.addCallback(lambda r: self.assertEquals(r,'foo')) | |
125 | self.assert_(not self.pdm.quick_has_id(did)) |
|
128 | self.assert_(not self.pdm.quick_has_id(did)) | |
126 |
|
129 | |||
127 | def test_get_before_callback(self): |
|
130 | def test_get_before_callback(self): | |
128 | d = defer.Deferred() |
|
131 | d = defer.Deferred() | |
129 | did = self.pdm.save_pending_deferred(d) |
|
132 | did = self.pdm.save_pending_deferred(d) | |
130 | d2 = self.pdm.get_pending_deferred(did,True) |
|
133 | d2 = self.pdm.get_pending_deferred(did,True) | |
131 | d.callback('foo') |
|
134 | d.callback('foo') | |
132 | d2.addCallback(lambda r: self.assertEquals(r,'foo')) |
|
135 | d2.addCallback(lambda r: self.assertEquals(r,'foo')) | |
133 | self.assert_(not self.pdm.quick_has_id(did)) |
|
136 | self.assert_(not self.pdm.quick_has_id(did)) | |
134 | d = defer.Deferred() |
|
137 | d = defer.Deferred() | |
135 | did = self.pdm.save_pending_deferred(d) |
|
138 | did = self.pdm.save_pending_deferred(d) | |
136 | d2 = self.pdm.get_pending_deferred(did,True) |
|
139 | d2 = self.pdm.get_pending_deferred(did,True) | |
137 | d2.addCallback(lambda r: self.assertEquals(r,'foo')) |
|
140 | d2.addCallback(lambda r: self.assertEquals(r,'foo')) | |
138 | d.callback('foo') |
|
141 | d.callback('foo') | |
139 | self.assert_(not self.pdm.quick_has_id(did)) |
|
142 | self.assert_(not self.pdm.quick_has_id(did)) | |
140 |
|
143 | |||
141 | def test_get_after_errback(self): |
|
144 | def test_get_after_errback(self): | |
142 | class MyError(Exception): |
|
145 | class MyError(Exception): | |
143 | pass |
|
146 | pass | |
144 | d = defer.Deferred() |
|
147 | d = defer.Deferred() | |
145 | did = self.pdm.save_pending_deferred(d) |
|
148 | did = self.pdm.save_pending_deferred(d) | |
146 | d.errback(failure.Failure(MyError('foo'))) |
|
149 | d.errback(failure.Failure(MyError('foo'))) | |
147 | d2 = self.pdm.get_pending_deferred(did,True) |
|
150 | d2 = self.pdm.get_pending_deferred(did,True) | |
148 | d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException)) |
|
151 | d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException)) | |
149 | self.assert_(not self.pdm.quick_has_id(did)) |
|
152 | self.assert_(not self.pdm.quick_has_id(did)) | |
150 |
|
153 | |||
151 | def test_get_before_errback(self): |
|
154 | def test_get_before_errback(self): | |
152 | class MyError(Exception): |
|
155 | class MyError(Exception): | |
153 | pass |
|
156 | pass | |
154 | d = defer.Deferred() |
|
157 | d = defer.Deferred() | |
155 | did = self.pdm.save_pending_deferred(d) |
|
158 | did = self.pdm.save_pending_deferred(d) | |
156 | d2 = self.pdm.get_pending_deferred(did,True) |
|
159 | d2 = self.pdm.get_pending_deferred(did,True) | |
157 | d.errback(failure.Failure(MyError('foo'))) |
|
160 | d.errback(failure.Failure(MyError('foo'))) | |
158 | d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException)) |
|
161 | d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException)) | |
159 | self.assert_(not self.pdm.quick_has_id(did)) |
|
162 | self.assert_(not self.pdm.quick_has_id(did)) | |
160 | d = defer.Deferred() |
|
163 | d = defer.Deferred() | |
161 | did = self.pdm.save_pending_deferred(d) |
|
164 | did = self.pdm.save_pending_deferred(d) | |
162 | d2 = self.pdm.get_pending_deferred(did,True) |
|
165 | d2 = self.pdm.get_pending_deferred(did,True) | |
163 | d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException)) |
|
166 | d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException)) | |
164 | d.errback(failure.Failure(MyError('foo'))) |
|
167 | d.errback(failure.Failure(MyError('foo'))) | |
165 | self.assert_(not self.pdm.quick_has_id(did)) |
|
168 | self.assert_(not self.pdm.quick_has_id(did)) | |
166 |
|
169 | |||
167 | def test_noresult_noblock(self): |
|
170 | def test_noresult_noblock(self): | |
168 | d = defer.Deferred() |
|
171 | d = defer.Deferred() | |
169 | did = self.pdm.save_pending_deferred(d) |
|
172 | did = self.pdm.save_pending_deferred(d) | |
170 | d2 = self.pdm.get_pending_deferred(did,False) |
|
173 | d2 = self.pdm.get_pending_deferred(did,False) | |
171 | d2.addErrback(lambda f: self.assertRaises(error.ResultNotCompleted, f.raiseException)) |
|
174 | d2.addErrback(lambda f: self.assertRaises(error.ResultNotCompleted, f.raiseException)) | |
172 |
|
175 | |||
173 | def test_with_callbacks(self): |
|
176 | def test_with_callbacks(self): | |
174 | d = defer.Deferred() |
|
177 | d = defer.Deferred() | |
175 | d.addCallback(lambda r: r+' foo') |
|
178 | d.addCallback(lambda r: r+' foo') | |
176 | d.addCallback(lambda r: r+' bar') |
|
179 | d.addCallback(lambda r: r+' bar') | |
177 | did = self.pdm.save_pending_deferred(d) |
|
180 | did = self.pdm.save_pending_deferred(d) | |
178 | d2 = self.pdm.get_pending_deferred(did,True) |
|
181 | d2 = self.pdm.get_pending_deferred(did,True) | |
179 | d.callback('bam') |
|
182 | d.callback('bam') | |
180 | d2.addCallback(lambda r: self.assertEquals(r,'bam foo bar')) |
|
183 | d2.addCallback(lambda r: self.assertEquals(r,'bam foo bar')) | |
181 |
|
184 | |||
182 | def test_with_errbacks(self): |
|
185 | def test_with_errbacks(self): | |
183 | class MyError(Exception): |
|
186 | class MyError(Exception): | |
184 | pass |
|
187 | pass | |
185 | d = defer.Deferred() |
|
188 | d = defer.Deferred() | |
186 | d.addCallback(lambda r: 'foo') |
|
189 | d.addCallback(lambda r: 'foo') | |
187 | d.addErrback(lambda f: 'caught error') |
|
190 | d.addErrback(lambda f: 'caught error') | |
188 | did = self.pdm.save_pending_deferred(d) |
|
191 | did = self.pdm.save_pending_deferred(d) | |
189 | d2 = self.pdm.get_pending_deferred(did,True) |
|
192 | d2 = self.pdm.get_pending_deferred(did,True) | |
190 | d.errback(failure.Failure(MyError('bam'))) |
|
193 | d.errback(failure.Failure(MyError('bam'))) | |
191 | d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException)) |
|
194 | d2.addErrback(lambda f: self.assertRaises(MyError, f.raiseException)) | |
192 |
|
195 | |||
193 | def test_nested_deferreds(self): |
|
196 | def test_nested_deferreds(self): | |
194 | d = defer.Deferred() |
|
197 | d = defer.Deferred() | |
195 | d2 = defer.Deferred() |
|
198 | d2 = defer.Deferred() | |
196 | d.addCallback(lambda r: d2) |
|
199 | d.addCallback(lambda r: d2) | |
197 | did = self.pdm.save_pending_deferred(d) |
|
200 | did = self.pdm.save_pending_deferred(d) | |
198 | d.callback('foo') |
|
201 | d.callback('foo') | |
199 | d3 = self.pdm.get_pending_deferred(did,False) |
|
202 | d3 = self.pdm.get_pending_deferred(did,False) | |
200 | d3.addErrback(lambda f: self.assertRaises(error.ResultNotCompleted, f.raiseException)) |
|
203 | d3.addErrback(lambda f: self.assertRaises(error.ResultNotCompleted, f.raiseException)) | |
201 | d2.callback('bar') |
|
204 | d2.callback('bar') | |
202 | d3 = self.pdm.get_pending_deferred(did,False) |
|
205 | d3 = self.pdm.get_pending_deferred(did,False) | |
203 | d3.addCallback(lambda r: self.assertEquals(r,'bar')) |
|
206 | d3.addCallback(lambda r: self.assertEquals(r,'bar')) | |
204 |
|
207 | |||
205 | #------------------------------------------------------------------------------- |
|
208 | #------------------------------------------------------------------------------- | |
206 | # Regular Unittests |
|
209 | # Regular Unittests | |
207 | #------------------------------------------------------------------------------- |
|
210 | #------------------------------------------------------------------------------- | |
208 |
|
211 | |||
209 | # This ensures that the code will run either standalone as a script, or that it |
|
212 | # This ensures that the code will run either standalone as a script, or that it | |
210 | # can be picked up by Twisted's `trial` test wrapper to run all the tests. |
|
213 | # can be picked up by Twisted's `trial` test wrapper to run all the tests. | |
211 | if tcommon.pexpect is not None: |
|
214 | if tcommon.pexpect is not None: | |
212 | if __name__ == '__main__': |
|
215 | if __name__ == '__main__': | |
213 | unittest.main(testLoader=IPDocTestLoader(dt_files,dt_modules)) |
|
216 | unittest.main(testLoader=IPDocTestLoader(dt_files,dt_modules)) | |
214 | else: |
|
217 | else: | |
215 | testSuite = lambda : makeTestSuite(__name__,dt_files,dt_modules) |
|
218 | testSuite = lambda : makeTestSuite(__name__,dt_files,dt_modules) |
@@ -1,47 +1,50 | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 |
|
2 | |||
3 | """This file contains unittests for the kernel.task.py module.""" |
|
3 | """This file contains unittests for the kernel.task.py module.""" | |
4 |
|
4 | |||
5 | __docformat__ = "restructuredtext en" |
|
5 | __docformat__ = "restructuredtext en" | |
6 |
|
6 | |||
7 | #------------------------------------------------------------------------------- |
|
7 | #------------------------------------------------------------------------------- | |
8 | # Copyright (C) 2008 The IPython Development Team |
|
8 | # Copyright (C) 2008 The IPython Development Team | |
9 | # |
|
9 | # | |
10 | # Distributed under the terms of the BSD License. The full license is in |
|
10 | # Distributed under the terms of the BSD License. The full license is in | |
11 | # the file COPYING, distributed as part of this software. |
|
11 | # the file COPYING, distributed as part of this software. | |
12 | #------------------------------------------------------------------------------- |
|
12 | #------------------------------------------------------------------------------- | |
13 |
|
13 | |||
14 | #------------------------------------------------------------------------------- |
|
14 | #------------------------------------------------------------------------------- | |
15 | # Imports |
|
15 | # Imports | |
16 | #------------------------------------------------------------------------------- |
|
16 | #------------------------------------------------------------------------------- | |
17 |
|
17 | |||
|
18 | try: | |||
18 | import time |
|
19 | import time | |
19 |
|
20 | |||
20 | from twisted.internet import defer |
|
21 | from twisted.internet import defer | |
21 | from twisted.trial import unittest |
|
22 | from twisted.trial import unittest | |
22 |
|
23 | |||
23 | from IPython.kernel import task, controllerservice as cs, engineservice as es |
|
24 | from IPython.kernel import task, controllerservice as cs, engineservice as es | |
24 | from IPython.kernel.multiengine import IMultiEngine |
|
25 | from IPython.kernel.multiengine import IMultiEngine | |
25 | from IPython.testing.util import DeferredTestCase |
|
26 | from IPython.testing.util import DeferredTestCase | |
26 | from IPython.kernel.tests.tasktest import ITaskControllerTestCase |
|
27 | from IPython.kernel.tests.tasktest import ITaskControllerTestCase | |
27 |
|
28 | except ImportError: | ||
|
29 | pass | |||
|
30 | else: | |||
28 | #------------------------------------------------------------------------------- |
|
31 | #------------------------------------------------------------------------------- | |
29 | # Tests |
|
32 | # Tests | |
30 | #------------------------------------------------------------------------------- |
|
33 | #------------------------------------------------------------------------------- | |
31 |
|
34 | |||
32 | class BasicTaskControllerTestCase(DeferredTestCase, ITaskControllerTestCase): |
|
35 | class BasicTaskControllerTestCase(DeferredTestCase, ITaskControllerTestCase): | |
33 |
|
36 | |||
34 | def setUp(self): |
|
37 | def setUp(self): | |
35 | self.controller = cs.ControllerService() |
|
38 | self.controller = cs.ControllerService() | |
36 | self.controller.startService() |
|
39 | self.controller.startService() | |
37 | self.multiengine = IMultiEngine(self.controller) |
|
40 | self.multiengine = IMultiEngine(self.controller) | |
38 | self.tc = task.ITaskController(self.controller) |
|
41 | self.tc = task.ITaskController(self.controller) | |
39 | self.tc.failurePenalty = 0 |
|
42 | self.tc.failurePenalty = 0 | |
40 | self.engines=[] |
|
43 | self.engines=[] | |
41 |
|
44 | |||
42 | def tearDown(self): |
|
45 | def tearDown(self): | |
43 | self.controller.stopService() |
|
46 | self.controller.stopService() | |
44 | for e in self.engines: |
|
47 | for e in self.engines: | |
45 | e.stopService() |
|
48 | e.stopService() | |
46 |
|
49 | |||
47 |
|
50 |
@@ -1,86 +1,90 | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 | # encoding: utf-8 |
|
2 | # encoding: utf-8 | |
3 |
|
3 | |||
4 | __docformat__ = "restructuredtext en" |
|
4 | __docformat__ = "restructuredtext en" | |
5 |
|
5 | |||
6 | #------------------------------------------------------------------------------- |
|
6 | #------------------------------------------------------------------------------- | |
7 | # Copyright (C) 2008 The IPython Development Team |
|
7 | # Copyright (C) 2008 The IPython Development Team | |
8 | # |
|
8 | # | |
9 | # Distributed under the terms of the BSD License. The full license is in |
|
9 | # Distributed under the terms of the BSD License. The full license is in | |
10 | # the file COPYING, distributed as part of this software. |
|
10 | # the file COPYING, distributed as part of this software. | |
11 | #------------------------------------------------------------------------------- |
|
11 | #------------------------------------------------------------------------------- | |
12 |
|
12 | |||
13 | #------------------------------------------------------------------------------- |
|
13 | #------------------------------------------------------------------------------- | |
14 | # Imports |
|
14 | # Imports | |
15 | #------------------------------------------------------------------------------- |
|
15 | #------------------------------------------------------------------------------- | |
16 |
|
16 | |||
|
17 | try: | |||
17 | import time |
|
18 | import time | |
18 |
|
19 | |||
19 | from twisted.internet import defer, reactor |
|
20 | from twisted.internet import defer, reactor | |
20 |
|
21 | |||
21 | from IPython.kernel.fcutil import Tub, UnauthenticatedTub |
|
22 | from IPython.kernel.fcutil import Tub, UnauthenticatedTub | |
22 |
|
23 | |||
23 | from IPython.kernel import task as taskmodule |
|
24 | from IPython.kernel import task as taskmodule | |
24 | from IPython.kernel import controllerservice as cs |
|
25 | from IPython.kernel import controllerservice as cs | |
25 | import IPython.kernel.multiengine as me |
|
26 | import IPython.kernel.multiengine as me | |
26 | from IPython.testing.util import DeferredTestCase |
|
27 | from IPython.testing.util import DeferredTestCase | |
27 | from IPython.kernel.multienginefc import IFCSynchronousMultiEngine |
|
28 | from IPython.kernel.multienginefc import IFCSynchronousMultiEngine | |
28 | from IPython.kernel.taskfc import IFCTaskController |
|
29 | from IPython.kernel.taskfc import IFCTaskController | |
29 | from IPython.kernel.util import printer |
|
30 | from IPython.kernel.util import printer | |
30 | from IPython.kernel.tests.tasktest import ITaskControllerTestCase |
|
31 | from IPython.kernel.tests.tasktest import ITaskControllerTestCase | |
31 | from IPython.kernel.clientconnector import ClientConnector |
|
32 | from IPython.kernel.clientconnector import ClientConnector | |
|
33 | except ImportError: | |||
|
34 | pass | |||
|
35 | else: | |||
32 |
|
36 | |||
33 | #------------------------------------------------------------------------------- |
|
37 | #------------------------------------------------------------------------------- | |
34 | # Tests |
|
38 | # Tests | |
35 | #------------------------------------------------------------------------------- |
|
39 | #------------------------------------------------------------------------------- | |
36 |
|
40 | |||
37 | class TaskTest(DeferredTestCase, ITaskControllerTestCase): |
|
41 | class TaskTest(DeferredTestCase, ITaskControllerTestCase): | |
38 |
|
42 | |||
39 | def setUp(self): |
|
43 | def setUp(self): | |
40 |
|
44 | |||
41 | self.engines = [] |
|
45 | self.engines = [] | |
42 |
|
46 | |||
43 | self.controller = cs.ControllerService() |
|
47 | self.controller = cs.ControllerService() | |
44 | self.controller.startService() |
|
48 | self.controller.startService() | |
45 | self.imultiengine = me.IMultiEngine(self.controller) |
|
49 | self.imultiengine = me.IMultiEngine(self.controller) | |
46 | self.itc = taskmodule.ITaskController(self.controller) |
|
50 | self.itc = taskmodule.ITaskController(self.controller) | |
47 | self.itc.failurePenalty = 0 |
|
51 | self.itc.failurePenalty = 0 | |
48 |
|
52 | |||
49 | self.mec_referenceable = IFCSynchronousMultiEngine(self.imultiengine) |
|
53 | self.mec_referenceable = IFCSynchronousMultiEngine(self.imultiengine) | |
50 | self.tc_referenceable = IFCTaskController(self.itc) |
|
54 | self.tc_referenceable = IFCTaskController(self.itc) | |
51 |
|
55 | |||
52 | self.controller_tub = Tub() |
|
56 | self.controller_tub = Tub() | |
53 | self.controller_tub.listenOn('tcp:10105:interface=127.0.0.1') |
|
57 | self.controller_tub.listenOn('tcp:10105:interface=127.0.0.1') | |
54 | self.controller_tub.setLocation('127.0.0.1:10105') |
|
58 | self.controller_tub.setLocation('127.0.0.1:10105') | |
55 |
|
59 | |||
56 | mec_furl = self.controller_tub.registerReference(self.mec_referenceable) |
|
60 | mec_furl = self.controller_tub.registerReference(self.mec_referenceable) | |
57 | tc_furl = self.controller_tub.registerReference(self.tc_referenceable) |
|
61 | tc_furl = self.controller_tub.registerReference(self.tc_referenceable) | |
58 | self.controller_tub.startService() |
|
62 | self.controller_tub.startService() | |
59 |
|
63 | |||
60 | self.client_tub = ClientConnector() |
|
64 | self.client_tub = ClientConnector() | |
61 | d = self.client_tub.get_multiengine_client(mec_furl) |
|
65 | d = self.client_tub.get_multiengine_client(mec_furl) | |
62 | d.addCallback(self.handle_mec_client) |
|
66 | d.addCallback(self.handle_mec_client) | |
63 | d.addCallback(lambda _: self.client_tub.get_task_client(tc_furl)) |
|
67 | d.addCallback(lambda _: self.client_tub.get_task_client(tc_furl)) | |
64 | d.addCallback(self.handle_tc_client) |
|
68 | d.addCallback(self.handle_tc_client) | |
65 | return d |
|
69 | return d | |
66 |
|
70 | |||
67 | def handle_mec_client(self, client): |
|
71 | def handle_mec_client(self, client): | |
68 | self.multiengine = client |
|
72 | self.multiengine = client | |
69 |
|
73 | |||
70 | def handle_tc_client(self, client): |
|
74 | def handle_tc_client(self, client): | |
71 | self.tc = client |
|
75 | self.tc = client | |
72 |
|
76 | |||
73 | def tearDown(self): |
|
77 | def tearDown(self): | |
74 | dlist = [] |
|
78 | dlist = [] | |
75 | # Shut down the multiengine client |
|
79 | # Shut down the multiengine client | |
76 | d = self.client_tub.tub.stopService() |
|
80 | d = self.client_tub.tub.stopService() | |
77 | dlist.append(d) |
|
81 | dlist.append(d) | |
78 | # Shut down the engines |
|
82 | # Shut down the engines | |
79 | for e in self.engines: |
|
83 | for e in self.engines: | |
80 | e.stopService() |
|
84 | e.stopService() | |
81 | # Shut down the controller |
|
85 | # Shut down the controller | |
82 | d = self.controller_tub.stopService() |
|
86 | d = self.controller_tub.stopService() | |
83 | d.addBoth(lambda _: self.controller.stopService()) |
|
87 | d.addBoth(lambda _: self.controller.stopService()) | |
84 | dlist.append(d) |
|
88 | dlist.append(d) | |
85 | return defer.DeferredList(dlist) |
|
89 | return defer.DeferredList(dlist) | |
86 |
|
90 |
@@ -1,31 +1,36 | |||||
1 | include README_Windows.txt |
|
1 | include README_Windows.txt | |
2 | include win32_manual_post_install.py |
|
2 | include win32_manual_post_install.py | |
3 | include ipython.py |
|
3 | include ipython.py | |
4 |
|
4 | |||
5 | graft scripts |
|
5 | graft scripts | |
6 |
|
6 | |||
7 | graft setupext |
|
7 | graft setupext | |
8 |
|
8 | |||
9 | graft IPython/UserConfig |
|
9 | graft IPython/UserConfig | |
10 |
|
10 | |||
|
11 | graft IPython/kernel | |||
|
12 | graft IPython/config | |||
|
13 | graft IPython/testing | |||
|
14 | graft IPython/tools | |||
|
15 | ||||
11 | graft doc |
|
16 | graft doc | |
12 | exclude doc/\#* |
|
17 | exclude doc/\#* | |
13 | exclude doc/*.1 |
|
18 | exclude doc/*.1 | |
14 | exclude doc/ChangeLog.* |
|
19 | exclude doc/ChangeLog.* | |
15 | exclude doc/update_version.sh |
|
20 | exclude doc/update_version.sh | |
16 |
|
21 | |||
17 | # There seems to be no way of excluding whole subdirectories, other than |
|
22 | # There seems to be no way of excluding whole subdirectories, other than | |
18 | # manually excluding all their subdirs. distutils really is horrible... |
|
23 | # manually excluding all their subdirs. distutils really is horrible... | |
19 | exclude doc/attic/* |
|
24 | exclude doc/attic/* | |
20 | exclude doc/build/doctrees/* |
|
25 | exclude doc/build/doctrees/* | |
21 | exclude doc/build/html/_sources/* |
|
26 | exclude doc/build/html/_sources/* | |
22 | exclude doc/build/html/_static/* |
|
27 | exclude doc/build/html/_static/* | |
23 | exclude doc/build/html/* |
|
28 | exclude doc/build/html/* | |
24 | exclude doc/build/latex/* |
|
29 | exclude doc/build/latex/* | |
25 |
|
30 | |||
26 | global-exclude *~ |
|
31 | global-exclude *~ | |
27 | global-exclude *.flc |
|
32 | global-exclude *.flc | |
28 | global-exclude *.pyc |
|
33 | global-exclude *.pyc | |
29 | global-exclude .dircopy.log |
|
34 | global-exclude .dircopy.log | |
30 | global-exclude .svn |
|
35 | global-exclude .svn | |
31 | global-exclude .bzr |
|
36 | global-exclude .bzr |
@@ -1,165 +1,169 | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 | # -*- coding: utf-8 -*- |
|
2 | # -*- coding: utf-8 -*- | |
3 | """Setup script for IPython. |
|
3 | """Setup script for IPython. | |
4 |
|
4 | |||
5 | Under Posix environments it works like a typical setup.py script. |
|
5 | Under Posix environments it works like a typical setup.py script. | |
6 | Under Windows, the command sdist is not supported, since IPython |
|
6 | Under Windows, the command sdist is not supported, since IPython | |
7 | requires utilities which are not available under Windows.""" |
|
7 | requires utilities which are not available under Windows.""" | |
8 |
|
8 | |||
9 | #------------------------------------------------------------------------------- |
|
9 | #------------------------------------------------------------------------------- | |
10 | # Copyright (C) 2008 The IPython Development Team |
|
10 | # Copyright (C) 2008 The IPython Development Team | |
11 | # |
|
11 | # | |
12 | # Distributed under the terms of the BSD License. The full license is in |
|
12 | # Distributed under the terms of the BSD License. The full license is in | |
13 | # the file COPYING, distributed as part of this software. |
|
13 | # the file COPYING, distributed as part of this software. | |
14 | #------------------------------------------------------------------------------- |
|
14 | #------------------------------------------------------------------------------- | |
15 |
|
15 | |||
16 | #------------------------------------------------------------------------------- |
|
16 | #------------------------------------------------------------------------------- | |
17 | # Imports |
|
17 | # Imports | |
18 | #------------------------------------------------------------------------------- |
|
18 | #------------------------------------------------------------------------------- | |
19 |
|
19 | |||
20 | # Stdlib imports |
|
20 | # Stdlib imports | |
21 | import os |
|
21 | import os | |
22 | import sys |
|
22 | import sys | |
23 |
|
23 | |||
24 | from glob import glob |
|
24 | from glob import glob | |
25 |
|
25 | |||
26 | # BEFORE importing distutils, remove MANIFEST. distutils doesn't properly |
|
26 | # BEFORE importing distutils, remove MANIFEST. distutils doesn't properly | |
27 | # update it when the contents of directories change. |
|
27 | # update it when the contents of directories change. | |
28 | if os.path.exists('MANIFEST'): os.remove('MANIFEST') |
|
28 | if os.path.exists('MANIFEST'): os.remove('MANIFEST') | |
29 |
|
29 | |||
30 | from distutils.core import setup |
|
30 | from distutils.core import setup | |
31 |
|
31 | |||
32 | # Local imports |
|
32 | # Local imports | |
33 | from IPython.genutils import target_update |
|
33 | from IPython.genutils import target_update | |
34 |
|
34 | |||
35 | from setupbase import ( |
|
35 | from setupbase import ( | |
36 | setup_args, |
|
36 | setup_args, | |
37 | find_packages, |
|
37 | find_packages, | |
38 | find_package_data, |
|
38 | find_package_data, | |
39 | find_scripts, |
|
39 | find_scripts, | |
40 | find_data_files, |
|
40 | find_data_files, | |
41 | check_for_dependencies |
|
41 | check_for_dependencies | |
42 | ) |
|
42 | ) | |
43 |
|
43 | |||
44 | isfile = os.path.isfile |
|
44 | isfile = os.path.isfile | |
45 |
|
45 | |||
46 | #------------------------------------------------------------------------------- |
|
46 | #------------------------------------------------------------------------------- | |
47 | # Handle OS specific things |
|
47 | # Handle OS specific things | |
48 | #------------------------------------------------------------------------------- |
|
48 | #------------------------------------------------------------------------------- | |
49 |
|
49 | |||
50 | if os.name == 'posix': |
|
50 | if os.name == 'posix': | |
51 | os_name = 'posix' |
|
51 | os_name = 'posix' | |
52 | elif os.name in ['nt','dos']: |
|
52 | elif os.name in ['nt','dos']: | |
53 | os_name = 'windows' |
|
53 | os_name = 'windows' | |
54 | else: |
|
54 | else: | |
55 | print 'Unsupported operating system:',os.name |
|
55 | print 'Unsupported operating system:',os.name | |
56 | sys.exit(1) |
|
56 | sys.exit(1) | |
57 |
|
57 | |||
58 | # Under Windows, 'sdist' has not been supported. Now that the docs build with |
|
58 | # Under Windows, 'sdist' has not been supported. Now that the docs build with | |
59 | # Sphinx it might work, but let's not turn it on until someone confirms that it |
|
59 | # Sphinx it might work, but let's not turn it on until someone confirms that it | |
60 | # actually works. |
|
60 | # actually works. | |
61 | if os_name == 'windows' and 'sdist' in sys.argv: |
|
61 | if os_name == 'windows' and 'sdist' in sys.argv: | |
62 | print 'The sdist command is not available under Windows. Exiting.' |
|
62 | print 'The sdist command is not available under Windows. Exiting.' | |
63 | sys.exit(1) |
|
63 | sys.exit(1) | |
64 |
|
64 | |||
65 | #------------------------------------------------------------------------------- |
|
65 | #------------------------------------------------------------------------------- | |
66 | # Things related to the IPython documentation |
|
66 | # Things related to the IPython documentation | |
67 | #------------------------------------------------------------------------------- |
|
67 | #------------------------------------------------------------------------------- | |
68 |
|
68 | |||
69 | # update the manuals when building a source dist |
|
69 | # update the manuals when building a source dist | |
70 | if len(sys.argv) >= 2 and sys.argv[1] in ('sdist','bdist_rpm'): |
|
70 | if len(sys.argv) >= 2 and sys.argv[1] in ('sdist','bdist_rpm'): | |
71 | import textwrap |
|
71 | import textwrap | |
72 |
|
72 | |||
73 | # List of things to be updated. Each entry is a triplet of args for |
|
73 | # List of things to be updated. Each entry is a triplet of args for | |
74 | # target_update() |
|
74 | # target_update() | |
75 | to_update = [ # The do_sphinx scripts builds html and pdf, so just one |
|
75 | to_update = [ | |
76 | # target is enough to cover all manual generation |
|
|||
77 | ('doc/manual/ipython.pdf', |
|
|||
78 | ['IPython/Release.py','doc/source/ipython.rst'], |
|
|||
79 | "cd doc && python do_sphinx.py" ), |
|
|||
80 |
|
||||
81 | # FIXME - Disabled for now: we need to redo an automatic way |
|
76 | # FIXME - Disabled for now: we need to redo an automatic way | |
82 | # of generating the magic info inside the rst. |
|
77 | # of generating the magic info inside the rst. | |
83 | #('doc/magic.tex', |
|
78 | #('doc/magic.tex', | |
84 | #['IPython/Magic.py'], |
|
79 | #['IPython/Magic.py'], | |
85 | #"cd doc && ./update_magic.sh" ), |
|
80 | #"cd doc && ./update_magic.sh" ), | |
86 |
|
81 | |||
87 | ('doc/ipython.1.gz', |
|
82 | ('doc/ipython.1.gz', | |
88 | ['doc/ipython.1'], |
|
83 | ['doc/ipython.1'], | |
89 | "cd doc && gzip -9c ipython.1 > ipython.1.gz"), |
|
84 | "cd doc && gzip -9c ipython.1 > ipython.1.gz"), | |
90 |
|
85 | |||
91 | ('doc/pycolor.1.gz', |
|
86 | ('doc/pycolor.1.gz', | |
92 | ['doc/pycolor.1'], |
|
87 | ['doc/pycolor.1'], | |
93 | "cd doc && gzip -9c pycolor.1 > pycolor.1.gz"), |
|
88 | "cd doc && gzip -9c pycolor.1 > pycolor.1.gz"), | |
94 | ] |
|
89 | ] | |
95 |
|
90 | |||
|
91 | try: | |||
|
92 | import sphinx | |||
|
93 | except ImportError: | |||
|
94 | pass | |||
|
95 | else: | |||
|
96 | # The do_sphinx scripts builds html and pdf, so just one | |||
|
97 | # target is enough to cover all manual generation | |||
|
98 | to_update.append( | |||
|
99 | ('doc/manual/ipython.pdf', | |||
|
100 | ['IPython/Release.py','doc/source/ipython.rst'], | |||
|
101 | "cd doc && python do_sphinx.py") | |||
|
102 | ) | |||
96 | [ target_update(*t) for t in to_update ] |
|
103 | [ target_update(*t) for t in to_update ] | |
97 |
|
104 | |||
98 | #--------------------------------------------------------------------------- |
|
105 | #--------------------------------------------------------------------------- | |
99 | # Find all the packages, package data, scripts and data_files |
|
106 | # Find all the packages, package data, scripts and data_files | |
100 | #--------------------------------------------------------------------------- |
|
107 | #--------------------------------------------------------------------------- | |
101 |
|
108 | |||
102 | packages = find_packages() |
|
109 | packages = find_packages() | |
103 | package_data = find_package_data() |
|
110 | package_data = find_package_data() | |
104 | scripts = find_scripts() |
|
111 | scripts = find_scripts() | |
105 | data_files = find_data_files() |
|
112 | data_files = find_data_files() | |
106 |
|
113 | |||
107 | #--------------------------------------------------------------------------- |
|
114 | #--------------------------------------------------------------------------- | |
108 | # Handle dependencies and setuptools specific things |
|
115 | # Handle dependencies and setuptools specific things | |
109 | #--------------------------------------------------------------------------- |
|
116 | #--------------------------------------------------------------------------- | |
110 |
|
117 | |||
111 | # This dict is used for passing extra arguments that are setuptools |
|
118 | # This dict is used for passing extra arguments that are setuptools | |
112 | # specific to setup |
|
119 | # specific to setup | |
113 | setuptools_extra_args = {} |
|
120 | setuptools_extra_args = {} | |
114 |
|
121 | |||
115 | if 'setuptools' in sys.modules: |
|
122 | if 'setuptools' in sys.modules: | |
116 | setuptools_extra_args['zip_safe'] = False |
|
123 | setuptools_extra_args['zip_safe'] = False | |
117 | setuptools_extra_args['entry_points'] = { |
|
124 | setuptools_extra_args['entry_points'] = { | |
118 | 'console_scripts': [ |
|
125 | 'console_scripts': [ | |
119 | 'ipython = IPython.ipapi:launch_new_instance', |
|
126 | 'ipython = IPython.ipapi:launch_new_instance', | |
120 | 'pycolor = IPython.PyColorize:main', |
|
127 | 'pycolor = IPython.PyColorize:main', | |
121 | 'ipcontroller = IPython.kernel.scripts.ipcontroller:main', |
|
128 | 'ipcontroller = IPython.kernel.scripts.ipcontroller:main', | |
122 | 'ipengine = IPython.kernel.scripts.ipengine:main', |
|
129 | 'ipengine = IPython.kernel.scripts.ipengine:main', | |
123 | 'ipcluster = IPython.kernel.scripts.ipcluster:main' |
|
130 | 'ipcluster = IPython.kernel.scripts.ipcluster:main' | |
124 | ] |
|
131 | ] | |
125 | } |
|
132 | } | |
126 | setup_args["extras_require"] = dict( |
|
133 | setup_args["extras_require"] = dict( | |
127 | kernel = [ |
|
134 | kernel = [ | |
128 | "zope.interface>=3.4.1", |
|
135 | "zope.interface>=3.4.1", | |
129 | "Twisted>=8.0.1", |
|
136 | "Twisted>=8.0.1", | |
130 | "foolscap>=0.2.6" |
|
137 | "foolscap>=0.2.6" | |
131 | ], |
|
138 | ], | |
132 | doc=['Sphinx>=0.3','pygments'], |
|
139 | doc=['Sphinx>=0.3','pygments'], | |
133 | test='nose>=0.10.1', |
|
140 | test='nose>=0.10.1', | |
134 | security=["pyOpenSSL>=0.6"] |
|
141 | security=["pyOpenSSL>=0.6"] | |
135 | ) |
|
142 | ) | |
136 | # Allow setuptools to handle the scripts |
|
143 | # Allow setuptools to handle the scripts | |
137 | scripts = [] |
|
144 | scripts = [] | |
138 | # eggs will lack docs, examples |
|
145 | # eggs will lack docs, examples | |
139 | data_files = [] |
|
146 | data_files = [] | |
140 | else: |
|
147 | else: | |
141 | # package_data of setuptools was introduced to distutils in 2.4 |
|
148 | # package_data of setuptools was introduced to distutils in 2.4 | |
142 | cfgfiles = filter(isfile, glob('IPython/UserConfig/*')) |
|
149 | cfgfiles = filter(isfile, glob('IPython/UserConfig/*')) | |
143 | if sys.version_info < (2,4): |
|
150 | if sys.version_info < (2,4): | |
144 | data_files.append(('lib', 'IPython/UserConfig', cfgfiles)) |
|
151 | data_files.append(('lib', 'IPython/UserConfig', cfgfiles)) | |
145 | # If we are running without setuptools, call this function which will |
|
152 | # If we are running without setuptools, call this function which will | |
146 | # check for dependencies an inform the user what is needed. This is |
|
153 | # check for dependencies an inform the user what is needed. This is | |
147 | # just to make life easy for users. |
|
154 | # just to make life easy for users. | |
148 | check_for_dependencies() |
|
155 | check_for_dependencies() | |
149 |
|
156 | |||
150 |
|
157 | |||
151 | #--------------------------------------------------------------------------- |
|
158 | #--------------------------------------------------------------------------- | |
152 | # Do the actual setup now |
|
159 | # Do the actual setup now | |
153 | #--------------------------------------------------------------------------- |
|
160 | #--------------------------------------------------------------------------- | |
154 |
|
161 | |||
155 | print packages |
|
|||
156 |
|
||||
157 |
|
||||
158 | setup_args['packages'] = packages |
|
162 | setup_args['packages'] = packages | |
159 | setup_args['package_data'] = package_data |
|
163 | setup_args['package_data'] = package_data | |
160 | setup_args['scripts'] = scripts |
|
164 | setup_args['scripts'] = scripts | |
161 | setup_args['data_files'] = data_files |
|
165 | setup_args['data_files'] = data_files | |
162 | setup_args.update(setuptools_extra_args) |
|
166 | setup_args.update(setuptools_extra_args) | |
163 |
|
167 | |||
164 | if __name__ == '__main__': |
|
168 | if __name__ == '__main__': | |
165 | setup(**setup_args) |
|
169 | setup(**setup_args) |
@@ -1,20 +1,20 | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 | """Wrapper to run setup.py using setuptools.""" |
|
2 | """Wrapper to run setup.py using setuptools.""" | |
3 |
|
3 | |||
4 | import os |
|
4 | import os | |
5 | import sys |
|
5 | import sys | |
6 |
|
6 | |||
7 | # Add my local path to sys.path |
|
7 | # Add my local path to sys.path | |
8 | home = os.environ['HOME'] |
|
8 | home = os.environ['HOME'] | |
9 | sys.path.insert(0,'%s/usr/local/lib/python%s/site-packages' % |
|
9 | sys.path.insert(0,'%s/usr/local/lib/python%s/site-packages' % | |
10 | (home,sys.version[:3])) |
|
10 | (home,sys.version[:3])) | |
11 |
|
11 | |||
12 | # now, import setuptools and call the actual setup |
|
12 | # now, import setuptools and call the actual setup | |
13 | import setuptools |
|
13 | import setuptools | |
14 | print sys.argv |
|
14 | # print sys.argv | |
15 | #sys.argv=['','bdist_egg'] |
|
15 | #sys.argv=['','bdist_egg'] | |
16 | execfile('setup.py') |
|
16 | execfile('setup.py') | |
17 |
|
17 | |||
18 | # clean up the junk left around by setuptools |
|
18 | # clean up the junk left around by setuptools | |
19 | if "develop" not in sys.argv: |
|
19 | if "develop" not in sys.argv: | |
20 | os.system('rm -rf ipython.egg-info build') |
|
20 | os.system('rm -rf ipython.egg-info build') |
General Comments 0
You need to be logged in to leave comments.
Login now