From 24c3fc63757528309ceff9bde92ecc25465b5caf Mon Sep 17 00:00:00 2001 From: Alejandro Infante Date: Fri, 6 Dec 2019 13:21:05 -0300 Subject: [PATCH 01/34] Fix bug in only affecting VisualWorks. The lookup for message type shall only be performed on PBAbstractMessage subclasses without itself. --- src/PythonBridge/Character.extension.st | 22 +- src/PythonBridge/Collection.extension.st | 12 +- src/PythonBridge/Dictionary.extension.st | 22 +- src/PythonBridge/False.extension.st | 22 +- src/PythonBridge/Float.extension.st | 22 +- src/PythonBridge/Fraction.extension.st | 22 +- src/PythonBridge/Integer.extension.st | 22 +- src/PythonBridge/Object.extension.st | 12 +- src/PythonBridge/P3GGenerable.extension.st | 22 +- src/PythonBridge/P3GStatement.extension.st | 12 +- src/PythonBridge/PBAbstractAnswer.class.st | 60 +- src/PythonBridge/PBAbstractFinalizer.class.st | 20 +- src/PythonBridge/PBAbstractMessage.class.st | 58 +- .../PBAbstractMessageBroker.class.st | 248 ++++---- src/PythonBridge/PBAbstractProcess.class.st | 238 ++++---- .../PBAbstractSerializerWrapper.class.st | 30 +- .../PBAbstractWeakRegistry.class.st | 30 +- src/PythonBridge/PBAnswer.class.st | 18 +- src/PythonBridge/PBApplication.class.st | 522 ++++++++--------- src/PythonBridge/PBApplicationTest.class.st | 30 +- .../PBApplicationTestResource.class.st | 74 +-- src/PythonBridge/PBAsyncMessage.class.st | 30 +- .../PBAsyncMessageHandler.class.st | 10 +- src/PythonBridge/PBBinding.class.st | 140 ++--- src/PythonBridge/PBBlockFinalizer.class.st | 60 +- src/PythonBridge/PBCF.class.st | 224 ++++---- src/PythonBridge/PBCallbackAnswer.class.st | 48 +- src/PythonBridge/PBCallbackMessage.class.st | 86 +-- src/PythonBridge/PBCommand.class.st | 220 +++---- src/PythonBridge/PBCommandFactory.class.st | 290 +++++----- .../PBCommandFactoryTest.class.st | 104 ++-- src/PythonBridge/PBCommandQueue.class.st | 250 ++++---- src/PythonBridge/PBCommandQueueTest.class.st | 212 +++---- src/PythonBridge/PBCommandTest.class.st | 60 +- .../PBCommunicationError.class.st | 10 +- .../PBCommunicationHandler.class.st | 94 +-- src/PythonBridge/PBConnectionTest.class.st | 130 ++--- src/PythonBridge/PBDeserializeTest.class.st | 140 ++--- src/PythonBridge/PBDeserializer.class.st | 100 ++-- src/PythonBridge/PBDropQueue.class.st | 20 +- .../PBEnqueueCommandMessage.class.st | 154 ++--- src/PythonBridge/PBErrorAnswer.class.st | 48 +- .../PBErrorHandlingAction.class.st | 30 +- src/PythonBridge/PBErrorLog.class.st | 20 +- src/PythonBridge/PBErrorMessage.class.st | 116 ++-- .../PBExcecutionHandlerTest.class.st | 74 +-- src/PythonBridge/PBExecutionHandler.class.st | 384 ++++++------- src/PythonBridge/PBFatalErrorLog.class.st | 10 +- src/PythonBridge/PBHandler.class.st | 86 +-- src/PythonBridge/PBIgnore.class.st | 20 +- src/PythonBridge/PBIsAliveMessage.class.st | 30 +- .../PBJsonSerializerTest.class.st | 128 ++--- src/PythonBridge/PBLog.class.st | 84 +-- src/PythonBridge/PBLoggingHandler.class.st | 58 +- .../PBLoggingHandlerTest.class.st | 64 +-- src/PythonBridge/PBMapper.class.st | 120 ++-- src/PythonBridge/PBMapperFactory.class.st | 116 ++-- src/PythonBridge/PBMapping.class.st | 10 +- src/PythonBridge/PBMessage.class.st | 70 +-- src/PythonBridge/PBMessageBrokerTest.class.st | 542 +++++++++--------- src/PythonBridge/PBMessageHandler.class.st | 108 ++-- .../PBMessageHandlerTest.class.st | 154 ++--- src/PythonBridge/PBMessageTest.class.st | 124 ++-- src/PythonBridge/PBObject.class.st | 316 +++++----- .../PBObjectFinalizationTest.class.st | 116 ++-- src/PythonBridge/PBObjectFinalizer.class.st | 20 +- src/PythonBridge/PBObjectRegistry.class.st | 112 ++-- src/PythonBridge/PBObserver.class.st | 164 +++--- src/PythonBridge/PBPlatform.class.st | 344 +++++------ src/PythonBridge/PBProcessTest.class.st | 112 ++-- src/PythonBridge/PBPromise.class.st | 148 ++--- src/PythonBridge/PBPromiseRegistry.class.st | 90 +-- .../PBPromiseRegistryTest.class.st | 120 ++-- src/PythonBridge/PBProxyObject.class.st | 122 ++-- .../PBPython3GenerationTest.class.st | 74 +-- src/PythonBridge/PBPythonError.class.st | 180 +++--- .../PBPythonErrorHandlingTest.class.st | 10 +- src/PythonBridge/PBPythonHandler.class.st | 80 +-- src/PythonBridge/PBPythonObjectTest.class.st | 92 +-- src/PythonBridge/PBPythonValueTrait.trait.st | 22 +- src/PythonBridge/PBRAnswer.class.st | 48 +- src/PythonBridge/PBRAsyncMessage.class.st | 30 +- src/PythonBridge/PBRMessage.class.st | 56 +- src/PythonBridge/PBRMessageTest.class.st | 102 ++-- src/PythonBridge/PBRStubAnswer.class.st | 54 +- src/PythonBridge/PBRStubMessage.class.st | 72 +-- src/PythonBridge/PBRSyncMessage.class.st | 88 +-- src/PythonBridge/PBRegistryFinalizer.class.st | 112 ++-- src/PythonBridge/PBReplaceCommand.class.st | 62 +- src/PythonBridge/PBRetry.class.st | 10 +- src/PythonBridge/PBSendCommandTest.class.st | 164 +++--- src/PythonBridge/PBSerializationTest.class.st | 52 +- src/PythonBridge/PBSerializeTest.class.st | 62 +- src/PythonBridge/PBSerializer.class.st | 52 +- src/PythonBridge/PBSettings.class.st | 74 +-- .../PBSimpleApplicationTest.class.st | 134 ++--- src/PythonBridge/PBSocketAddress.class.st | 84 +-- src/PythonBridge/PBStubAnswer.class.st | 50 +- src/PythonBridge/PBStubApplication.class.st | 30 +- src/PythonBridge/PBStubMessage.class.st | 94 +-- src/PythonBridge/PBSyncMessage.class.st | 100 ++-- .../PBSyncMessageHandler.class.st | 48 +- src/PythonBridge/PBTestCase.class.st | 166 +++--- src/PythonBridge/PBUiManager.class.st | 30 +- .../PBUpdatePromiseMessage.class.st | 62 +- src/PythonBridge/PBUtils.class.st | 30 +- src/PythonBridge/PBWeakFinalizerTest.class.st | 208 +++---- .../SequenceableCollection.extension.st | 22 +- src/PythonBridge/Set.extension.st | 22 +- src/PythonBridge/True.extension.st | 22 +- src/PythonBridge/UndefinedObject.extension.st | 22 +- src/PythonBridge/package.st | 2 +- 112 files changed, 5291 insertions(+), 5291 deletions(-) diff --git a/src/PythonBridge/Character.extension.st b/src/PythonBridge/Character.extension.st index 8f93738..493ee2a 100644 --- a/src/PythonBridge/Character.extension.st +++ b/src/PythonBridge/Character.extension.st @@ -1,11 +1,11 @@ -Extension { #name : #Character } - -{ #category : #'*PythonBridge' } -Character >> isPythonGenerable [ - ^ true -] - -{ #category : #'*PythonBridge' } -Character >> isPythonValue [ - ^ true -] +Extension { #name : #Character } + +{ #category : #'*PythonBridge' } +Character >> isPythonGenerable [ + ^ true +] + +{ #category : #'*PythonBridge' } +Character >> isPythonValue [ + ^ true +] diff --git a/src/PythonBridge/Collection.extension.st b/src/PythonBridge/Collection.extension.st index fd6c18c..03b9de8 100644 --- a/src/PythonBridge/Collection.extension.st +++ b/src/PythonBridge/Collection.extension.st @@ -1,6 +1,6 @@ -Extension { #name : #Collection } - -{ #category : #'*PythonBridge' } -Collection >> ensureDo: aBlock [ - self do: [ :el | aBlock valueUninterruptably ] -] +Extension { #name : #Collection } + +{ #category : #'*PythonBridge' } +Collection >> ensureDo: aBlock [ + self do: [ :el | aBlock valueUninterruptably ] +] diff --git a/src/PythonBridge/Dictionary.extension.st b/src/PythonBridge/Dictionary.extension.st index 10a708c..e1fedb5 100644 --- a/src/PythonBridge/Dictionary.extension.st +++ b/src/PythonBridge/Dictionary.extension.st @@ -1,11 +1,11 @@ -Extension { #name : #Dictionary } - -{ #category : #'*PythonBridge' } -Dictionary >> isPythonGenerable [ - ^ true -] - -{ #category : #'*PythonBridge' } -Dictionary >> isPythonValue [ - ^ true -] +Extension { #name : #Dictionary } + +{ #category : #'*PythonBridge' } +Dictionary >> isPythonGenerable [ + ^ true +] + +{ #category : #'*PythonBridge' } +Dictionary >> isPythonValue [ + ^ true +] diff --git a/src/PythonBridge/False.extension.st b/src/PythonBridge/False.extension.st index d040c29..fc0d62f 100644 --- a/src/PythonBridge/False.extension.st +++ b/src/PythonBridge/False.extension.st @@ -1,11 +1,11 @@ -Extension { #name : #False } - -{ #category : #'*PythonBridge' } -False >> isPythonGenerable [ - ^ true -] - -{ #category : #'*PythonBridge' } -False >> isPythonValue [ - ^ true -] +Extension { #name : #False } + +{ #category : #'*PythonBridge' } +False >> isPythonGenerable [ + ^ true +] + +{ #category : #'*PythonBridge' } +False >> isPythonValue [ + ^ true +] diff --git a/src/PythonBridge/Float.extension.st b/src/PythonBridge/Float.extension.st index 5c0bbf2..83803fb 100644 --- a/src/PythonBridge/Float.extension.st +++ b/src/PythonBridge/Float.extension.st @@ -1,11 +1,11 @@ -Extension { #name : #Float } - -{ #category : #'*PythonBridge' } -Float >> isPythonGenerable [ - ^ true -] - -{ #category : #'*PythonBridge' } -Float >> isPythonValue [ - ^ true -] +Extension { #name : #Float } + +{ #category : #'*PythonBridge' } +Float >> isPythonGenerable [ + ^ true +] + +{ #category : #'*PythonBridge' } +Float >> isPythonValue [ + ^ true +] diff --git a/src/PythonBridge/Fraction.extension.st b/src/PythonBridge/Fraction.extension.st index 8a5bd2e..c65cd20 100644 --- a/src/PythonBridge/Fraction.extension.st +++ b/src/PythonBridge/Fraction.extension.st @@ -1,11 +1,11 @@ -Extension { #name : #Fraction } - -{ #category : #'*PythonBridge' } -Fraction >> isPythonGenerable [ - ^ true -] - -{ #category : #'*PythonBridge' } -Fraction >> isPythonValue [ - ^ true -] +Extension { #name : #Fraction } + +{ #category : #'*PythonBridge' } +Fraction >> isPythonGenerable [ + ^ true +] + +{ #category : #'*PythonBridge' } +Fraction >> isPythonValue [ + ^ true +] diff --git a/src/PythonBridge/Integer.extension.st b/src/PythonBridge/Integer.extension.st index aa63e8f..6788f37 100644 --- a/src/PythonBridge/Integer.extension.st +++ b/src/PythonBridge/Integer.extension.st @@ -1,11 +1,11 @@ -Extension { #name : #Integer } - -{ #category : #'*PythonBridge' } -Integer >> isPythonGenerable [ - ^ true -] - -{ #category : #'*PythonBridge' } -Integer >> isPythonValue [ - ^ true -] +Extension { #name : #Integer } + +{ #category : #'*PythonBridge' } +Integer >> isPythonGenerable [ + ^ true +] + +{ #category : #'*PythonBridge' } +Integer >> isPythonValue [ + ^ true +] diff --git a/src/PythonBridge/Object.extension.st b/src/PythonBridge/Object.extension.st index 400f956..3a4278b 100644 --- a/src/PythonBridge/Object.extension.st +++ b/src/PythonBridge/Object.extension.st @@ -1,6 +1,6 @@ -Extension { #name : #Object } - -{ #category : #'*PythonBridge' } -Object >> isPythonGenerable [ - ^ false -] +Extension { #name : #Object } + +{ #category : #'*PythonBridge' } +Object >> isPythonGenerable [ + ^ false +] diff --git a/src/PythonBridge/P3GGenerable.extension.st b/src/PythonBridge/P3GGenerable.extension.st index 879a751..6ab5e55 100644 --- a/src/PythonBridge/P3GGenerable.extension.st +++ b/src/PythonBridge/P3GGenerable.extension.st @@ -1,11 +1,11 @@ -Extension { #name : #P3GGenerable } - -{ #category : #'*PythonBridge' } -P3GGenerable >> isPythonGenerable [ - ^ true -] - -{ #category : #'*PythonBridge' } -P3GGenerable >> isPythonValue [ - ^ true -] +Extension { #name : #P3GGenerable } + +{ #category : #'*PythonBridge' } +P3GGenerable >> isPythonGenerable [ + ^ true +] + +{ #category : #'*PythonBridge' } +P3GGenerable >> isPythonValue [ + ^ true +] diff --git a/src/PythonBridge/P3GStatement.extension.st b/src/PythonBridge/P3GStatement.extension.st index 2b8427a..4ee756e 100644 --- a/src/PythonBridge/P3GStatement.extension.st +++ b/src/PythonBridge/P3GStatement.extension.st @@ -1,6 +1,6 @@ -Extension { #name : #P3GStatement } - -{ #category : #'*PythonBridge' } -P3GStatement >> isPythonValue [ - ^ false -] +Extension { #name : #P3GStatement } + +{ #category : #'*PythonBridge' } +P3GStatement >> isPythonValue [ + ^ false +] diff --git a/src/PythonBridge/PBAbstractAnswer.class.st b/src/PythonBridge/PBAbstractAnswer.class.st index 7d2e04d..492dd7b 100644 --- a/src/PythonBridge/PBAbstractAnswer.class.st +++ b/src/PythonBridge/PBAbstractAnswer.class.st @@ -1,30 +1,30 @@ -Class { - #name : #PBAbstractAnswer, - #superclass : #Object, - #instVars : [ - 'message' - ], - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #'instance creation' } -PBAbstractAnswer class >> answerFor: aMessage [ - ^ self new - message: aMessage; - yourself -] - -{ #category : #accessing } -PBAbstractAnswer >> message [ - ^ message -] - -{ #category : #accessing } -PBAbstractAnswer >> message: anObject [ - message := anObject -] - -{ #category : #accessing } -PBAbstractAnswer >> type [ - ^ message type -] +Class { + #name : #PBAbstractAnswer, + #superclass : #Object, + #instVars : [ + 'message' + ], + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #'instance creation' } +PBAbstractAnswer class >> answerFor: aMessage [ + ^ self new + message: aMessage; + yourself +] + +{ #category : #accessing } +PBAbstractAnswer >> message [ + ^ message +] + +{ #category : #accessing } +PBAbstractAnswer >> message: anObject [ + message := anObject +] + +{ #category : #accessing } +PBAbstractAnswer >> type [ + ^ message type +] diff --git a/src/PythonBridge/PBAbstractFinalizer.class.st b/src/PythonBridge/PBAbstractFinalizer.class.st index 2919de7..bc6dc5f 100644 --- a/src/PythonBridge/PBAbstractFinalizer.class.st +++ b/src/PythonBridge/PBAbstractFinalizer.class.st @@ -1,10 +1,10 @@ -Class { - #name : #PBAbstractFinalizer, - #superclass : #Object, - #category : #'PythonBridge-Platform' -} - -{ #category : #finalization } -PBAbstractFinalizer >> finalize [ - self subclassResponsibility -] +Class { + #name : #PBAbstractFinalizer, + #superclass : #Object, + #category : #'PythonBridge-Platform' +} + +{ #category : #finalization } +PBAbstractFinalizer >> finalize [ + self subclassResponsibility +] diff --git a/src/PythonBridge/PBAbstractMessage.class.st b/src/PythonBridge/PBAbstractMessage.class.st index eb86d88..b70d8ef 100644 --- a/src/PythonBridge/PBAbstractMessage.class.st +++ b/src/PythonBridge/PBAbstractMessage.class.st @@ -1,29 +1,29 @@ -Class { - #name : #PBAbstractMessage, - #superclass : #Object, - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #testing } -PBAbstractMessage class >> isReverseMessage [ - "Reverse messages corresponds to messages that start on Python to Pharo. In other words - in reverse direction from normal messages." - self subclassResponsibility -] - -{ #category : #accessing } -PBAbstractMessage class >> type [ - self subclassResponsibility -] - -{ #category : #testing } -PBAbstractMessage >> isReverseMessage [ - "Reverse messages corresponds to messages that start on Python to Pharo. In other words - in reverse direction from normal messages." - ^ self class isReverseMessage -] - -{ #category : #accessing } -PBAbstractMessage >> type [ - ^ self class type -] +Class { + #name : #PBAbstractMessage, + #superclass : #Object, + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #testing } +PBAbstractMessage class >> isReverseMessage [ + "Reverse messages corresponds to messages that start on Python to Pharo. In other words + in reverse direction from normal messages." + self subclassResponsibility +] + +{ #category : #accessing } +PBAbstractMessage class >> type [ + self subclassResponsibility +] + +{ #category : #testing } +PBAbstractMessage >> isReverseMessage [ + "Reverse messages corresponds to messages that start on Python to Pharo. In other words + in reverse direction from normal messages." + ^ self class isReverseMessage +] + +{ #category : #accessing } +PBAbstractMessage >> type [ + ^ self class type +] diff --git a/src/PythonBridge/PBAbstractMessageBroker.class.st b/src/PythonBridge/PBAbstractMessageBroker.class.st index 6848628..a571759 100644 --- a/src/PythonBridge/PBAbstractMessageBroker.class.st +++ b/src/PythonBridge/PBAbstractMessageBroker.class.st @@ -1,124 +1,124 @@ -Class { - #name : #PBAbstractMessageBroker, - #superclass : #Object, - #instVars : [ - 'debugMode', - 'messageCallbacks', - 'settings' - ], - #category : #'PythonBridge-Platform' -} - -{ #category : #accessing } -PBAbstractMessageBroker class >> pythonMethodArg [ - self subclassResponsibility -] - -{ #category : #accessing } -PBAbstractMessageBroker class >> serializer [ - ^ self serializerClass new -] - -{ #category : #accessing } -PBAbstractMessageBroker class >> serializerClass [ - self subclassResponsibility -] - -{ #category : #'as yet unclassified' } -PBAbstractMessageBroker class >> settings: settings [ - ^ self new - settings: settings; - yourself -] - -{ #category : #messaging } -PBAbstractMessageBroker >> addCallback: aBlock messageClass: messageClass [ - messageCallbacks at: messageClass put: aBlock -] - -{ #category : #private } -PBAbstractMessageBroker >> handle: dict reverseMessageClass: msgClass [ - | handler | - (messageCallbacks includesKey: msgClass) ifFalse: [ PBCommunicationError signal ]. - handler := PBMessageHandler - forMessage: (msgClass decodeFrom: dict) - callback: (messageCallbacks at: msgClass). - handler handleMessage. - ^ handler -] - -{ #category : #initialization } -PBAbstractMessageBroker >> initialize [ - super initialize. - messageCallbacks := Dictionary new. - debugMode := false -] - -{ #category : #testing } -PBAbstractMessageBroker >> isRunning [ - self subclassResponsibility -] - -{ #category : #accessing } -PBAbstractMessageBroker >> port [ - ^ settings pharoSocketAddress port -] - -{ #category : #accessing } -PBAbstractMessageBroker >> pythonUri [ - ^ 'http://' , settings pythonSocketAddress printAddress -] - -{ #category : #private } -PBAbstractMessageBroker >> resolveMessageFromType: aType [ - ^ PBAbstractMessage withAllSubclasses - detect: [ :cls | cls type = aType ] - ifNone: [ Error signal: 'Message ' , aType , ' not understood.' ]. -] - -{ #category : #messaging } -PBAbstractMessageBroker >> sendAsyncMessage: aMessage [ - self subclassResponsibility -] - -{ #category : #messaging } -PBAbstractMessageBroker >> sendMessage: aMessage [ - ^ aMessage isSync - ifTrue: [ self sendSyncMessage: aMessage ] - ifFalse: [ self sendAsyncMessage: aMessage ] -] - -{ #category : #messaging } -PBAbstractMessageBroker >> sendSyncMessage: aMessage [ - self subclassResponsibility -] - -{ #category : #accessing } -PBAbstractMessageBroker >> serializer [ - ^ self class serializer -] - -{ #category : #accessing } -PBAbstractMessageBroker >> setDebugMode [ - debugMode := true. -] - -{ #category : #accessing } -PBAbstractMessageBroker >> settings [ - ^ settings -] - -{ #category : #accessing } -PBAbstractMessageBroker >> settings: anObject [ - settings := anObject -] - -{ #category : #'start-stop' } -PBAbstractMessageBroker >> start [ - self subclassResponsibility -] - -{ #category : #'start-stop' } -PBAbstractMessageBroker >> stop [ - self subclassResponsibility -] +Class { + #name : #PBAbstractMessageBroker, + #superclass : #Object, + #instVars : [ + 'debugMode', + 'messageCallbacks', + 'settings' + ], + #category : #'PythonBridge-Platform' +} + +{ #category : #accessing } +PBAbstractMessageBroker class >> pythonMethodArg [ + self subclassResponsibility +] + +{ #category : #accessing } +PBAbstractMessageBroker class >> serializer [ + ^ self serializerClass new +] + +{ #category : #accessing } +PBAbstractMessageBroker class >> serializerClass [ + self subclassResponsibility +] + +{ #category : #'as yet unclassified' } +PBAbstractMessageBroker class >> settings: settings [ + ^ self new + settings: settings; + yourself +] + +{ #category : #messaging } +PBAbstractMessageBroker >> addCallback: aBlock messageClass: messageClass [ + messageCallbacks at: messageClass put: aBlock +] + +{ #category : #private } +PBAbstractMessageBroker >> handle: dict reverseMessageClass: msgClass [ + | handler | + (messageCallbacks includesKey: msgClass) ifFalse: [ PBCommunicationError signal ]. + handler := PBMessageHandler + forMessage: (msgClass decodeFrom: dict) + callback: (messageCallbacks at: msgClass). + handler handleMessage. + ^ handler +] + +{ #category : #initialization } +PBAbstractMessageBroker >> initialize [ + super initialize. + messageCallbacks := Dictionary new. + debugMode := false +] + +{ #category : #testing } +PBAbstractMessageBroker >> isRunning [ + self subclassResponsibility +] + +{ #category : #accessing } +PBAbstractMessageBroker >> port [ + ^ settings pharoSocketAddress port +] + +{ #category : #accessing } +PBAbstractMessageBroker >> pythonUri [ + ^ 'http://' , settings pythonSocketAddress printAddress +] + +{ #category : #private } +PBAbstractMessageBroker >> resolveMessageFromType: aType [ + ^ PBAbstractMessage allSubclasses + detect: [ :cls | cls type = aType ] + ifNone: [ Error signal: 'Message ' , aType , ' not understood.' ]. +] + +{ #category : #messaging } +PBAbstractMessageBroker >> sendAsyncMessage: aMessage [ + self subclassResponsibility +] + +{ #category : #messaging } +PBAbstractMessageBroker >> sendMessage: aMessage [ + ^ aMessage isSync + ifTrue: [ self sendSyncMessage: aMessage ] + ifFalse: [ self sendAsyncMessage: aMessage ] +] + +{ #category : #messaging } +PBAbstractMessageBroker >> sendSyncMessage: aMessage [ + self subclassResponsibility +] + +{ #category : #accessing } +PBAbstractMessageBroker >> serializer [ + ^ self class serializer +] + +{ #category : #accessing } +PBAbstractMessageBroker >> setDebugMode [ + debugMode := true. +] + +{ #category : #accessing } +PBAbstractMessageBroker >> settings [ + ^ settings +] + +{ #category : #accessing } +PBAbstractMessageBroker >> settings: anObject [ + settings := anObject +] + +{ #category : #'start-stop' } +PBAbstractMessageBroker >> start [ + self subclassResponsibility +] + +{ #category : #'start-stop' } +PBAbstractMessageBroker >> stop [ + self subclassResponsibility +] diff --git a/src/PythonBridge/PBAbstractProcess.class.st b/src/PythonBridge/PBAbstractProcess.class.st index 8066e27..d9be73b 100644 --- a/src/PythonBridge/PBAbstractProcess.class.st +++ b/src/PythonBridge/PBAbstractProcess.class.st @@ -1,119 +1,119 @@ -Class { - #name : #PBAbstractProcess, - #superclass : #Object, - #instVars : [ - 'pythonMainFile', - 'debugMode', - 'settings', - 'workingDirectory' - ], - #category : #'PythonBridge-Platform' -} - -{ #category : #accessing } -PBAbstractProcess class >> application: application [ - ^ self - settings: application settings - application: application -] - -{ #category : #accessing } -PBAbstractProcess class >> platform [ - self subclassResponsibility -] - -{ #category : #accessing } -PBAbstractProcess class >> settings: settings application: application [ - ^ self - settings: settings - workingDirectory: (PBPlatform current folderForApplication: application) - debugMode: application class debugMode -] - -{ #category : #accessing } -PBAbstractProcess class >> settings: settings workingDirectory: fileRef [ - ^ self new - settings: settings; - workingDirectory: fileRef; - yourself -] - -{ #category : #accessing } -PBAbstractProcess class >> settings: settings workingDirectory: fileRef debugMode: flag [ - ^ self new - settings: settings; - workingDirectory: fileRef; - debugMode: flag; - yourself -] - -{ #category : #hooks } -PBAbstractProcess class >> workingDirectory [ - ^ self platform folderForApplication: PBApplication -] - -{ #category : #accessing } -PBAbstractProcess >> debugMode [ - ^ debugMode -] - -{ #category : #accessing } -PBAbstractProcess >> debugMode: anObject [ - debugMode := anObject -] - -{ #category : #accessing } -PBAbstractProcess >> errorMessage [ - self subclassResponsibility -] - -{ #category : #initialization } -PBAbstractProcess >> initialize [ - super initialize. - debugMode := false -] - -{ #category : #testing } -PBAbstractProcess >> isRunning [ - self subclassResponsibility -] - -{ #category : #accessing } -PBAbstractProcess >> pythonMainFile [ - ^ pythonMainFile ifNil: [ self workingDirectory / 'start_bridge.py' ] -] - -{ #category : #accessing } -PBAbstractProcess >> pythonMainFile: anObject [ - pythonMainFile := anObject -] - -{ #category : #accessing } -PBAbstractProcess >> settings [ - ^ settings -] - -{ #category : #accessing } -PBAbstractProcess >> settings: anObject [ - settings := anObject -] - -{ #category : #'start-stop' } -PBAbstractProcess >> start [ - self subclassResponsibility -] - -{ #category : #'start-stop' } -PBAbstractProcess >> stop [ - self subclassResponsibility -] - -{ #category : #accessing } -PBAbstractProcess >> workingDirectory [ - ^ workingDirectory -] - -{ #category : #accessing } -PBAbstractProcess >> workingDirectory: anObject [ - workingDirectory := anObject -] +Class { + #name : #PBAbstractProcess, + #superclass : #Object, + #instVars : [ + 'pythonMainFile', + 'debugMode', + 'settings', + 'workingDirectory' + ], + #category : #'PythonBridge-Platform' +} + +{ #category : #accessing } +PBAbstractProcess class >> application: application [ + ^ self + settings: application settings + application: application +] + +{ #category : #accessing } +PBAbstractProcess class >> platform [ + self subclassResponsibility +] + +{ #category : #accessing } +PBAbstractProcess class >> settings: settings application: application [ + ^ self + settings: settings + workingDirectory: (PBPlatform current folderForApplication: application) + debugMode: application class debugMode +] + +{ #category : #accessing } +PBAbstractProcess class >> settings: settings workingDirectory: fileRef [ + ^ self new + settings: settings; + workingDirectory: fileRef; + yourself +] + +{ #category : #accessing } +PBAbstractProcess class >> settings: settings workingDirectory: fileRef debugMode: flag [ + ^ self new + settings: settings; + workingDirectory: fileRef; + debugMode: flag; + yourself +] + +{ #category : #hooks } +PBAbstractProcess class >> workingDirectory [ + ^ self platform folderForApplication: PBApplication +] + +{ #category : #accessing } +PBAbstractProcess >> debugMode [ + ^ debugMode +] + +{ #category : #accessing } +PBAbstractProcess >> debugMode: anObject [ + debugMode := anObject +] + +{ #category : #accessing } +PBAbstractProcess >> errorMessage [ + self subclassResponsibility +] + +{ #category : #initialization } +PBAbstractProcess >> initialize [ + super initialize. + debugMode := false +] + +{ #category : #testing } +PBAbstractProcess >> isRunning [ + self subclassResponsibility +] + +{ #category : #accessing } +PBAbstractProcess >> pythonMainFile [ + ^ pythonMainFile ifNil: [ self workingDirectory / 'start_bridge.py' ] +] + +{ #category : #accessing } +PBAbstractProcess >> pythonMainFile: anObject [ + pythonMainFile := anObject +] + +{ #category : #accessing } +PBAbstractProcess >> settings [ + ^ settings +] + +{ #category : #accessing } +PBAbstractProcess >> settings: anObject [ + settings := anObject +] + +{ #category : #'start-stop' } +PBAbstractProcess >> start [ + self subclassResponsibility +] + +{ #category : #'start-stop' } +PBAbstractProcess >> stop [ + self subclassResponsibility +] + +{ #category : #accessing } +PBAbstractProcess >> workingDirectory [ + ^ workingDirectory +] + +{ #category : #accessing } +PBAbstractProcess >> workingDirectory: anObject [ + workingDirectory := anObject +] diff --git a/src/PythonBridge/PBAbstractSerializerWrapper.class.st b/src/PythonBridge/PBAbstractSerializerWrapper.class.st index dcd4d8e..cf1c71e 100644 --- a/src/PythonBridge/PBAbstractSerializerWrapper.class.st +++ b/src/PythonBridge/PBAbstractSerializerWrapper.class.st @@ -1,15 +1,15 @@ -Class { - #name : #PBAbstractSerializerWrapper, - #superclass : #Object, - #category : #'PythonBridge-Platform' -} - -{ #category : #private } -PBAbstractSerializerWrapper >> deserialize: aString [ - self subclassResponsibility -] - -{ #category : #private } -PBAbstractSerializerWrapper >> serialize: anObject [ - self subclassResponsibility -] +Class { + #name : #PBAbstractSerializerWrapper, + #superclass : #Object, + #category : #'PythonBridge-Platform' +} + +{ #category : #private } +PBAbstractSerializerWrapper >> deserialize: aString [ + self subclassResponsibility +] + +{ #category : #private } +PBAbstractSerializerWrapper >> serialize: anObject [ + self subclassResponsibility +] diff --git a/src/PythonBridge/PBAbstractWeakRegistry.class.st b/src/PythonBridge/PBAbstractWeakRegistry.class.st index 92691e2..7ec8cc8 100644 --- a/src/PythonBridge/PBAbstractWeakRegistry.class.st +++ b/src/PythonBridge/PBAbstractWeakRegistry.class.st @@ -1,15 +1,15 @@ -Class { - #name : #PBAbstractWeakRegistry, - #superclass : #Object, - #category : #'PythonBridge-Platform' -} - -{ #category : #'as yet unclassified' } -PBAbstractWeakRegistry >> destroy [ - self subclassResponsibility -] - -{ #category : #'as yet unclassified' } -PBAbstractWeakRegistry >> registerObject: anObject finalizer: finalizer [ - self subclassResponsibility -] +Class { + #name : #PBAbstractWeakRegistry, + #superclass : #Object, + #category : #'PythonBridge-Platform' +} + +{ #category : #'as yet unclassified' } +PBAbstractWeakRegistry >> destroy [ + self subclassResponsibility +] + +{ #category : #'as yet unclassified' } +PBAbstractWeakRegistry >> registerObject: anObject finalizer: finalizer [ + self subclassResponsibility +] diff --git a/src/PythonBridge/PBAnswer.class.st b/src/PythonBridge/PBAnswer.class.st index f202b88..fa3e2a7 100644 --- a/src/PythonBridge/PBAnswer.class.st +++ b/src/PythonBridge/PBAnswer.class.st @@ -1,9 +1,9 @@ -Class { - #name : #PBAnswer, - #superclass : #PBAbstractAnswer, - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #converting } -PBAnswer >> decode: dict [ -] +Class { + #name : #PBAnswer, + #superclass : #PBAbstractAnswer, + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #converting } +PBAnswer >> decode: dict [ +] diff --git a/src/PythonBridge/PBApplication.class.st b/src/PythonBridge/PBApplication.class.st index 2636e86..06a0113 100644 --- a/src/PythonBridge/PBApplication.class.st +++ b/src/PythonBridge/PBApplication.class.st @@ -1,261 +1,261 @@ -Class { - #name : #PBApplication, - #superclass : #Object, - #instVars : [ - 'communicationHandler', - 'processHandler', - 'loggingHandler', - 'executionHandler', - 'settings' - ], - #classVars : [ - 'DebugMode' - ], - #classInstVars : [ - 'uniqueInstance' - ], - #category : #'PythonBridge-Global' -} - -{ #category : #accessing } -PBApplication class >> baseApplication [ - ^ PBApplication -] - -{ #category : #debug } -PBApplication class >> debugMode [ - ^ DebugMode ifNil: [ false ] -] - -{ #category : #debug } -PBApplication class >> debugMode: bool [ - ^ DebugMode := bool -] - -{ #category : #'start-stop' } -PBApplication class >> do: aBlockClosure [ - | retVal | - self isRunning ifTrue: [ ^ aBlockClosure value ]. - [ - self start. - retVal := aBlockClosure cull: self uniqueInstance. - self uniqueInstance commandFactory << nil. - self uniqueInstance commandFactory send waitForValue. ] ensure: [ self stop ]. - ^ retVal -] - -{ #category : #testing } -PBApplication class >> isRunning [ - ^ uniqueInstance notNil and: [ uniqueInstance isRunning ] -] - -{ #category : #testing } -PBApplication class >> module [ - ^ self uniqueInstance module -] - -{ #category : #'pipenv setup' } -PBApplication class >> platform [ - ^ PBPlatform current -] - -{ #category : #'python hooks file' } -PBApplication class >> repositoryFileReference [ - ^ self platform folderForApplication: self -] - -{ #category : #instructions } -PBApplication class >> resetUniqueInstance [ - uniqueInstance ifNotNil: [ - [ uniqueInstance stop ] - on: Error - do: [ PBPlatform current uiManager inform: 'Error on reseting unique instance.' ]. ]. - uniqueInstance := nil -] - -{ #category : #instructions } -PBApplication class >> send: obj [ - self assert: self isRunning. - ^ self uniqueInstance send: obj -] - -{ #category : #'start-stop' } -PBApplication class >> start [ - self isRunning ifTrue: [ Error signal: 'Keras already running.' ]. - self stop. - uniqueInstance := self new. - uniqueInstance commandFactory reset. - uniqueInstance start -] - -{ #category : #'start-stop' } -PBApplication class >> stop [ - uniqueInstance ifNotNil: [ - uniqueInstance stop. ]. - uniqueInstance := nil -] - -{ #category : #testing } -PBApplication class >> test [ - self assert: (self do: [ :app | - app commandFactory << (P3GBinaryOperator new - left: 1; - right: 2; - operator: $+; - yourself). - app commandFactory send waitForValue - ]) = 3 -] - -{ #category : #instructions } -PBApplication class >> uniqueInstance [ - ^ uniqueInstance -] - -{ #category : #accessing } -PBApplication class >> uniqueInstance: anObject [ - uniqueInstance := anObject -] - -{ #category : #utils } -PBApplication >> addMapping: pythonType to: pythonFunction [ - self commandFactory - send: (#bridge_globals asP3GI => #msg_service => #addMapping - callWith: (Array with: pythonType with: pythonFunction)) -] - -{ #category : #accessing } -PBApplication >> commandFactory [ - ^ PBCF -] - -{ #category : #accessing } -PBApplication >> communicationHandler [ - ^ communicationHandler -] - -{ #category : #accessing } -PBApplication >> errorMessage [ - "Fetch the error message from the stderr stream, from the processhander" - ^ processHandler errorMessage -] - -{ #category : #accessing } -PBApplication >> executionHandler [ - ^ executionHandler -] - -{ #category : #handlers } -PBApplication >> handlers [ - ^ Array - with: loggingHandler - with: communicationHandler - with: processHandler - with: executionHandler -] - -{ #category : #initialization } -PBApplication >> initialize [ - super initialize. - settings := PBPlatform current defaultSettings. - self initializeHandlers. -] - -{ #category : #initialization } -PBApplication >> initializeHandlers [ - loggingHandler := PBLoggingHandler application: self. - communicationHandler := PBCommunicationHandler application: self. - processHandler := PBPythonHandler application: self. - executionHandler := PBExecutionHandler application: self -] - -{ #category : #testing } -PBApplication >> isPythonReady [ - "Ensures python webserver is ready for receiving commands" - ^ self communicationHandler isPythonReady -] - -{ #category : #testing } -PBApplication >> isRunning [ - ^ self handlers allSatisfy: #isRunning -] - -{ #category : #logging } -PBApplication >> log: aLog [ - self loggingHandler log: aLog -] - -{ #category : #accessing } -PBApplication >> loggingHandler [ - ^ loggingHandler -] - -{ #category : #accessing } -PBApplication >> module [ - self subclassResponsibility -] - -{ #category : #'instance creation' } -PBApplication >> newCommandFactory [ - ^ self executionHandler newCommandFactory -] - -{ #category : #accessing } -PBApplication >> postInitialization [ - -] - -{ #category : #accessing } -PBApplication >> processHandler [ - ^ processHandler -] - -{ #category : #'as yet unclassified' } -PBApplication >> registerObject: aPythonObject [ - self executionHandler registerObject: aPythonObject -] - -{ #category : #instructions } -PBApplication >> send: aCommand [ - self isRunning ifFalse: [ Error signal: 'Bridge not running.' ]. - ^ executionHandler sendCommand: aCommand -] - -{ #category : #accessing } -PBApplication >> settings [ - ^ settings -] - -{ #category : #accessing } -PBApplication >> settings: anObject [ - settings := anObject -] - -{ #category : #accessing } -PBApplication >> start [ - self handlers do: #start. - self commandFactory reset. - self waitInitialization. - self postInitialization. - self commandFactory send. -] - -{ #category : #'as yet unclassified' } -PBApplication >> stop [ - self handlers select: #notNil thenDo: #stop -] - -{ #category : #'as yet unclassified' } -PBApplication >> waitInitialization [ - "Timeout of 10 seconds and try every 0.5 seconds" - 1 to: 10 by: 0.5 do: [ :t | - self isPythonReady - ifTrue: [ ^ self ] - ifFalse: [ (Delay forMilliseconds: 500) wait ] ]. - Error signal: 'Python application initialization failed!' - " - Print the result of executing the following line: - - self errorMessage - " -] +Class { + #name : #PBApplication, + #superclass : #Object, + #instVars : [ + 'communicationHandler', + 'processHandler', + 'loggingHandler', + 'executionHandler', + 'settings' + ], + #classVars : [ + 'DebugMode' + ], + #classInstVars : [ + 'uniqueInstance' + ], + #category : #'PythonBridge-Global' +} + +{ #category : #accessing } +PBApplication class >> baseApplication [ + ^ PBApplication +] + +{ #category : #debug } +PBApplication class >> debugMode [ + ^ DebugMode ifNil: [ false ] +] + +{ #category : #debug } +PBApplication class >> debugMode: bool [ + ^ DebugMode := bool +] + +{ #category : #'start-stop' } +PBApplication class >> do: aBlockClosure [ + | retVal | + self isRunning ifTrue: [ ^ aBlockClosure value ]. + [ + self start. + retVal := aBlockClosure cull: self uniqueInstance. + self uniqueInstance commandFactory << nil. + self uniqueInstance commandFactory send waitForValue. ] ensure: [ self stop ]. + ^ retVal +] + +{ #category : #testing } +PBApplication class >> isRunning [ + ^ uniqueInstance notNil and: [ uniqueInstance isRunning ] +] + +{ #category : #testing } +PBApplication class >> module [ + ^ self uniqueInstance module +] + +{ #category : #'pipenv setup' } +PBApplication class >> platform [ + ^ PBPlatform current +] + +{ #category : #'python hooks file' } +PBApplication class >> repositoryFileReference [ + ^ self platform folderForApplication: self +] + +{ #category : #instructions } +PBApplication class >> resetUniqueInstance [ + uniqueInstance ifNotNil: [ + [ uniqueInstance stop ] + on: Error + do: [ PBPlatform current uiManager inform: 'Error on reseting unique instance.' ]. ]. + uniqueInstance := nil +] + +{ #category : #instructions } +PBApplication class >> send: obj [ + self assert: self isRunning. + ^ self uniqueInstance send: obj +] + +{ #category : #'start-stop' } +PBApplication class >> start [ + self isRunning ifTrue: [ Error signal: 'Keras already running.' ]. + self stop. + uniqueInstance := self new. + uniqueInstance commandFactory reset. + uniqueInstance start +] + +{ #category : #'start-stop' } +PBApplication class >> stop [ + uniqueInstance ifNotNil: [ + uniqueInstance stop. ]. + uniqueInstance := nil +] + +{ #category : #testing } +PBApplication class >> test [ + self assert: (self do: [ :app | + app commandFactory << (P3GBinaryOperator new + left: 1; + right: 2; + operator: $+; + yourself). + app commandFactory send waitForValue + ]) = 3 +] + +{ #category : #instructions } +PBApplication class >> uniqueInstance [ + ^ uniqueInstance +] + +{ #category : #accessing } +PBApplication class >> uniqueInstance: anObject [ + uniqueInstance := anObject +] + +{ #category : #utils } +PBApplication >> addMapping: pythonType to: pythonFunction [ + self commandFactory + send: (#bridge_globals asP3GI => #msg_service => #addMapping + callWith: (Array with: pythonType with: pythonFunction)) +] + +{ #category : #accessing } +PBApplication >> commandFactory [ + ^ PBCF +] + +{ #category : #accessing } +PBApplication >> communicationHandler [ + ^ communicationHandler +] + +{ #category : #accessing } +PBApplication >> errorMessage [ + "Fetch the error message from the stderr stream, from the processhander" + ^ processHandler errorMessage +] + +{ #category : #accessing } +PBApplication >> executionHandler [ + ^ executionHandler +] + +{ #category : #handlers } +PBApplication >> handlers [ + ^ Array + with: loggingHandler + with: communicationHandler + with: processHandler + with: executionHandler +] + +{ #category : #initialization } +PBApplication >> initialize [ + super initialize. + settings := PBPlatform current defaultSettings. + self initializeHandlers. +] + +{ #category : #initialization } +PBApplication >> initializeHandlers [ + loggingHandler := PBLoggingHandler application: self. + communicationHandler := PBCommunicationHandler application: self. + processHandler := PBPythonHandler application: self. + executionHandler := PBExecutionHandler application: self +] + +{ #category : #testing } +PBApplication >> isPythonReady [ + "Ensures python webserver is ready for receiving commands" + ^ self communicationHandler isPythonReady +] + +{ #category : #testing } +PBApplication >> isRunning [ + ^ self handlers allSatisfy: #isRunning +] + +{ #category : #logging } +PBApplication >> log: aLog [ + self loggingHandler log: aLog +] + +{ #category : #accessing } +PBApplication >> loggingHandler [ + ^ loggingHandler +] + +{ #category : #accessing } +PBApplication >> module [ + self subclassResponsibility +] + +{ #category : #'instance creation' } +PBApplication >> newCommandFactory [ + ^ self executionHandler newCommandFactory +] + +{ #category : #accessing } +PBApplication >> postInitialization [ + +] + +{ #category : #accessing } +PBApplication >> processHandler [ + ^ processHandler +] + +{ #category : #'as yet unclassified' } +PBApplication >> registerObject: aPythonObject [ + self executionHandler registerObject: aPythonObject +] + +{ #category : #instructions } +PBApplication >> send: aCommand [ + self isRunning ifFalse: [ Error signal: 'Bridge not running.' ]. + ^ executionHandler sendCommand: aCommand +] + +{ #category : #accessing } +PBApplication >> settings [ + ^ settings +] + +{ #category : #accessing } +PBApplication >> settings: anObject [ + settings := anObject +] + +{ #category : #accessing } +PBApplication >> start [ + self handlers do: #start. + self commandFactory reset. + self waitInitialization. + self postInitialization. + self commandFactory send. +] + +{ #category : #'as yet unclassified' } +PBApplication >> stop [ + self handlers select: #notNil thenDo: #stop +] + +{ #category : #'as yet unclassified' } +PBApplication >> waitInitialization [ + "Timeout of 10 seconds and try every 0.5 seconds" + 1 to: 10 by: 0.5 do: [ :t | + self isPythonReady + ifTrue: [ ^ self ] + ifFalse: [ (Delay forMilliseconds: 500) wait ] ]. + Error signal: 'Python application initialization failed!' + " + Print the result of executing the following line: + + self errorMessage + " +] diff --git a/src/PythonBridge/PBApplicationTest.class.st b/src/PythonBridge/PBApplicationTest.class.st index 1ef4584..2dfe826 100644 --- a/src/PythonBridge/PBApplicationTest.class.st +++ b/src/PythonBridge/PBApplicationTest.class.st @@ -1,15 +1,15 @@ -Class { - #name : #PBApplicationTest, - #superclass : #PBTestCase, - #category : #'PythonBridge-Tests' -} - -{ #category : #accessing } -PBApplicationTest class >> appResource [ - ^ PBApplicationTestResource -] - -{ #category : #initialization } -PBApplicationTest >> applicationClass [ - ^ PBApplication -] +Class { + #name : #PBApplicationTest, + #superclass : #PBTestCase, + #category : #'PythonBridge-Tests' +} + +{ #category : #accessing } +PBApplicationTest class >> appResource [ + ^ PBApplicationTestResource +] + +{ #category : #initialization } +PBApplicationTest >> applicationClass [ + ^ PBApplication +] diff --git a/src/PythonBridge/PBApplicationTestResource.class.st b/src/PythonBridge/PBApplicationTestResource.class.st index fab5c19..c22f9f2 100644 --- a/src/PythonBridge/PBApplicationTestResource.class.st +++ b/src/PythonBridge/PBApplicationTestResource.class.st @@ -1,37 +1,37 @@ -Class { - #name : #PBApplicationTestResource, - #superclass : #TestResource, - #instVars : [ - 'application' - ], - #category : #'PythonBridge-Tests' -} - -{ #category : #initialization } -PBApplicationTestResource >> app [ - ^ self application -] - -{ #category : #initialization } -PBApplicationTestResource >> application [ - ^ application -] - -{ #category : #initialization } -PBApplicationTestResource >> applicationClass [ - ^ PBApplication -] - -{ #category : #initialization } -PBApplicationTestResource >> setUp [ - super setUp. - self applicationClass stop. - self applicationClass start. - application := self applicationClass uniqueInstance -] - -{ #category : #initialization } -PBApplicationTestResource >> tearDown [ - self applicationClass stop. - super tearDown. -] +Class { + #name : #PBApplicationTestResource, + #superclass : #TestResource, + #instVars : [ + 'application' + ], + #category : #'PythonBridge-Tests' +} + +{ #category : #initialization } +PBApplicationTestResource >> app [ + ^ self application +] + +{ #category : #initialization } +PBApplicationTestResource >> application [ + ^ application +] + +{ #category : #initialization } +PBApplicationTestResource >> applicationClass [ + ^ PBApplication +] + +{ #category : #initialization } +PBApplicationTestResource >> setUp [ + super setUp. + self applicationClass stop. + self applicationClass start. + application := self applicationClass uniqueInstance +] + +{ #category : #initialization } +PBApplicationTestResource >> tearDown [ + self applicationClass stop. + super tearDown. +] diff --git a/src/PythonBridge/PBAsyncMessage.class.st b/src/PythonBridge/PBAsyncMessage.class.st index ccf18f6..56fc828 100644 --- a/src/PythonBridge/PBAsyncMessage.class.st +++ b/src/PythonBridge/PBAsyncMessage.class.st @@ -1,15 +1,15 @@ -Class { - #name : #PBAsyncMessage, - #superclass : #PBMessage, - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #accessing } -PBAsyncMessage class >> type [ - ^ #ASYNC -] - -{ #category : #testing } -PBAsyncMessage >> isSync [ - ^ false -] +Class { + #name : #PBAsyncMessage, + #superclass : #PBMessage, + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #accessing } +PBAsyncMessage class >> type [ + ^ #ASYNC +] + +{ #category : #testing } +PBAsyncMessage >> isSync [ + ^ false +] diff --git a/src/PythonBridge/PBAsyncMessageHandler.class.st b/src/PythonBridge/PBAsyncMessageHandler.class.st index 69ace7c..985d4e0 100644 --- a/src/PythonBridge/PBAsyncMessageHandler.class.st +++ b/src/PythonBridge/PBAsyncMessageHandler.class.st @@ -1,5 +1,5 @@ -Class { - #name : #PBAsyncMessageHandler, - #superclass : #PBMessageHandler, - #category : #'PythonBridge-Platform' -} +Class { + #name : #PBAsyncMessageHandler, + #superclass : #PBMessageHandler, + #category : #'PythonBridge-Platform' +} diff --git a/src/PythonBridge/PBBinding.class.st b/src/PythonBridge/PBBinding.class.st index 2efdcc1..7949243 100644 --- a/src/PythonBridge/PBBinding.class.st +++ b/src/PythonBridge/PBBinding.class.st @@ -1,70 +1,70 @@ -Class { - #name : #PBBinding, - #superclass : #Object, - #instVars : [ - 'object', - 'key' - ], - #category : #'PythonBridge-Execution' -} - -{ #category : #'instance creation' } -PBBinding class >> key: aKey wrap: anObject [ - ^ self new - key: aKey; - object: anObject; - yourself -] - -{ #category : #'instance creation' } -PBBinding class >> wrap: anObject [ - ^ self new - object: anObject; - yourself -] - -{ #category : #initialization } -PBBinding >> initialize [ - super initialize. - key := PBUtils newP3VariableName -] - -{ #category : #testing } -PBBinding >> isPythonGenerable [ - ^ true -] - -{ #category : #testing } -PBBinding >> isPythonValue [ - ^ true -] - -{ #category : #accessing } -PBBinding >> key [ - ^ key -] - -{ #category : #accessing } -PBBinding >> key: anObject [ - key := anObject -] - -{ #category : #accessing } -PBBinding >> object [ - ^ object -] - -{ #category : #accessing } -PBBinding >> object: anObject [ - object := anObject -] - -{ #category : #'instance creation' } -PBBinding >> pythonVariable [ - ^ key asP3GI -] - -{ #category : #testing } -PBBinding >> writePython3On: aStream [ - self pythonVariable writePython3On: aStream -] +Class { + #name : #PBBinding, + #superclass : #Object, + #instVars : [ + 'object', + 'key' + ], + #category : #'PythonBridge-Execution' +} + +{ #category : #'instance creation' } +PBBinding class >> key: aKey wrap: anObject [ + ^ self new + key: aKey; + object: anObject; + yourself +] + +{ #category : #'instance creation' } +PBBinding class >> wrap: anObject [ + ^ self new + object: anObject; + yourself +] + +{ #category : #initialization } +PBBinding >> initialize [ + super initialize. + key := PBUtils newP3VariableName +] + +{ #category : #testing } +PBBinding >> isPythonGenerable [ + ^ true +] + +{ #category : #testing } +PBBinding >> isPythonValue [ + ^ true +] + +{ #category : #accessing } +PBBinding >> key [ + ^ key +] + +{ #category : #accessing } +PBBinding >> key: anObject [ + key := anObject +] + +{ #category : #accessing } +PBBinding >> object [ + ^ object +] + +{ #category : #accessing } +PBBinding >> object: anObject [ + object := anObject +] + +{ #category : #'instance creation' } +PBBinding >> pythonVariable [ + ^ key asP3GI +] + +{ #category : #testing } +PBBinding >> writePython3On: aStream [ + self pythonVariable writePython3On: aStream +] diff --git a/src/PythonBridge/PBBlockFinalizer.class.st b/src/PythonBridge/PBBlockFinalizer.class.st index f479902..d87dbcf 100644 --- a/src/PythonBridge/PBBlockFinalizer.class.st +++ b/src/PythonBridge/PBBlockFinalizer.class.st @@ -1,30 +1,30 @@ -Class { - #name : #PBBlockFinalizer, - #superclass : #PBAbstractFinalizer, - #instVars : [ - 'block' - ], - #category : #'PythonBridge-Platform' -} - -{ #category : #accessing } -PBBlockFinalizer class >> block: aBlock [ - ^ self new - block: aBlock; - yourself -] - -{ #category : #accessing } -PBBlockFinalizer >> block [ - ^ block -] - -{ #category : #accessing } -PBBlockFinalizer >> block: anObject [ - block := anObject -] - -{ #category : #finalization } -PBBlockFinalizer >> finalize [ - ^ block value -] +Class { + #name : #PBBlockFinalizer, + #superclass : #PBAbstractFinalizer, + #instVars : [ + 'block' + ], + #category : #'PythonBridge-Platform' +} + +{ #category : #accessing } +PBBlockFinalizer class >> block: aBlock [ + ^ self new + block: aBlock; + yourself +] + +{ #category : #accessing } +PBBlockFinalizer >> block [ + ^ block +] + +{ #category : #accessing } +PBBlockFinalizer >> block: anObject [ + block := anObject +] + +{ #category : #finalization } +PBBlockFinalizer >> finalize [ + ^ block value +] diff --git a/src/PythonBridge/PBCF.class.st b/src/PythonBridge/PBCF.class.st index 473df56..b581352 100644 --- a/src/PythonBridge/PBCF.class.st +++ b/src/PythonBridge/PBCF.class.st @@ -1,112 +1,112 @@ -Class { - #name : #PBCF, - #superclass : #Object, - #classInstVars : [ - 'current' - ], - #category : #'PythonBridge-Global' -} - -{ #category : #'as yet unclassified' } -PBCF class >> << aPythonStatement [ - ^ self current << aPythonStatement -] - -{ #category : #'as yet unclassified' } -PBCF class >> addBinding: aBinding [ - ^ self current addBinding: aBinding -] - -{ #category : #'as yet unclassified' } -PBCF class >> addObserver: anObserver [ - ^ self current addObserver: anObserver -] - -{ #category : #'as yet unclassified' } -PBCF class >> append: aPythonStatement [ - ^ self current append: aPythonStatement -] - -{ #category : #initialization } -PBCF class >> application [ - ^ self applicationClass uniqueInstance -] - -{ #category : #initialization } -PBCF class >> applicationClass [ - ^ PBApplication -] - -{ #category : #'as yet unclassified' } -PBCF class >> bindingAt: varName put: anObject [ - ^ self current bindingAt: varName put: anObject -] - -{ #category : #'as yet unclassified' } -PBCF class >> bindingWrap: anObject [ - ^ self current bindingWrap: anObject -] - -{ #category : #'as yet unclassified' } -PBCF class >> buildCommand [ - | command | - command := self current buildCommand. - self reset. - ^ command -] - -{ #category : #accessing } -PBCF class >> current [ - ^ current -] - -{ #category : #accessing } -PBCF class >> current: cf [ - current := cf -] - -{ #category : #'reflective operations' } -PBCF class >> doesNotUnderstand: aMessage [ - ^ aMessage sendTo: self current -] - -{ #category : #'instance creation' } -PBCF class >> newCommandFactory [ - ^ self application newCommandFactory -] - -{ #category : #'as yet unclassified' } -PBCF class >> observerFromCallback: aBlock [ - ^ self current observerFromCallback: aBlock -] - -{ #category : #accessing } -PBCF class >> reset [ - current := self newCommandFactory -] - -{ #category : #'old api' } -PBCF class >> send [ - ^ self application send: self buildCommand -] - -{ #category : #'old api' } -PBCF class >> send: aPythonStatement [ - self << aPythonStatement. - ^ self send -] - -{ #category : #'old api' } -PBCF class >> sendAndWait [ - ^ self send waitForValue -] - -{ #category : #'old api' } -PBCF class >> sendAndWait: aPythonStatement [ - ^ (self send: aPythonStatement) waitForValue -] - -{ #category : #'as yet unclassified' } -PBCF class >> transformBlock: aBlock [ - ^ self current transformBlock: aBlock -] +Class { + #name : #PBCF, + #superclass : #Object, + #classInstVars : [ + 'current' + ], + #category : #'PythonBridge-Global' +} + +{ #category : #'as yet unclassified' } +PBCF class >> << aPythonStatement [ + ^ self current << aPythonStatement +] + +{ #category : #'as yet unclassified' } +PBCF class >> addBinding: aBinding [ + ^ self current addBinding: aBinding +] + +{ #category : #'as yet unclassified' } +PBCF class >> addObserver: anObserver [ + ^ self current addObserver: anObserver +] + +{ #category : #'as yet unclassified' } +PBCF class >> append: aPythonStatement [ + ^ self current append: aPythonStatement +] + +{ #category : #initialization } +PBCF class >> application [ + ^ self applicationClass uniqueInstance +] + +{ #category : #initialization } +PBCF class >> applicationClass [ + ^ PBApplication +] + +{ #category : #'as yet unclassified' } +PBCF class >> bindingAt: varName put: anObject [ + ^ self current bindingAt: varName put: anObject +] + +{ #category : #'as yet unclassified' } +PBCF class >> bindingWrap: anObject [ + ^ self current bindingWrap: anObject +] + +{ #category : #'as yet unclassified' } +PBCF class >> buildCommand [ + | command | + command := self current buildCommand. + self reset. + ^ command +] + +{ #category : #accessing } +PBCF class >> current [ + ^ current +] + +{ #category : #accessing } +PBCF class >> current: cf [ + current := cf +] + +{ #category : #'reflective operations' } +PBCF class >> doesNotUnderstand: aMessage [ + ^ aMessage sendTo: self current +] + +{ #category : #'instance creation' } +PBCF class >> newCommandFactory [ + ^ self application newCommandFactory +] + +{ #category : #'as yet unclassified' } +PBCF class >> observerFromCallback: aBlock [ + ^ self current observerFromCallback: aBlock +] + +{ #category : #accessing } +PBCF class >> reset [ + current := self newCommandFactory +] + +{ #category : #'old api' } +PBCF class >> send [ + ^ self application send: self buildCommand +] + +{ #category : #'old api' } +PBCF class >> send: aPythonStatement [ + self << aPythonStatement. + ^ self send +] + +{ #category : #'old api' } +PBCF class >> sendAndWait [ + ^ self send waitForValue +] + +{ #category : #'old api' } +PBCF class >> sendAndWait: aPythonStatement [ + ^ (self send: aPythonStatement) waitForValue +] + +{ #category : #'as yet unclassified' } +PBCF class >> transformBlock: aBlock [ + ^ self current transformBlock: aBlock +] diff --git a/src/PythonBridge/PBCallbackAnswer.class.st b/src/PythonBridge/PBCallbackAnswer.class.st index 18bf9d0..04b57c8 100644 --- a/src/PythonBridge/PBCallbackAnswer.class.st +++ b/src/PythonBridge/PBCallbackAnswer.class.st @@ -1,24 +1,24 @@ -Class { - #name : #PBCallbackAnswer, - #superclass : #PBRAnswer, - #instVars : [ - 'value' - ], - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #encoding } -PBCallbackAnswer >> privateEncode: dict [ - super privateEncode: dict. - dict at: #value put: value -] - -{ #category : #accessing } -PBCallbackAnswer >> value [ - ^ value -] - -{ #category : #accessing } -PBCallbackAnswer >> value: anObject [ - value := anObject -] +Class { + #name : #PBCallbackAnswer, + #superclass : #PBRAnswer, + #instVars : [ + 'value' + ], + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #encoding } +PBCallbackAnswer >> privateEncode: dict [ + super privateEncode: dict. + dict at: #value put: value +] + +{ #category : #accessing } +PBCallbackAnswer >> value [ + ^ value +] + +{ #category : #accessing } +PBCallbackAnswer >> value: anObject [ + value := anObject +] diff --git a/src/PythonBridge/PBCallbackMessage.class.st b/src/PythonBridge/PBCallbackMessage.class.st index 930654f..5f05e05 100644 --- a/src/PythonBridge/PBCallbackMessage.class.st +++ b/src/PythonBridge/PBCallbackMessage.class.st @@ -1,43 +1,43 @@ -Class { - #name : #PBCallbackMessage, - #superclass : #PBRSyncMessage, - #instVars : [ - 'commandId', - 'observerId', - 'value' - ], - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #accessing } -PBCallbackMessage class >> answerClass [ - ^ PBCallbackAnswer -] - -{ #category : #accessing } -PBCallbackMessage class >> type [ - ^ #CALLBACK -] - -{ #category : #accessing } -PBCallbackMessage >> commandId [ - ^ commandId -] - -{ #category : #accessing } -PBCallbackMessage >> observerId [ - ^ observerId -] - -{ #category : #'as yet unclassified' } -PBCallbackMessage >> privateDecode: dict [ - super privateDecode: dict. - commandId := dict at: #commandId. - observerId := dict at: #observerId. - value := dict at: #value -] - -{ #category : #accessing } -PBCallbackMessage >> value [ - ^ value -] +Class { + #name : #PBCallbackMessage, + #superclass : #PBRSyncMessage, + #instVars : [ + 'commandId', + 'observerId', + 'value' + ], + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #accessing } +PBCallbackMessage class >> answerClass [ + ^ PBCallbackAnswer +] + +{ #category : #accessing } +PBCallbackMessage class >> type [ + ^ #CALLBACK +] + +{ #category : #accessing } +PBCallbackMessage >> commandId [ + ^ commandId +] + +{ #category : #accessing } +PBCallbackMessage >> observerId [ + ^ observerId +] + +{ #category : #'as yet unclassified' } +PBCallbackMessage >> privateDecode: dict [ + super privateDecode: dict. + commandId := dict at: #commandId. + observerId := dict at: #observerId. + value := dict at: #value +] + +{ #category : #accessing } +PBCallbackMessage >> value [ + ^ value +] diff --git a/src/PythonBridge/PBCommand.class.st b/src/PythonBridge/PBCommand.class.st index df888f3..eef043e 100644 --- a/src/PythonBridge/PBCommand.class.st +++ b/src/PythonBridge/PBCommand.class.st @@ -1,110 +1,110 @@ -Class { - #name : #PBCommand, - #superclass : #Object, - #instVars : [ - 'id', - 'instructions', - 'bindings', - 'observers', - 'promise', - 'transformBlock' - ], - #category : #'PythonBridge-Execution' -} - -{ #category : #accessing } -PBCommand >> bindings [ - ^ bindings -] - -{ #category : #accessing } -PBCommand >> bindings: bindingCol [ - bindings := bindingCol -] - -{ #category : #accessing } -PBCommand >> bindingsDictionary [ - ^ self bindings asDictionary -] - -{ #category : #accessing } -PBCommand >> getObserver: observerId [ - ^ observers detect: [ :obs | obs id = observerId ] -] - -{ #category : #accessing } -PBCommand >> id [ - ^ id -] - -{ #category : #accessing } -PBCommand >> id: anObject [ - id := anObject -] - -{ #category : #initialization } -PBCommand >> initialize [ - super initialize. - id := PBPlatform current newRandomName. - bindings := #(). - observers := #(). - instructions := OrderedCollection new. - transformBlock := #yourself -] - -{ #category : #accessing } -PBCommand >> instructions [ - ^ instructions -] - -{ #category : #accessing } -PBCommand >> instructions: anObject [ - instructions := anObject -] - -{ #category : #testing } -PBCommand >> isValid [ - ^ [ self id isString and: [ - (self bindings allSatisfy: [ :assoc | assoc key isString ]) and: [ - self observers allSatisfy: [ :obs | obs callback isBlock ] ] ] ] on: Error do: [ false ] -] - -{ #category : #accessing } -PBCommand >> observers [ - ^ observers -] - -{ #category : #accessing } -PBCommand >> observers: anObject [ - observers := anObject -] - -{ #category : #accessing } -PBCommand >> promise [ - ^ promise -] - -{ #category : #accessing } -PBCommand >> promise: anObject [ - promise := anObject -] - -{ #category : #'as yet unclassified' } -PBCommand >> pythonCode [ - | py3CodeStream | - py3CodeStream := String new writeStream. - self instructions do: [ :instr | - instr writePython3On: py3CodeStream. - py3CodeStream << String lf ]. - ^ py3CodeStream contents -] - -{ #category : #accessing } -PBCommand >> transformBlock [ - ^ transformBlock -] - -{ #category : #accessing } -PBCommand >> transformBlock: anObject [ - transformBlock := anObject -] +Class { + #name : #PBCommand, + #superclass : #Object, + #instVars : [ + 'id', + 'instructions', + 'bindings', + 'observers', + 'promise', + 'transformBlock' + ], + #category : #'PythonBridge-Execution' +} + +{ #category : #accessing } +PBCommand >> bindings [ + ^ bindings +] + +{ #category : #accessing } +PBCommand >> bindings: bindingCol [ + bindings := bindingCol +] + +{ #category : #accessing } +PBCommand >> bindingsDictionary [ + ^ self bindings asDictionary +] + +{ #category : #accessing } +PBCommand >> getObserver: observerId [ + ^ observers detect: [ :obs | obs id = observerId ] +] + +{ #category : #accessing } +PBCommand >> id [ + ^ id +] + +{ #category : #accessing } +PBCommand >> id: anObject [ + id := anObject +] + +{ #category : #initialization } +PBCommand >> initialize [ + super initialize. + id := PBPlatform current newRandomName. + bindings := #(). + observers := #(). + instructions := OrderedCollection new. + transformBlock := #yourself +] + +{ #category : #accessing } +PBCommand >> instructions [ + ^ instructions +] + +{ #category : #accessing } +PBCommand >> instructions: anObject [ + instructions := anObject +] + +{ #category : #testing } +PBCommand >> isValid [ + ^ [ self id isString and: [ + (self bindings allSatisfy: [ :assoc | assoc key isString ]) and: [ + self observers allSatisfy: [ :obs | obs callback isBlock ] ] ] ] on: Error do: [ false ] +] + +{ #category : #accessing } +PBCommand >> observers [ + ^ observers +] + +{ #category : #accessing } +PBCommand >> observers: anObject [ + observers := anObject +] + +{ #category : #accessing } +PBCommand >> promise [ + ^ promise +] + +{ #category : #accessing } +PBCommand >> promise: anObject [ + promise := anObject +] + +{ #category : #'as yet unclassified' } +PBCommand >> pythonCode [ + | py3CodeStream | + py3CodeStream := String new writeStream. + self instructions do: [ :instr | + instr writePython3On: py3CodeStream. + py3CodeStream << String lf ]. + ^ py3CodeStream contents +] + +{ #category : #accessing } +PBCommand >> transformBlock [ + ^ transformBlock +] + +{ #category : #accessing } +PBCommand >> transformBlock: anObject [ + transformBlock := anObject +] diff --git a/src/PythonBridge/PBCommandFactory.class.st b/src/PythonBridge/PBCommandFactory.class.st index eeb332b..08bb87c 100644 --- a/src/PythonBridge/PBCommandFactory.class.st +++ b/src/PythonBridge/PBCommandFactory.class.st @@ -1,145 +1,145 @@ -Class { - #name : #PBCommandFactory, - #superclass : #Object, - #instVars : [ - 'application', - 'bindingsDictionary', - 'observers', - 'transformBlock', - 'command', - 'instructions' - ], - #category : #'PythonBridge-Execution' -} - -{ #category : #streaming } -PBCommandFactory >> << aPythonStatement [ - instructions add: aPythonStatement -] - -{ #category : #bindings } -PBCommandFactory >> addBinding: aBinding [ - bindingsDictionary at: aBinding pythonVariable name put: aBinding object. - ^ aBinding -] - -{ #category : #observers } -PBCommandFactory >> addObserver: anObserver [ - observers add: anObserver. - ^ anObserver -] - -{ #category : #streaming } -PBCommandFactory >> append: aPythonStatement [ - instructions add: aPythonStatement -] - -{ #category : #accessing } -PBCommandFactory >> application [ - ^ application -] - -{ #category : #accessing } -PBCommandFactory >> application: anObject [ - application := anObject -] - -{ #category : #bindings } -PBCommandFactory >> bindingAt: varName put: anObject [ - bindingsDictionary at: varName put: anObject. - ^ PBBinding key: varName wrap: anObject -] - -{ #category : #bindings } -PBCommandFactory >> bindingWrap: anObject [ - ^ self addBinding: (PBBinding wrap: anObject) -] - -{ #category : #send } -PBCommandFactory >> buildCommand [ - | finishedCommand | - finishedCommand := command - instructions: self instructionsWithNotifyAtEnd; - bindings: bindingsDictionary associations; - observers: observers; - transformBlock: transformBlock; - yourself. - self initialize. - ^ finishedCommand -] - -{ #category : #accessing } -PBCommandFactory >> decorateTransform: aBlock [ - | previousBlock | - previousBlock := transformBlock. - ^ transformBlock := [ :obj | aBlock value: (previousBlock value: obj) ] -] - -{ #category : #initialization } -PBCommandFactory >> initialize [ - super initialize. - self reset -] - -{ #category : #accessing } -PBCommandFactory >> instructionsWithNotifyAtEnd [ - | instructionsCopy | - instructionsCopy := instructions copy. - instructionsCopy ifEmpty: [ instructionsCopy := OrderedCollection with: nil ]. - instructionsCopy last isPythonValue ifFalse: [ - instructionsCopy := instructionsCopy asOrderedCollection. - instructionsCopy add: nil ]. - instructionsCopy - at: instructionsCopy size - put: (self setNotifyToInstruction: instructionsCopy last). - ^ instructionsCopy -] - -{ #category : #observers } -PBCommandFactory >> observerFromCallback: aBlock [ - | observer | - observer := (PBObserver callback: aBlock) - command: command; - yourself. - ^ self addObserver: observer -] - -{ #category : #initialization } -PBCommandFactory >> reset [ - instructions := OrderedCollection new. - bindingsDictionary := Dictionary new. - observers := OrderedCollection new. - command := PBCommand new. - transformBlock := #yourself -] - -{ #category : #send } -PBCommandFactory >> send [ - ^ self sendCommand -] - -{ #category : #send } -PBCommandFactory >> sendAndWait [ - ^ self sendCommand waitForValue -] - -{ #category : #send } -PBCommandFactory >> sendCommand [ - ^ self application send: self buildCommand -] - -{ #category : #initialization } -PBCommandFactory >> setNotifyToInstruction: aP3gInstruction [ - ^ 'notify' asP3GIdentifier - callWith: (Array with: aP3gInstruction with: command id) -] - -{ #category : #accessing } -PBCommandFactory >> transformBlock [ - ^ transformBlock -] - -{ #category : #accessing } -PBCommandFactory >> transformBlock: anObject [ - transformBlock := anObject -] +Class { + #name : #PBCommandFactory, + #superclass : #Object, + #instVars : [ + 'application', + 'bindingsDictionary', + 'observers', + 'transformBlock', + 'command', + 'instructions' + ], + #category : #'PythonBridge-Execution' +} + +{ #category : #streaming } +PBCommandFactory >> << aPythonStatement [ + instructions add: aPythonStatement +] + +{ #category : #bindings } +PBCommandFactory >> addBinding: aBinding [ + bindingsDictionary at: aBinding pythonVariable name put: aBinding object. + ^ aBinding +] + +{ #category : #observers } +PBCommandFactory >> addObserver: anObserver [ + observers add: anObserver. + ^ anObserver +] + +{ #category : #streaming } +PBCommandFactory >> append: aPythonStatement [ + instructions add: aPythonStatement +] + +{ #category : #accessing } +PBCommandFactory >> application [ + ^ application +] + +{ #category : #accessing } +PBCommandFactory >> application: anObject [ + application := anObject +] + +{ #category : #bindings } +PBCommandFactory >> bindingAt: varName put: anObject [ + bindingsDictionary at: varName put: anObject. + ^ PBBinding key: varName wrap: anObject +] + +{ #category : #bindings } +PBCommandFactory >> bindingWrap: anObject [ + ^ self addBinding: (PBBinding wrap: anObject) +] + +{ #category : #send } +PBCommandFactory >> buildCommand [ + | finishedCommand | + finishedCommand := command + instructions: self instructionsWithNotifyAtEnd; + bindings: bindingsDictionary associations; + observers: observers; + transformBlock: transformBlock; + yourself. + self initialize. + ^ finishedCommand +] + +{ #category : #accessing } +PBCommandFactory >> decorateTransform: aBlock [ + | previousBlock | + previousBlock := transformBlock. + ^ transformBlock := [ :obj | aBlock value: (previousBlock value: obj) ] +] + +{ #category : #initialization } +PBCommandFactory >> initialize [ + super initialize. + self reset +] + +{ #category : #accessing } +PBCommandFactory >> instructionsWithNotifyAtEnd [ + | instructionsCopy | + instructionsCopy := instructions copy. + instructionsCopy ifEmpty: [ instructionsCopy := OrderedCollection with: nil ]. + instructionsCopy last isPythonValue ifFalse: [ + instructionsCopy := instructionsCopy asOrderedCollection. + instructionsCopy add: nil ]. + instructionsCopy + at: instructionsCopy size + put: (self setNotifyToInstruction: instructionsCopy last). + ^ instructionsCopy +] + +{ #category : #observers } +PBCommandFactory >> observerFromCallback: aBlock [ + | observer | + observer := (PBObserver callback: aBlock) + command: command; + yourself. + ^ self addObserver: observer +] + +{ #category : #initialization } +PBCommandFactory >> reset [ + instructions := OrderedCollection new. + bindingsDictionary := Dictionary new. + observers := OrderedCollection new. + command := PBCommand new. + transformBlock := #yourself +] + +{ #category : #send } +PBCommandFactory >> send [ + ^ self sendCommand +] + +{ #category : #send } +PBCommandFactory >> sendAndWait [ + ^ self sendCommand waitForValue +] + +{ #category : #send } +PBCommandFactory >> sendCommand [ + ^ self application send: self buildCommand +] + +{ #category : #initialization } +PBCommandFactory >> setNotifyToInstruction: aP3gInstruction [ + ^ 'notify' asP3GIdentifier + callWith: (Array with: aP3gInstruction with: command id) +] + +{ #category : #accessing } +PBCommandFactory >> transformBlock [ + ^ transformBlock +] + +{ #category : #accessing } +PBCommandFactory >> transformBlock: anObject [ + transformBlock := anObject +] diff --git a/src/PythonBridge/PBCommandFactoryTest.class.st b/src/PythonBridge/PBCommandFactoryTest.class.st index 4da673a..d60127b 100644 --- a/src/PythonBridge/PBCommandFactoryTest.class.st +++ b/src/PythonBridge/PBCommandFactoryTest.class.st @@ -1,52 +1,52 @@ -Class { - #name : #PBCommandFactoryTest, - #superclass : #TestCase, - #instVars : [ - 'factory' - ], - #category : #'PythonBridge-Tests' -} - -{ #category : #initialization } -PBCommandFactoryTest >> setUp [ - factory := PBCommandFactory new -] - -{ #category : #tests } -PBCommandFactoryTest >> testBuildEmptyCommand [ - | command | - command := factory buildCommand. - self assert: command instructions size equals: 1. - self assert: command instructions first class equals: P3GCall. - self assert: command instructions first target name equals: 'notify'. - self assert: command instructions first positionalArguments first equals: nil. - self assert: command bindings isEmpty -] - -{ #category : #tests } -PBCommandFactoryTest >> testBuildFullCommand [ - | command instructions | - factory << (P3GString string: 'foo'). - factory bindingAt: #myVar put: 3. - command := factory buildCommand. - instructions := command instructions. - self assert: command instructions first positionalArguments first string equals: 'foo'. - self assert: (command bindingsDictionary at: #myVar) equals: 3 -] - -{ #category : #tests } -PBCommandFactoryTest >> testBuildSimpleCommand [ - | command instructions | - factory << (P3GString string: 'foo'). - command := factory buildCommand. - instructions := command instructions. - self assert: command instructions first positionalArguments first string equals: 'foo'. -] - -{ #category : #tests } -PBCommandFactoryTest >> testBuildWithObservers [ - | command | - factory observerFromCallback: [ 32 ]. - command := factory buildCommand. - self assert: command observers first callback value equals: 32. -] +Class { + #name : #PBCommandFactoryTest, + #superclass : #TestCase, + #instVars : [ + 'factory' + ], + #category : #'PythonBridge-Tests' +} + +{ #category : #initialization } +PBCommandFactoryTest >> setUp [ + factory := PBCommandFactory new +] + +{ #category : #tests } +PBCommandFactoryTest >> testBuildEmptyCommand [ + | command | + command := factory buildCommand. + self assert: command instructions size equals: 1. + self assert: command instructions first class equals: P3GCall. + self assert: command instructions first target name equals: 'notify'. + self assert: command instructions first positionalArguments first equals: nil. + self assert: command bindings isEmpty +] + +{ #category : #tests } +PBCommandFactoryTest >> testBuildFullCommand [ + | command instructions | + factory << (P3GString string: 'foo'). + factory bindingAt: #myVar put: 3. + command := factory buildCommand. + instructions := command instructions. + self assert: command instructions first positionalArguments first string equals: 'foo'. + self assert: (command bindingsDictionary at: #myVar) equals: 3 +] + +{ #category : #tests } +PBCommandFactoryTest >> testBuildSimpleCommand [ + | command instructions | + factory << (P3GString string: 'foo'). + command := factory buildCommand. + instructions := command instructions. + self assert: command instructions first positionalArguments first string equals: 'foo'. +] + +{ #category : #tests } +PBCommandFactoryTest >> testBuildWithObservers [ + | command | + factory observerFromCallback: [ 32 ]. + command := factory buildCommand. + self assert: command observers first callback value equals: 32. +] diff --git a/src/PythonBridge/PBCommandQueue.class.st b/src/PythonBridge/PBCommandQueue.class.st index 16a6f62..94e356b 100644 --- a/src/PythonBridge/PBCommandQueue.class.st +++ b/src/PythonBridge/PBCommandQueue.class.st @@ -1,125 +1,125 @@ -Class { - #name : #PBCommandQueue, - #superclass : #Object, - #instVars : [ - 'currentIndex', - 'innerCollection', - 'executionHandler' - ], - #category : #'PythonBridge-Execution' -} - -{ #category : #accessing } -PBCommandQueue class >> executionHandler: aHandler [ - ^ self new - executionHandler: aHandler; - yourself -] - -{ #category : #accessing } -PBCommandQueue >> cleanIndex: anIndex [ - self debugMode ifTrue: [ ^ self ]. - currentIndex := currentIndex - 1. - innerCollection removeAt: anIndex -] - -{ #category : #accessing } -PBCommandQueue >> completedCommands [ - ^ innerCollection first: currentIndex -] - -{ #category : #accessing } -PBCommandQueue >> currentCommand [ - self isFinished ifTrue: [ ^ nil ]. - ^ innerCollection at: currentIndex -] - -{ #category : #accessing } -PBCommandQueue >> debugMode [ - ^ PBApplication debugMode -] - -{ #category : #accessing } -PBCommandQueue >> enqueueCommand: aCommand [ - innerCollection add: aCommand -] - -{ #category : #accessing } -PBCommandQueue >> excecutionHandler [ - ^ executionHandler -] - -{ #category : #accessing } -PBCommandQueue >> executionHandler [ - ^ executionHandler -] - -{ #category : #accessing } -PBCommandQueue >> executionHandler: anObject [ - executionHandler := anObject -] - -{ #category : #accessing } -PBCommandQueue >> finishCommand: aCommand [ - ^ self finishCommandId: aCommand id -] - -{ #category : #accessing } -PBCommandQueue >> finishCommandId: id [ - | commandIndex | - self currentCommand ifNotNil: [ :command | - command id = id - ifTrue: [ - self cleanIndex: currentIndex. - currentIndex := currentIndex + 1. - ^ true ] ]. - commandIndex := innerCollection detectIndex: [ :command | command id = id ]. - commandIndex > currentIndex - ifTrue: [ - currentIndex := commandIndex + 1. - self log: (PBErrorLog message: 'Out of sync command queue. Pharo is delayed.') ] - ifFalse: [ - self log: (PBErrorLog message: 'Out of sync command queue. Python is delayed.') ]. - self cleanIndex: commandIndex. - ^ false -] - -{ #category : #accessing } -PBCommandQueue >> getCommand: aCommandId [ - ^ innerCollection detect: [ :command | command id = aCommandId ] -] - -{ #category : #initialization } -PBCommandQueue >> initialize [ - super initialize. - innerCollection := OrderedCollection new. - currentIndex := 1 -] - -{ #category : #accessing } -PBCommandQueue >> isFinished [ - ^ innerCollection size < currentIndex -] - -{ #category : #accessing } -PBCommandQueue >> list [ - ^ innerCollection -] - -{ #category : #accessing } -PBCommandQueue >> nextCommand [ - | nextCommandIndex | - nextCommandIndex := currentIndex + 1. - innerCollection size < nextCommandIndex ifTrue: [ ^ nil ]. - ^ innerCollection at: nextCommandIndex -] - -{ #category : #accessing } -PBCommandQueue >> queue [ - ^ self waitingCommands -] - -{ #category : #accessing } -PBCommandQueue >> waitingCommands [ - ^ innerCollection allButFirst: currentIndex -] +Class { + #name : #PBCommandQueue, + #superclass : #Object, + #instVars : [ + 'currentIndex', + 'innerCollection', + 'executionHandler' + ], + #category : #'PythonBridge-Execution' +} + +{ #category : #accessing } +PBCommandQueue class >> executionHandler: aHandler [ + ^ self new + executionHandler: aHandler; + yourself +] + +{ #category : #accessing } +PBCommandQueue >> cleanIndex: anIndex [ + self debugMode ifTrue: [ ^ self ]. + currentIndex := currentIndex - 1. + innerCollection removeAt: anIndex +] + +{ #category : #accessing } +PBCommandQueue >> completedCommands [ + ^ innerCollection first: currentIndex +] + +{ #category : #accessing } +PBCommandQueue >> currentCommand [ + self isFinished ifTrue: [ ^ nil ]. + ^ innerCollection at: currentIndex +] + +{ #category : #accessing } +PBCommandQueue >> debugMode [ + ^ PBApplication debugMode +] + +{ #category : #accessing } +PBCommandQueue >> enqueueCommand: aCommand [ + innerCollection add: aCommand +] + +{ #category : #accessing } +PBCommandQueue >> excecutionHandler [ + ^ executionHandler +] + +{ #category : #accessing } +PBCommandQueue >> executionHandler [ + ^ executionHandler +] + +{ #category : #accessing } +PBCommandQueue >> executionHandler: anObject [ + executionHandler := anObject +] + +{ #category : #accessing } +PBCommandQueue >> finishCommand: aCommand [ + ^ self finishCommandId: aCommand id +] + +{ #category : #accessing } +PBCommandQueue >> finishCommandId: id [ + | commandIndex | + self currentCommand ifNotNil: [ :command | + command id = id + ifTrue: [ + self cleanIndex: currentIndex. + currentIndex := currentIndex + 1. + ^ true ] ]. + commandIndex := innerCollection detectIndex: [ :command | command id = id ]. + commandIndex > currentIndex + ifTrue: [ + currentIndex := commandIndex + 1. + self log: (PBErrorLog message: 'Out of sync command queue. Pharo is delayed.') ] + ifFalse: [ + self log: (PBErrorLog message: 'Out of sync command queue. Python is delayed.') ]. + self cleanIndex: commandIndex. + ^ false +] + +{ #category : #accessing } +PBCommandQueue >> getCommand: aCommandId [ + ^ innerCollection detect: [ :command | command id = aCommandId ] +] + +{ #category : #initialization } +PBCommandQueue >> initialize [ + super initialize. + innerCollection := OrderedCollection new. + currentIndex := 1 +] + +{ #category : #accessing } +PBCommandQueue >> isFinished [ + ^ innerCollection size < currentIndex +] + +{ #category : #accessing } +PBCommandQueue >> list [ + ^ innerCollection +] + +{ #category : #accessing } +PBCommandQueue >> nextCommand [ + | nextCommandIndex | + nextCommandIndex := currentIndex + 1. + innerCollection size < nextCommandIndex ifTrue: [ ^ nil ]. + ^ innerCollection at: nextCommandIndex +] + +{ #category : #accessing } +PBCommandQueue >> queue [ + ^ self waitingCommands +] + +{ #category : #accessing } +PBCommandQueue >> waitingCommands [ + ^ innerCollection allButFirst: currentIndex +] diff --git a/src/PythonBridge/PBCommandQueueTest.class.st b/src/PythonBridge/PBCommandQueueTest.class.st index ade0938..292c378 100644 --- a/src/PythonBridge/PBCommandQueueTest.class.st +++ b/src/PythonBridge/PBCommandQueueTest.class.st @@ -1,106 +1,106 @@ -Class { - #name : #PBCommandQueueTest, - #superclass : #TestCase, - #instVars : [ - 'queue', - 'app' - ], - #category : #'PythonBridge-Tests' -} - -{ #category : #initialization } -PBCommandQueueTest >> setUp [ - | execHandler | - app := PBStubApplication new. - execHandler := PBExecutionHandler basicNew - application: app; - yourself. - queue := PBCommandQueue executionHandler: execHandler -] - -{ #category : #tests } -PBCommandQueueTest >> testCleaningCommand [ - | cc1 cc2 | - cc1 := PBCommand new. - cc2 := PBCommand new. - queue enqueueCommand: cc1. - queue enqueueCommand: cc2. - self assert: (queue finishCommand: cc1). - self assert: queue list size equals: 1. - self assert: (queue finishCommand: cc2). - self assert: queue isFinished -] - -{ #category : #tests } -PBCommandQueueTest >> testEmptyQueue [ - self assert: queue list isEmpty. - self assert: queue isFinished. - self assert: queue currentCommand isNil -] - -{ #category : #tests } -PBCommandQueueTest >> testEnqueue [ - | c | - c := PBCommand new. - queue enqueueCommand: c. - self assert: queue list size equals: 1. - self assert: queue currentCommand equals: c. - -] - -{ #category : #tests } -PBCommandQueueTest >> testFinishCommand [ - | cc | - cc := PBCommand new. - queue enqueueCommand: cc. - self assert: (queue finishCommand: cc). - self assert: queue isFinished -] - -{ #category : #tests } -PBCommandQueueTest >> testFinishCommand2 [ - | cc | - cc := PBCommand new. - queue enqueueCommand: cc. - queue enqueueCommand: PBCommand new. - self assert: (queue finishCommand: cc). - self deny: queue isFinished -] - -{ #category : #tests } -PBCommandQueueTest >> testFinishNotFoundCommand [ - self - should: [ queue finishCommandId: 'aa' ] - raise: Error -] - -{ #category : #tests } -PBCommandQueueTest >> testFinishOutOfSync1Command [ - | cc1 cc2 | - cc1 := PBCommand new. - cc2 := PBCommand new. - queue enqueueCommand: cc1. - queue enqueueCommand: cc2. - self deny: (queue finishCommand: cc2). - self assert: queue isFinished -] - -{ #category : #tests } -PBCommandQueueTest >> testFinishOutOfSync2Command [ - | cc1 cc2 | - cc1 := PBCommand new. - cc2 := PBCommand new. - queue enqueueCommand: cc1. - queue enqueueCommand: cc2. - self deny: (queue finishCommand: cc2). - self deny: (queue finishCommand: cc1). - self assert: queue isFinished -] - -{ #category : #tests } -PBCommandQueueTest >> testNotFoundCommand [ - queue enqueueCommand: PBCommand new. - self - should: [ queue finishCommandId: 'aa' ] - raise: Error -] +Class { + #name : #PBCommandQueueTest, + #superclass : #TestCase, + #instVars : [ + 'queue', + 'app' + ], + #category : #'PythonBridge-Tests' +} + +{ #category : #initialization } +PBCommandQueueTest >> setUp [ + | execHandler | + app := PBStubApplication new. + execHandler := PBExecutionHandler basicNew + application: app; + yourself. + queue := PBCommandQueue executionHandler: execHandler +] + +{ #category : #tests } +PBCommandQueueTest >> testCleaningCommand [ + | cc1 cc2 | + cc1 := PBCommand new. + cc2 := PBCommand new. + queue enqueueCommand: cc1. + queue enqueueCommand: cc2. + self assert: (queue finishCommand: cc1). + self assert: queue list size equals: 1. + self assert: (queue finishCommand: cc2). + self assert: queue isFinished +] + +{ #category : #tests } +PBCommandQueueTest >> testEmptyQueue [ + self assert: queue list isEmpty. + self assert: queue isFinished. + self assert: queue currentCommand isNil +] + +{ #category : #tests } +PBCommandQueueTest >> testEnqueue [ + | c | + c := PBCommand new. + queue enqueueCommand: c. + self assert: queue list size equals: 1. + self assert: queue currentCommand equals: c. + +] + +{ #category : #tests } +PBCommandQueueTest >> testFinishCommand [ + | cc | + cc := PBCommand new. + queue enqueueCommand: cc. + self assert: (queue finishCommand: cc). + self assert: queue isFinished +] + +{ #category : #tests } +PBCommandQueueTest >> testFinishCommand2 [ + | cc | + cc := PBCommand new. + queue enqueueCommand: cc. + queue enqueueCommand: PBCommand new. + self assert: (queue finishCommand: cc). + self deny: queue isFinished +] + +{ #category : #tests } +PBCommandQueueTest >> testFinishNotFoundCommand [ + self + should: [ queue finishCommandId: 'aa' ] + raise: Error +] + +{ #category : #tests } +PBCommandQueueTest >> testFinishOutOfSync1Command [ + | cc1 cc2 | + cc1 := PBCommand new. + cc2 := PBCommand new. + queue enqueueCommand: cc1. + queue enqueueCommand: cc2. + self deny: (queue finishCommand: cc2). + self assert: queue isFinished +] + +{ #category : #tests } +PBCommandQueueTest >> testFinishOutOfSync2Command [ + | cc1 cc2 | + cc1 := PBCommand new. + cc2 := PBCommand new. + queue enqueueCommand: cc1. + queue enqueueCommand: cc2. + self deny: (queue finishCommand: cc2). + self deny: (queue finishCommand: cc1). + self assert: queue isFinished +] + +{ #category : #tests } +PBCommandQueueTest >> testNotFoundCommand [ + queue enqueueCommand: PBCommand new. + self + should: [ queue finishCommandId: 'aa' ] + raise: Error +] diff --git a/src/PythonBridge/PBCommandTest.class.st b/src/PythonBridge/PBCommandTest.class.st index 2a37b7c..76d7659 100644 --- a/src/PythonBridge/PBCommandTest.class.st +++ b/src/PythonBridge/PBCommandTest.class.st @@ -1,30 +1,30 @@ -Class { - #name : #PBCommandTest, - #superclass : #TestCase, - #category : #'PythonBridge-Tests' -} - -{ #category : #tests } -PBCommandTest >> testNewCommandHasEmtptyBindings [ - | command | - command := PBCommand new. - self assert: command id isString. - self assert: command id notEmpty. - self assert: command bindings equals: #(). -] - -{ #category : #tests } -PBCommandTest >> testNotValidBindingsKeyNotString [ - | command | - command := PBCommand new. - command bindings: { 33 -> 'bar' }. - self deny: command isValid -] - -{ #category : #tests } -PBCommandTest >> testNotValidBindingsNotAssoc [ - | command | - command := PBCommand new. - command bindings: { '33' -> 'bar'. 'foo' }. - self deny: command isValid -] +Class { + #name : #PBCommandTest, + #superclass : #TestCase, + #category : #'PythonBridge-Tests' +} + +{ #category : #tests } +PBCommandTest >> testNewCommandHasEmtptyBindings [ + | command | + command := PBCommand new. + self assert: command id isString. + self assert: command id notEmpty. + self assert: command bindings equals: #(). +] + +{ #category : #tests } +PBCommandTest >> testNotValidBindingsKeyNotString [ + | command | + command := PBCommand new. + command bindings: { 33 -> 'bar' }. + self deny: command isValid +] + +{ #category : #tests } +PBCommandTest >> testNotValidBindingsNotAssoc [ + | command | + command := PBCommand new. + command bindings: { '33' -> 'bar'. 'foo' }. + self deny: command isValid +] diff --git a/src/PythonBridge/PBCommunicationError.class.st b/src/PythonBridge/PBCommunicationError.class.st index 3bd5886..ba36855 100644 --- a/src/PythonBridge/PBCommunicationError.class.st +++ b/src/PythonBridge/PBCommunicationError.class.st @@ -1,5 +1,5 @@ -Class { - #name : #PBCommunicationError, - #superclass : #Error, - #category : #'PythonBridge-Platform' -} +Class { + #name : #PBCommunicationError, + #superclass : #Error, + #category : #'PythonBridge-Platform' +} diff --git a/src/PythonBridge/PBCommunicationHandler.class.st b/src/PythonBridge/PBCommunicationHandler.class.st index a191cec..a5506a5 100644 --- a/src/PythonBridge/PBCommunicationHandler.class.st +++ b/src/PythonBridge/PBCommunicationHandler.class.st @@ -1,47 +1,47 @@ -Class { - #name : #PBCommunicationHandler, - #superclass : #PBHandler, - #instVars : [ - 'messageBroker' - ], - #category : #'PythonBridge-Core' -} - -{ #category : #adding } -PBCommunicationHandler >> addHandler: aBlock forMessageClass: messageClass [ - ^ messageBroker addCallback: aBlock messageClass: messageClass -] - -{ #category : #initialization } -PBCommunicationHandler >> initializeHandler [ - super initializeHandler. - messageBroker := PBPlatform current messageBroker: self application settings -] - -{ #category : #testing } -PBCommunicationHandler >> isPythonReady [ - | semaphore ans | - semaphore := Semaphore new. - [ ans := [self sendMessage: PBIsAliveMessage new. - true ] - on: PBCommunicationError - do: [ :e | false ]. - semaphore signal ] forkAt: Processor lowIOPriority. - semaphore waitTimeoutMSecs: 100. - ^ ans notNil and: ans -] - -{ #category : #adding } -PBCommunicationHandler >> sendMessage: aMessage [ - ^ messageBroker sendMessage: aMessage -] - -{ #category : #accessing } -PBCommunicationHandler >> start [ - ^ messageBroker start -] - -{ #category : #accessing } -PBCommunicationHandler >> stop [ - ^ messageBroker stop -] +Class { + #name : #PBCommunicationHandler, + #superclass : #PBHandler, + #instVars : [ + 'messageBroker' + ], + #category : #'PythonBridge-Core' +} + +{ #category : #adding } +PBCommunicationHandler >> addHandler: aBlock forMessageClass: messageClass [ + ^ messageBroker addCallback: aBlock messageClass: messageClass +] + +{ #category : #initialization } +PBCommunicationHandler >> initializeHandler [ + super initializeHandler. + messageBroker := PBPlatform current messageBroker: self application settings +] + +{ #category : #testing } +PBCommunicationHandler >> isPythonReady [ + | semaphore ans | + semaphore := Semaphore new. + [ ans := [self sendMessage: PBIsAliveMessage new. + true ] + on: PBCommunicationError + do: [ :e | false ]. + semaphore signal ] forkAt: Processor lowIOPriority. + semaphore waitTimeoutMSecs: 100. + ^ ans notNil and: ans +] + +{ #category : #adding } +PBCommunicationHandler >> sendMessage: aMessage [ + ^ messageBroker sendMessage: aMessage +] + +{ #category : #accessing } +PBCommunicationHandler >> start [ + ^ messageBroker start +] + +{ #category : #accessing } +PBCommunicationHandler >> stop [ + ^ messageBroker stop +] diff --git a/src/PythonBridge/PBConnectionTest.class.st b/src/PythonBridge/PBConnectionTest.class.st index 29d2d09..f67b61b 100644 --- a/src/PythonBridge/PBConnectionTest.class.st +++ b/src/PythonBridge/PBConnectionTest.class.st @@ -1,65 +1,65 @@ -Class { - #name : #PBConnectionTest, - #superclass : #TestCase, - #instVars : [ - 'application', - 'oldApplication', - 'oldApp', - 'oldCF' - ], - #category : #'PythonBridge-Tests' -} - -{ #category : #running } -PBConnectionTest >> setUp [ - oldApp := PBApplication uniqueInstance. - oldCF := PBCF current. - PBCF current: nil. - application := PBApplication new. - PBApplication uniqueInstance: application -] - -{ #category : #running } -PBConnectionTest >> tearDown [ - application stop. - PBApplication uniqueInstance: oldApp. - PBCF current: oldCF -] - -{ #category : #tests } -PBConnectionTest >> testNotRunning [ - self deny: application isRunning -] - -{ #category : #tests } -PBConnectionTest >> testSimpleExecution [ - self deny: application isRunning. - application start. - application send: - (PBCommand new instructions: - (Array with: (P3GBinaryOperator new - left: 1; - right: 2; - operator: $+; - yourself))). - application stop. - (Delay forMilliseconds: 150) wait. - self should: [ application send: - (PBCommand new instructions: - (Array with: (P3GBinaryOperator new - left: 1; - right: 2; - operator: $+; - yourself))) ] raise: Error. -] - -{ #category : #tests } -PBConnectionTest >> testStartStopProcess [ - self deny: application isRunning. - application start. - self assert: application processHandler isRunning. - application stop. - (Delay forMilliseconds: 150) wait. - self deny: application isRunning. - self deny: application processHandler isRunning -] +Class { + #name : #PBConnectionTest, + #superclass : #TestCase, + #instVars : [ + 'application', + 'oldApplication', + 'oldApp', + 'oldCF' + ], + #category : #'PythonBridge-Tests' +} + +{ #category : #running } +PBConnectionTest >> setUp [ + oldApp := PBApplication uniqueInstance. + oldCF := PBCF current. + PBCF current: nil. + application := PBApplication new. + PBApplication uniqueInstance: application +] + +{ #category : #running } +PBConnectionTest >> tearDown [ + application stop. + PBApplication uniqueInstance: oldApp. + PBCF current: oldCF +] + +{ #category : #tests } +PBConnectionTest >> testNotRunning [ + self deny: application isRunning +] + +{ #category : #tests } +PBConnectionTest >> testSimpleExecution [ + self deny: application isRunning. + application start. + application send: + (PBCommand new instructions: + (Array with: (P3GBinaryOperator new + left: 1; + right: 2; + operator: $+; + yourself))). + application stop. + (Delay forMilliseconds: 150) wait. + self should: [ application send: + (PBCommand new instructions: + (Array with: (P3GBinaryOperator new + left: 1; + right: 2; + operator: $+; + yourself))) ] raise: Error. +] + +{ #category : #tests } +PBConnectionTest >> testStartStopProcess [ + self deny: application isRunning. + application start. + self assert: application processHandler isRunning. + application stop. + (Delay forMilliseconds: 150) wait. + self deny: application isRunning. + self deny: application processHandler isRunning +] diff --git a/src/PythonBridge/PBDeserializeTest.class.st b/src/PythonBridge/PBDeserializeTest.class.st index 03ece53..405b964 100644 --- a/src/PythonBridge/PBDeserializeTest.class.st +++ b/src/PythonBridge/PBDeserializeTest.class.st @@ -1,70 +1,70 @@ -Class { - #name : #PBDeserializeTest, - #superclass : #TestCase, - #instVars : [ - 'mapper' - ], - #category : #'PythonBridge-Tests' -} - -{ #category : #running } -PBDeserializeTest >> application [ - ^ 'FOO' -] - -{ #category : #running } -PBDeserializeTest >> deserialize: anObject [ - ^ self deserializer deserialize: anObject -] - -{ #category : #running } -PBDeserializeTest >> deserializer [ - ^ mapper deserializer - serializerWrapper: PBPlatform current class httpMessageBrokerClass serializer; - yourself -] - -{ #category : #running } -PBDeserializeTest >> setUp [ - super setUp. - mapper := PBMapperFactory forExecutionHandler: self stubExecutionHandler -] - -{ #category : #running } -PBDeserializeTest >> stubExecutionHandler [ - ^ PBExecutionHandler new - application: self application; - yourself -] - -{ #category : #tests } -PBDeserializeTest >> testDeserializeArray [ - self assert: (self deserialize: '[33,"foo"]') equals: #(33 'foo') -] - -{ #category : #tests } -PBDeserializeTest >> testDeserializeNull [ - self assert: (self deserialize: 'null') equals: nil -] - -{ #category : #tests } -PBDeserializeTest >> testDeserializeProxy [ - | proxy | - proxy := self deserialize: '{"__pyclass__":"MyClass","__pyid__":"abcde12345"}'. - self assert: proxy pythonClass equals: #MyClass. - self assert: proxy application equals: self deserializer application. - self assert: proxy application equals: 'FOO'. - self assert: proxy pythonVariable equals: 'abcde12345' asP3GI -] - -{ #category : #tests } -PBDeserializeTest >> testDeserializeProxyInArray [ - | proxy arr | - arr := self deserialize: '[{"__pyclass__":"MyClass","__pyid__":"abcde12345"}]'. - self assert: arr size equals: 1. - proxy := arr first. - self assert: proxy pythonClass equals: #MyClass. - self assert: proxy application equals: self deserializer application. - self assert: proxy application equals: 'FOO'. - self assert: proxy pythonVariable equals: 'abcde12345' asP3GI -] +Class { + #name : #PBDeserializeTest, + #superclass : #TestCase, + #instVars : [ + 'mapper' + ], + #category : #'PythonBridge-Tests' +} + +{ #category : #running } +PBDeserializeTest >> application [ + ^ 'FOO' +] + +{ #category : #running } +PBDeserializeTest >> deserialize: anObject [ + ^ self deserializer deserialize: anObject +] + +{ #category : #running } +PBDeserializeTest >> deserializer [ + ^ mapper deserializer + serializerWrapper: PBPlatform current class httpMessageBrokerClass serializer; + yourself +] + +{ #category : #running } +PBDeserializeTest >> setUp [ + super setUp. + mapper := PBMapperFactory forExecutionHandler: self stubExecutionHandler +] + +{ #category : #running } +PBDeserializeTest >> stubExecutionHandler [ + ^ PBExecutionHandler new + application: self application; + yourself +] + +{ #category : #tests } +PBDeserializeTest >> testDeserializeArray [ + self assert: (self deserialize: '[33,"foo"]') equals: #(33 'foo') +] + +{ #category : #tests } +PBDeserializeTest >> testDeserializeNull [ + self assert: (self deserialize: 'null') equals: nil +] + +{ #category : #tests } +PBDeserializeTest >> testDeserializeProxy [ + | proxy | + proxy := self deserialize: '{"__pyclass__":"MyClass","__pyid__":"abcde12345"}'. + self assert: proxy pythonClass equals: #MyClass. + self assert: proxy application equals: self deserializer application. + self assert: proxy application equals: 'FOO'. + self assert: proxy pythonVariable equals: 'abcde12345' asP3GI +] + +{ #category : #tests } +PBDeserializeTest >> testDeserializeProxyInArray [ + | proxy arr | + arr := self deserialize: '[{"__pyclass__":"MyClass","__pyid__":"abcde12345"}]'. + self assert: arr size equals: 1. + proxy := arr first. + self assert: proxy pythonClass equals: #MyClass. + self assert: proxy application equals: self deserializer application. + self assert: proxy application equals: 'FOO'. + self assert: proxy pythonVariable equals: 'abcde12345' asP3GI +] diff --git a/src/PythonBridge/PBDeserializer.class.st b/src/PythonBridge/PBDeserializer.class.st index 3540dd3..64f3a0b 100644 --- a/src/PythonBridge/PBDeserializer.class.st +++ b/src/PythonBridge/PBDeserializer.class.st @@ -1,50 +1,50 @@ -Class { - #name : #PBDeserializer, - #superclass : #PBMapper, - #category : #'PythonBridge-Serialization' -} - -{ #category : #'private protocol' } -PBDeserializer class >> deserialize: anObject [ - ^ self new - deserialize: anObject -] - -{ #category : #'private protocol' } -PBDeserializer >> application [ - ^ self executionHandler application -] - -{ #category : #'private protocol' } -PBDeserializer >> buildProxyFor: rawObject [ - | proxy | - proxy := PBProxyObject - pythonClass: (rawObject at: #__pyclass__) - pythonVar: (rawObject at: #__pyid__) asP3GI - application: self application. - self executionHandler registerObject: proxy. - ^ proxy -] - -{ #category : #'private protocol' } -PBDeserializer >> deserialize: str [ - ^ self privateDeserialize: (serializerWrapper deserialize: str). -] - -{ #category : #'private protocol' } -PBDeserializer >> objectRegistry [ - ^ self executionHandler objectRegistry -] - -{ #category : #'private protocol' } -PBDeserializer >> privateDeserialize: rawObj [ - rawObj isCollection ifFalse: [ ^ rawObj ]. - rawObj isDictionary and: [ (rawObj includesKey: #__pyid__) - ifTrue: [ ^ self reifyProxyFor: rawObj ] ]. - ^ rawObj collect: [ :elem | self privateDeserialize: elem ] -] - -{ #category : #'private protocol' } -PBDeserializer >> reifyProxyFor: rawObj [ - ^ self objectRegistry resolve: (rawObj at: #__pyid__) ifAbsent: [ self buildProxyFor: rawObj ] -] +Class { + #name : #PBDeserializer, + #superclass : #PBMapper, + #category : #'PythonBridge-Serialization' +} + +{ #category : #'private protocol' } +PBDeserializer class >> deserialize: anObject [ + ^ self new + deserialize: anObject +] + +{ #category : #'private protocol' } +PBDeserializer >> application [ + ^ self executionHandler application +] + +{ #category : #'private protocol' } +PBDeserializer >> buildProxyFor: rawObject [ + | proxy | + proxy := PBProxyObject + pythonClass: (rawObject at: #__pyclass__) + pythonVar: (rawObject at: #__pyid__) asP3GI + application: self application. + self executionHandler registerObject: proxy. + ^ proxy +] + +{ #category : #'private protocol' } +PBDeserializer >> deserialize: str [ + ^ self privateDeserialize: (serializerWrapper deserialize: str). +] + +{ #category : #'private protocol' } +PBDeserializer >> objectRegistry [ + ^ self executionHandler objectRegistry +] + +{ #category : #'private protocol' } +PBDeserializer >> privateDeserialize: rawObj [ + rawObj isCollection ifFalse: [ ^ rawObj ]. + rawObj isDictionary and: [ (rawObj includesKey: #__pyid__) + ifTrue: [ ^ self reifyProxyFor: rawObj ] ]. + ^ rawObj collect: [ :elem | self privateDeserialize: elem ] +] + +{ #category : #'private protocol' } +PBDeserializer >> reifyProxyFor: rawObj [ + ^ self objectRegistry resolve: (rawObj at: #__pyid__) ifAbsent: [ self buildProxyFor: rawObj ] +] diff --git a/src/PythonBridge/PBDropQueue.class.st b/src/PythonBridge/PBDropQueue.class.st index 9c35838..35e355c 100644 --- a/src/PythonBridge/PBDropQueue.class.st +++ b/src/PythonBridge/PBDropQueue.class.st @@ -1,10 +1,10 @@ -Class { - #name : #PBDropQueue, - #superclass : #PBErrorHandlingAction, - #category : #'PythonBridge-ErrorHandling' -} - -{ #category : #'as yet unclassified' } -PBDropQueue >> actionSymbol [ - ^ #'DROP_QUEUE' -] +Class { + #name : #PBDropQueue, + #superclass : #PBErrorHandlingAction, + #category : #'PythonBridge-ErrorHandling' +} + +{ #category : #'as yet unclassified' } +PBDropQueue >> actionSymbol [ + ^ #'DROP_QUEUE' +] diff --git a/src/PythonBridge/PBEnqueueCommandMessage.class.st b/src/PythonBridge/PBEnqueueCommandMessage.class.st index 2d46cfd..d8678b9 100644 --- a/src/PythonBridge/PBEnqueueCommandMessage.class.st +++ b/src/PythonBridge/PBEnqueueCommandMessage.class.st @@ -1,77 +1,77 @@ -Class { - #name : #PBEnqueueCommandMessage, - #superclass : #PBAsyncMessage, - #instVars : [ - 'commandId', - 'statements', - 'bindings' - ], - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #'as yet unclassified' } -PBEnqueueCommandMessage class >> commandId: commandId statements: statements bindings: bindings [ - ^ self new - commandId: commandId; - statements: statements; - bindings: bindings; - yourself -] - -{ #category : #'as yet unclassified' } -PBEnqueueCommandMessage class >> type [ - ^ 'ENQUEUE' -] - -{ #category : #adding } -PBEnqueueCommandMessage >> addBinding: assoc [ - bindings add: assoc -] - -{ #category : #adding } -PBEnqueueCommandMessage >> addBindings: assocs [ - assocs do: [ :assoc | self addBinding: assoc ] -] - -{ #category : #accessing } -PBEnqueueCommandMessage >> bindings [ - ^ bindings -] - -{ #category : #accessing } -PBEnqueueCommandMessage >> bindings: anObject [ - bindings := anObject -] - -{ #category : #accessing } -PBEnqueueCommandMessage >> commandId [ - ^ commandId -] - -{ #category : #accessing } -PBEnqueueCommandMessage >> commandId: anObject [ - commandId := anObject -] - -{ #category : #adding } -PBEnqueueCommandMessage >> initialize [ - super initialize. - bindings := Dictionary new -] - -{ #category : #adding } -PBEnqueueCommandMessage >> privateEncode: dict [ - dict at: #commandId put: commandId. - dict at: #statements put: statements. - dict at: #bindings put: bindings -] - -{ #category : #accessing } -PBEnqueueCommandMessage >> statements [ - ^ statements -] - -{ #category : #accessing } -PBEnqueueCommandMessage >> statements: anObject [ - statements := anObject -] +Class { + #name : #PBEnqueueCommandMessage, + #superclass : #PBAsyncMessage, + #instVars : [ + 'commandId', + 'statements', + 'bindings' + ], + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #'as yet unclassified' } +PBEnqueueCommandMessage class >> commandId: commandId statements: statements bindings: bindings [ + ^ self new + commandId: commandId; + statements: statements; + bindings: bindings; + yourself +] + +{ #category : #'as yet unclassified' } +PBEnqueueCommandMessage class >> type [ + ^ 'ENQUEUE' +] + +{ #category : #adding } +PBEnqueueCommandMessage >> addBinding: assoc [ + bindings add: assoc +] + +{ #category : #adding } +PBEnqueueCommandMessage >> addBindings: assocs [ + assocs do: [ :assoc | self addBinding: assoc ] +] + +{ #category : #accessing } +PBEnqueueCommandMessage >> bindings [ + ^ bindings +] + +{ #category : #accessing } +PBEnqueueCommandMessage >> bindings: anObject [ + bindings := anObject +] + +{ #category : #accessing } +PBEnqueueCommandMessage >> commandId [ + ^ commandId +] + +{ #category : #accessing } +PBEnqueueCommandMessage >> commandId: anObject [ + commandId := anObject +] + +{ #category : #adding } +PBEnqueueCommandMessage >> initialize [ + super initialize. + bindings := Dictionary new +] + +{ #category : #adding } +PBEnqueueCommandMessage >> privateEncode: dict [ + dict at: #commandId put: commandId. + dict at: #statements put: statements. + dict at: #bindings put: bindings +] + +{ #category : #accessing } +PBEnqueueCommandMessage >> statements [ + ^ statements +] + +{ #category : #accessing } +PBEnqueueCommandMessage >> statements: anObject [ + statements := anObject +] diff --git a/src/PythonBridge/PBErrorAnswer.class.st b/src/PythonBridge/PBErrorAnswer.class.st index afa8666..517c10b 100644 --- a/src/PythonBridge/PBErrorAnswer.class.st +++ b/src/PythonBridge/PBErrorAnswer.class.st @@ -1,24 +1,24 @@ -Class { - #name : #PBErrorAnswer, - #superclass : #PBRAnswer, - #instVars : [ - 'handlingAction' - ], - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #accessing } -PBErrorAnswer >> handlingAction [ - ^ handlingAction -] - -{ #category : #accessing } -PBErrorAnswer >> handlingAction: anObject [ - handlingAction := anObject -] - -{ #category : #encoding } -PBErrorAnswer >> privateEncode: dict [ - super privateEncode: dict. - dict at: #action put: handlingAction encodeAsDictionary -] +Class { + #name : #PBErrorAnswer, + #superclass : #PBRAnswer, + #instVars : [ + 'handlingAction' + ], + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #accessing } +PBErrorAnswer >> handlingAction [ + ^ handlingAction +] + +{ #category : #accessing } +PBErrorAnswer >> handlingAction: anObject [ + handlingAction := anObject +] + +{ #category : #encoding } +PBErrorAnswer >> privateEncode: dict [ + super privateEncode: dict. + dict at: #action put: handlingAction encodeAsDictionary +] diff --git a/src/PythonBridge/PBErrorHandlingAction.class.st b/src/PythonBridge/PBErrorHandlingAction.class.st index 5b34e51..d8b14cd 100644 --- a/src/PythonBridge/PBErrorHandlingAction.class.st +++ b/src/PythonBridge/PBErrorHandlingAction.class.st @@ -1,15 +1,15 @@ -Class { - #name : #PBErrorHandlingAction, - #superclass : #Object, - #category : #'PythonBridge-ErrorHandling' -} - -{ #category : #'as yet unclassified' } -PBErrorHandlingAction >> actionSymbol [ - self subclassResponsibility -] - -{ #category : #'as yet unclassified' } -PBErrorHandlingAction >> encodeAsDictionary [ - ^ { #action -> self actionSymbol } asDictionary -] +Class { + #name : #PBErrorHandlingAction, + #superclass : #Object, + #category : #'PythonBridge-ErrorHandling' +} + +{ #category : #'as yet unclassified' } +PBErrorHandlingAction >> actionSymbol [ + self subclassResponsibility +] + +{ #category : #'as yet unclassified' } +PBErrorHandlingAction >> encodeAsDictionary [ + ^ { #action -> self actionSymbol } asDictionary +] diff --git a/src/PythonBridge/PBErrorLog.class.st b/src/PythonBridge/PBErrorLog.class.st index 62fd9fb..f6cb89e 100644 --- a/src/PythonBridge/PBErrorLog.class.st +++ b/src/PythonBridge/PBErrorLog.class.st @@ -1,10 +1,10 @@ -Class { - #name : #PBErrorLog, - #superclass : #PBLog, - #category : #'PythonBridge-Logs' -} - -{ #category : #testing } -PBErrorLog >> isError [ - ^ true -] +Class { + #name : #PBErrorLog, + #superclass : #PBLog, + #category : #'PythonBridge-Logs' +} + +{ #category : #testing } +PBErrorLog >> isError [ + ^ true +] diff --git a/src/PythonBridge/PBErrorMessage.class.st b/src/PythonBridge/PBErrorMessage.class.st index 0c700aa..eb3525f 100644 --- a/src/PythonBridge/PBErrorMessage.class.st +++ b/src/PythonBridge/PBErrorMessage.class.st @@ -1,58 +1,58 @@ -Class { - #name : #PBErrorMessage, - #superclass : #PBRSyncMessage, - #instVars : [ - 'commandId', - 'errorMessage', - 'trace' - ], - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #accessing } -PBErrorMessage class >> answerClass [ - ^ PBErrorAnswer -] - -{ #category : #accessing } -PBErrorMessage class >> type [ - ^ #ERR -] - -{ #category : #accessing } -PBErrorMessage >> commandId [ - ^ commandId -] - -{ #category : #accessing } -PBErrorMessage >> commandId: anObject [ - commandId := anObject -] - -{ #category : #accessing } -PBErrorMessage >> errorMessage [ - ^ errorMessage -] - -{ #category : #accessing } -PBErrorMessage >> errorMessage: anObject [ - errorMessage := anObject -] - -{ #category : #'as yet unclassified' } -PBErrorMessage >> privateDecode: dict [ - super privateDecode: dict. - commandId := dict at: #commandId. - errorMessage := dict at: #errMsg. - trace := dict at: #trace -] - -{ #category : #accessing } -PBErrorMessage >> trace [ - ^ trace -] - -{ #category : #accessing } -PBErrorMessage >> trace: anObject [ - trace := anObject -] +Class { + #name : #PBErrorMessage, + #superclass : #PBRSyncMessage, + #instVars : [ + 'commandId', + 'errorMessage', + 'trace' + ], + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #accessing } +PBErrorMessage class >> answerClass [ + ^ PBErrorAnswer +] + +{ #category : #accessing } +PBErrorMessage class >> type [ + ^ #ERR +] + +{ #category : #accessing } +PBErrorMessage >> commandId [ + ^ commandId +] + +{ #category : #accessing } +PBErrorMessage >> commandId: anObject [ + commandId := anObject +] + +{ #category : #accessing } +PBErrorMessage >> errorMessage [ + ^ errorMessage +] + +{ #category : #accessing } +PBErrorMessage >> errorMessage: anObject [ + errorMessage := anObject +] + +{ #category : #'as yet unclassified' } +PBErrorMessage >> privateDecode: dict [ + super privateDecode: dict. + commandId := dict at: #commandId. + errorMessage := dict at: #errMsg. + trace := dict at: #trace +] + +{ #category : #accessing } +PBErrorMessage >> trace [ + ^ trace +] + +{ #category : #accessing } +PBErrorMessage >> trace: anObject [ + trace := anObject +] diff --git a/src/PythonBridge/PBExcecutionHandlerTest.class.st b/src/PythonBridge/PBExcecutionHandlerTest.class.st index 808430f..918381a 100644 --- a/src/PythonBridge/PBExcecutionHandlerTest.class.st +++ b/src/PythonBridge/PBExcecutionHandlerTest.class.st @@ -1,37 +1,37 @@ -Class { - #name : #PBExcecutionHandlerTest, - #superclass : #TestCase, - #instVars : [ - 'execHandler', - 'commandFactory' - ], - #category : #'PythonBridge-Tests' -} - -{ #category : #initialization } -PBExcecutionHandlerTest >> setUp [ - | app | - app := PBStubApplication new. - execHandler := PBExecutionHandler new - application: app; - yourself. - commandFactory := PBCommandFactory new. -] - -{ #category : #accessing } -PBExcecutionHandlerTest >> testJSONSerializeEncodeBindings [ - | message | - commandFactory bindingAt: #foo put: #(). - message := execHandler buildMessageFromCommand: commandFactory buildCommand. - self assert: (message bindings at: #foo) equals: (execHandler serialize: #()). - self deny: (message bindings at: #foo) = #() -] - -{ #category : #accessing } -PBExcecutionHandlerTest >> testSerializeEncodeBindings [ - | message | - commandFactory bindingAt: #foo put: #(). - message := execHandler buildMessageFromCommand: commandFactory buildCommand. - self assert: (message bindings at: #foo) equals: (execHandler serialize: #()). - self deny: (message bindings at: #foo) = #() -] +Class { + #name : #PBExcecutionHandlerTest, + #superclass : #TestCase, + #instVars : [ + 'execHandler', + 'commandFactory' + ], + #category : #'PythonBridge-Tests' +} + +{ #category : #initialization } +PBExcecutionHandlerTest >> setUp [ + | app | + app := PBStubApplication new. + execHandler := PBExecutionHandler new + application: app; + yourself. + commandFactory := PBCommandFactory new. +] + +{ #category : #accessing } +PBExcecutionHandlerTest >> testJSONSerializeEncodeBindings [ + | message | + commandFactory bindingAt: #foo put: #(). + message := execHandler buildMessageFromCommand: commandFactory buildCommand. + self assert: (message bindings at: #foo) equals: (execHandler serialize: #()). + self deny: (message bindings at: #foo) = #() +] + +{ #category : #accessing } +PBExcecutionHandlerTest >> testSerializeEncodeBindings [ + | message | + commandFactory bindingAt: #foo put: #(). + message := execHandler buildMessageFromCommand: commandFactory buildCommand. + self assert: (message bindings at: #foo) equals: (execHandler serialize: #()). + self deny: (message bindings at: #foo) = #() +] diff --git a/src/PythonBridge/PBExecutionHandler.class.st b/src/PythonBridge/PBExecutionHandler.class.st index fb58fb1..3389c9a 100644 --- a/src/PythonBridge/PBExecutionHandler.class.st +++ b/src/PythonBridge/PBExecutionHandler.class.st @@ -1,192 +1,192 @@ -Class { - #name : #PBExecutionHandler, - #superclass : #PBHandler, - #instVars : [ - 'commandQueue', - 'weakRegistry', - 'objectRegistry', - 'promiseRegistry', - 'mapperFactory' - ], - #category : #'PythonBridge-Execution' -} - -{ #category : #'private protocol' } -PBExecutionHandler >> buildMessageFromCommand: command [ - | message | - message := PBEnqueueCommandMessage - commandId: command id - statements: command pythonCode - bindings: (command bindings asDictionary collect: [ :obj | self serialize: obj ]). - message addBinding: #pharoCommandId -> (self serialize: command id). - ^ message -] - -{ #category : #'private protocol' } -PBExecutionHandler >> communicationHandler [ - ^ self application communicationHandler -] - -{ #category : #'private protocol' } -PBExecutionHandler >> deserialize: anObject [ - ^ mapperFactory deserializer deserialize: anObject -] - -{ #category : #'private protocol' } -PBExecutionHandler >> getObserverAtCommandId: commandId id: observerId [ - ^ (commandQueue getCommand: commandId) getObserver: observerId -] - -{ #category : #initialization } -PBExecutionHandler >> initialize [ - super initialize. - commandQueue := PBCommandQueue new. - mapperFactory := PBMapperFactory forExecutionHandler: self. - promiseRegistry := PBPromiseRegistry new. - weakRegistry := PBPlatform current weakRegistry. - objectRegistry := PBObjectRegistry new -] - -{ #category : #initialization } -PBExecutionHandler >> initializeHandler [ - self communicationHandler - addHandler: [ :msg | self notifyHandler: msg ] forMessageClass: PBUpdatePromiseMessage; - addHandler: [ :msg | self notifyErrorHandler: msg ] forMessageClass: PBErrorMessage; - addHandler: [ :msg | self notifyCallbackHandler: msg ] forMessageClass: PBCallbackMessage -] - -{ #category : #'private protocol' } -PBExecutionHandler >> mapperFactory [ - ^ mapperFactory -] - -{ #category : #'as yet unclassified' } -PBExecutionHandler >> newCommandFactory [ - ^ PBCommandFactory new - application: self application; - yourself -] - -{ #category : #handlers } -PBExecutionHandler >> notifyCallbackHandler: msg [ - | val serialization | - val := self - signalObserver: (self getObserverAtCommandId: msg commandId id: msg observerId) - withValue: (self deserialize: msg value). - serialization := [ self serialize: val ] on: Error do: [ :err | - self application log: err printString. - self serialize: nil ]. - ^ msg createAnswer - value: serialization; - yourself -] - -{ #category : #handlers } -PBExecutionHandler >> notifyErrorHandler: errorMsg [ - | error | - error := PBPythonError new - application: self application; - command: (commandQueue getCommand: errorMsg commandId); - errorMessage: errorMsg errorMessage; - trace: errorMsg trace; - yourself. - self safeTriggerDebugger: error. - ^ errorMsg createAnswer - handlingAction: error proceedAction; - yourself -] - -{ #category : #handlers } -PBExecutionHandler >> notifyHandler: updatePromiseMsg [ - self - updatePromiseId: updatePromiseMsg promiseId - with: (self deserialize: updatePromiseMsg value) -] - -{ #category : #initialization } -PBExecutionHandler >> objectRegistry [ - ^ objectRegistry -] - -{ #category : #'private protocol' } -PBExecutionHandler >> primitiveSendCommand: command [ - ^ self communicationHandler sendMessage: (self buildMessageFromCommand: command) -] - -{ #category : #'as yet unclassified' } -PBExecutionHandler >> registerObject: aPythonObject [ - objectRegistry registerObject: aPythonObject. - weakRegistry - registerObject: aPythonObject - finalizer: (PBRegistryFinalizer - pythonVariable: aPythonObject pythonVariable - executionHandler: self) -] - -{ #category : #'private protocol' } -PBExecutionHandler >> registerPromiseForCommand: aCommand [ - | promise | - promise := PBPromise new - id: aCommand id; - transformBlock: aCommand transformBlock; - yourself. - aCommand promise: promise. - promiseRegistry addPromise: promise. - ^ promise -] - -{ #category : #'as yet unclassified' } -PBExecutionHandler >> safeTriggerDebugger: error [ - | sem | - sem := Semaphore new. - [ [ self triggerDebugger: error ] ensure: [ sem signal ] ] - on: PBPythonError fork: [ :e | PBPlatform current uiManager spawnDebuggerOnException: e ]. - sem wait. - ^ error proceedAction: error defaultProceedAction -] - -{ #category : #'private protocol' } -PBExecutionHandler >> sendCommand: command [ - | promise | - self assert: command isValid. - commandQueue enqueueCommand: command. - promise := self registerPromiseForCommand: command. - self primitiveSendCommand: command. - ^ promise -] - -{ #category : #'private protocol' } -PBExecutionHandler >> serialize: anObject [ - ^ mapperFactory serializer serialize: anObject -] - -{ #category : #'private protocol' } -PBExecutionHandler >> signalObserver: observer withValue: object [ - ^ observer pharoNotify: object -] - -{ #category : #accessing } -PBExecutionHandler >> stop [ - super stop. - weakRegistry destroy -] - -{ #category : #'as yet unclassified' } -PBExecutionHandler >> triggerDebugger: pythonError [ - "This method is called when an error rised on Python execution." - "Inspect error to review the Command that caused the error. - For ignoring error: - pythonError proceedAction: PBIgnore new - For aborting: - pythonError proceedAction: PBDropQueue new - For replacing the command that caused the error: - pythonError proceedAction: P3ReplaceCommandAction new newCommand: **Your crafted command** - To execute your action you just need to 'Proceed' in the debugger." - pythonError signal. -] - -{ #category : #'private protocol' } -PBExecutionHandler >> updatePromiseId: id with: anObject [ - commandQueue finishCommandId: id. - promiseRegistry removeAndSignalPromiseId: id with: anObject -] +Class { + #name : #PBExecutionHandler, + #superclass : #PBHandler, + #instVars : [ + 'commandQueue', + 'weakRegistry', + 'objectRegistry', + 'promiseRegistry', + 'mapperFactory' + ], + #category : #'PythonBridge-Execution' +} + +{ #category : #'private protocol' } +PBExecutionHandler >> buildMessageFromCommand: command [ + | message | + message := PBEnqueueCommandMessage + commandId: command id + statements: command pythonCode + bindings: (command bindings asDictionary collect: [ :obj | self serialize: obj ]). + message addBinding: #pharoCommandId -> (self serialize: command id). + ^ message +] + +{ #category : #'private protocol' } +PBExecutionHandler >> communicationHandler [ + ^ self application communicationHandler +] + +{ #category : #'private protocol' } +PBExecutionHandler >> deserialize: anObject [ + ^ mapperFactory deserializer deserialize: anObject +] + +{ #category : #'private protocol' } +PBExecutionHandler >> getObserverAtCommandId: commandId id: observerId [ + ^ (commandQueue getCommand: commandId) getObserver: observerId +] + +{ #category : #initialization } +PBExecutionHandler >> initialize [ + super initialize. + commandQueue := PBCommandQueue new. + mapperFactory := PBMapperFactory forExecutionHandler: self. + promiseRegistry := PBPromiseRegistry new. + weakRegistry := PBPlatform current weakRegistry. + objectRegistry := PBObjectRegistry new +] + +{ #category : #initialization } +PBExecutionHandler >> initializeHandler [ + self communicationHandler + addHandler: [ :msg | self notifyHandler: msg ] forMessageClass: PBUpdatePromiseMessage; + addHandler: [ :msg | self notifyErrorHandler: msg ] forMessageClass: PBErrorMessage; + addHandler: [ :msg | self notifyCallbackHandler: msg ] forMessageClass: PBCallbackMessage +] + +{ #category : #'private protocol' } +PBExecutionHandler >> mapperFactory [ + ^ mapperFactory +] + +{ #category : #'as yet unclassified' } +PBExecutionHandler >> newCommandFactory [ + ^ PBCommandFactory new + application: self application; + yourself +] + +{ #category : #handlers } +PBExecutionHandler >> notifyCallbackHandler: msg [ + | val serialization | + val := self + signalObserver: (self getObserverAtCommandId: msg commandId id: msg observerId) + withValue: (self deserialize: msg value). + serialization := [ self serialize: val ] on: Error do: [ :err | + self application log: err printString. + self serialize: nil ]. + ^ msg createAnswer + value: serialization; + yourself +] + +{ #category : #handlers } +PBExecutionHandler >> notifyErrorHandler: errorMsg [ + | error | + error := PBPythonError new + application: self application; + command: (commandQueue getCommand: errorMsg commandId); + errorMessage: errorMsg errorMessage; + trace: errorMsg trace; + yourself. + self safeTriggerDebugger: error. + ^ errorMsg createAnswer + handlingAction: error proceedAction; + yourself +] + +{ #category : #handlers } +PBExecutionHandler >> notifyHandler: updatePromiseMsg [ + self + updatePromiseId: updatePromiseMsg promiseId + with: (self deserialize: updatePromiseMsg value) +] + +{ #category : #initialization } +PBExecutionHandler >> objectRegistry [ + ^ objectRegistry +] + +{ #category : #'private protocol' } +PBExecutionHandler >> primitiveSendCommand: command [ + ^ self communicationHandler sendMessage: (self buildMessageFromCommand: command) +] + +{ #category : #'as yet unclassified' } +PBExecutionHandler >> registerObject: aPythonObject [ + objectRegistry registerObject: aPythonObject. + weakRegistry + registerObject: aPythonObject + finalizer: (PBRegistryFinalizer + pythonVariable: aPythonObject pythonVariable + executionHandler: self) +] + +{ #category : #'private protocol' } +PBExecutionHandler >> registerPromiseForCommand: aCommand [ + | promise | + promise := PBPromise new + id: aCommand id; + transformBlock: aCommand transformBlock; + yourself. + aCommand promise: promise. + promiseRegistry addPromise: promise. + ^ promise +] + +{ #category : #'as yet unclassified' } +PBExecutionHandler >> safeTriggerDebugger: error [ + | sem | + sem := Semaphore new. + [ [ self triggerDebugger: error ] ensure: [ sem signal ] ] + on: PBPythonError fork: [ :e | PBPlatform current uiManager spawnDebuggerOnException: e ]. + sem wait. + ^ error proceedAction: error defaultProceedAction +] + +{ #category : #'private protocol' } +PBExecutionHandler >> sendCommand: command [ + | promise | + self assert: command isValid. + commandQueue enqueueCommand: command. + promise := self registerPromiseForCommand: command. + self primitiveSendCommand: command. + ^ promise +] + +{ #category : #'private protocol' } +PBExecutionHandler >> serialize: anObject [ + ^ mapperFactory serializer serialize: anObject +] + +{ #category : #'private protocol' } +PBExecutionHandler >> signalObserver: observer withValue: object [ + ^ observer pharoNotify: object +] + +{ #category : #accessing } +PBExecutionHandler >> stop [ + super stop. + weakRegistry destroy +] + +{ #category : #'as yet unclassified' } +PBExecutionHandler >> triggerDebugger: pythonError [ + "This method is called when an error rised on Python execution." + "Inspect error to review the Command that caused the error. + For ignoring error: + pythonError proceedAction: PBIgnore new + For aborting: + pythonError proceedAction: PBDropQueue new + For replacing the command that caused the error: + pythonError proceedAction: P3ReplaceCommandAction new newCommand: **Your crafted command** + To execute your action you just need to 'Proceed' in the debugger." + pythonError signal. +] + +{ #category : #'private protocol' } +PBExecutionHandler >> updatePromiseId: id with: anObject [ + commandQueue finishCommandId: id. + promiseRegistry removeAndSignalPromiseId: id with: anObject +] diff --git a/src/PythonBridge/PBFatalErrorLog.class.st b/src/PythonBridge/PBFatalErrorLog.class.st index 9097e76..dfcde82 100644 --- a/src/PythonBridge/PBFatalErrorLog.class.st +++ b/src/PythonBridge/PBFatalErrorLog.class.st @@ -1,5 +1,5 @@ -Class { - #name : #PBFatalErrorLog, - #superclass : #PBErrorLog, - #category : #'PythonBridge-Logs' -} +Class { + #name : #PBFatalErrorLog, + #superclass : #PBErrorLog, + #category : #'PythonBridge-Logs' +} diff --git a/src/PythonBridge/PBHandler.class.st b/src/PythonBridge/PBHandler.class.st index ce950af..0894a2e 100644 --- a/src/PythonBridge/PBHandler.class.st +++ b/src/PythonBridge/PBHandler.class.st @@ -1,43 +1,43 @@ -Class { - #name : #PBHandler, - #superclass : #Object, - #instVars : [ - 'application' - ], - #category : #'PythonBridge-Core' -} - -{ #category : #'as yet unclassified' } -PBHandler class >> application: anApplication [ - ^ self new - application: anApplication; - initializeHandler; - yourself -] - -{ #category : #accessing } -PBHandler >> application [ - ^ application -] - -{ #category : #accessing } -PBHandler >> application: anObject [ - application := anObject -] - -{ #category : #initialization } -PBHandler >> initializeHandler [ -] - -{ #category : #testing } -PBHandler >> isRunning [ - ^ true -] - -{ #category : #accessing } -PBHandler >> start [ -] - -{ #category : #accessing } -PBHandler >> stop [ -] +Class { + #name : #PBHandler, + #superclass : #Object, + #instVars : [ + 'application' + ], + #category : #'PythonBridge-Core' +} + +{ #category : #'as yet unclassified' } +PBHandler class >> application: anApplication [ + ^ self new + application: anApplication; + initializeHandler; + yourself +] + +{ #category : #accessing } +PBHandler >> application [ + ^ application +] + +{ #category : #accessing } +PBHandler >> application: anObject [ + application := anObject +] + +{ #category : #initialization } +PBHandler >> initializeHandler [ +] + +{ #category : #testing } +PBHandler >> isRunning [ + ^ true +] + +{ #category : #accessing } +PBHandler >> start [ +] + +{ #category : #accessing } +PBHandler >> stop [ +] diff --git a/src/PythonBridge/PBIgnore.class.st b/src/PythonBridge/PBIgnore.class.st index ea40057..da08714 100644 --- a/src/PythonBridge/PBIgnore.class.st +++ b/src/PythonBridge/PBIgnore.class.st @@ -1,10 +1,10 @@ -Class { - #name : #PBIgnore, - #superclass : #PBErrorHandlingAction, - #category : #'PythonBridge-ErrorHandling' -} - -{ #category : #'as yet unclassified' } -PBIgnore >> actionSymbol [ - ^ #'IGNORE' -] +Class { + #name : #PBIgnore, + #superclass : #PBErrorHandlingAction, + #category : #'PythonBridge-ErrorHandling' +} + +{ #category : #'as yet unclassified' } +PBIgnore >> actionSymbol [ + ^ #'IGNORE' +] diff --git a/src/PythonBridge/PBIsAliveMessage.class.st b/src/PythonBridge/PBIsAliveMessage.class.st index d00676c..8f49514 100644 --- a/src/PythonBridge/PBIsAliveMessage.class.st +++ b/src/PythonBridge/PBIsAliveMessage.class.st @@ -1,15 +1,15 @@ -Class { - #name : #PBIsAliveMessage, - #superclass : #PBSyncMessage, - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #accessing } -PBIsAliveMessage class >> answerClass [ - ^ PBAnswer -] - -{ #category : #accessing } -PBIsAliveMessage class >> type [ - ^ #IS_ALIVE -] +Class { + #name : #PBIsAliveMessage, + #superclass : #PBSyncMessage, + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #accessing } +PBIsAliveMessage class >> answerClass [ + ^ PBAnswer +] + +{ #category : #accessing } +PBIsAliveMessage class >> type [ + ^ #IS_ALIVE +] diff --git a/src/PythonBridge/PBJsonSerializerTest.class.st b/src/PythonBridge/PBJsonSerializerTest.class.st index 99e344e..c135e4a 100644 --- a/src/PythonBridge/PBJsonSerializerTest.class.st +++ b/src/PythonBridge/PBJsonSerializerTest.class.st @@ -1,64 +1,64 @@ -Class { - #name : #PBJsonSerializerTest, - #superclass : #TestCase, - #instVars : [ - 'serializer' - ], - #category : #'PythonBridge-Platform' -} - -{ #category : #testing } -PBJsonSerializerTest class >> isAbstract [ - ^ self == PBJsonSerializerTest -] - -{ #category : #asserting } -PBJsonSerializerTest >> assertDeserialize: aString equals: anObject [ - self assert: (serializer deserialize: aString) equals: anObject -] - -{ #category : #asserting } -PBJsonSerializerTest >> assertSerialize: anObject equals: aString [ - self assert: (serializer serialize: anObject) equals: aString -] - -{ #category : #running } -PBJsonSerializerTest >> jsonSerializerClass [ - self subclassResponsibility -] - -{ #category : #running } -PBJsonSerializerTest >> setUp [ - super setUp. - serializer := self jsonSerializerClass new -] - -{ #category : #tests } -PBJsonSerializerTest >> testDeserializeArray [ - self assertDeserialize: '[33,"foo"]' equals: #(33 'foo') -] - -{ #category : #tests } -PBJsonSerializerTest >> testDeserializeNestedArrays [ - self assertDeserialize: '[33,["foo","bar"]]' equals: #(33 #('foo' 'bar')) -] - -{ #category : #tests } -PBJsonSerializerTest >> testDeserializeNil [ - self assertDeserialize: 'null' equals: nil -] - -{ #category : #tests } -PBJsonSerializerTest >> testSerializeArray [ - self assertSerialize: #(33 'foo') equals: '[33,"foo"]' -] - -{ #category : #tests } -PBJsonSerializerTest >> testSerializeNestedArrays [ - self assertSerialize: #(33 #('foo' 'bar')) equals: '[33,["foo","bar"]]' -] - -{ #category : #tests } -PBJsonSerializerTest >> testSerializeNil [ - self assertSerialize: nil equals: 'null' -] +Class { + #name : #PBJsonSerializerTest, + #superclass : #TestCase, + #instVars : [ + 'serializer' + ], + #category : #'PythonBridge-Platform' +} + +{ #category : #testing } +PBJsonSerializerTest class >> isAbstract [ + ^ self == PBJsonSerializerTest +] + +{ #category : #asserting } +PBJsonSerializerTest >> assertDeserialize: aString equals: anObject [ + self assert: (serializer deserialize: aString) equals: anObject +] + +{ #category : #asserting } +PBJsonSerializerTest >> assertSerialize: anObject equals: aString [ + self assert: (serializer serialize: anObject) equals: aString +] + +{ #category : #running } +PBJsonSerializerTest >> jsonSerializerClass [ + self subclassResponsibility +] + +{ #category : #running } +PBJsonSerializerTest >> setUp [ + super setUp. + serializer := self jsonSerializerClass new +] + +{ #category : #tests } +PBJsonSerializerTest >> testDeserializeArray [ + self assertDeserialize: '[33,"foo"]' equals: #(33 'foo') +] + +{ #category : #tests } +PBJsonSerializerTest >> testDeserializeNestedArrays [ + self assertDeserialize: '[33,["foo","bar"]]' equals: #(33 #('foo' 'bar')) +] + +{ #category : #tests } +PBJsonSerializerTest >> testDeserializeNil [ + self assertDeserialize: 'null' equals: nil +] + +{ #category : #tests } +PBJsonSerializerTest >> testSerializeArray [ + self assertSerialize: #(33 'foo') equals: '[33,"foo"]' +] + +{ #category : #tests } +PBJsonSerializerTest >> testSerializeNestedArrays [ + self assertSerialize: #(33 #('foo' 'bar')) equals: '[33,["foo","bar"]]' +] + +{ #category : #tests } +PBJsonSerializerTest >> testSerializeNil [ + self assertSerialize: nil equals: 'null' +] diff --git a/src/PythonBridge/PBLog.class.st b/src/PythonBridge/PBLog.class.st index 43f491e..3d18f6c 100644 --- a/src/PythonBridge/PBLog.class.st +++ b/src/PythonBridge/PBLog.class.st @@ -1,42 +1,42 @@ -Class { - #name : #PBLog, - #superclass : #Object, - #instVars : [ - 'message' - ], - #category : #'PythonBridge-Logs' -} - -{ #category : #accessing } -PBLog class >> message: aString [ - ^ self new - message: aString; - yourself -] - -{ #category : #testing } -PBLog >> isError [ - ^ false -] - -{ #category : #accessing } -PBLog >> message [ - ^ message -] - -{ #category : #accessing } -PBLog >> message: anObject [ - message := anObject -] - -{ #category : #printing } -PBLog >> printOn: str [ - message - ifNil: [ super printOn: str ] - ifNotNil: [ - str - << self class name; - << ': '; - << message; - cr ] -] +Class { + #name : #PBLog, + #superclass : #Object, + #instVars : [ + 'message' + ], + #category : #'PythonBridge-Logs' +} + +{ #category : #accessing } +PBLog class >> message: aString [ + ^ self new + message: aString; + yourself +] + +{ #category : #testing } +PBLog >> isError [ + ^ false +] + +{ #category : #accessing } +PBLog >> message [ + ^ message +] + +{ #category : #accessing } +PBLog >> message: anObject [ + message := anObject +] + +{ #category : #printing } +PBLog >> printOn: str [ + message + ifNil: [ super printOn: str ] + ifNotNil: [ + str + << self class name; + << ': '; + << message; + cr ] +] diff --git a/src/PythonBridge/PBLoggingHandler.class.st b/src/PythonBridge/PBLoggingHandler.class.st index 73da321..50eb56b 100644 --- a/src/PythonBridge/PBLoggingHandler.class.st +++ b/src/PythonBridge/PBLoggingHandler.class.st @@ -1,29 +1,29 @@ -Class { - #name : #PBLoggingHandler, - #superclass : #PBHandler, - #instVars : [ - 'logs' - ], - #category : #'PythonBridge-Core' -} - -{ #category : #accessing } -PBLoggingHandler >> errorLogs [ - ^ logs select: #isError -] - -{ #category : #initialization } -PBLoggingHandler >> initialize [ - super initialize. - logs := OrderedCollection new -] - -{ #category : #log } -PBLoggingHandler >> log: aLog [ - logs add: aLog -] - -{ #category : #accessing } -PBLoggingHandler >> logs [ - ^ logs -] +Class { + #name : #PBLoggingHandler, + #superclass : #PBHandler, + #instVars : [ + 'logs' + ], + #category : #'PythonBridge-Core' +} + +{ #category : #accessing } +PBLoggingHandler >> errorLogs [ + ^ logs select: #isError +] + +{ #category : #initialization } +PBLoggingHandler >> initialize [ + super initialize. + logs := OrderedCollection new +] + +{ #category : #log } +PBLoggingHandler >> log: aLog [ + logs add: aLog +] + +{ #category : #accessing } +PBLoggingHandler >> logs [ + ^ logs +] diff --git a/src/PythonBridge/PBLoggingHandlerTest.class.st b/src/PythonBridge/PBLoggingHandlerTest.class.st index cfec1f7..e492716 100644 --- a/src/PythonBridge/PBLoggingHandlerTest.class.st +++ b/src/PythonBridge/PBLoggingHandlerTest.class.st @@ -1,32 +1,32 @@ -Class { - #name : #PBLoggingHandlerTest, - #superclass : #TestCase, - #instVars : [ - 'logger' - ], - #category : #'PythonBridge-Tests' -} - -{ #category : #'as yet unclassified' } -PBLoggingHandlerTest >> logs [ - ^ logger logs -] - -{ #category : #initialization } -PBLoggingHandlerTest >> setUp [ - logger := PBLoggingHandler new -] - -{ #category : #tests } -PBLoggingHandlerTest >> testAddLog [ - logger log: (PBLog message: 'Foo'). - self assert: logger logs first message equals: 'Foo' -] - -{ #category : #tests } -PBLoggingHandlerTest >> testErrorLog [ - logger log: (PBLog message: 'Foo'). - self assert: logger errorLogs isEmpty. - logger log: (PBErrorLog message: 'Bar'). - self assert: logger errorLogs first message equals: 'Bar'. -] +Class { + #name : #PBLoggingHandlerTest, + #superclass : #TestCase, + #instVars : [ + 'logger' + ], + #category : #'PythonBridge-Tests' +} + +{ #category : #'as yet unclassified' } +PBLoggingHandlerTest >> logs [ + ^ logger logs +] + +{ #category : #initialization } +PBLoggingHandlerTest >> setUp [ + logger := PBLoggingHandler new +] + +{ #category : #tests } +PBLoggingHandlerTest >> testAddLog [ + logger log: (PBLog message: 'Foo'). + self assert: logger logs first message equals: 'Foo' +] + +{ #category : #tests } +PBLoggingHandlerTest >> testErrorLog [ + logger log: (PBLog message: 'Foo'). + self assert: logger errorLogs isEmpty. + logger log: (PBErrorLog message: 'Bar'). + self assert: logger errorLogs first message equals: 'Bar'. +] diff --git a/src/PythonBridge/PBMapper.class.st b/src/PythonBridge/PBMapper.class.st index 12086fe..2060bf2 100644 --- a/src/PythonBridge/PBMapper.class.st +++ b/src/PythonBridge/PBMapper.class.st @@ -1,60 +1,60 @@ -Class { - #name : #PBMapper, - #superclass : #Object, - #instVars : [ - 'mappings', - 'serializerWrapper', - 'executionHandler', - 'application' - ], - #category : #'PythonBridge-Serialization' -} - -{ #category : #'as yet unclassified' } -PBMapper class >> mappings: mappings executionHandler: handler [ - ^ self new - mappings: mappings; - executionHandler: handler; - yourself -] - -{ #category : #accessing } -PBMapper >> application [ - ^ executionHandler application -] - -{ #category : #accessing } -PBMapper >> application: anObject [ - application := anObject -] - -{ #category : #accessing } -PBMapper >> executionHandler [ - ^ executionHandler -] - -{ #category : #accessing } -PBMapper >> executionHandler: anObject [ - executionHandler := anObject -] - -{ #category : #initialization } -PBMapper >> initialize [ - super initialize. - serializerWrapper := PBPlatform current serializer -] - -{ #category : #accessing } -PBMapper >> mappings [ - ^ mappings -] - -{ #category : #accessing } -PBMapper >> mappings: anObject [ - mappings := anObject -] - -{ #category : #accessing } -PBMapper >> serializerWrapper: anObject [ - serializerWrapper := anObject -] +Class { + #name : #PBMapper, + #superclass : #Object, + #instVars : [ + 'mappings', + 'serializerWrapper', + 'executionHandler', + 'application' + ], + #category : #'PythonBridge-Serialization' +} + +{ #category : #'as yet unclassified' } +PBMapper class >> mappings: mappings executionHandler: handler [ + ^ self new + mappings: mappings; + executionHandler: handler; + yourself +] + +{ #category : #accessing } +PBMapper >> application [ + ^ executionHandler application +] + +{ #category : #accessing } +PBMapper >> application: anObject [ + application := anObject +] + +{ #category : #accessing } +PBMapper >> executionHandler [ + ^ executionHandler +] + +{ #category : #accessing } +PBMapper >> executionHandler: anObject [ + executionHandler := anObject +] + +{ #category : #initialization } +PBMapper >> initialize [ + super initialize. + serializerWrapper := PBPlatform current serializer +] + +{ #category : #accessing } +PBMapper >> mappings [ + ^ mappings +] + +{ #category : #accessing } +PBMapper >> mappings: anObject [ + mappings := anObject +] + +{ #category : #accessing } +PBMapper >> serializerWrapper: anObject [ + serializerWrapper := anObject +] diff --git a/src/PythonBridge/PBMapperFactory.class.st b/src/PythonBridge/PBMapperFactory.class.st index b2890b5..8bbb7f4 100644 --- a/src/PythonBridge/PBMapperFactory.class.st +++ b/src/PythonBridge/PBMapperFactory.class.st @@ -1,58 +1,58 @@ -Class { - #name : #PBMapperFactory, - #superclass : #Object, - #instVars : [ - 'executionHandler', - 'serializationMappings', - 'deserializationMappings' - ], - #category : #'PythonBridge-Serialization' -} - -{ #category : #'as yet unclassified' } -PBMapperFactory class >> forExecutionHandler: handler [ - ^ self new - executionHandler: handler; - yourself -] - -{ #category : #initialization } -PBMapperFactory >> deserializer [ - ^ self deserializerClass - mappings: serializationMappings - executionHandler: executionHandler -] - -{ #category : #initialization } -PBMapperFactory >> deserializerClass [ - ^ PBDeserializer -] - -{ #category : #accessing } -PBMapperFactory >> executionHandler [ - ^ executionHandler -] - -{ #category : #accessing } -PBMapperFactory >> executionHandler: anObject [ - executionHandler := anObject -] - -{ #category : #initialization } -PBMapperFactory >> initialize [ - super initialize. - serializationMappings := OrderedCollection new. - deserializationMappings := OrderedCollection new -] - -{ #category : #initialization } -PBMapperFactory >> serializer [ - ^ self serializerClass - mappings: serializationMappings - executionHandler: executionHandler -] - -{ #category : #initialization } -PBMapperFactory >> serializerClass [ - ^ PBSerializer -] +Class { + #name : #PBMapperFactory, + #superclass : #Object, + #instVars : [ + 'executionHandler', + 'serializationMappings', + 'deserializationMappings' + ], + #category : #'PythonBridge-Serialization' +} + +{ #category : #'as yet unclassified' } +PBMapperFactory class >> forExecutionHandler: handler [ + ^ self new + executionHandler: handler; + yourself +] + +{ #category : #initialization } +PBMapperFactory >> deserializer [ + ^ self deserializerClass + mappings: serializationMappings + executionHandler: executionHandler +] + +{ #category : #initialization } +PBMapperFactory >> deserializerClass [ + ^ PBDeserializer +] + +{ #category : #accessing } +PBMapperFactory >> executionHandler [ + ^ executionHandler +] + +{ #category : #accessing } +PBMapperFactory >> executionHandler: anObject [ + executionHandler := anObject +] + +{ #category : #initialization } +PBMapperFactory >> initialize [ + super initialize. + serializationMappings := OrderedCollection new. + deserializationMappings := OrderedCollection new +] + +{ #category : #initialization } +PBMapperFactory >> serializer [ + ^ self serializerClass + mappings: serializationMappings + executionHandler: executionHandler +] + +{ #category : #initialization } +PBMapperFactory >> serializerClass [ + ^ PBSerializer +] diff --git a/src/PythonBridge/PBMapping.class.st b/src/PythonBridge/PBMapping.class.st index 77f3944..032d1c5 100644 --- a/src/PythonBridge/PBMapping.class.st +++ b/src/PythonBridge/PBMapping.class.st @@ -1,5 +1,5 @@ -Class { - #name : #PBMapping, - #superclass : #Object, - #category : #'PythonBridge-Serialization' -} +Class { + #name : #PBMapping, + #superclass : #Object, + #category : #'PythonBridge-Serialization' +} diff --git a/src/PythonBridge/PBMessage.class.st b/src/PythonBridge/PBMessage.class.st index a67d4f2..1bfd6a2 100644 --- a/src/PythonBridge/PBMessage.class.st +++ b/src/PythonBridge/PBMessage.class.st @@ -1,35 +1,35 @@ -Class { - #name : #PBMessage, - #superclass : #PBAbstractMessage, - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #testing } -PBMessage class >> isReverseMessage [ - "Reverse messages corresponds to messages that start on Python to Pharo. In other words - in reverse direction from normal messages." - ^ false -] - -{ #category : #accessing } -PBMessage class >> type [ - ^ #MSG -] - -{ #category : #encoding } -PBMessage >> encode [ - | dict | - dict := Dictionary new. - dict at: #type put: self type. - self privateEncode: dict. - ^ dict -] - -{ #category : #testing } -PBMessage >> isSync [ - self subclassResponsibility -] - -{ #category : #encoding } -PBMessage >> privateEncode: dict [ -] +Class { + #name : #PBMessage, + #superclass : #PBAbstractMessage, + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #testing } +PBMessage class >> isReverseMessage [ + "Reverse messages corresponds to messages that start on Python to Pharo. In other words + in reverse direction from normal messages." + ^ false +] + +{ #category : #accessing } +PBMessage class >> type [ + ^ #MSG +] + +{ #category : #encoding } +PBMessage >> encode [ + | dict | + dict := Dictionary new. + dict at: #type put: self type. + self privateEncode: dict. + ^ dict +] + +{ #category : #testing } +PBMessage >> isSync [ + self subclassResponsibility +] + +{ #category : #encoding } +PBMessage >> privateEncode: dict [ +] diff --git a/src/PythonBridge/PBMessageBrokerTest.class.st b/src/PythonBridge/PBMessageBrokerTest.class.st index 04064bf..93ccbb5 100644 --- a/src/PythonBridge/PBMessageBrokerTest.class.st +++ b/src/PythonBridge/PBMessageBrokerTest.class.st @@ -1,271 +1,271 @@ -Class { - #name : #PBMessageBrokerTest, - #superclass : #TestCase, - #instVars : [ - 'broker', - 'handlerBlock', - 'handlerException', - 'settings' - ], - #category : #'PythonBridge-Platform' -} - -{ #category : #testing } -PBMessageBrokerTest class >> isAbstract [ - ^ self == PBMessageBrokerTest -] - -{ #category : #accessing } -PBMessageBrokerTest >> answer: aDictionary [ - self subclassResponsibility -] - -{ #category : #utils } -PBMessageBrokerTest >> assertCommunicationError: aBlock [ - self should: aBlock raise: PBCommunicationError -] - -{ #category : #accessing } -PBMessageBrokerTest >> brokerUri [ - ^ 'http://' , settings pharoSocketAddress printAddress -] - -{ #category : #initialization } -PBMessageBrokerTest >> buildAndStartStubServer [ - self subclassResponsibility -] - -{ #category : #running } -PBMessageBrokerTest >> defaultSettings [ - ^ PBSettings - pharoSocketAddress: (PBSocketAddress ipOrName: 'localhost' port: 6538) - pythonSocketAddress: (PBSocketAddress ipOrName: 'localhost' port: 6539) -] - -{ #category : #utils } -PBMessageBrokerTest >> errorResponse [ -] - -{ #category : #hooks } -PBMessageBrokerTest >> for: messageClass setCallback: aBlock [ - ^ broker addCallback: aBlock messageClass: messageClass -] - -{ #category : #initialization } -PBMessageBrokerTest >> initialize [ - super initialize. - handlerBlock := [ :r | ] -] - -{ #category : #hooks } -PBMessageBrokerTest >> messageBrokerClass [ - self subclassResponsibility -] - -{ #category : #accessing } -PBMessageBrokerTest >> pythonUri [ - ^ 'http://' , settings pythonSocketAddress printAddress -] - -{ #category : #utils } -PBMessageBrokerTest >> sendMessageToBroker: dict [ - self subclassResponsibility -] - -{ #category : #utils } -PBMessageBrokerTest >> sendMessageToBroker: dict answerBlock: aBlock [ - self subclassResponsibility -] - -{ #category : #utils } -PBMessageBrokerTest >> sendMessageToBroker: dict answerEquals: ansDict [ - | flag | - flag := false. - self sendMessageToBroker: dict answerBlock: [ :ansAssoc | - flag := true. - self assert: ansAssoc value equals: ansDict ]. - self assert: flag -] - -{ #category : #accessing } -PBMessageBrokerTest >> setHandler: aBlock [ - handlerBlock := aBlock -] - -{ #category : #running } -PBMessageBrokerTest >> setUp [ - super setUp. - settings := self defaultSettings. - broker := self messageBrokerClass settings: settings. - broker start. - self buildAndStartStubServer. - self sleepAWhile -] - -{ #category : #utils } -PBMessageBrokerTest >> sleepAWhile [ - "Sleeping for a while so the async message has a chance to perform a change." - self subclassResponsibility -] - -{ #category : #running } -PBMessageBrokerTest >> stopStubServer [ - self subclassResponsibility -] - -{ #category : #running } -PBMessageBrokerTest >> tearDown [ - broker ifNotNil: [ broker stop ]. - self stopStubServer -] - -{ #category : #tests } -PBMessageBrokerTest >> testEnqueueCommandMessage [ - | flag msg | - flag := false. - msg := PBEnqueueCommandMessage - commandId: '7365' - statements: 'foo().cat()' - bindings: { #foo -> 42 . #bar -> 'zork' } asDictionary. - self setHandler: [ :assoc | | bindings | - self assert: assoc key equals: PBEnqueueCommandMessage type. - self assert: assoc value size equals: 4. - self assert: (assoc value at: 'type') equals: PBEnqueueCommandMessage type. - self assert: (assoc value at: 'commandId') equals: '7365'. - self assert: (assoc value at: 'statements') equals: 'foo().cat()'. - bindings := assoc value at: 'bindings'. - self assert: bindings size equals: 2. - self assert: (bindings at: 'foo') equals: 42. - self assert: (bindings at: 'bar') equals: 'zork'. - flag := true ]. - broker sendMessage: msg. - self sleepAWhile. - self assert: flag -] - -{ #category : #tests } -PBMessageBrokerTest >> testErrorOnCallback [ - | flag | - flag := false. - self for: PBRSyncMessage setCallback: [ :msg | - Error signal. - flag := true ]. - self assertCommunicationError: [ - self - sendMessageToBroker: { - #type -> PBRSyncMessage type. - #__sync -> 'foobar' } asDictionary - answerBlock: [ ] ]. - self deny: flag -] - -{ #category : #tests } -PBMessageBrokerTest >> testEvalAnswer [ - | flag | - flag := false. - self for: PBUpdatePromiseMessage setCallback: [ :msg | - self assert: msg type equals: PBUpdatePromiseMessage type. - self assert: msg value equals: 'foobar'. - self assert: msg promiseId equals: '4fcb36d'. - flag := true ]. - self sendMessageToBroker: { - #type -> PBUpdatePromiseMessage type. - #id -> '4fcb36d'. - #value -> 'foobar' } asDictionary. - self assert: flag -] - -{ #category : #tests } -PBMessageBrokerTest >> testIsAliveMessage [ - | flag msg | - flag := false. - self setHandler: [ :assoc | - self assert: assoc key equals: PBIsAliveMessage type. - self assert: assoc value associations size equals: 2. - self assert: (assoc value at: #type) equals: PBIsAliveMessage type. - self assert: (assoc value at: #__sync) equals: msg syncId. - flag := true. - self answer: { #type -> PBIsAliveMessage type. #__sync -> msg syncId } asDictionary ]. - msg := PBIsAliveMessage new. - broker sendMessage: msg. - self assert: flag -] - -{ #category : #tests } -PBMessageBrokerTest >> testIsRunning [ - self assert: broker isRunning -] - -{ #category : #tests } -PBMessageBrokerTest >> testRMessageWithParams [ - | flag | - flag := false. - self for: PBCallbackMessage setCallback: [ :msg | - flag := true. - self assert: msg type equals: PBCallbackMessage type. - self assert: msg commandId equals: 10. - self assert: msg observerId equals: 'foo'. - self assert: msg value equals: 'lalala'. - self assert: msg syncId equals: 'zork'. - msg createAnswer - value: 13; - yourself ]. - self - sendMessageToBroker: { - #type -> PBCallbackMessage type. - #commandId -> 10. - #observerId -> 'foo'. - #value -> 'lalala'. - #__sync -> 'zork' } asDictionary - answerEquals: { - #type -> PBCallbackMessage type. - #value -> 13. - #__sync -> 'zork' } asDictionary. - self assert: flag. -] - -{ #category : #tests } -PBMessageBrokerTest >> testRSyncMessage [ - | flag | - flag := false. - self for: PBRSyncMessage setCallback: [ :msg | - flag := true. - msg createAnswer ]. - self - sendMessageToBroker: { - #type -> PBRSyncMessage type. - #__sync -> 'foobar' } asDictionary - answerEquals: { - #type -> PBRSyncMessage type. - #__sync -> 'foobar' } asDictionary. - self assert: flag. -] - -{ #category : #tests } -PBMessageBrokerTest >> testSyncMessage [ - | flag msg ans | - flag := false. - self setHandler: [ :assoc | - self assert: assoc key equals: PBSyncMessage type. - self assert: assoc value associations size equals: 2. - self assert: (assoc value at: #type) equals: PBSyncMessage type. - self assert: (assoc value at: #__sync) equals: msg syncId. - flag := true. - self answer: { #type -> PBSyncMessage type . #__sync -> msg syncId } asDictionary ]. - msg := PBSyncMessage new. - ans := broker sendMessage: msg. - self assert: ans message equals: msg. - self assert: flag -] - -{ #category : #tests } -PBMessageBrokerTest >> testWrongRouteAnswer [ - | flag | - flag := false. - self for: PBCallbackMessage setCallback: [ :dict | - flag := true ]. - self assertCommunicationError: [ self sendMessageToBroker: { - #type -> PBRSyncMessage type. - #__sync -> 'foobar' } asDictionary ]. - self deny: flag -] +Class { + #name : #PBMessageBrokerTest, + #superclass : #TestCase, + #instVars : [ + 'broker', + 'handlerBlock', + 'handlerException', + 'settings' + ], + #category : #'PythonBridge-Platform' +} + +{ #category : #testing } +PBMessageBrokerTest class >> isAbstract [ + ^ self == PBMessageBrokerTest +] + +{ #category : #accessing } +PBMessageBrokerTest >> answer: aDictionary [ + self subclassResponsibility +] + +{ #category : #utils } +PBMessageBrokerTest >> assertCommunicationError: aBlock [ + self should: aBlock raise: PBCommunicationError +] + +{ #category : #accessing } +PBMessageBrokerTest >> brokerUri [ + ^ 'http://' , settings pharoSocketAddress printAddress +] + +{ #category : #initialization } +PBMessageBrokerTest >> buildAndStartStubServer [ + self subclassResponsibility +] + +{ #category : #running } +PBMessageBrokerTest >> defaultSettings [ + ^ PBSettings + pharoSocketAddress: (PBSocketAddress ipOrName: 'localhost' port: 6538) + pythonSocketAddress: (PBSocketAddress ipOrName: 'localhost' port: 6539) +] + +{ #category : #utils } +PBMessageBrokerTest >> errorResponse [ +] + +{ #category : #hooks } +PBMessageBrokerTest >> for: messageClass setCallback: aBlock [ + ^ broker addCallback: aBlock messageClass: messageClass +] + +{ #category : #initialization } +PBMessageBrokerTest >> initialize [ + super initialize. + handlerBlock := [ :r | ] +] + +{ #category : #hooks } +PBMessageBrokerTest >> messageBrokerClass [ + self subclassResponsibility +] + +{ #category : #accessing } +PBMessageBrokerTest >> pythonUri [ + ^ 'http://' , settings pythonSocketAddress printAddress +] + +{ #category : #utils } +PBMessageBrokerTest >> sendMessageToBroker: dict [ + self subclassResponsibility +] + +{ #category : #utils } +PBMessageBrokerTest >> sendMessageToBroker: dict answerBlock: aBlock [ + self subclassResponsibility +] + +{ #category : #utils } +PBMessageBrokerTest >> sendMessageToBroker: dict answerEquals: ansDict [ + | flag | + flag := false. + self sendMessageToBroker: dict answerBlock: [ :ansAssoc | + flag := true. + self assert: ansAssoc value equals: ansDict ]. + self assert: flag +] + +{ #category : #accessing } +PBMessageBrokerTest >> setHandler: aBlock [ + handlerBlock := aBlock +] + +{ #category : #running } +PBMessageBrokerTest >> setUp [ + super setUp. + settings := self defaultSettings. + broker := self messageBrokerClass settings: settings. + broker start. + self buildAndStartStubServer. + self sleepAWhile +] + +{ #category : #utils } +PBMessageBrokerTest >> sleepAWhile [ + "Sleeping for a while so the async message has a chance to perform a change." + self subclassResponsibility +] + +{ #category : #running } +PBMessageBrokerTest >> stopStubServer [ + self subclassResponsibility +] + +{ #category : #running } +PBMessageBrokerTest >> tearDown [ + broker ifNotNil: [ broker stop ]. + self stopStubServer +] + +{ #category : #tests } +PBMessageBrokerTest >> testEnqueueCommandMessage [ + | flag msg | + flag := false. + msg := PBEnqueueCommandMessage + commandId: '7365' + statements: 'foo().cat()' + bindings: { #foo -> 42 . #bar -> 'zork' } asDictionary. + self setHandler: [ :assoc | | bindings | + self assert: assoc key equals: PBEnqueueCommandMessage type. + self assert: assoc value size equals: 4. + self assert: (assoc value at: 'type') equals: PBEnqueueCommandMessage type. + self assert: (assoc value at: 'commandId') equals: '7365'. + self assert: (assoc value at: 'statements') equals: 'foo().cat()'. + bindings := assoc value at: 'bindings'. + self assert: bindings size equals: 2. + self assert: (bindings at: 'foo') equals: 42. + self assert: (bindings at: 'bar') equals: 'zork'. + flag := true ]. + broker sendMessage: msg. + self sleepAWhile. + self assert: flag +] + +{ #category : #tests } +PBMessageBrokerTest >> testErrorOnCallback [ + | flag | + flag := false. + self for: PBRSyncMessage setCallback: [ :msg | + Error signal. + flag := true ]. + self assertCommunicationError: [ + self + sendMessageToBroker: { + #type -> PBRSyncMessage type. + #__sync -> 'foobar' } asDictionary + answerBlock: [ ] ]. + self deny: flag +] + +{ #category : #tests } +PBMessageBrokerTest >> testEvalAnswer [ + | flag | + flag := false. + self for: PBUpdatePromiseMessage setCallback: [ :msg | + self assert: msg type equals: PBUpdatePromiseMessage type. + self assert: msg value equals: 'foobar'. + self assert: msg promiseId equals: '4fcb36d'. + flag := true ]. + self sendMessageToBroker: { + #type -> PBUpdatePromiseMessage type. + #id -> '4fcb36d'. + #value -> 'foobar' } asDictionary. + self assert: flag +] + +{ #category : #tests } +PBMessageBrokerTest >> testIsAliveMessage [ + | flag msg | + flag := false. + self setHandler: [ :assoc | + self assert: assoc key equals: PBIsAliveMessage type. + self assert: assoc value associations size equals: 2. + self assert: (assoc value at: #type) equals: PBIsAliveMessage type. + self assert: (assoc value at: #__sync) equals: msg syncId. + flag := true. + self answer: { #type -> PBIsAliveMessage type. #__sync -> msg syncId } asDictionary ]. + msg := PBIsAliveMessage new. + broker sendMessage: msg. + self assert: flag +] + +{ #category : #tests } +PBMessageBrokerTest >> testIsRunning [ + self assert: broker isRunning +] + +{ #category : #tests } +PBMessageBrokerTest >> testRMessageWithParams [ + | flag | + flag := false. + self for: PBCallbackMessage setCallback: [ :msg | + flag := true. + self assert: msg type equals: PBCallbackMessage type. + self assert: msg commandId equals: 10. + self assert: msg observerId equals: 'foo'. + self assert: msg value equals: 'lalala'. + self assert: msg syncId equals: 'zork'. + msg createAnswer + value: 13; + yourself ]. + self + sendMessageToBroker: { + #type -> PBCallbackMessage type. + #commandId -> 10. + #observerId -> 'foo'. + #value -> 'lalala'. + #__sync -> 'zork' } asDictionary + answerEquals: { + #type -> PBCallbackMessage type. + #value -> 13. + #__sync -> 'zork' } asDictionary. + self assert: flag. +] + +{ #category : #tests } +PBMessageBrokerTest >> testRSyncMessage [ + | flag | + flag := false. + self for: PBRSyncMessage setCallback: [ :msg | + flag := true. + msg createAnswer ]. + self + sendMessageToBroker: { + #type -> PBRSyncMessage type. + #__sync -> 'foobar' } asDictionary + answerEquals: { + #type -> PBRSyncMessage type. + #__sync -> 'foobar' } asDictionary. + self assert: flag. +] + +{ #category : #tests } +PBMessageBrokerTest >> testSyncMessage [ + | flag msg ans | + flag := false. + self setHandler: [ :assoc | + self assert: assoc key equals: PBSyncMessage type. + self assert: assoc value associations size equals: 2. + self assert: (assoc value at: #type) equals: PBSyncMessage type. + self assert: (assoc value at: #__sync) equals: msg syncId. + flag := true. + self answer: { #type -> PBSyncMessage type . #__sync -> msg syncId } asDictionary ]. + msg := PBSyncMessage new. + ans := broker sendMessage: msg. + self assert: ans message equals: msg. + self assert: flag +] + +{ #category : #tests } +PBMessageBrokerTest >> testWrongRouteAnswer [ + | flag | + flag := false. + self for: PBCallbackMessage setCallback: [ :dict | + flag := true ]. + self assertCommunicationError: [ self sendMessageToBroker: { + #type -> PBRSyncMessage type. + #__sync -> 'foobar' } asDictionary ]. + self deny: flag +] diff --git a/src/PythonBridge/PBMessageHandler.class.st b/src/PythonBridge/PBMessageHandler.class.st index 06c79ed..aad669b 100644 --- a/src/PythonBridge/PBMessageHandler.class.st +++ b/src/PythonBridge/PBMessageHandler.class.st @@ -1,54 +1,54 @@ -Class { - #name : #PBMessageHandler, - #superclass : #Object, - #instVars : [ - 'message', - 'callback' - ], - #category : #'PythonBridge-Platform' -} - -{ #category : #'as yet unclassified' } -PBMessageHandler class >> forMessage: msg callback: block [ - ^ (self handlerClassForMessage: msg) new - message: msg; - callback: block; - yourself -] - -{ #category : #'as yet unclassified' } -PBMessageHandler class >> handlerClassForMessage: msg [ - ^ msg isSync - ifTrue: [ PBSyncMessageHandler ] - ifFalse: [ PBAsyncMessageHandler ] -] - -{ #category : #accessing } -PBMessageHandler >> callback [ - ^ callback -] - -{ #category : #accessing } -PBMessageHandler >> callback: anObject [ - callback := anObject -] - -{ #category : #accessing } -PBMessageHandler >> handleMessage [ - callback value: message -] - -{ #category : #accessing } -PBMessageHandler >> message [ - ^ message -] - -{ #category : #accessing } -PBMessageHandler >> message: anObject [ - message := anObject -] - -{ #category : #asserting } -PBMessageHandler >> shouldAnswer [ - ^ false -] +Class { + #name : #PBMessageHandler, + #superclass : #Object, + #instVars : [ + 'message', + 'callback' + ], + #category : #'PythonBridge-Platform' +} + +{ #category : #'as yet unclassified' } +PBMessageHandler class >> forMessage: msg callback: block [ + ^ (self handlerClassForMessage: msg) new + message: msg; + callback: block; + yourself +] + +{ #category : #'as yet unclassified' } +PBMessageHandler class >> handlerClassForMessage: msg [ + ^ msg isSync + ifTrue: [ PBSyncMessageHandler ] + ifFalse: [ PBAsyncMessageHandler ] +] + +{ #category : #accessing } +PBMessageHandler >> callback [ + ^ callback +] + +{ #category : #accessing } +PBMessageHandler >> callback: anObject [ + callback := anObject +] + +{ #category : #accessing } +PBMessageHandler >> handleMessage [ + callback value: message +] + +{ #category : #accessing } +PBMessageHandler >> message [ + ^ message +] + +{ #category : #accessing } +PBMessageHandler >> message: anObject [ + message := anObject +] + +{ #category : #asserting } +PBMessageHandler >> shouldAnswer [ + ^ false +] diff --git a/src/PythonBridge/PBMessageHandlerTest.class.st b/src/PythonBridge/PBMessageHandlerTest.class.st index 09a1c6b..6d60215 100644 --- a/src/PythonBridge/PBMessageHandlerTest.class.st +++ b/src/PythonBridge/PBMessageHandlerTest.class.st @@ -1,77 +1,77 @@ -Class { - #name : #PBMessageHandlerTest, - #superclass : #TestCase, - #category : #'PythonBridge-Platform' -} - -{ #category : #tests } -PBMessageHandlerTest >> testAsyncMessage [ - | flag msg handler | - flag := false. - msg := PBAsyncMessage new. - handler := PBMessageHandler - forMessage: msg - callback: [ :aMsg | - self assert: msg equals: aMsg. - flag := true ]. - self deny: flag. - handler handleMessage. - self deny: handler shouldAnswer. - self assert: flag. - self should: [ handler answer ] raise: Error -] - -{ #category : #tests } -PBMessageHandlerTest >> testRAsyncMessage [ - | flag msg handler | - flag := false. - msg := PBRAsyncMessage new. - handler := PBMessageHandler - forMessage: msg - callback: [ :aMsg | - self assert: msg equals: aMsg. - flag := true ]. - self deny: flag. - handler handleMessage. - self deny: handler shouldAnswer. - self assert: flag. - self should: [ handler answer ] raise: Error -] - -{ #category : #tests } -PBMessageHandlerTest >> testRSyncMessage [ - | flag msg handler ans | - flag := false. - ans := nil. - msg := PBRSyncMessage new. - handler := PBMessageHandler - forMessage: msg - callback: [ :aMsg | - self assert: msg equals: aMsg. - flag := true. - ans := msg createAnswer ]. - self deny: flag. - handler handleMessage. - self assert: handler shouldAnswer. - self assert: flag. - self assert: handler answer equals: ans -] - -{ #category : #tests } -PBMessageHandlerTest >> testSyncMessage [ - | flag msg handler ans | - flag := false. - ans := nil. - msg := PBSyncMessage new. - handler := PBMessageHandler - forMessage: msg - callback: [ :aMsg | - self assert: msg equals: aMsg. - flag := true. - ans := msg createAnswer ]. - self deny: flag. - handler handleMessage. - self assert: handler shouldAnswer. - self assert: flag. - self assert: handler answer equals: ans -] +Class { + #name : #PBMessageHandlerTest, + #superclass : #TestCase, + #category : #'PythonBridge-Platform' +} + +{ #category : #tests } +PBMessageHandlerTest >> testAsyncMessage [ + | flag msg handler | + flag := false. + msg := PBAsyncMessage new. + handler := PBMessageHandler + forMessage: msg + callback: [ :aMsg | + self assert: msg equals: aMsg. + flag := true ]. + self deny: flag. + handler handleMessage. + self deny: handler shouldAnswer. + self assert: flag. + self should: [ handler answer ] raise: Error +] + +{ #category : #tests } +PBMessageHandlerTest >> testRAsyncMessage [ + | flag msg handler | + flag := false. + msg := PBRAsyncMessage new. + handler := PBMessageHandler + forMessage: msg + callback: [ :aMsg | + self assert: msg equals: aMsg. + flag := true ]. + self deny: flag. + handler handleMessage. + self deny: handler shouldAnswer. + self assert: flag. + self should: [ handler answer ] raise: Error +] + +{ #category : #tests } +PBMessageHandlerTest >> testRSyncMessage [ + | flag msg handler ans | + flag := false. + ans := nil. + msg := PBRSyncMessage new. + handler := PBMessageHandler + forMessage: msg + callback: [ :aMsg | + self assert: msg equals: aMsg. + flag := true. + ans := msg createAnswer ]. + self deny: flag. + handler handleMessage. + self assert: handler shouldAnswer. + self assert: flag. + self assert: handler answer equals: ans +] + +{ #category : #tests } +PBMessageHandlerTest >> testSyncMessage [ + | flag msg handler ans | + flag := false. + ans := nil. + msg := PBSyncMessage new. + handler := PBMessageHandler + forMessage: msg + callback: [ :aMsg | + self assert: msg equals: aMsg. + flag := true. + ans := msg createAnswer ]. + self deny: flag. + handler handleMessage. + self assert: handler shouldAnswer. + self assert: flag. + self assert: handler answer equals: ans +] diff --git a/src/PythonBridge/PBMessageTest.class.st b/src/PythonBridge/PBMessageTest.class.st index b1447e1..533672d 100644 --- a/src/PythonBridge/PBMessageTest.class.st +++ b/src/PythonBridge/PBMessageTest.class.st @@ -1,62 +1,62 @@ -Class { - #name : #PBMessageTest, - #superclass : #TestCase, - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #tests } -PBMessageTest >> stubMessage [ - ^ PBStubMessage new - ivar1: #foo; - ivar2: #(3 #bar); - yourself -] - -{ #category : #tests } -PBMessageTest >> testDecodeAnswer [ - | msg dict ans | - msg := self stubMessage. - dict := { - (#type -> #STUB). - (#ivar1 -> #foo). - (#ivar2f -> 3). - (#ivar2r -> #(#zork)). - (#__sync -> msg syncId)} asDictionary. - ans := msg createAnswer decode: dict. - self assert: ans ivar1 equals: #foo. - self assert: ans ivar2 equals: #(3 #zork). -] - -{ #category : #tests } -PBMessageTest >> testDecodeBaseMessage [ - self - assert: (PBSyncMessage new createAnswer decode: { #type -> #MSG } asDictionary) class - equals: PBAnswer -] - -{ #category : #tests } -PBMessageTest >> testEncodeBaseMessage [ - self - assert: PBMessage new encode - equals: { #type -> #MSG } asDictionary -] - -{ #category : #tests } -PBMessageTest >> testEncodeMessage [ - | msg dict | - msg := self stubMessage. - dict := { - (#type -> #STUB). - (#ivar1 -> #foo). - (#ivar2f -> 3). - (#ivar2r -> #(#bar)). - (#__sync -> msg syncId)} asDictionary. - self assert: msg encode equals: dict -] - -{ #category : #tests } -PBMessageTest >> testNoDuplicatedTypes [ - | messageClasses | - messageClasses := PBAbstractMessage allSubclasses. - self assert: (messageClasses collect: #type) asSet size equals: messageClasses size -] +Class { + #name : #PBMessageTest, + #superclass : #TestCase, + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #tests } +PBMessageTest >> stubMessage [ + ^ PBStubMessage new + ivar1: #foo; + ivar2: #(3 #bar); + yourself +] + +{ #category : #tests } +PBMessageTest >> testDecodeAnswer [ + | msg dict ans | + msg := self stubMessage. + dict := { + (#type -> #STUB). + (#ivar1 -> #foo). + (#ivar2f -> 3). + (#ivar2r -> #(#zork)). + (#__sync -> msg syncId)} asDictionary. + ans := msg createAnswer decode: dict. + self assert: ans ivar1 equals: #foo. + self assert: ans ivar2 equals: #(3 #zork). +] + +{ #category : #tests } +PBMessageTest >> testDecodeBaseMessage [ + self + assert: (PBSyncMessage new createAnswer decode: { #type -> #MSG } asDictionary) class + equals: PBAnswer +] + +{ #category : #tests } +PBMessageTest >> testEncodeBaseMessage [ + self + assert: PBMessage new encode + equals: { #type -> #MSG } asDictionary +] + +{ #category : #tests } +PBMessageTest >> testEncodeMessage [ + | msg dict | + msg := self stubMessage. + dict := { + (#type -> #STUB). + (#ivar1 -> #foo). + (#ivar2f -> 3). + (#ivar2r -> #(#bar)). + (#__sync -> msg syncId)} asDictionary. + self assert: msg encode equals: dict +] + +{ #category : #tests } +PBMessageTest >> testNoDuplicatedTypes [ + | messageClasses | + messageClasses := PBAbstractMessage allSubclasses. + self assert: (messageClasses collect: #type) asSet size equals: messageClasses size +] diff --git a/src/PythonBridge/PBObject.class.st b/src/PythonBridge/PBObject.class.st index fc33543..ee7ab39 100644 --- a/src/PythonBridge/PBObject.class.st +++ b/src/PythonBridge/PBObject.class.st @@ -1,158 +1,158 @@ -Class { - #name : #PBObject, - #superclass : #Object, - #traits : 'P3GAttributeAccess + P3GCallable', - #classTraits : 'P3GAttributeAccess classTrait + P3GCallable classTrait', - #instVars : [ - 'pythonVariable' - ], - #category : #'PythonBridge-Core' -} - -{ #category : #'instance creation' } -PBObject class >> fromProxy: aProxy [ - | obj | - obj := self new. - obj pythonVariable: aProxy pythonVariable. - self assert: obj pythonClass asString = aProxy pythonVariable. - ^ obj -] - -{ #category : #'instance creation' } -PBObject class >> fromPythonReference: pythonVar [ - ^ super new - pythonVariable: pythonVar; - yourself. -] - -{ #category : #'instance creation' } -PBObject class >> newPythonVar [ - ^ PBPlatform current newRandomName asP3GIdentifier -] - -{ #category : #initialization } -PBObject >> application [ - ^ self applicationClass uniqueInstance -] - -{ #category : #initialization } -PBObject >> applicationClass [ - self class == PBObject ifTrue: [ ^ PBApplication ]. - self subclassResponsibility -] - -{ #category : #'as yet unclassified' } -PBObject >> basicCreateObject [ - self basicCreateObjectArgs: #() -] - -{ #category : #'as yet unclassified' } -PBObject >> basicCreateObjectArgs: posArgs [ - self basicCreateObjectArgs: posArgs nameArgs: Dictionary new -] - -{ #category : #'as yet unclassified' } -PBObject >> basicCreateObjectArgs: posArgs nameArgs: nameArgs [ - ^ self basicCreateObjectExpr: - (self pythonConstructor - callWith: posArgs - with: nameArgs asDictionary) -] - -{ #category : #'as yet unclassified' } -PBObject >> basicCreateObjectExpr: anExpression [ - | varName | - self isCreated ifTrue: [ ^ self ]. - varName := self newPythonVar. - pythonVariable := varName. - self application commandFactory << ( - self registerIdPyExpression: anExpression). - self registerObject. - self application commandFactory send. -] - -{ #category : #'as yet unclassified' } -PBObject >> createObject [ - self subclassResponsibility -] - -{ #category : #'as yet unclassified' } -PBObject >> ensureCreateObject [ - self isCreated ifFalse: [ self createObject ] -] - -{ #category : #accessing } -PBObject >> id [ - ^ pythonVariable name -] - -{ #category : #'as yet unclassified' } -PBObject >> isCreated [ - ^ pythonVariable notNil -] - -{ #category : #p3generator } -PBObject >> isPythonGenerable [ - ^ true -] - -{ #category : #p3generator } -PBObject >> isPythonValue [ - ^ true -] - -{ #category : #accessing } -PBObject >> module [ - ^ self applicationClass module -] - -{ #category : #'instance creation' } -PBObject >> newPythonVar [ - ^ self class newPythonVar -] - -{ #category : #'as yet unclassified' } -PBObject >> pythonClass [ - self subclassResponsibility -] - -{ #category : #'as yet unclassified' } -PBObject >> pythonClassName [ - ^ self pythonClass attributeIdentifier name -] - -{ #category : #'as yet unclassified' } -PBObject >> pythonConstructor [ - ^ self pythonClass -] - -{ #category : #'as yet unclassified' } -PBObject >> pythonRegistryExpression [ - ^ #registry callWith: #() -] - -{ #category : #accessing } -PBObject >> pythonVariable [ - ^ pythonVariable -] - -{ #category : #'as yet unclassified' } -PBObject >> registerIdPyExpression: objExpr [ - ^ self pythonRegistryExpression => #register_with_id callWith: (Array with: objExpr with: self id) -] - -{ #category : #'as yet unclassified' } -PBObject >> registerObject [ - self application registerObject: self -] - -{ #category : #'as yet unclassified' } -PBObject >> resolveIdPyExpression [ - ^ self pythonRegistryExpression => #resolve callWith: (Array with: self id) -] - -{ #category : #'as yet unclassified' } -PBObject >> writePython3On: aStream [ - self assert: self isCreated. - self resolveIdPyExpression writePython3On: aStream -] +Class { + #name : #PBObject, + #superclass : #Object, + #traits : 'P3GAttributeAccess + P3GCallable', + #classTraits : 'P3GAttributeAccess classTrait + P3GCallable classTrait', + #instVars : [ + 'pythonVariable' + ], + #category : #'PythonBridge-Core' +} + +{ #category : #'instance creation' } +PBObject class >> fromProxy: aProxy [ + | obj | + obj := self new. + obj pythonVariable: aProxy pythonVariable. + self assert: obj pythonClass asString = aProxy pythonVariable. + ^ obj +] + +{ #category : #'instance creation' } +PBObject class >> fromPythonReference: pythonVar [ + ^ super new + pythonVariable: pythonVar; + yourself. +] + +{ #category : #'instance creation' } +PBObject class >> newPythonVar [ + ^ PBPlatform current newRandomName asP3GIdentifier +] + +{ #category : #initialization } +PBObject >> application [ + ^ self applicationClass uniqueInstance +] + +{ #category : #initialization } +PBObject >> applicationClass [ + self class == PBObject ifTrue: [ ^ PBApplication ]. + self subclassResponsibility +] + +{ #category : #'as yet unclassified' } +PBObject >> basicCreateObject [ + self basicCreateObjectArgs: #() +] + +{ #category : #'as yet unclassified' } +PBObject >> basicCreateObjectArgs: posArgs [ + self basicCreateObjectArgs: posArgs nameArgs: Dictionary new +] + +{ #category : #'as yet unclassified' } +PBObject >> basicCreateObjectArgs: posArgs nameArgs: nameArgs [ + ^ self basicCreateObjectExpr: + (self pythonConstructor + callWith: posArgs + with: nameArgs asDictionary) +] + +{ #category : #'as yet unclassified' } +PBObject >> basicCreateObjectExpr: anExpression [ + | varName | + self isCreated ifTrue: [ ^ self ]. + varName := self newPythonVar. + pythonVariable := varName. + self application commandFactory << ( + self registerIdPyExpression: anExpression). + self registerObject. + self application commandFactory send. +] + +{ #category : #'as yet unclassified' } +PBObject >> createObject [ + self subclassResponsibility +] + +{ #category : #'as yet unclassified' } +PBObject >> ensureCreateObject [ + self isCreated ifFalse: [ self createObject ] +] + +{ #category : #accessing } +PBObject >> id [ + ^ pythonVariable name +] + +{ #category : #'as yet unclassified' } +PBObject >> isCreated [ + ^ pythonVariable notNil +] + +{ #category : #p3generator } +PBObject >> isPythonGenerable [ + ^ true +] + +{ #category : #p3generator } +PBObject >> isPythonValue [ + ^ true +] + +{ #category : #accessing } +PBObject >> module [ + ^ self applicationClass module +] + +{ #category : #'instance creation' } +PBObject >> newPythonVar [ + ^ self class newPythonVar +] + +{ #category : #'as yet unclassified' } +PBObject >> pythonClass [ + self subclassResponsibility +] + +{ #category : #'as yet unclassified' } +PBObject >> pythonClassName [ + ^ self pythonClass attributeIdentifier name +] + +{ #category : #'as yet unclassified' } +PBObject >> pythonConstructor [ + ^ self pythonClass +] + +{ #category : #'as yet unclassified' } +PBObject >> pythonRegistryExpression [ + ^ #registry callWith: #() +] + +{ #category : #accessing } +PBObject >> pythonVariable [ + ^ pythonVariable +] + +{ #category : #'as yet unclassified' } +PBObject >> registerIdPyExpression: objExpr [ + ^ self pythonRegistryExpression => #register_with_id callWith: (Array with: objExpr with: self id) +] + +{ #category : #'as yet unclassified' } +PBObject >> registerObject [ + self application registerObject: self +] + +{ #category : #'as yet unclassified' } +PBObject >> resolveIdPyExpression [ + ^ self pythonRegistryExpression => #resolve callWith: (Array with: self id) +] + +{ #category : #'as yet unclassified' } +PBObject >> writePython3On: aStream [ + self assert: self isCreated. + self resolveIdPyExpression writePython3On: aStream +] diff --git a/src/PythonBridge/PBObjectFinalizationTest.class.st b/src/PythonBridge/PBObjectFinalizationTest.class.st index eb012ab..76fb9a9 100644 --- a/src/PythonBridge/PBObjectFinalizationTest.class.st +++ b/src/PythonBridge/PBObjectFinalizationTest.class.st @@ -1,58 +1,58 @@ -Class { - #name : #PBObjectFinalizationTest, - #superclass : #PBApplicationTest, - #instVars : [ - 'debugMode' - ], - #category : #'PythonBridge-Tests' -} - -{ #category : #asserting } -PBObjectFinalizationTest >> idInRegistry: anId [ - ^ self registryExpression => #hasId callWith: (Array with: anId) -] - -{ #category : #initialization } -PBObjectFinalizationTest >> setUp [ - super setUp. - debugMode := PBApplication debugMode. - PBApplication debugMode: false. -] - -{ #category : #initialization } -PBObjectFinalizationTest >> tearDown [ - PBApplication debugMode: debugMode. - super tearDown -] - -{ #category : #tests } -PBObjectFinalizationTest >> testCreateObjectAndGcItBeforeSending [ - "Bug when the object is garbage collected before sending the command to python, this trigger the gc in Python of an object that hasnt yer been created nor registered. Now we fixed this enforcing the message send in the basicCreateObject, though another way is to registering the object to the command with a hard-reference." - PBObject new basicCreateObjectExpr: 5.5. - Smalltalk garbageCollect. - Smalltalk garbageCollect. - self assert: true -] - -{ #category : #tests } -PBObjectFinalizationTest >> testGCSimpleObj [ - | obj id | - obj := PBObject new basicCreateObjectExpr: 5.5. - id := obj id. - self cf << obj. - self assert: self cfSend waitForValue equals: 5.5. - self assertExpression: (self idInRegistry: id) equals: true. - obj := nil. - Smalltalk garbageCollect. - Smalltalk garbageCollect. - self assertExpression: (self idInRegistry: id) equals: false. -] - -{ #category : #tests } -PBObjectFinalizationTest >> testSimpleCreateObjectFromExpr [ - | obj | - obj := PBObject new basicCreateObjectExpr: 5.5. - self cf << obj. - self assert: self cfSend waitForValue equals: 5.5. - self assertExpression: (self resolveId: obj id) equals: 5.5 -] +Class { + #name : #PBObjectFinalizationTest, + #superclass : #PBApplicationTest, + #instVars : [ + 'debugMode' + ], + #category : #'PythonBridge-Tests' +} + +{ #category : #asserting } +PBObjectFinalizationTest >> idInRegistry: anId [ + ^ self registryExpression => #hasId callWith: (Array with: anId) +] + +{ #category : #initialization } +PBObjectFinalizationTest >> setUp [ + super setUp. + debugMode := PBApplication debugMode. + PBApplication debugMode: false. +] + +{ #category : #initialization } +PBObjectFinalizationTest >> tearDown [ + PBApplication debugMode: debugMode. + super tearDown +] + +{ #category : #tests } +PBObjectFinalizationTest >> testCreateObjectAndGcItBeforeSending [ + "Bug when the object is garbage collected before sending the command to python, this trigger the gc in Python of an object that hasnt yer been created nor registered. Now we fixed this enforcing the message send in the basicCreateObject, though another way is to registering the object to the command with a hard-reference." + PBObject new basicCreateObjectExpr: 5.5. + Smalltalk garbageCollect. + Smalltalk garbageCollect. + self assert: true +] + +{ #category : #tests } +PBObjectFinalizationTest >> testGCSimpleObj [ + | obj id | + obj := PBObject new basicCreateObjectExpr: 5.5. + id := obj id. + self cf << obj. + self assert: self cfSend waitForValue equals: 5.5. + self assertExpression: (self idInRegistry: id) equals: true. + obj := nil. + Smalltalk garbageCollect. + Smalltalk garbageCollect. + self assertExpression: (self idInRegistry: id) equals: false. +] + +{ #category : #tests } +PBObjectFinalizationTest >> testSimpleCreateObjectFromExpr [ + | obj | + obj := PBObject new basicCreateObjectExpr: 5.5. + self cf << obj. + self assert: self cfSend waitForValue equals: 5.5. + self assertExpression: (self resolveId: obj id) equals: 5.5 +] diff --git a/src/PythonBridge/PBObjectFinalizer.class.st b/src/PythonBridge/PBObjectFinalizer.class.st index 4f04fcd..d6e2a8b 100644 --- a/src/PythonBridge/PBObjectFinalizer.class.st +++ b/src/PythonBridge/PBObjectFinalizer.class.st @@ -1,10 +1,10 @@ -Class { - #name : #PBObjectFinalizer, - #superclass : #Object, - #category : #'PythonBridge-Platform' -} - -{ #category : #finalization } -PBObjectFinalizer >> finalize [ - self subclassResponsibility -] +Class { + #name : #PBObjectFinalizer, + #superclass : #Object, + #category : #'PythonBridge-Platform' +} + +{ #category : #finalization } +PBObjectFinalizer >> finalize [ + self subclassResponsibility +] diff --git a/src/PythonBridge/PBObjectRegistry.class.st b/src/PythonBridge/PBObjectRegistry.class.st index 027eddf..01db2d5 100644 --- a/src/PythonBridge/PBObjectRegistry.class.st +++ b/src/PythonBridge/PBObjectRegistry.class.st @@ -1,56 +1,56 @@ -Class { - #name : #PBObjectRegistry, - #superclass : #Object, - #instVars : [ - 'objectTable', - 'semaphore', - 'idTable' - ], - #category : #'PythonBridge-Execution' -} - -{ #category : #'as yet unclassified' } -PBObjectRegistry >> hasId: anId [ - ^ semaphore critical: [ idTable includesKey: anId ] -] - -{ #category : #'as yet unclassified' } -PBObjectRegistry >> idTable [ - ^ idTable -] - -{ #category : #'as yet unclassified' } -PBObjectRegistry >> initialize [ - super initialize. - idTable := WeakValueDictionary new. - semaphore := Semaphore forMutualExclusion -] - -{ #category : #'as yet unclassified' } -PBObjectRegistry >> registerObject: anObject [ - semaphore critical: [ - idTable at: anObject id put: anObject ] -] - -{ #category : #'as yet unclassified' } -PBObjectRegistry >> resolve: anId [ - ^ semaphore critical: [ idTable at: anId ] -] - -{ #category : #'as yet unclassified' } -PBObjectRegistry >> resolve: anId ifAbsent: aBlock [ - | obj | - obj := semaphore critical: [ idTable at: anId ifAbsent: [ nil ] ]. - ^ obj ifNil: aBlock. - -] - -{ #category : #'as yet unclassified' } -PBObjectRegistry >> unregisterId: anId [ - semaphore critical: [ idTable removeKey: anId ] -] - -{ #category : #'as yet unclassified' } -PBObjectRegistry >> unregisterObject: anObject [ - semaphore critical: [ idTable removeKey: anObject id ] -] +Class { + #name : #PBObjectRegistry, + #superclass : #Object, + #instVars : [ + 'objectTable', + 'semaphore', + 'idTable' + ], + #category : #'PythonBridge-Execution' +} + +{ #category : #'as yet unclassified' } +PBObjectRegistry >> hasId: anId [ + ^ semaphore critical: [ idTable includesKey: anId ] +] + +{ #category : #'as yet unclassified' } +PBObjectRegistry >> idTable [ + ^ idTable +] + +{ #category : #'as yet unclassified' } +PBObjectRegistry >> initialize [ + super initialize. + idTable := WeakValueDictionary new. + semaphore := Semaphore forMutualExclusion +] + +{ #category : #'as yet unclassified' } +PBObjectRegistry >> registerObject: anObject [ + semaphore critical: [ + idTable at: anObject id put: anObject ] +] + +{ #category : #'as yet unclassified' } +PBObjectRegistry >> resolve: anId [ + ^ semaphore critical: [ idTable at: anId ] +] + +{ #category : #'as yet unclassified' } +PBObjectRegistry >> resolve: anId ifAbsent: aBlock [ + | obj | + obj := semaphore critical: [ idTable at: anId ifAbsent: [ nil ] ]. + ^ obj ifNil: aBlock. + +] + +{ #category : #'as yet unclassified' } +PBObjectRegistry >> unregisterId: anId [ + semaphore critical: [ idTable removeKey: anId ] +] + +{ #category : #'as yet unclassified' } +PBObjectRegistry >> unregisterObject: anObject [ + semaphore critical: [ idTable removeKey: anObject id ] +] diff --git a/src/PythonBridge/PBObserver.class.st b/src/PythonBridge/PBObserver.class.st index 278f4b2..82f5316 100644 --- a/src/PythonBridge/PBObserver.class.st +++ b/src/PythonBridge/PBObserver.class.st @@ -1,82 +1,82 @@ -Class { - #name : #PBObserver, - #superclass : #Object, - #traits : 'P3GCallable', - #classTraits : 'P3GCallable classTrait', - #instVars : [ - 'id', - 'callback', - 'command' - ], - #category : #'PythonBridge-Execution' -} - -{ #category : #accessing } -PBObserver class >> callback: aBlock [ - ^ self new - callback: aBlock; - yourself -] - -{ #category : #accessing } -PBObserver >> callback [ - ^ callback -] - -{ #category : #accessing } -PBObserver >> callback: anObject [ - callback := anObject -] - -{ #category : #accessing } -PBObserver >> command [ - ^ command -] - -{ #category : #accessing } -PBObserver >> command: anObject [ - command := anObject -] - -{ #category : #accessing } -PBObserver >> id [ - ^ id -] - -{ #category : #initialization } -PBObserver >> initialize [ - super initialize. - id := PBUtils newP3VariableName -] - -{ #category : #testing } -PBObserver >> isPythonGenerable [ - ^ true -] - -{ #category : #testing } -PBObserver >> isPythonValue [ - ^ true -] - -{ #category : #'error handling' } -PBObserver >> pharoNotify: anObject [ - ^ callback cull: anObject -] - -{ #category : #'error handling' } -PBObserver >> pythonNotify [ - ^ self pythonNotify: nil -] - -{ #category : #'error handling' } -PBObserver >> pythonNotify: anObject [ - ^ self callWith: (Array with: anObject) -] - -{ #category : #testing } -PBObserver >> writePython3On: aStream [ - (#observer asP3GI callWith: (Array - with: self command id - with: self id)) writePython3On: aStream -] +Class { + #name : #PBObserver, + #superclass : #Object, + #traits : 'P3GCallable', + #classTraits : 'P3GCallable classTrait', + #instVars : [ + 'id', + 'callback', + 'command' + ], + #category : #'PythonBridge-Execution' +} + +{ #category : #accessing } +PBObserver class >> callback: aBlock [ + ^ self new + callback: aBlock; + yourself +] + +{ #category : #accessing } +PBObserver >> callback [ + ^ callback +] + +{ #category : #accessing } +PBObserver >> callback: anObject [ + callback := anObject +] + +{ #category : #accessing } +PBObserver >> command [ + ^ command +] + +{ #category : #accessing } +PBObserver >> command: anObject [ + command := anObject +] + +{ #category : #accessing } +PBObserver >> id [ + ^ id +] + +{ #category : #initialization } +PBObserver >> initialize [ + super initialize. + id := PBUtils newP3VariableName +] + +{ #category : #testing } +PBObserver >> isPythonGenerable [ + ^ true +] + +{ #category : #testing } +PBObserver >> isPythonValue [ + ^ true +] + +{ #category : #'error handling' } +PBObserver >> pharoNotify: anObject [ + ^ callback cull: anObject +] + +{ #category : #'error handling' } +PBObserver >> pythonNotify [ + ^ self pythonNotify: nil +] + +{ #category : #'error handling' } +PBObserver >> pythonNotify: anObject [ + ^ self callWith: (Array with: anObject) +] + +{ #category : #testing } +PBObserver >> writePython3On: aStream [ + (#observer asP3GI callWith: (Array + with: self command id + with: self id)) writePython3On: aStream +] diff --git a/src/PythonBridge/PBPlatform.class.st b/src/PythonBridge/PBPlatform.class.st index 83237e5..c0658e9 100644 --- a/src/PythonBridge/PBPlatform.class.st +++ b/src/PythonBridge/PBPlatform.class.st @@ -1,172 +1,172 @@ -Class { - #name : #PBPlatform, - #superclass : #Object, - #instVars : [ - 'msgBrokerStrategy', - 'processStrategy' - ], - #classVars : [ - 'Current' - ], - #category : #'PythonBridge-Platform' -} - -{ #category : #accessing } -PBPlatform class >> current [ - ^ Current ifNil: [ Current := self getConcretePlatform new ] -] - -{ #category : #accessing } -PBPlatform class >> current: aPlatform [ - Current := aPlatform -] - -{ #category : #utils } -PBPlatform class >> getConcretePlatform [ - ^ (self allSubclasses reject: #isAbstract) - inject: nil - into: [ :candidate :next | - candidate - ifNil: [ next ] - ifNotNil: [ - candidate priority > next priority - ifTrue: [ candidate ] - ifFalse: [ next ] ] ] -] - -{ #category : #hooks } -PBPlatform class >> globalPythonProcessClass [ - self subclassResponsibility -] - -{ #category : #hooks } -PBPlatform class >> httpMessageBrokerClass [ - self subclassResponsibility -] - -{ #category : #testing } -PBPlatform class >> isAbstract [ - ^ self name = 'PBPlatform' asSymbol -] - -{ #category : #hooks } -PBPlatform class >> manualProcessClass [ - self subclassResponsibility -] - -{ #category : #hooks } -PBPlatform class >> pipenvProcessClass [ - self subclassResponsibility -] - -{ #category : #accessing } -PBPlatform class >> platform [ - ^ self current -] - -{ #category : #private } -PBPlatform class >> priority [ - ^ -547835385 -] - -{ #category : #hooks } -PBPlatform class >> socketMessageBrokerClass [ - self subclassResponsibility -] - -{ #category : #hooks } -PBPlatform class >> uiManagerClass [ - self subclassResponsibility -] - -{ #category : #hooks } -PBPlatform class >> weakRegistryClass [ - self subclassResponsibility -] - -{ #category : #'message broker strategy' } -PBPlatform >> defaultMessageBrokerClass [ - ^ self class httpMessageBrokerClass -] - -{ #category : #utils } -PBPlatform >> defaultSettings [ - ^ PBSettings - pharoSocketAddress: (PBSocketAddress ipOrName: 'localhost' port: (7000 + 99 atRandom)) - pythonSocketAddress: (PBSocketAddress ipOrName: 'localhost' port: (6900 + 99 atRandom)) -] - -{ #category : #hooks } -PBPlatform >> ensureEnvironmentForApp: anApplication [ - self subclassResponsibility -] - -{ #category : #hooks } -PBPlatform >> folderForApplication: application [ - self subclassResponsibility -] - -{ #category : #'module creation' } -PBPlatform >> messageBroker: settings [ - ^ self messageBrokerStrategy settings: settings -] - -{ #category : #'message broker strategy' } -PBPlatform >> messageBrokerStrategy [ - ^ msgBrokerStrategy ifNil: [ ^ self defaultMessageBrokerClass ] -] - -{ #category : #'message broker strategy' } -PBPlatform >> messageBrokerStrategy: msgBrokerCls [ - msgBrokerStrategy := msgBrokerCls -] - -{ #category : #utils } -PBPlatform >> newRandomName [ - self subclassResponsibility -] - -{ #category : #'module creation' } -PBPlatform >> process: application [ - ^ self processStrategy application: application -] - -{ #category : #'process strategy' } -PBPlatform >> processStrategy [ - ^ processStrategy ifNil: [ ^ self class pipenvProcessClass ] -] - -{ #category : #'process strategy' } -PBPlatform >> processStrategy: processCls [ - processStrategy := processCls -] - -{ #category : #'accessing modules' } -PBPlatform >> serializer [ - ^ self messageBrokerStrategy serializer -] - -{ #category : #'message broker strategy' } -PBPlatform >> setHttpMessageBroker [ - self messageBrokerStrategy: self class httpMessageBrokerClass -] - -{ #category : #'process strategy' } -PBPlatform >> setPipenvProcess [ - self processStrategy: self class pipenvProcessClass -] - -{ #category : #'message broker strategy' } -PBPlatform >> setSocketMessageBroker [ - self messageBrokerStrategy: self class socketMessageBrokerClass -] - -{ #category : #'module creation' } -PBPlatform >> uiManager [ - ^ self class uiManagerClass new -] - -{ #category : #'module creation' } -PBPlatform >> weakRegistry [ - ^ self class weakRegistryClass new -] +Class { + #name : #PBPlatform, + #superclass : #Object, + #instVars : [ + 'msgBrokerStrategy', + 'processStrategy' + ], + #classVars : [ + 'Current' + ], + #category : #'PythonBridge-Platform' +} + +{ #category : #accessing } +PBPlatform class >> current [ + ^ Current ifNil: [ Current := self getConcretePlatform new ] +] + +{ #category : #accessing } +PBPlatform class >> current: aPlatform [ + Current := aPlatform +] + +{ #category : #utils } +PBPlatform class >> getConcretePlatform [ + ^ (self allSubclasses reject: #isAbstract) + inject: nil + into: [ :candidate :next | + candidate + ifNil: [ next ] + ifNotNil: [ + candidate priority > next priority + ifTrue: [ candidate ] + ifFalse: [ next ] ] ] +] + +{ #category : #hooks } +PBPlatform class >> globalPythonProcessClass [ + self subclassResponsibility +] + +{ #category : #hooks } +PBPlatform class >> httpMessageBrokerClass [ + self subclassResponsibility +] + +{ #category : #testing } +PBPlatform class >> isAbstract [ + ^ self name = 'PBPlatform' asSymbol +] + +{ #category : #hooks } +PBPlatform class >> manualProcessClass [ + self subclassResponsibility +] + +{ #category : #hooks } +PBPlatform class >> pipenvProcessClass [ + self subclassResponsibility +] + +{ #category : #accessing } +PBPlatform class >> platform [ + ^ self current +] + +{ #category : #private } +PBPlatform class >> priority [ + ^ -547835385 +] + +{ #category : #hooks } +PBPlatform class >> socketMessageBrokerClass [ + self subclassResponsibility +] + +{ #category : #hooks } +PBPlatform class >> uiManagerClass [ + self subclassResponsibility +] + +{ #category : #hooks } +PBPlatform class >> weakRegistryClass [ + self subclassResponsibility +] + +{ #category : #'message broker strategy' } +PBPlatform >> defaultMessageBrokerClass [ + ^ self class httpMessageBrokerClass +] + +{ #category : #utils } +PBPlatform >> defaultSettings [ + ^ PBSettings + pharoSocketAddress: (PBSocketAddress ipOrName: 'localhost' port: (7000 + 99 atRandom)) + pythonSocketAddress: (PBSocketAddress ipOrName: 'localhost' port: (6900 + 99 atRandom)) +] + +{ #category : #hooks } +PBPlatform >> ensureEnvironmentForApp: anApplication [ + self subclassResponsibility +] + +{ #category : #hooks } +PBPlatform >> folderForApplication: application [ + self subclassResponsibility +] + +{ #category : #'module creation' } +PBPlatform >> messageBroker: settings [ + ^ self messageBrokerStrategy settings: settings +] + +{ #category : #'message broker strategy' } +PBPlatform >> messageBrokerStrategy [ + ^ msgBrokerStrategy ifNil: [ ^ self defaultMessageBrokerClass ] +] + +{ #category : #'message broker strategy' } +PBPlatform >> messageBrokerStrategy: msgBrokerCls [ + msgBrokerStrategy := msgBrokerCls +] + +{ #category : #utils } +PBPlatform >> newRandomName [ + self subclassResponsibility +] + +{ #category : #'module creation' } +PBPlatform >> process: application [ + ^ self processStrategy application: application +] + +{ #category : #'process strategy' } +PBPlatform >> processStrategy [ + ^ processStrategy ifNil: [ ^ self class pipenvProcessClass ] +] + +{ #category : #'process strategy' } +PBPlatform >> processStrategy: processCls [ + processStrategy := processCls +] + +{ #category : #'accessing modules' } +PBPlatform >> serializer [ + ^ self messageBrokerStrategy serializer +] + +{ #category : #'message broker strategy' } +PBPlatform >> setHttpMessageBroker [ + self messageBrokerStrategy: self class httpMessageBrokerClass +] + +{ #category : #'process strategy' } +PBPlatform >> setPipenvProcess [ + self processStrategy: self class pipenvProcessClass +] + +{ #category : #'message broker strategy' } +PBPlatform >> setSocketMessageBroker [ + self messageBrokerStrategy: self class socketMessageBrokerClass +] + +{ #category : #'module creation' } +PBPlatform >> uiManager [ + ^ self class uiManagerClass new +] + +{ #category : #'module creation' } +PBPlatform >> weakRegistry [ + ^ self class weakRegistryClass new +] diff --git a/src/PythonBridge/PBProcessTest.class.st b/src/PythonBridge/PBProcessTest.class.st index 29af69f..25727f2 100644 --- a/src/PythonBridge/PBProcessTest.class.st +++ b/src/PythonBridge/PBProcessTest.class.st @@ -1,56 +1,56 @@ -Class { - #name : #PBProcessTest, - #superclass : #TestCase, - #instVars : [ - 'process', - 'tmpPythonFile' - ], - #category : #'PythonBridge-Platform' -} - -{ #category : #testing } -PBProcessTest class >> isAbstract [ - ^ self == PBProcessTest -] - -{ #category : #running } -PBProcessTest >> defaultSettings [ - ^ PBSettings - pharoSocketAddress: (PBSocketAddress ipOrName: 'localhost' port: 6538) - pythonSocketAddress: (PBSocketAddress ipOrName: 'localhost' port: 6539) -] - -{ #category : #running } -PBProcessTest >> defaultTmpFile [ - self subclassResponsibility -] - -{ #category : #hooks } -PBProcessTest >> processClass [ - self subclassResponsibility -] - -{ #category : #running } -PBProcessTest >> setUp [ - super setUp. - process := self processClass - settings: self defaultSettings - workingDirectory: self processClass workingDirectory. - process pythonMainFile: self defaultTmpFile -] - -{ #category : #running } -PBProcessTest >> tearDown [ - process stop. - super tearDown -] - -{ #category : #running } -PBProcessTest >> testStartStopProcess [ - self deny: process isRunning. - process start. - self assert: process isRunning. - process stop. - (Delay forMilliseconds: 150) wait. - self deny: process isRunning -] +Class { + #name : #PBProcessTest, + #superclass : #TestCase, + #instVars : [ + 'process', + 'tmpPythonFile' + ], + #category : #'PythonBridge-Platform' +} + +{ #category : #testing } +PBProcessTest class >> isAbstract [ + ^ self == PBProcessTest +] + +{ #category : #running } +PBProcessTest >> defaultSettings [ + ^ PBSettings + pharoSocketAddress: (PBSocketAddress ipOrName: 'localhost' port: 6538) + pythonSocketAddress: (PBSocketAddress ipOrName: 'localhost' port: 6539) +] + +{ #category : #running } +PBProcessTest >> defaultTmpFile [ + self subclassResponsibility +] + +{ #category : #hooks } +PBProcessTest >> processClass [ + self subclassResponsibility +] + +{ #category : #running } +PBProcessTest >> setUp [ + super setUp. + process := self processClass + settings: self defaultSettings + workingDirectory: self processClass workingDirectory. + process pythonMainFile: self defaultTmpFile +] + +{ #category : #running } +PBProcessTest >> tearDown [ + process stop. + super tearDown +] + +{ #category : #running } +PBProcessTest >> testStartStopProcess [ + self deny: process isRunning. + process start. + self assert: process isRunning. + process stop. + (Delay forMilliseconds: 150) wait. + self deny: process isRunning +] diff --git a/src/PythonBridge/PBPromise.class.st b/src/PythonBridge/PBPromise.class.st index 3d867be..d00eab8 100644 --- a/src/PythonBridge/PBPromise.class.st +++ b/src/PythonBridge/PBPromise.class.st @@ -1,74 +1,74 @@ -Class { - #name : #PBPromise, - #superclass : #Object, - #instVars : [ - 'id', - 'semaphore', - 'transformBlock', - 'value' - ], - #category : #'PythonBridge-Execution' -} - -{ #category : #accessing } -PBPromise class >> id: id [ - ^ self new - id: id; - yourself -] - -{ #category : #accessing } -PBPromise >> id [ - ^ id -] - -{ #category : #accessing } -PBPromise >> id: anObject [ - id := anObject -] - -{ #category : #initialization } -PBPromise >> initialize [ - super initialize. - semaphore := Semaphore new. - value := nil. - transformBlock := #yourself -] - -{ #category : #signalling } -PBPromise >> isSignaled [ - ^ semaphore isSignaled -] - -{ #category : #signalling } -PBPromise >> signalAll [ - 1 to: semaphore size + 20 do: [ :s | semaphore signal ] -] - -{ #category : #signalling } -PBPromise >> signalWithValue: anObject [ - value := transformBlock value: anObject. - self signalAll. -] - -{ #category : #accessing } -PBPromise >> transformBlock [ - ^ transformBlock -] - -{ #category : #accessing } -PBPromise >> transformBlock: anObject [ - transformBlock := anObject -] - -{ #category : #signalling } -PBPromise >> value [ - ^ value -] - -{ #category : #signalling } -PBPromise >> waitForValue [ - self isSignaled ifTrue: [ ^ self value ]. - semaphore wait. - ^ self value -] +Class { + #name : #PBPromise, + #superclass : #Object, + #instVars : [ + 'id', + 'semaphore', + 'transformBlock', + 'value' + ], + #category : #'PythonBridge-Execution' +} + +{ #category : #accessing } +PBPromise class >> id: id [ + ^ self new + id: id; + yourself +] + +{ #category : #accessing } +PBPromise >> id [ + ^ id +] + +{ #category : #accessing } +PBPromise >> id: anObject [ + id := anObject +] + +{ #category : #initialization } +PBPromise >> initialize [ + super initialize. + semaphore := Semaphore new. + value := nil. + transformBlock := #yourself +] + +{ #category : #signalling } +PBPromise >> isSignaled [ + ^ semaphore isSignaled +] + +{ #category : #signalling } +PBPromise >> signalAll [ + 1 to: semaphore size + 20 do: [ :s | semaphore signal ] +] + +{ #category : #signalling } +PBPromise >> signalWithValue: anObject [ + value := transformBlock value: anObject. + self signalAll. +] + +{ #category : #accessing } +PBPromise >> transformBlock [ + ^ transformBlock +] + +{ #category : #accessing } +PBPromise >> transformBlock: anObject [ + transformBlock := anObject +] + +{ #category : #signalling } +PBPromise >> value [ + ^ value +] + +{ #category : #signalling } +PBPromise >> waitForValue [ + self isSignaled ifTrue: [ ^ self value ]. + semaphore wait. + ^ self value +] diff --git a/src/PythonBridge/PBPromiseRegistry.class.st b/src/PythonBridge/PBPromiseRegistry.class.st index 52d6161..5d295f1 100644 --- a/src/PythonBridge/PBPromiseRegistry.class.st +++ b/src/PythonBridge/PBPromiseRegistry.class.st @@ -1,45 +1,45 @@ -Class { - #name : #PBPromiseRegistry, - #superclass : #Object, - #instVars : [ - 'promiseTable', - 'semaphore' - ], - #category : #'PythonBridge-Execution' -} - -{ #category : #adding } -PBPromiseRegistry >> addPromise: aPromise [ - semaphore critical: [ promiseTable at: aPromise id put: aPromise ] -] - -{ #category : #initialization } -PBPromiseRegistry >> initialize [ - super initialize. - promiseTable := Dictionary new. - semaphore := Semaphore forMutualExclusion -] - -{ #category : #'private - testing' } -PBPromiseRegistry >> promiseTable [ - ^ promiseTable -] - -{ #category : #adding } -PBPromiseRegistry >> removeAndSignalPromiseId: id with: anObject [ - self signalPromiseId: id with: anObject. - self removePromiseId: id -] - -{ #category : #adding } -PBPromiseRegistry >> removePromiseId: id [ - semaphore critical: [ promiseTable removeKey: id ] -] - -{ #category : #adding } -PBPromiseRegistry >> signalPromiseId: id with: anObject [ - | promise | - semaphore critical: [ - promise := promiseTable at: id. - promise signalWithValue: anObject ] -] +Class { + #name : #PBPromiseRegistry, + #superclass : #Object, + #instVars : [ + 'promiseTable', + 'semaphore' + ], + #category : #'PythonBridge-Execution' +} + +{ #category : #adding } +PBPromiseRegistry >> addPromise: aPromise [ + semaphore critical: [ promiseTable at: aPromise id put: aPromise ] +] + +{ #category : #initialization } +PBPromiseRegistry >> initialize [ + super initialize. + promiseTable := Dictionary new. + semaphore := Semaphore forMutualExclusion +] + +{ #category : #'private - testing' } +PBPromiseRegistry >> promiseTable [ + ^ promiseTable +] + +{ #category : #adding } +PBPromiseRegistry >> removeAndSignalPromiseId: id with: anObject [ + self signalPromiseId: id with: anObject. + self removePromiseId: id +] + +{ #category : #adding } +PBPromiseRegistry >> removePromiseId: id [ + semaphore critical: [ promiseTable removeKey: id ] +] + +{ #category : #adding } +PBPromiseRegistry >> signalPromiseId: id with: anObject [ + | promise | + semaphore critical: [ + promise := promiseTable at: id. + promise signalWithValue: anObject ] +] diff --git a/src/PythonBridge/PBPromiseRegistryTest.class.st b/src/PythonBridge/PBPromiseRegistryTest.class.st index 9d723e1..d3af20a 100644 --- a/src/PythonBridge/PBPromiseRegistryTest.class.st +++ b/src/PythonBridge/PBPromiseRegistryTest.class.st @@ -1,60 +1,60 @@ -Class { - #name : #PBPromiseRegistryTest, - #superclass : #TestCase, - #instVars : [ - 'registry' - ], - #category : #'PythonBridge-Tests' -} - -{ #category : #initialization } -PBPromiseRegistryTest >> setUp [ - registry := PBPromiseRegistry new -] - -{ #category : #initialization } -PBPromiseRegistryTest >> testAddPromise [ - registry addPromise: (PBPromise id: '123'). - self assert: registry promiseTable size equals: 1. - self assert: registry promiseTable anyOne id equals: '123' -] - -{ #category : #initialization } -PBPromiseRegistryTest >> testRemovePromiseId [ - registry addPromise: (PBPromise id: '123'). - registry removePromiseId: '123'. - self assert: registry promiseTable size equals: 0 -] - -{ #category : #initialization } -PBPromiseRegistryTest >> testSignalPromise [ - | semaphore flag promise | - semaphore := Semaphore new. - flag := false. - promise := (PBPromise id: '123'). - registry addPromise: promise. - [ - self assert: promise waitForValue equals: #foo. - flag := true. - semaphore signal. ] fork. - registry signalPromiseId: '123' with: #foo. - semaphore wait. - self assert: flag -] - -{ #category : #initialization } -PBPromiseRegistryTest >> testSignalPromiseWithTransformBlock [ - | semaphore flag promise | - semaphore := Semaphore new. - flag := false. - promise := (PBPromise id: '123') - transformBlock: [ :obj | 55 ]. - registry addPromise: promise. - [ - self assert: promise waitForValue equals: 55. - flag := true. - semaphore signal. ] fork. - registry signalPromiseId: '123' with: #foo. - semaphore wait. - self assert: flag -] +Class { + #name : #PBPromiseRegistryTest, + #superclass : #TestCase, + #instVars : [ + 'registry' + ], + #category : #'PythonBridge-Tests' +} + +{ #category : #initialization } +PBPromiseRegistryTest >> setUp [ + registry := PBPromiseRegistry new +] + +{ #category : #initialization } +PBPromiseRegistryTest >> testAddPromise [ + registry addPromise: (PBPromise id: '123'). + self assert: registry promiseTable size equals: 1. + self assert: registry promiseTable anyOne id equals: '123' +] + +{ #category : #initialization } +PBPromiseRegistryTest >> testRemovePromiseId [ + registry addPromise: (PBPromise id: '123'). + registry removePromiseId: '123'. + self assert: registry promiseTable size equals: 0 +] + +{ #category : #initialization } +PBPromiseRegistryTest >> testSignalPromise [ + | semaphore flag promise | + semaphore := Semaphore new. + flag := false. + promise := (PBPromise id: '123'). + registry addPromise: promise. + [ + self assert: promise waitForValue equals: #foo. + flag := true. + semaphore signal. ] fork. + registry signalPromiseId: '123' with: #foo. + semaphore wait. + self assert: flag +] + +{ #category : #initialization } +PBPromiseRegistryTest >> testSignalPromiseWithTransformBlock [ + | semaphore flag promise | + semaphore := Semaphore new. + flag := false. + promise := (PBPromise id: '123') + transformBlock: [ :obj | 55 ]. + registry addPromise: promise. + [ + self assert: promise waitForValue equals: 55. + flag := true. + semaphore signal. ] fork. + registry signalPromiseId: '123' with: #foo. + semaphore wait. + self assert: flag +] diff --git a/src/PythonBridge/PBProxyObject.class.st b/src/PythonBridge/PBProxyObject.class.st index b7ac03e..76e9468 100644 --- a/src/PythonBridge/PBProxyObject.class.st +++ b/src/PythonBridge/PBProxyObject.class.st @@ -1,61 +1,61 @@ -Class { - #name : #PBProxyObject, - #superclass : #PBObject, - #instVars : [ - 'pythonClass', - 'application' - ], - #category : #'PythonBridge-Core' -} - -{ #category : #'as yet unclassified' } -PBProxyObject class >> pythonClass: pythonClass pythonVar: pyVar application: application [ - ^ self new - pythonVariable: pyVar; - pythonClass: pythonClass; - application: application; - yourself -] - -{ #category : #accessing } -PBProxyObject >> application [ - ^ application -] - -{ #category : #accessing } -PBProxyObject >> application: anObject [ - application := anObject -] - -{ #category : #accessing } -PBProxyObject >> applicationClass [ - ^ self application class -] - -{ #category : #hooks } -PBProxyObject >> createObject [ - self shouldNotImplement -] - -{ #category : #printing } -PBProxyObject >> printOn: str [ - str - << (pythonClass asString first isVowel ifTrue: ['an '] ifFalse: ['a ']); - << pythonClass asString; - << ' (Proxy)' -] - -{ #category : #accessing } -PBProxyObject >> pythonClass [ - ^ pythonClass -] - -{ #category : #accessing } -PBProxyObject >> pythonClass: anObject [ - pythonClass := anObject -] - -{ #category : #accessing } -PBProxyObject >> pythonVariable: pyVar [ - pythonVariable := pyVar -] +Class { + #name : #PBProxyObject, + #superclass : #PBObject, + #instVars : [ + 'pythonClass', + 'application' + ], + #category : #'PythonBridge-Core' +} + +{ #category : #'as yet unclassified' } +PBProxyObject class >> pythonClass: pythonClass pythonVar: pyVar application: application [ + ^ self new + pythonVariable: pyVar; + pythonClass: pythonClass; + application: application; + yourself +] + +{ #category : #accessing } +PBProxyObject >> application [ + ^ application +] + +{ #category : #accessing } +PBProxyObject >> application: anObject [ + application := anObject +] + +{ #category : #accessing } +PBProxyObject >> applicationClass [ + ^ self application class +] + +{ #category : #hooks } +PBProxyObject >> createObject [ + self shouldNotImplement +] + +{ #category : #printing } +PBProxyObject >> printOn: str [ + str + << (pythonClass asString first isVowel ifTrue: ['an '] ifFalse: ['a ']); + << pythonClass asString; + << ' (Proxy)' +] + +{ #category : #accessing } +PBProxyObject >> pythonClass [ + ^ pythonClass +] + +{ #category : #accessing } +PBProxyObject >> pythonClass: anObject [ + pythonClass := anObject +] + +{ #category : #accessing } +PBProxyObject >> pythonVariable: pyVar [ + pythonVariable := pyVar +] diff --git a/src/PythonBridge/PBPython3GenerationTest.class.st b/src/PythonBridge/PBPython3GenerationTest.class.st index e328abd..655ee8e 100644 --- a/src/PythonBridge/PBPython3GenerationTest.class.st +++ b/src/PythonBridge/PBPython3GenerationTest.class.st @@ -1,37 +1,37 @@ -Class { - #name : #PBPython3GenerationTest, - #superclass : #TestCase, - #category : #'PythonBridge-Tests' -} - -{ #category : #'as yet unclassified' } -PBPython3GenerationTest >> getPythonCode: aPythonExpression [ - ^ self getPythonCodeUsingStream: [ :str | aPythonExpression writePython3On: str ] -] - -{ #category : #'as yet unclassified' } -PBPython3GenerationTest >> getPythonCodeUsingStream: aBlock [ - | stream | - stream := String new writeStream. - aBlock value: stream. - ^ stream contents -] - -{ #category : #tests } -PBPython3GenerationTest >> testBinding [ - | binding | - binding := PBBinding wrap: 32. - self - assert: (self getPythonCode: binding) - equals: binding key -] - -{ #category : #tests } -PBPython3GenerationTest >> testObserverNotify [ - | obs | - obs := PBObserver callback: [ 32 ]. - obs command: PBCommand new. - self - assert: (self getPythonCode: (obs pythonNotify: 'foobar')) - equals: 'observer(''' , obs command id , ''',''' , obs id , ''')(''foobar'')' -] +Class { + #name : #PBPython3GenerationTest, + #superclass : #TestCase, + #category : #'PythonBridge-Tests' +} + +{ #category : #'as yet unclassified' } +PBPython3GenerationTest >> getPythonCode: aPythonExpression [ + ^ self getPythonCodeUsingStream: [ :str | aPythonExpression writePython3On: str ] +] + +{ #category : #'as yet unclassified' } +PBPython3GenerationTest >> getPythonCodeUsingStream: aBlock [ + | stream | + stream := String new writeStream. + aBlock value: stream. + ^ stream contents +] + +{ #category : #tests } +PBPython3GenerationTest >> testBinding [ + | binding | + binding := PBBinding wrap: 32. + self + assert: (self getPythonCode: binding) + equals: binding key +] + +{ #category : #tests } +PBPython3GenerationTest >> testObserverNotify [ + | obs | + obs := PBObserver callback: [ 32 ]. + obs command: PBCommand new. + self + assert: (self getPythonCode: (obs pythonNotify: 'foobar')) + equals: 'observer(''' , obs command id , ''',''' , obs id , ''')(''foobar'')' +] diff --git a/src/PythonBridge/PBPythonError.class.st b/src/PythonBridge/PBPythonError.class.st index b8eb2a0..3eb0fe8 100644 --- a/src/PythonBridge/PBPythonError.class.st +++ b/src/PythonBridge/PBPythonError.class.st @@ -1,90 +1,90 @@ -Class { - #name : #PBPythonError, - #superclass : #Notification, - #instVars : [ - 'command', - 'errorMessage', - 'application', - 'proceedAction', - 'trace' - ], - #category : #'PythonBridge-ErrorHandling' -} - -{ #category : #accessing } -PBPythonError >> application [ - ^ application -] - -{ #category : #accessing } -PBPythonError >> application: anObject [ - application := anObject -] - -{ #category : #accessing } -PBPythonError >> command [ - ^ command -] - -{ #category : #accessing } -PBPythonError >> command: anObject [ - command := anObject -] - -{ #category : #accessing } -PBPythonError >> defaultAction [ - "No one has handled this error, but now give them a chance to decide how to debug it. If none handle this either then open debugger (see UnhandedError-defaultAction)" - - ^ PBPlatform current uiManager spawnDebuggerOnException: self -] - -{ #category : #'as yet unclassified' } -PBPythonError >> defaultProceedAction [ - ^ PBDropQueue new -] - -{ #category : #accessing } -PBPythonError >> errorMessage [ - ^ errorMessage -] - -{ #category : #accessing } -PBPythonError >> errorMessage: anObject [ - errorMessage := anObject -] - -{ #category : #initialization } -PBPythonError >> initialize [ - super initialize. - proceedAction := self defaultProceedAction -] - -{ #category : #accessing } -PBPythonError >> isResumable [ - ^ true -] - -{ #category : #accessing } -PBPythonError >> messageText [ - ^ errorMessage -] - -{ #category : #accessing } -PBPythonError >> proceedAction [ - ^ proceedAction -] - -{ #category : #accessing } -PBPythonError >> proceedAction: anObject [ - proceedAction := anObject -] - -{ #category : #tracing } -PBPythonError >> trace [ - ^ trace -] - -{ #category : #tracing } -PBPythonError >> trace: aTrace [ - trace := aTrace -] +Class { + #name : #PBPythonError, + #superclass : #Notification, + #instVars : [ + 'command', + 'errorMessage', + 'application', + 'proceedAction', + 'trace' + ], + #category : #'PythonBridge-ErrorHandling' +} + +{ #category : #accessing } +PBPythonError >> application [ + ^ application +] + +{ #category : #accessing } +PBPythonError >> application: anObject [ + application := anObject +] + +{ #category : #accessing } +PBPythonError >> command [ + ^ command +] + +{ #category : #accessing } +PBPythonError >> command: anObject [ + command := anObject +] + +{ #category : #accessing } +PBPythonError >> defaultAction [ + "No one has handled this error, but now give them a chance to decide how to debug it. If none handle this either then open debugger (see UnhandedError-defaultAction)" + + ^ PBPlatform current uiManager spawnDebuggerOnException: self +] + +{ #category : #'as yet unclassified' } +PBPythonError >> defaultProceedAction [ + ^ PBDropQueue new +] + +{ #category : #accessing } +PBPythonError >> errorMessage [ + ^ errorMessage +] + +{ #category : #accessing } +PBPythonError >> errorMessage: anObject [ + errorMessage := anObject +] + +{ #category : #initialization } +PBPythonError >> initialize [ + super initialize. + proceedAction := self defaultProceedAction +] + +{ #category : #accessing } +PBPythonError >> isResumable [ + ^ true +] + +{ #category : #accessing } +PBPythonError >> messageText [ + ^ errorMessage +] + +{ #category : #accessing } +PBPythonError >> proceedAction [ + ^ proceedAction +] + +{ #category : #accessing } +PBPythonError >> proceedAction: anObject [ + proceedAction := anObject +] + +{ #category : #tracing } +PBPythonError >> trace [ + ^ trace +] + +{ #category : #tracing } +PBPythonError >> trace: aTrace [ + trace := aTrace +] diff --git a/src/PythonBridge/PBPythonErrorHandlingTest.class.st b/src/PythonBridge/PBPythonErrorHandlingTest.class.st index acfc570..13aa0c6 100644 --- a/src/PythonBridge/PBPythonErrorHandlingTest.class.st +++ b/src/PythonBridge/PBPythonErrorHandlingTest.class.st @@ -1,5 +1,5 @@ -Class { - #name : #PBPythonErrorHandlingTest, - #superclass : #PBApplicationTest, - #category : #'PythonBridge-Tests' -} +Class { + #name : #PBPythonErrorHandlingTest, + #superclass : #PBApplicationTest, + #category : #'PythonBridge-Tests' +} diff --git a/src/PythonBridge/PBPythonHandler.class.st b/src/PythonBridge/PBPythonHandler.class.st index 04d70d4..a955663 100644 --- a/src/PythonBridge/PBPythonHandler.class.st +++ b/src/PythonBridge/PBPythonHandler.class.st @@ -1,40 +1,40 @@ -Class { - #name : #PBPythonHandler, - #superclass : #PBHandler, - #instVars : [ - 'process' - ], - #category : #'PythonBridge-Core' -} - -{ #category : #accessing } -PBPythonHandler >> errorMessage [ - ^ process errorMessage -] - -{ #category : #initialization } -PBPythonHandler >> initializeHandler [ - super initializeHandler. - process := PBPlatform current process: self application -] - -{ #category : #testing } -PBPythonHandler >> isRunning [ - ^ process isRunning -] - -{ #category : #accessing } -PBPythonHandler >> platform [ - ^ PBPlatform current -] - -{ #category : #testing } -PBPythonHandler >> start [ - self platform ensureEnvironmentForApp: self application. - ^ process start -] - -{ #category : #testing } -PBPythonHandler >> stop [ - ^ process stop -] +Class { + #name : #PBPythonHandler, + #superclass : #PBHandler, + #instVars : [ + 'process' + ], + #category : #'PythonBridge-Core' +} + +{ #category : #accessing } +PBPythonHandler >> errorMessage [ + ^ process errorMessage +] + +{ #category : #initialization } +PBPythonHandler >> initializeHandler [ + super initializeHandler. + process := PBPlatform current process: self application +] + +{ #category : #testing } +PBPythonHandler >> isRunning [ + ^ process isRunning +] + +{ #category : #accessing } +PBPythonHandler >> platform [ + ^ PBPlatform current +] + +{ #category : #testing } +PBPythonHandler >> start [ + self platform ensureEnvironmentForApp: self application. + ^ process start +] + +{ #category : #testing } +PBPythonHandler >> stop [ + ^ process stop +] diff --git a/src/PythonBridge/PBPythonObjectTest.class.st b/src/PythonBridge/PBPythonObjectTest.class.st index 87dbef6..efdb228 100644 --- a/src/PythonBridge/PBPythonObjectTest.class.st +++ b/src/PythonBridge/PBPythonObjectTest.class.st @@ -1,46 +1,46 @@ -Class { - #name : #PBPythonObjectTest, - #superclass : #PBApplicationTest, - #category : #'PythonBridge-Tests' -} - -{ #category : #tests } -PBPythonObjectTest >> setUp [ - super setUp. - self cf << (#PythonBridge asP3GI => #object_registry) import -] - -{ #category : #tests } -PBPythonObjectTest >> stubPythonObjectExpression [ - ^ #PythonBridge asP3GI => #object_registry => #Registry callWith: #() -] - -{ #category : #tests } -PBPythonObjectTest >> testProxyIdentity [ - | obj | - self cf << self stubPythonObjectExpression. - obj := self cfSend waitForValue. - self assert: obj class equals: PBProxyObject. - self assertInstanceClass: obj name: 'Registry'. - self cf << (self resolveId: obj id). - self assert: self cfSend waitForValue equals: obj -] - -{ #category : #tests } -PBPythonObjectTest >> testSimpleObjectIdentity [ - | obj | - obj := PBObject new basicCreateObjectExpr: self stubPythonObjectExpression. - self cf << obj. - self assert: self cfSend waitForValue equals: obj. - self assertExpression: (self resolveId: obj id) equals: obj -] - -{ #category : #tests } -PBPythonObjectTest >> testSimpleProxy [ - | obj | - self cf << self stubPythonObjectExpression. - obj := self cfSend waitForValue. - self assert: obj class equals: PBProxyObject. - self assertInstanceClass: obj name: 'Registry'. - self assertExpression: (obj => #hasId callWith: #(0)) equals: false -] +Class { + #name : #PBPythonObjectTest, + #superclass : #PBApplicationTest, + #category : #'PythonBridge-Tests' +} + +{ #category : #tests } +PBPythonObjectTest >> setUp [ + super setUp. + self cf << (#PythonBridge asP3GI => #object_registry) import +] + +{ #category : #tests } +PBPythonObjectTest >> stubPythonObjectExpression [ + ^ #PythonBridge asP3GI => #object_registry => #Registry callWith: #() +] + +{ #category : #tests } +PBPythonObjectTest >> testProxyIdentity [ + | obj | + self cf << self stubPythonObjectExpression. + obj := self cfSend waitForValue. + self assert: obj class equals: PBProxyObject. + self assertInstanceClass: obj name: 'Registry'. + self cf << (self resolveId: obj id). + self assert: self cfSend waitForValue equals: obj +] + +{ #category : #tests } +PBPythonObjectTest >> testSimpleObjectIdentity [ + | obj | + obj := PBObject new basicCreateObjectExpr: self stubPythonObjectExpression. + self cf << obj. + self assert: self cfSend waitForValue equals: obj. + self assertExpression: (self resolveId: obj id) equals: obj +] + +{ #category : #tests } +PBPythonObjectTest >> testSimpleProxy [ + | obj | + self cf << self stubPythonObjectExpression. + obj := self cfSend waitForValue. + self assert: obj class equals: PBProxyObject. + self assertInstanceClass: obj name: 'Registry'. + self assertExpression: (obj => #hasId callWith: #(0)) equals: false +] diff --git a/src/PythonBridge/PBPythonValueTrait.trait.st b/src/PythonBridge/PBPythonValueTrait.trait.st index 795a274..3930a7c 100644 --- a/src/PythonBridge/PBPythonValueTrait.trait.st +++ b/src/PythonBridge/PBPythonValueTrait.trait.st @@ -1,11 +1,11 @@ -Trait { - #name : #PBPythonValueTrait, - #traits : 'P3GAttributeAccess', - #classTraits : 'P3GAttributeAccess classTrait', - #category : #'PythonBridge-P3Generator' -} - -{ #category : #testing } -PBPythonValueTrait >> isPythonValue [ - ^ true -] +Trait { + #name : #PBPythonValueTrait, + #traits : 'P3GAttributeAccess', + #classTraits : 'P3GAttributeAccess classTrait', + #category : #'PythonBridge-P3Generator' +} + +{ #category : #testing } +PBPythonValueTrait >> isPythonValue [ + ^ true +] diff --git a/src/PythonBridge/PBRAnswer.class.st b/src/PythonBridge/PBRAnswer.class.st index 392067b..eba8aa2 100644 --- a/src/PythonBridge/PBRAnswer.class.st +++ b/src/PythonBridge/PBRAnswer.class.st @@ -1,24 +1,24 @@ -Class { - #name : #PBRAnswer, - #superclass : #PBAbstractAnswer, - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #encoding } -PBRAnswer >> encode [ - | dict | - dict := Dictionary new. - dict at: #type put: self type. - self privateEncode: dict. - ^ dict -] - -{ #category : #encoding } -PBRAnswer >> privateEncode: dict [ - dict at: #__sync put: self syncId -] - -{ #category : #writing } -PBRAnswer >> syncId [ - ^ message syncId -] +Class { + #name : #PBRAnswer, + #superclass : #PBAbstractAnswer, + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #encoding } +PBRAnswer >> encode [ + | dict | + dict := Dictionary new. + dict at: #type put: self type. + self privateEncode: dict. + ^ dict +] + +{ #category : #encoding } +PBRAnswer >> privateEncode: dict [ + dict at: #__sync put: self syncId +] + +{ #category : #writing } +PBRAnswer >> syncId [ + ^ message syncId +] diff --git a/src/PythonBridge/PBRAsyncMessage.class.st b/src/PythonBridge/PBRAsyncMessage.class.st index 45c6ac2..fb66893 100644 --- a/src/PythonBridge/PBRAsyncMessage.class.st +++ b/src/PythonBridge/PBRAsyncMessage.class.st @@ -1,15 +1,15 @@ -Class { - #name : #PBRAsyncMessage, - #superclass : #PBRMessage, - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #accessing } -PBRAsyncMessage class >> type [ - ^ #RASYNC -] - -{ #category : #testing } -PBRAsyncMessage >> isSync [ - ^ false -] +Class { + #name : #PBRAsyncMessage, + #superclass : #PBRMessage, + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #accessing } +PBRAsyncMessage class >> type [ + ^ #RASYNC +] + +{ #category : #testing } +PBRAsyncMessage >> isSync [ + ^ false +] diff --git a/src/PythonBridge/PBRMessage.class.st b/src/PythonBridge/PBRMessage.class.st index 87bce7e..54a95e9 100644 --- a/src/PythonBridge/PBRMessage.class.st +++ b/src/PythonBridge/PBRMessage.class.st @@ -1,28 +1,28 @@ -Class { - #name : #PBRMessage, - #superclass : #PBAbstractMessage, - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #actions } -PBRMessage class >> decodeFrom: aDict [ - ^ self new - privateDecode: aDict; - yourself -] - -{ #category : #testing } -PBRMessage class >> isReverseMessage [ - "Reverse messages corresponds to messages that start on Python to Pharo. In other words - in reverse direction from normal messages." - ^ true -] - -{ #category : #accessing } -PBRMessage class >> type [ - ^ #RMSG -] - -{ #category : #'as yet unclassified' } -PBRMessage >> privateDecode: aDict [ -] +Class { + #name : #PBRMessage, + #superclass : #PBAbstractMessage, + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #actions } +PBRMessage class >> decodeFrom: aDict [ + ^ self new + privateDecode: aDict; + yourself +] + +{ #category : #testing } +PBRMessage class >> isReverseMessage [ + "Reverse messages corresponds to messages that start on Python to Pharo. In other words + in reverse direction from normal messages." + ^ true +] + +{ #category : #accessing } +PBRMessage class >> type [ + ^ #RMSG +] + +{ #category : #'as yet unclassified' } +PBRMessage >> privateDecode: aDict [ +] diff --git a/src/PythonBridge/PBRMessageTest.class.st b/src/PythonBridge/PBRMessageTest.class.st index f6c63f6..a9fe5aa 100644 --- a/src/PythonBridge/PBRMessageTest.class.st +++ b/src/PythonBridge/PBRMessageTest.class.st @@ -1,51 +1,51 @@ -Class { - #name : #PBRMessageTest, - #superclass : #TestCase, - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #tests } -PBRMessageTest >> stubDict [ - ^ {#type -> #RSTUB . - #ivar1 -> #foo . - #ivar2f -> 3 . - #ivar2r -> #(#bar) . - #__sync -> 'ab45d3' - } asDictionary -] - -{ #category : #tests } -PBRMessageTest >> testDecodeRMessage [ - | msg | - msg := PBRMessage decodeFrom: { #type -> #RMSG } asDictionary. - self assert: msg class equals: PBRMessage. - self assert: msg type equals: #RMSG -] - -{ #category : #tests } -PBRMessageTest >> testDecodeRStubMessage [ - | msg | - msg := PBRStubMessage decodeFrom: self stubDict. - self assert: msg ivar1 equals: #foo. - self assert: msg ivar2 equals: #(3 #bar). - self assert: msg syncId equals: 'ab45d3' -] - -{ #category : #tests } -PBRMessageTest >> testEncodeRAnswer [ - | msg ans | - msg := PBRSyncMessage decodeFrom: { #type -> #RSYNC . #__sync -> 'abcde1234' } asDictionary. - ans := msg createAnswer. - self assert: ans syncId equals: 'abcde1234'. - self assert: ans encode equals: { #type -> #RSYNC . #__sync -> 'abcde1234' } asDictionary -] - -{ #category : #tests } -PBRMessageTest >> testEncodeRStubAnswer [ - | msg ans | - msg := PBRStubMessage decodeFrom: self stubDict. - ans := msg createAnswer. - ans ivar1: #foo. - ans ivar2: #(3 #bar). - self assert: ans encode equals: self stubDict -] +Class { + #name : #PBRMessageTest, + #superclass : #TestCase, + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #tests } +PBRMessageTest >> stubDict [ + ^ {#type -> #RSTUB . + #ivar1 -> #foo . + #ivar2f -> 3 . + #ivar2r -> #(#bar) . + #__sync -> 'ab45d3' + } asDictionary +] + +{ #category : #tests } +PBRMessageTest >> testDecodeRMessage [ + | msg | + msg := PBRMessage decodeFrom: { #type -> #RMSG } asDictionary. + self assert: msg class equals: PBRMessage. + self assert: msg type equals: #RMSG +] + +{ #category : #tests } +PBRMessageTest >> testDecodeRStubMessage [ + | msg | + msg := PBRStubMessage decodeFrom: self stubDict. + self assert: msg ivar1 equals: #foo. + self assert: msg ivar2 equals: #(3 #bar). + self assert: msg syncId equals: 'ab45d3' +] + +{ #category : #tests } +PBRMessageTest >> testEncodeRAnswer [ + | msg ans | + msg := PBRSyncMessage decodeFrom: { #type -> #RSYNC . #__sync -> 'abcde1234' } asDictionary. + ans := msg createAnswer. + self assert: ans syncId equals: 'abcde1234'. + self assert: ans encode equals: { #type -> #RSYNC . #__sync -> 'abcde1234' } asDictionary +] + +{ #category : #tests } +PBRMessageTest >> testEncodeRStubAnswer [ + | msg ans | + msg := PBRStubMessage decodeFrom: self stubDict. + ans := msg createAnswer. + ans ivar1: #foo. + ans ivar2: #(3 #bar). + self assert: ans encode equals: self stubDict +] diff --git a/src/PythonBridge/PBRStubAnswer.class.st b/src/PythonBridge/PBRStubAnswer.class.st index 593378c..a7d0835 100644 --- a/src/PythonBridge/PBRStubAnswer.class.st +++ b/src/PythonBridge/PBRStubAnswer.class.st @@ -1,27 +1,27 @@ -Class { - #name : #PBRStubAnswer, - #superclass : #PBRAnswer, - #instVars : [ - 'ivar1', - 'ivar2' - ], - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #accessing } -PBRStubAnswer >> ivar1: anObject [ - ivar1 := anObject -] - -{ #category : #accessing } -PBRStubAnswer >> ivar2: anObject [ - ivar2 := anObject -] - -{ #category : #encoding } -PBRStubAnswer >> privateEncode: dict [ - super privateEncode: dict. - dict at: #ivar1 put: ivar1. - dict at: #ivar2f put: ivar2 first. - dict at: #ivar2r put: ivar2 allButFirst. -] +Class { + #name : #PBRStubAnswer, + #superclass : #PBRAnswer, + #instVars : [ + 'ivar1', + 'ivar2' + ], + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #accessing } +PBRStubAnswer >> ivar1: anObject [ + ivar1 := anObject +] + +{ #category : #accessing } +PBRStubAnswer >> ivar2: anObject [ + ivar2 := anObject +] + +{ #category : #encoding } +PBRStubAnswer >> privateEncode: dict [ + super privateEncode: dict. + dict at: #ivar1 put: ivar1. + dict at: #ivar2f put: ivar2 first. + dict at: #ivar2r put: ivar2 allButFirst. +] diff --git a/src/PythonBridge/PBRStubMessage.class.st b/src/PythonBridge/PBRStubMessage.class.st index 467e664..4a055b5 100644 --- a/src/PythonBridge/PBRStubMessage.class.st +++ b/src/PythonBridge/PBRStubMessage.class.st @@ -1,36 +1,36 @@ -Class { - #name : #PBRStubMessage, - #superclass : #PBRSyncMessage, - #instVars : [ - 'ivar1', - 'ivar2' - ], - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #accessing } -PBRStubMessage class >> answerClass [ - ^ PBRStubAnswer -] - -{ #category : #accessing } -PBRStubMessage class >> type [ - ^ #RSTUB -] - -{ #category : #accessing } -PBRStubMessage >> ivar1 [ - ^ ivar1 -] - -{ #category : #accessing } -PBRStubMessage >> ivar2 [ - ^ ivar2 -] - -{ #category : #'as yet unclassified' } -PBRStubMessage >> privateDecode: dict [ - super privateDecode: dict. - ivar1 := dict at: #ivar1. - ivar2 := {dict at: #ivar2f} , (dict at: #ivar2r) -] +Class { + #name : #PBRStubMessage, + #superclass : #PBRSyncMessage, + #instVars : [ + 'ivar1', + 'ivar2' + ], + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #accessing } +PBRStubMessage class >> answerClass [ + ^ PBRStubAnswer +] + +{ #category : #accessing } +PBRStubMessage class >> type [ + ^ #RSTUB +] + +{ #category : #accessing } +PBRStubMessage >> ivar1 [ + ^ ivar1 +] + +{ #category : #accessing } +PBRStubMessage >> ivar2 [ + ^ ivar2 +] + +{ #category : #'as yet unclassified' } +PBRStubMessage >> privateDecode: dict [ + super privateDecode: dict. + ivar1 := dict at: #ivar1. + ivar2 := {dict at: #ivar2f} , (dict at: #ivar2r) +] diff --git a/src/PythonBridge/PBRSyncMessage.class.st b/src/PythonBridge/PBRSyncMessage.class.st index 90a04ef..40cb68b 100644 --- a/src/PythonBridge/PBRSyncMessage.class.st +++ b/src/PythonBridge/PBRSyncMessage.class.st @@ -1,44 +1,44 @@ -Class { - #name : #PBRSyncMessage, - #superclass : #PBRMessage, - #instVars : [ - 'syncId' - ], - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #accessing } -PBRSyncMessage class >> answerClass [ - ^ PBRAnswer -] - -{ #category : #accessing } -PBRSyncMessage class >> type [ - ^ #RSYNC -] - -{ #category : #accessing } -PBRSyncMessage >> answerClass [ - ^ self class answerClass -] - -{ #category : #accessing } -PBRSyncMessage >> createAnswer [ - ^ self answerClass answerFor: self -] - -{ #category : #testing } -PBRSyncMessage >> isSync [ - ^ true -] - -{ #category : #'as yet unclassified' } -PBRSyncMessage >> privateDecode: dict [ - super privateDecode: dict. - syncId := dict at: #__sync -] - -{ #category : #accessing } -PBRSyncMessage >> syncId [ - ^ syncId -] +Class { + #name : #PBRSyncMessage, + #superclass : #PBRMessage, + #instVars : [ + 'syncId' + ], + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #accessing } +PBRSyncMessage class >> answerClass [ + ^ PBRAnswer +] + +{ #category : #accessing } +PBRSyncMessage class >> type [ + ^ #RSYNC +] + +{ #category : #accessing } +PBRSyncMessage >> answerClass [ + ^ self class answerClass +] + +{ #category : #accessing } +PBRSyncMessage >> createAnswer [ + ^ self answerClass answerFor: self +] + +{ #category : #testing } +PBRSyncMessage >> isSync [ + ^ true +] + +{ #category : #'as yet unclassified' } +PBRSyncMessage >> privateDecode: dict [ + super privateDecode: dict. + syncId := dict at: #__sync +] + +{ #category : #accessing } +PBRSyncMessage >> syncId [ + ^ syncId +] diff --git a/src/PythonBridge/PBRegistryFinalizer.class.st b/src/PythonBridge/PBRegistryFinalizer.class.st index afc9286..d596e88 100644 --- a/src/PythonBridge/PBRegistryFinalizer.class.st +++ b/src/PythonBridge/PBRegistryFinalizer.class.st @@ -1,56 +1,56 @@ -Class { - #name : #PBRegistryFinalizer, - #superclass : #PBAbstractFinalizer, - #instVars : [ - 'pythonVariable', - 'executionHandler' - ], - #category : #'PythonBridge-Execution' -} - -{ #category : #accessing } -PBRegistryFinalizer class >> pythonVariable: aPythonVariable executionHandler: executionHandler [ - ^ self new - pythonVariable: aPythonVariable; - executionHandler: executionHandler - yourself -] - -{ #category : #accessing } -PBRegistryFinalizer >> executionHandler [ - ^ executionHandler -] - -{ #category : #accessing } -PBRegistryFinalizer >> executionHandler: anObject [ - executionHandler := anObject -] - -{ #category : #finalization } -PBRegistryFinalizer >> finalize [ - | cf | - executionHandler isRunning ifFalse: [ ^ self ]. - cf := executionHandler newCommandFactory. - cf << (self removeId: pythonVariable name). - cf send. -] - -{ #category : #accessing } -PBRegistryFinalizer >> pythonVariable [ - ^ pythonVariable -] - -{ #category : #accessing } -PBRegistryFinalizer >> pythonVariable: anObject [ - pythonVariable := anObject -] - -{ #category : #asserting } -PBRegistryFinalizer >> registryExpression [ - ^ #registry callWith: #() -] - -{ #category : #asserting } -PBRegistryFinalizer >> removeId: anId [ - ^ self registryExpression => #clean callWith: (Array with: anId) -] +Class { + #name : #PBRegistryFinalizer, + #superclass : #PBAbstractFinalizer, + #instVars : [ + 'pythonVariable', + 'executionHandler' + ], + #category : #'PythonBridge-Execution' +} + +{ #category : #accessing } +PBRegistryFinalizer class >> pythonVariable: aPythonVariable executionHandler: executionHandler [ + ^ self new + pythonVariable: aPythonVariable; + executionHandler: executionHandler + yourself +] + +{ #category : #accessing } +PBRegistryFinalizer >> executionHandler [ + ^ executionHandler +] + +{ #category : #accessing } +PBRegistryFinalizer >> executionHandler: anObject [ + executionHandler := anObject +] + +{ #category : #finalization } +PBRegistryFinalizer >> finalize [ + | cf | + executionHandler isRunning ifFalse: [ ^ self ]. + cf := executionHandler newCommandFactory. + cf << (self removeId: pythonVariable name). + cf send. +] + +{ #category : #accessing } +PBRegistryFinalizer >> pythonVariable [ + ^ pythonVariable +] + +{ #category : #accessing } +PBRegistryFinalizer >> pythonVariable: anObject [ + pythonVariable := anObject +] + +{ #category : #asserting } +PBRegistryFinalizer >> registryExpression [ + ^ #registry callWith: #() +] + +{ #category : #asserting } +PBRegistryFinalizer >> removeId: anId [ + ^ self registryExpression => #clean callWith: (Array with: anId) +] diff --git a/src/PythonBridge/PBReplaceCommand.class.st b/src/PythonBridge/PBReplaceCommand.class.st index 2a10f31..cf3bb7f 100644 --- a/src/PythonBridge/PBReplaceCommand.class.st +++ b/src/PythonBridge/PBReplaceCommand.class.st @@ -1,31 +1,31 @@ -Class { - #name : #PBReplaceCommand, - #superclass : #PBErrorHandlingAction, - #instVars : [ - 'newCommand' - ], - #category : #'PythonBridge-ErrorHandling' -} - -{ #category : #'as yet unclassified' } -PBReplaceCommand >> actionSymbol [ - ^ #'REPLACE_COMMAND' -] - -{ #category : #'as yet unclassified' } -PBReplaceCommand >> encodeAsDictionary [ - | response | - response := super encodeAsDictionary. - response at: #command put: newCommand encodeAsDictionary. - ^ response -] - -{ #category : #accessing } -PBReplaceCommand >> newCommand [ - ^ newCommand -] - -{ #category : #accessing } -PBReplaceCommand >> newCommand: anObject [ - newCommand := anObject -] +Class { + #name : #PBReplaceCommand, + #superclass : #PBErrorHandlingAction, + #instVars : [ + 'newCommand' + ], + #category : #'PythonBridge-ErrorHandling' +} + +{ #category : #'as yet unclassified' } +PBReplaceCommand >> actionSymbol [ + ^ #'REPLACE_COMMAND' +] + +{ #category : #'as yet unclassified' } +PBReplaceCommand >> encodeAsDictionary [ + | response | + response := super encodeAsDictionary. + response at: #command put: newCommand encodeAsDictionary. + ^ response +] + +{ #category : #accessing } +PBReplaceCommand >> newCommand [ + ^ newCommand +] + +{ #category : #accessing } +PBReplaceCommand >> newCommand: anObject [ + newCommand := anObject +] diff --git a/src/PythonBridge/PBRetry.class.st b/src/PythonBridge/PBRetry.class.st index 21b22d9..0cb2d80 100644 --- a/src/PythonBridge/PBRetry.class.st +++ b/src/PythonBridge/PBRetry.class.st @@ -1,5 +1,5 @@ -Class { - #name : #PBRetry, - #superclass : #PBErrorHandlingAction, - #category : #'PythonBridge-ErrorHandling' -} +Class { + #name : #PBRetry, + #superclass : #PBErrorHandlingAction, + #category : #'PythonBridge-ErrorHandling' +} diff --git a/src/PythonBridge/PBSendCommandTest.class.st b/src/PythonBridge/PBSendCommandTest.class.st index 1d8f1ff..15bd605 100644 --- a/src/PythonBridge/PBSendCommandTest.class.st +++ b/src/PythonBridge/PBSendCommandTest.class.st @@ -1,82 +1,82 @@ -Class { - #name : #PBSendCommandTest, - #superclass : #PBApplicationTest, - #category : #'PythonBridge-Tests' -} - -{ #category : #tests } -PBSendCommandTest >> testAddBinding [ - | binding | - binding := PBBinding wrap: #((2) 3). - self cf addBinding: binding. - self cf << binding. - self assert: self cfSend waitForValue equals: #((2) 3) -] - -{ #category : #tests } -PBSendCommandTest >> testAddObserver [ - | observer callbackExecuted promiseSem | - promiseSem := Semaphore new. - callbackExecuted := false. - observer := self cf observerFromCallback: [ :obj | - promiseSem wait. - self assert: obj equals: 33. - self deny: promise isSignaled. - callbackExecuted := true ]. - self cf << (observer pythonNotify: 33). - self cf << 2. - self cfSend. - promiseSem signal. - self assert: promise waitForValue equals: 2. - self assert: callbackExecuted -] - -{ #category : #tests } -PBSendCommandTest >> testCallbackReturnValue [ - | observer callbackExecuted promiseSem | - promiseSem := Semaphore new. - callbackExecuted := false. - observer := self cf observerFromCallback: [ :obj | - promiseSem wait. - self assert: obj equals: 33. - self deny: promise isSignaled. - callbackExecuted := true. - 5 ]. - self cf << (observer pythonNotify: 33). - self cfSend. - promiseSem signal. - self assert: promise waitForValue equals: 5. - self assert: callbackExecuted -] - -{ #category : #tests } -PBSendCommandTest >> testInvalidCallbackReturn [ - | observer callbackExecuted promiseSem | - promiseSem := Semaphore new. - callbackExecuted := false. - observer := self cf observerFromCallback: [ :obj | - promiseSem wait. - self assert: obj equals: 33. - self deny: promise isSignaled. - callbackExecuted := true. - self ]. - self cf << (observer pythonNotify: 33). - self cfSend. - promiseSem signal. - self assert: promise waitForValue equals: nil. - self assert: callbackExecuted -] - -{ #category : #tests } -PBSendCommandTest >> testSendAssignAsLastMessage [ - self cf << (#foo asP3GI <- 33). - self cfSend. - self assert: promise waitForValue equals: nil -] - -{ #category : #tests } -PBSendCommandTest >> testSendImportAsLastMessage [ - self cf << #sys asP3GI import. - self cfSend. - self assert: promise waitForValue equals: nil -] +Class { + #name : #PBSendCommandTest, + #superclass : #PBApplicationTest, + #category : #'PythonBridge-Tests' +} + +{ #category : #tests } +PBSendCommandTest >> testAddBinding [ + | binding | + binding := PBBinding wrap: #((2) 3). + self cf addBinding: binding. + self cf << binding. + self assert: self cfSend waitForValue equals: #((2) 3) +] + +{ #category : #tests } +PBSendCommandTest >> testAddObserver [ + | observer callbackExecuted promiseSem | + promiseSem := Semaphore new. + callbackExecuted := false. + observer := self cf observerFromCallback: [ :obj | + promiseSem wait. + self assert: obj equals: 33. + self deny: promise isSignaled. + callbackExecuted := true ]. + self cf << (observer pythonNotify: 33). + self cf << 2. + self cfSend. + promiseSem signal. + self assert: promise waitForValue equals: 2. + self assert: callbackExecuted +] + +{ #category : #tests } +PBSendCommandTest >> testCallbackReturnValue [ + | observer callbackExecuted promiseSem | + promiseSem := Semaphore new. + callbackExecuted := false. + observer := self cf observerFromCallback: [ :obj | + promiseSem wait. + self assert: obj equals: 33. + self deny: promise isSignaled. + callbackExecuted := true. + 5 ]. + self cf << (observer pythonNotify: 33). + self cfSend. + promiseSem signal. + self assert: promise waitForValue equals: 5. + self assert: callbackExecuted +] + +{ #category : #tests } +PBSendCommandTest >> testInvalidCallbackReturn [ + | observer callbackExecuted promiseSem | + promiseSem := Semaphore new. + callbackExecuted := false. + observer := self cf observerFromCallback: [ :obj | + promiseSem wait. + self assert: obj equals: 33. + self deny: promise isSignaled. + callbackExecuted := true. + self ]. + self cf << (observer pythonNotify: 33). + self cfSend. + promiseSem signal. + self assert: promise waitForValue equals: nil. + self assert: callbackExecuted +] + +{ #category : #tests } +PBSendCommandTest >> testSendAssignAsLastMessage [ + self cf << (#foo asP3GI <- 33). + self cfSend. + self assert: promise waitForValue equals: nil +] + +{ #category : #tests } +PBSendCommandTest >> testSendImportAsLastMessage [ + self cf << #sys asP3GI import. + self cfSend. + self assert: promise waitForValue equals: nil +] diff --git a/src/PythonBridge/PBSerializationTest.class.st b/src/PythonBridge/PBSerializationTest.class.st index b22aba8..fd6fef0 100644 --- a/src/PythonBridge/PBSerializationTest.class.st +++ b/src/PythonBridge/PBSerializationTest.class.st @@ -1,26 +1,26 @@ -Class { - #name : #PBSerializationTest, - #superclass : #PBApplicationTest, - #category : #'PythonBridge-Tests' -} - -{ #category : #tests } -PBSerializationTest >> testSendAndRetrieveFloat [ - self cf << 2.2. - self cfSend. - self assert: promise waitForValue equals: 2.2. -] - -{ #category : #tests } -PBSerializationTest >> testSendAndRetrieveInteger [ - self cf << 2. - self cfSend. - self assert: promise waitForValue equals: 2. -] - -{ #category : #tests } -PBSerializationTest >> testSendAndRetrieveNil [ - self cf << nil. - self cfSend. - self assert: promise waitForValue equals: nil -] +Class { + #name : #PBSerializationTest, + #superclass : #PBApplicationTest, + #category : #'PythonBridge-Tests' +} + +{ #category : #tests } +PBSerializationTest >> testSendAndRetrieveFloat [ + self cf << 2.2. + self cfSend. + self assert: promise waitForValue equals: 2.2. +] + +{ #category : #tests } +PBSerializationTest >> testSendAndRetrieveInteger [ + self cf << 2. + self cfSend. + self assert: promise waitForValue equals: 2. +] + +{ #category : #tests } +PBSerializationTest >> testSendAndRetrieveNil [ + self cf << nil. + self cfSend. + self assert: promise waitForValue equals: nil +] diff --git a/src/PythonBridge/PBSerializeTest.class.st b/src/PythonBridge/PBSerializeTest.class.st index 7eb5c0e..b984cfc 100644 --- a/src/PythonBridge/PBSerializeTest.class.st +++ b/src/PythonBridge/PBSerializeTest.class.st @@ -1,31 +1,31 @@ -Class { - #name : #PBSerializeTest, - #superclass : #TestCase, - #instVars : [ - 'mapper' - ], - #category : #'PythonBridge-Tests' -} - -{ #category : #tests } -PBSerializeTest >> serializer [ - ^ mapper serializer - serializerWrapper: PBPlatform current class httpMessageBrokerClass serializer; - yourself -] - -{ #category : #tests } -PBSerializeTest >> setUp [ - super setUp. - mapper := PBMapperFactory forExecutionHandler: self -] - -{ #category : #tests } -PBSerializeTest >> testSerializeArray [ - self assert: (self serializer serialize: #(33 'foo')) equals: '[33,"foo"]' -] - -{ #category : #tests } -PBSerializeTest >> testSerializeNil [ - self assert: (self serializer serialize: nil) equals: 'null' -] +Class { + #name : #PBSerializeTest, + #superclass : #TestCase, + #instVars : [ + 'mapper' + ], + #category : #'PythonBridge-Tests' +} + +{ #category : #tests } +PBSerializeTest >> serializer [ + ^ mapper serializer + serializerWrapper: PBPlatform current class httpMessageBrokerClass serializer; + yourself +] + +{ #category : #tests } +PBSerializeTest >> setUp [ + super setUp. + mapper := PBMapperFactory forExecutionHandler: self +] + +{ #category : #tests } +PBSerializeTest >> testSerializeArray [ + self assert: (self serializer serialize: #(33 'foo')) equals: '[33,"foo"]' +] + +{ #category : #tests } +PBSerializeTest >> testSerializeNil [ + self assert: (self serializer serialize: nil) equals: 'null' +] diff --git a/src/PythonBridge/PBSerializer.class.st b/src/PythonBridge/PBSerializer.class.st index edb8599..21a8cd3 100644 --- a/src/PythonBridge/PBSerializer.class.st +++ b/src/PythonBridge/PBSerializer.class.st @@ -1,26 +1,26 @@ -Class { - #name : #PBSerializer, - #superclass : #PBMapper, - #category : #'PythonBridge-Serialization' -} - -{ #category : #private } -PBSerializer class >> deserialize: anObject [ - ^ PBDeserializer deserialize: anObject -] - -{ #category : #private } -PBSerializer class >> deserialize: anObject forApplication: application [ - ^ PBDeserializer deserialize: anObject forApplication: application -] - -{ #category : #private } -PBSerializer class >> serialize: anObject [ - ^ self new - serialize: anObject -] - -{ #category : #api } -PBSerializer >> serialize: anObject [ - ^ serializerWrapper serialize: anObject -] +Class { + #name : #PBSerializer, + #superclass : #PBMapper, + #category : #'PythonBridge-Serialization' +} + +{ #category : #private } +PBSerializer class >> deserialize: anObject [ + ^ PBDeserializer deserialize: anObject +] + +{ #category : #private } +PBSerializer class >> deserialize: anObject forApplication: application [ + ^ PBDeserializer deserialize: anObject forApplication: application +] + +{ #category : #private } +PBSerializer class >> serialize: anObject [ + ^ self new + serialize: anObject +] + +{ #category : #api } +PBSerializer >> serialize: anObject [ + ^ serializerWrapper serialize: anObject +] diff --git a/src/PythonBridge/PBSettings.class.st b/src/PythonBridge/PBSettings.class.st index f2c7ca0..5418f66 100644 --- a/src/PythonBridge/PBSettings.class.st +++ b/src/PythonBridge/PBSettings.class.st @@ -1,37 +1,37 @@ -Class { - #name : #PBSettings, - #superclass : #Object, - #instVars : [ - 'pharoSocketAddress', - 'pythonSocketAddress' - ], - #category : #'PythonBridge-Platform' -} - -{ #category : #'as yet unclassified' } -PBSettings class >> pharoSocketAddress: pharoSocketAddress pythonSocketAddress: pythonSocketAddress [ - ^ self new - pharoSocketAddress: pharoSocketAddress; - pythonSocketAddress: pythonSocketAddress; - yourself -] - -{ #category : #accessing } -PBSettings >> pharoSocketAddress [ - ^ pharoSocketAddress -] - -{ #category : #accessing } -PBSettings >> pharoSocketAddress: anObject [ - pharoSocketAddress := anObject -] - -{ #category : #accessing } -PBSettings >> pythonSocketAddress [ - ^ pythonSocketAddress -] - -{ #category : #accessing } -PBSettings >> pythonSocketAddress: anObject [ - pythonSocketAddress := anObject -] +Class { + #name : #PBSettings, + #superclass : #Object, + #instVars : [ + 'pharoSocketAddress', + 'pythonSocketAddress' + ], + #category : #'PythonBridge-Platform' +} + +{ #category : #'as yet unclassified' } +PBSettings class >> pharoSocketAddress: pharoSocketAddress pythonSocketAddress: pythonSocketAddress [ + ^ self new + pharoSocketAddress: pharoSocketAddress; + pythonSocketAddress: pythonSocketAddress; + yourself +] + +{ #category : #accessing } +PBSettings >> pharoSocketAddress [ + ^ pharoSocketAddress +] + +{ #category : #accessing } +PBSettings >> pharoSocketAddress: anObject [ + pharoSocketAddress := anObject +] + +{ #category : #accessing } +PBSettings >> pythonSocketAddress [ + ^ pythonSocketAddress +] + +{ #category : #accessing } +PBSettings >> pythonSocketAddress: anObject [ + pythonSocketAddress := anObject +] diff --git a/src/PythonBridge/PBSimpleApplicationTest.class.st b/src/PythonBridge/PBSimpleApplicationTest.class.st index ca35cc6..9aed354 100644 --- a/src/PythonBridge/PBSimpleApplicationTest.class.st +++ b/src/PythonBridge/PBSimpleApplicationTest.class.st @@ -1,67 +1,67 @@ -Class { - #name : #PBSimpleApplicationTest, - #superclass : #PBApplicationTest, - #category : #'PythonBridge-Tests' -} - -{ #category : #tests } -PBSimpleApplicationTest >> testDoubleRetrieveValue [ - | promise | - self cf << (P3GBinaryOperator new - left: 1; - right: 2; - operator: $+; - yourself). - promise := self cf send. - self assert: promise waitForValue equals: 3. - self cf << (P3GBinaryOperator new - left: 3; - right: 4; - operator: $*; - yourself). - promise := self cf send. - self assert: promise waitForValue equals: 12 -] - -{ #category : #tests } -PBSimpleApplicationTest >> testSimpleLambda [ - self cf << ((P3GLambda - argument: #a asP3GI - expression: #a asP3GI + 1) callWith: #( 2 )). - self assert: self cf send waitForValue equals: 3 -] - -{ #category : #tests } -PBSimpleApplicationTest >> testSimpleMapping [ - | obj type | - obj := self cf sendAndWait: #bridge_globals asP3GI => #msg_service. - type := self cf sendAndWait: (#type asP3GI callWith: (Array with: obj)). - self application addMapping: type to: (P3GLambda - argument: #x asP3GI - expression: 'STRING!!'). - self assert: (self cf sendAndWait: obj) equals: 'STRING!!' -] - -{ #category : #tests } -PBSimpleApplicationTest >> testSimpleRetrieveSameValue [ - | promise | - self cf << (P3GBinaryOperator new - left: 1; - right: 2; - operator: $+; - yourself). - promise := self cf send. - self assert: promise waitForValue equals: 3 -] - -{ #category : #tests } -PBSimpleApplicationTest >> testSimpleRetrieveSameValue2 [ - | promise | - self cf << (P3GBinaryOperator new - left: 3; - right: 4; - operator: $*; - yourself). - promise := self cf send. - self assert: promise waitForValue equals: 12 -] +Class { + #name : #PBSimpleApplicationTest, + #superclass : #PBApplicationTest, + #category : #'PythonBridge-Tests' +} + +{ #category : #tests } +PBSimpleApplicationTest >> testDoubleRetrieveValue [ + | promise | + self cf << (P3GBinaryOperator new + left: 1; + right: 2; + operator: $+; + yourself). + promise := self cf send. + self assert: promise waitForValue equals: 3. + self cf << (P3GBinaryOperator new + left: 3; + right: 4; + operator: $*; + yourself). + promise := self cf send. + self assert: promise waitForValue equals: 12 +] + +{ #category : #tests } +PBSimpleApplicationTest >> testSimpleLambda [ + self cf << ((P3GLambda + argument: #a asP3GI + expression: #a asP3GI + 1) callWith: #( 2 )). + self assert: self cf send waitForValue equals: 3 +] + +{ #category : #tests } +PBSimpleApplicationTest >> testSimpleMapping [ + | obj type | + obj := self cf sendAndWait: #bridge_globals asP3GI => #msg_service. + type := self cf sendAndWait: (#type asP3GI callWith: (Array with: obj)). + self application addMapping: type to: (P3GLambda + argument: #x asP3GI + expression: 'STRING!!'). + self assert: (self cf sendAndWait: obj) equals: 'STRING!!' +] + +{ #category : #tests } +PBSimpleApplicationTest >> testSimpleRetrieveSameValue [ + | promise | + self cf << (P3GBinaryOperator new + left: 1; + right: 2; + operator: $+; + yourself). + promise := self cf send. + self assert: promise waitForValue equals: 3 +] + +{ #category : #tests } +PBSimpleApplicationTest >> testSimpleRetrieveSameValue2 [ + | promise | + self cf << (P3GBinaryOperator new + left: 3; + right: 4; + operator: $*; + yourself). + promise := self cf send. + self assert: promise waitForValue equals: 12 +] diff --git a/src/PythonBridge/PBSocketAddress.class.st b/src/PythonBridge/PBSocketAddress.class.st index c220a0e..5e643a0 100644 --- a/src/PythonBridge/PBSocketAddress.class.st +++ b/src/PythonBridge/PBSocketAddress.class.st @@ -1,42 +1,42 @@ -Class { - #name : #PBSocketAddress, - #superclass : #Object, - #instVars : [ - 'ipOrName', - 'port' - ], - #category : #'PythonBridge-Platform' -} - -{ #category : #'as yet unclassified' } -PBSocketAddress class >> ipOrName: ipOrName port: aPort [ - ^ self new - ipOrName: ipOrName; - port: aPort; - yourself -] - -{ #category : #accessing } -PBSocketAddress >> ipOrName [ - ^ ipOrName -] - -{ #category : #accessing } -PBSocketAddress >> ipOrName: anObject [ - ipOrName := anObject -] - -{ #category : #accessing } -PBSocketAddress >> port [ - ^ port -] - -{ #category : #accessing } -PBSocketAddress >> port: anObject [ - port := anObject -] - -{ #category : #printing } -PBSocketAddress >> printAddress [ - ^ ipOrName , ':' , port asString -] +Class { + #name : #PBSocketAddress, + #superclass : #Object, + #instVars : [ + 'ipOrName', + 'port' + ], + #category : #'PythonBridge-Platform' +} + +{ #category : #'as yet unclassified' } +PBSocketAddress class >> ipOrName: ipOrName port: aPort [ + ^ self new + ipOrName: ipOrName; + port: aPort; + yourself +] + +{ #category : #accessing } +PBSocketAddress >> ipOrName [ + ^ ipOrName +] + +{ #category : #accessing } +PBSocketAddress >> ipOrName: anObject [ + ipOrName := anObject +] + +{ #category : #accessing } +PBSocketAddress >> port [ + ^ port +] + +{ #category : #accessing } +PBSocketAddress >> port: anObject [ + port := anObject +] + +{ #category : #printing } +PBSocketAddress >> printAddress [ + ^ ipOrName , ':' , port asString +] diff --git a/src/PythonBridge/PBStubAnswer.class.st b/src/PythonBridge/PBStubAnswer.class.st index 534506b..636a7f7 100644 --- a/src/PythonBridge/PBStubAnswer.class.st +++ b/src/PythonBridge/PBStubAnswer.class.st @@ -1,25 +1,25 @@ -Class { - #name : #PBStubAnswer, - #superclass : #PBAnswer, - #instVars : [ - 'ivar1', - 'ivar2' - ], - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #converting } -PBStubAnswer >> decode: dict [ - ivar1 := dict at: #ivar1. - ivar2 := { dict at: #ivar2f } , (dict at: #ivar2r) -] - -{ #category : #accessing } -PBStubAnswer >> ivar1 [ - ^ ivar1 -] - -{ #category : #accessing } -PBStubAnswer >> ivar2 [ - ^ ivar2 -] +Class { + #name : #PBStubAnswer, + #superclass : #PBAnswer, + #instVars : [ + 'ivar1', + 'ivar2' + ], + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #converting } +PBStubAnswer >> decode: dict [ + ivar1 := dict at: #ivar1. + ivar2 := { dict at: #ivar2f } , (dict at: #ivar2r) +] + +{ #category : #accessing } +PBStubAnswer >> ivar1 [ + ^ ivar1 +] + +{ #category : #accessing } +PBStubAnswer >> ivar2 [ + ^ ivar2 +] diff --git a/src/PythonBridge/PBStubApplication.class.st b/src/PythonBridge/PBStubApplication.class.st index 0f3ac25..7ad1e23 100644 --- a/src/PythonBridge/PBStubApplication.class.st +++ b/src/PythonBridge/PBStubApplication.class.st @@ -1,15 +1,15 @@ -Class { - #name : #PBStubApplication, - #superclass : #PBApplication, - #category : #'PythonBridge-Tests' -} - -{ #category : #initialization } -PBStubApplication >> handlers [ - ^ Array with: loggingHandler -] - -{ #category : #initialization } -PBStubApplication >> initializeHandlers [ - loggingHandler := PBLoggingHandler application: self. -] +Class { + #name : #PBStubApplication, + #superclass : #PBApplication, + #category : #'PythonBridge-Tests' +} + +{ #category : #initialization } +PBStubApplication >> handlers [ + ^ Array with: loggingHandler +] + +{ #category : #initialization } +PBStubApplication >> initializeHandlers [ + loggingHandler := PBLoggingHandler application: self. +] diff --git a/src/PythonBridge/PBStubMessage.class.st b/src/PythonBridge/PBStubMessage.class.st index fbeac62..804163b 100644 --- a/src/PythonBridge/PBStubMessage.class.st +++ b/src/PythonBridge/PBStubMessage.class.st @@ -1,47 +1,47 @@ -Class { - #name : #PBStubMessage, - #superclass : #PBSyncMessage, - #instVars : [ - 'ivar1', - 'ivar2' - ], - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #accessing } -PBStubMessage class >> answerClass [ - ^ PBStubAnswer -] - -{ #category : #accessing } -PBStubMessage class >> type [ - ^ #STUB -] - -{ #category : #accessing } -PBStubMessage >> ivar1 [ - ^ ivar1 -] - -{ #category : #accessing } -PBStubMessage >> ivar1: anObject [ - ivar1 := anObject -] - -{ #category : #accessing } -PBStubMessage >> ivar2 [ - ^ ivar2 -] - -{ #category : #accessing } -PBStubMessage >> ivar2: anObject [ - ivar2 := anObject -] - -{ #category : #encode } -PBStubMessage >> privateEncode: aDict [ - super privateEncode: aDict. - aDict at: #ivar1 put: ivar1. - aDict at: #ivar2f put: ivar2 first. - aDict at: #ivar2r put: ivar2 allButFirst. -] +Class { + #name : #PBStubMessage, + #superclass : #PBSyncMessage, + #instVars : [ + 'ivar1', + 'ivar2' + ], + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #accessing } +PBStubMessage class >> answerClass [ + ^ PBStubAnswer +] + +{ #category : #accessing } +PBStubMessage class >> type [ + ^ #STUB +] + +{ #category : #accessing } +PBStubMessage >> ivar1 [ + ^ ivar1 +] + +{ #category : #accessing } +PBStubMessage >> ivar1: anObject [ + ivar1 := anObject +] + +{ #category : #accessing } +PBStubMessage >> ivar2 [ + ^ ivar2 +] + +{ #category : #accessing } +PBStubMessage >> ivar2: anObject [ + ivar2 := anObject +] + +{ #category : #encode } +PBStubMessage >> privateEncode: aDict [ + super privateEncode: aDict. + aDict at: #ivar1 put: ivar1. + aDict at: #ivar2f put: ivar2 first. + aDict at: #ivar2r put: ivar2 allButFirst. +] diff --git a/src/PythonBridge/PBSyncMessage.class.st b/src/PythonBridge/PBSyncMessage.class.st index 0fc4fd3..76c4a61 100644 --- a/src/PythonBridge/PBSyncMessage.class.st +++ b/src/PythonBridge/PBSyncMessage.class.st @@ -1,50 +1,50 @@ -Class { - #name : #PBSyncMessage, - #superclass : #PBMessage, - #instVars : [ - 'syncId' - ], - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #accessing } -PBSyncMessage class >> answerClass [ - ^ PBAnswer -] - -{ #category : #accessing } -PBSyncMessage class >> type [ - ^ #SYNC -] - -{ #category : #accessing } -PBSyncMessage >> answerClass [ - ^ self class answerClass -] - -{ #category : #accessing } -PBSyncMessage >> createAnswer [ - ^ self answerClass answerFor: self -] - -{ #category : #initialization } -PBSyncMessage >> initialize [ - super initialize. - syncId := PBPlatform current newRandomName -] - -{ #category : #testing } -PBSyncMessage >> isSync [ - ^ true -] - -{ #category : #writing } -PBSyncMessage >> privateEncode: aDict [ - super privateEncode: aDict. - aDict at: #__sync put: self syncId -] - -{ #category : #writing } -PBSyncMessage >> syncId [ - ^ syncId -] +Class { + #name : #PBSyncMessage, + #superclass : #PBMessage, + #instVars : [ + 'syncId' + ], + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #accessing } +PBSyncMessage class >> answerClass [ + ^ PBAnswer +] + +{ #category : #accessing } +PBSyncMessage class >> type [ + ^ #SYNC +] + +{ #category : #accessing } +PBSyncMessage >> answerClass [ + ^ self class answerClass +] + +{ #category : #accessing } +PBSyncMessage >> createAnswer [ + ^ self answerClass answerFor: self +] + +{ #category : #initialization } +PBSyncMessage >> initialize [ + super initialize. + syncId := PBPlatform current newRandomName +] + +{ #category : #testing } +PBSyncMessage >> isSync [ + ^ true +] + +{ #category : #writing } +PBSyncMessage >> privateEncode: aDict [ + super privateEncode: aDict. + aDict at: #__sync put: self syncId +] + +{ #category : #writing } +PBSyncMessage >> syncId [ + ^ syncId +] diff --git a/src/PythonBridge/PBSyncMessageHandler.class.st b/src/PythonBridge/PBSyncMessageHandler.class.st index b5c2108..ff6f558 100644 --- a/src/PythonBridge/PBSyncMessageHandler.class.st +++ b/src/PythonBridge/PBSyncMessageHandler.class.st @@ -1,24 +1,24 @@ -Class { - #name : #PBSyncMessageHandler, - #superclass : #PBMessageHandler, - #instVars : [ - 'answer' - ], - #category : #'PythonBridge-Platform' -} - -{ #category : #accessing } -PBSyncMessageHandler >> answer [ - ^ answer -] - -{ #category : #accessing } -PBSyncMessageHandler >> handleMessage [ - answer := callback value: message. - self assert: answer class = message answerClass. -] - -{ #category : #asserting } -PBSyncMessageHandler >> shouldAnswer [ - ^ true -] +Class { + #name : #PBSyncMessageHandler, + #superclass : #PBMessageHandler, + #instVars : [ + 'answer' + ], + #category : #'PythonBridge-Platform' +} + +{ #category : #accessing } +PBSyncMessageHandler >> answer [ + ^ answer +] + +{ #category : #accessing } +PBSyncMessageHandler >> handleMessage [ + answer := callback value: message. + self assert: answer class = message answerClass. +] + +{ #category : #asserting } +PBSyncMessageHandler >> shouldAnswer [ + ^ true +] diff --git a/src/PythonBridge/PBTestCase.class.st b/src/PythonBridge/PBTestCase.class.st index 2713cbf..20af39e 100644 --- a/src/PythonBridge/PBTestCase.class.st +++ b/src/PythonBridge/PBTestCase.class.st @@ -1,83 +1,83 @@ -Class { - #name : #PBTestCase, - #superclass : #TestCase, - #instVars : [ - 'commandFactory', - 'promise' - ], - #category : #'PythonBridge-Tests' -} - -{ #category : #accessing } -PBTestCase class >> appResource [ - self subclassResponsibility -] - -{ #category : #accessing } -PBTestCase class >> resources [ - ^ super resources , (Array with: self appResource) -] - -{ #category : #initialization } -PBTestCase >> app [ - ^ self application -] - -{ #category : #initialization } -PBTestCase >> application [ - ^ self applicationClass uniqueInstance -] - -{ #category : #initialization } -PBTestCase >> applicationClass [ - self subclassResponsibility -] - -{ #category : #asserting } -PBTestCase >> assertClass: cls name: aName [ - self cf << (cls => #__name__). - self assert: self cf send waitForValue equals: aName -] - -{ #category : #asserting } -PBTestCase >> assertExpression: expr equals: aBlockOrValue [ - self cf << expr. - self assert: self cf send waitForValue equals: aBlockOrValue value -] - -{ #category : #asserting } -PBTestCase >> assertInstanceClass: obj name: aName [ - self cf << ((#type asP3GI callWith: (Array with: obj)) => #__name__). - self assert: self cf send waitForValue equals: aName -] - -{ #category : #initialization } -PBTestCase >> cf [ - ^ self commandFactory -] - -{ #category : #initialization } -PBTestCase >> cfSend [ - ^ promise := self cf send -] - -{ #category : #initialization } -PBTestCase >> commandFactory [ - ^ self application commandFactory -] - -{ #category : #asserting } -PBTestCase >> registryExpression [ - ^ #registry callWith: #() -] - -{ #category : #asserting } -PBTestCase >> resolveId: anId [ - ^ self registryExpression => #resolve callWith: (Array with: anId) -] - -{ #category : #running } -PBTestCase >> setUp [ - super setUp. - self cf reset -] +Class { + #name : #PBTestCase, + #superclass : #TestCase, + #instVars : [ + 'commandFactory', + 'promise' + ], + #category : #'PythonBridge-Tests' +} + +{ #category : #accessing } +PBTestCase class >> appResource [ + self subclassResponsibility +] + +{ #category : #accessing } +PBTestCase class >> resources [ + ^ super resources , (Array with: self appResource) +] + +{ #category : #initialization } +PBTestCase >> app [ + ^ self application +] + +{ #category : #initialization } +PBTestCase >> application [ + ^ self applicationClass uniqueInstance +] + +{ #category : #initialization } +PBTestCase >> applicationClass [ + self subclassResponsibility +] + +{ #category : #asserting } +PBTestCase >> assertClass: cls name: aName [ + self cf << (cls => #__name__). + self assert: self cf send waitForValue equals: aName +] + +{ #category : #asserting } +PBTestCase >> assertExpression: expr equals: aBlockOrValue [ + self cf << expr. + self assert: self cf send waitForValue equals: aBlockOrValue value +] + +{ #category : #asserting } +PBTestCase >> assertInstanceClass: obj name: aName [ + self cf << ((#type asP3GI callWith: (Array with: obj)) => #__name__). + self assert: self cf send waitForValue equals: aName +] + +{ #category : #initialization } +PBTestCase >> cf [ + ^ self commandFactory +] + +{ #category : #initialization } +PBTestCase >> cfSend [ + ^ promise := self cf send +] + +{ #category : #initialization } +PBTestCase >> commandFactory [ + ^ self application commandFactory +] + +{ #category : #asserting } +PBTestCase >> registryExpression [ + ^ #registry callWith: #() +] + +{ #category : #asserting } +PBTestCase >> resolveId: anId [ + ^ self registryExpression => #resolve callWith: (Array with: anId) +] + +{ #category : #running } +PBTestCase >> setUp [ + super setUp. + self cf reset +] diff --git a/src/PythonBridge/PBUiManager.class.st b/src/PythonBridge/PBUiManager.class.st index 536b455..9ddf317 100644 --- a/src/PythonBridge/PBUiManager.class.st +++ b/src/PythonBridge/PBUiManager.class.st @@ -1,15 +1,15 @@ -Class { - #name : #PBUiManager, - #superclass : #Object, - #category : #'PythonBridge-Platform' -} - -{ #category : #hooks } -PBUiManager >> notify: aString [ - self subclassResponsibility -] - -{ #category : #hooks } -PBUiManager >> spawnDebuggerOnException: anException [ - self subclassResponsibility -] +Class { + #name : #PBUiManager, + #superclass : #Object, + #category : #'PythonBridge-Platform' +} + +{ #category : #hooks } +PBUiManager >> notify: aString [ + self subclassResponsibility +] + +{ #category : #hooks } +PBUiManager >> spawnDebuggerOnException: anException [ + self subclassResponsibility +] diff --git a/src/PythonBridge/PBUpdatePromiseMessage.class.st b/src/PythonBridge/PBUpdatePromiseMessage.class.st index 55ead90..70a0e35 100644 --- a/src/PythonBridge/PBUpdatePromiseMessage.class.st +++ b/src/PythonBridge/PBUpdatePromiseMessage.class.st @@ -1,31 +1,31 @@ -Class { - #name : #PBUpdatePromiseMessage, - #superclass : #PBRAsyncMessage, - #instVars : [ - 'promiseId', - 'value' - ], - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #accessing } -PBUpdatePromiseMessage class >> type [ - ^ #EVAL -] - -{ #category : #'as yet unclassified' } -PBUpdatePromiseMessage >> privateDecode: dict [ - super privateDecode: dict. - promiseId := dict at: #id. - value := dict at: #value -] - -{ #category : #accessing } -PBUpdatePromiseMessage >> promiseId [ - ^ promiseId -] - -{ #category : #accessing } -PBUpdatePromiseMessage >> value [ - ^ value -] +Class { + #name : #PBUpdatePromiseMessage, + #superclass : #PBRAsyncMessage, + #instVars : [ + 'promiseId', + 'value' + ], + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #accessing } +PBUpdatePromiseMessage class >> type [ + ^ #EVAL +] + +{ #category : #'as yet unclassified' } +PBUpdatePromiseMessage >> privateDecode: dict [ + super privateDecode: dict. + promiseId := dict at: #id. + value := dict at: #value +] + +{ #category : #accessing } +PBUpdatePromiseMessage >> promiseId [ + ^ promiseId +] + +{ #category : #accessing } +PBUpdatePromiseMessage >> value [ + ^ value +] diff --git a/src/PythonBridge/PBUtils.class.st b/src/PythonBridge/PBUtils.class.st index 0403a13..cd3eb86 100644 --- a/src/PythonBridge/PBUtils.class.st +++ b/src/PythonBridge/PBUtils.class.st @@ -1,15 +1,15 @@ -Class { - #name : #PBUtils, - #superclass : #Object, - #category : #'PythonBridge-Core' -} - -{ #category : #'instance creation' } -PBUtils class >> newP3Variable [ - ^ self newP3VariableName asP3GI -] - -{ #category : #'instance creation' } -PBUtils class >> newP3VariableName [ - ^ PBPlatform current newRandomName -] +Class { + #name : #PBUtils, + #superclass : #Object, + #category : #'PythonBridge-Core' +} + +{ #category : #'instance creation' } +PBUtils class >> newP3Variable [ + ^ self newP3VariableName asP3GI +] + +{ #category : #'instance creation' } +PBUtils class >> newP3VariableName [ + ^ PBPlatform current newRandomName +] diff --git a/src/PythonBridge/PBWeakFinalizerTest.class.st b/src/PythonBridge/PBWeakFinalizerTest.class.st index 6648dd2..9a4443e 100644 --- a/src/PythonBridge/PBWeakFinalizerTest.class.st +++ b/src/PythonBridge/PBWeakFinalizerTest.class.st @@ -1,104 +1,104 @@ -Class { - #name : #PBWeakFinalizerTest, - #superclass : #TestCase, - #instVars : [ - 'weakRegistry', - 'assertCounter' - ], - #category : #'PythonBridge-Platform' -} - -{ #category : #testing } -PBWeakFinalizerTest class >> isAbstract [ - ^ self == PBWeakFinalizerTest -] - -{ #category : #running } -PBWeakFinalizerTest >> assertCount: anInteger [ - self assert: assertCounter equals: anInteger -] - -{ #category : #running } -PBWeakFinalizerTest >> countFinalizer [ - ^ PBBlockFinalizer block: [ assertCounter := assertCounter + 1 ] -] - -{ #category : #running } -PBWeakFinalizerTest >> setUp [ - super setUp. - weakRegistry := self weakRegistryClass new. - assertCounter := 0 -] - -{ #category : #running } -PBWeakFinalizerTest >> tearDown [ - weakRegistry destroy. - super tearDown -] - -{ #category : #running } -PBWeakFinalizerTest >> testBlockFinalizer [ - self assertCount: 0. - self countFinalizer finalize. - self assertCount: 1 -] - -{ #category : #running } -PBWeakFinalizerTest >> testDestroy [ - | obj | - obj := Object new. - weakRegistry registerObject: obj finalizer: self countFinalizer. - weakRegistry destroy. - obj := nil. - self triggerGC. - self assertCount: 0 -] - -{ #category : #running } -PBWeakFinalizerTest >> testGcMultObjects [ - | obj1 obj2 obj3 | - obj1 := Object new. - obj2 := Object new. - obj3 := Object new. - weakRegistry registerObject: obj1 finalizer: self countFinalizer. - weakRegistry registerObject: obj2 finalizer: self countFinalizer. - obj1 := nil. - self triggerGC. - self assertCount: 1. - weakRegistry registerObject: obj3 finalizer: self countFinalizer. - self triggerGC. - self assertCount: 1. - obj2 := nil. - obj3 := nil. - self triggerGC. - self assertCount: 3 -] - -{ #category : #running } -PBWeakFinalizerTest >> testGcObject [ - | obj | - obj := Object new. - weakRegistry registerObject: obj finalizer: self countFinalizer. - obj := nil. - self triggerGC. - self assertCount: 1 -] - -{ #category : #running } -PBWeakFinalizerTest >> testNotGcObject [ - | obj | - obj := Object new. - weakRegistry registerObject: obj finalizer: self countFinalizer. - self triggerGC. - self assertCount: 0 -] - -{ #category : #running } -PBWeakFinalizerTest >> triggerGC [ - self subclassResponsibility -] - -{ #category : #running } -PBWeakFinalizerTest >> weakRegistryClass [ - self subclassResponsibility -] +Class { + #name : #PBWeakFinalizerTest, + #superclass : #TestCase, + #instVars : [ + 'weakRegistry', + 'assertCounter' + ], + #category : #'PythonBridge-Platform' +} + +{ #category : #testing } +PBWeakFinalizerTest class >> isAbstract [ + ^ self == PBWeakFinalizerTest +] + +{ #category : #running } +PBWeakFinalizerTest >> assertCount: anInteger [ + self assert: assertCounter equals: anInteger +] + +{ #category : #running } +PBWeakFinalizerTest >> countFinalizer [ + ^ PBBlockFinalizer block: [ assertCounter := assertCounter + 1 ] +] + +{ #category : #running } +PBWeakFinalizerTest >> setUp [ + super setUp. + weakRegistry := self weakRegistryClass new. + assertCounter := 0 +] + +{ #category : #running } +PBWeakFinalizerTest >> tearDown [ + weakRegistry destroy. + super tearDown +] + +{ #category : #running } +PBWeakFinalizerTest >> testBlockFinalizer [ + self assertCount: 0. + self countFinalizer finalize. + self assertCount: 1 +] + +{ #category : #running } +PBWeakFinalizerTest >> testDestroy [ + | obj | + obj := Object new. + weakRegistry registerObject: obj finalizer: self countFinalizer. + weakRegistry destroy. + obj := nil. + self triggerGC. + self assertCount: 0 +] + +{ #category : #running } +PBWeakFinalizerTest >> testGcMultObjects [ + | obj1 obj2 obj3 | + obj1 := Object new. + obj2 := Object new. + obj3 := Object new. + weakRegistry registerObject: obj1 finalizer: self countFinalizer. + weakRegistry registerObject: obj2 finalizer: self countFinalizer. + obj1 := nil. + self triggerGC. + self assertCount: 1. + weakRegistry registerObject: obj3 finalizer: self countFinalizer. + self triggerGC. + self assertCount: 1. + obj2 := nil. + obj3 := nil. + self triggerGC. + self assertCount: 3 +] + +{ #category : #running } +PBWeakFinalizerTest >> testGcObject [ + | obj | + obj := Object new. + weakRegistry registerObject: obj finalizer: self countFinalizer. + obj := nil. + self triggerGC. + self assertCount: 1 +] + +{ #category : #running } +PBWeakFinalizerTest >> testNotGcObject [ + | obj | + obj := Object new. + weakRegistry registerObject: obj finalizer: self countFinalizer. + self triggerGC. + self assertCount: 0 +] + +{ #category : #running } +PBWeakFinalizerTest >> triggerGC [ + self subclassResponsibility +] + +{ #category : #running } +PBWeakFinalizerTest >> weakRegistryClass [ + self subclassResponsibility +] diff --git a/src/PythonBridge/SequenceableCollection.extension.st b/src/PythonBridge/SequenceableCollection.extension.st index 31137fd..2222b1d 100644 --- a/src/PythonBridge/SequenceableCollection.extension.st +++ b/src/PythonBridge/SequenceableCollection.extension.st @@ -1,11 +1,11 @@ -Extension { #name : #SequenceableCollection } - -{ #category : #'*PythonBridge' } -SequenceableCollection >> isPythonGenerable [ - ^ true -] - -{ #category : #'*PythonBridge' } -SequenceableCollection >> isPythonValue [ - ^ true -] +Extension { #name : #SequenceableCollection } + +{ #category : #'*PythonBridge' } +SequenceableCollection >> isPythonGenerable [ + ^ true +] + +{ #category : #'*PythonBridge' } +SequenceableCollection >> isPythonValue [ + ^ true +] diff --git a/src/PythonBridge/Set.extension.st b/src/PythonBridge/Set.extension.st index d5b9ce6..3f0a8eb 100644 --- a/src/PythonBridge/Set.extension.st +++ b/src/PythonBridge/Set.extension.st @@ -1,11 +1,11 @@ -Extension { #name : #Set } - -{ #category : #'*PythonBridge' } -Set >> isPythonGenerable [ - ^ true -] - -{ #category : #'*PythonBridge' } -Set >> isPythonValue [ - ^ true -] +Extension { #name : #Set } + +{ #category : #'*PythonBridge' } +Set >> isPythonGenerable [ + ^ true +] + +{ #category : #'*PythonBridge' } +Set >> isPythonValue [ + ^ true +] diff --git a/src/PythonBridge/True.extension.st b/src/PythonBridge/True.extension.st index fe1ad98..07f7eb6 100644 --- a/src/PythonBridge/True.extension.st +++ b/src/PythonBridge/True.extension.st @@ -1,11 +1,11 @@ -Extension { #name : #True } - -{ #category : #'*PythonBridge' } -True >> isPythonGenerable [ - ^ true -] - -{ #category : #'*PythonBridge' } -True >> isPythonValue [ - ^ true -] +Extension { #name : #True } + +{ #category : #'*PythonBridge' } +True >> isPythonGenerable [ + ^ true +] + +{ #category : #'*PythonBridge' } +True >> isPythonValue [ + ^ true +] diff --git a/src/PythonBridge/UndefinedObject.extension.st b/src/PythonBridge/UndefinedObject.extension.st index a2af7d4..9c1b225 100644 --- a/src/PythonBridge/UndefinedObject.extension.st +++ b/src/PythonBridge/UndefinedObject.extension.st @@ -1,11 +1,11 @@ -Extension { #name : #UndefinedObject } - -{ #category : #'*PythonBridge' } -UndefinedObject >> isPythonGenerable [ - ^ true -] - -{ #category : #'*PythonBridge' } -UndefinedObject >> isPythonValue [ - ^ true -] +Extension { #name : #UndefinedObject } + +{ #category : #'*PythonBridge' } +UndefinedObject >> isPythonGenerable [ + ^ true +] + +{ #category : #'*PythonBridge' } +UndefinedObject >> isPythonValue [ + ^ true +] diff --git a/src/PythonBridge/package.st b/src/PythonBridge/package.st index 3f3c901..45fd065 100644 --- a/src/PythonBridge/package.st +++ b/src/PythonBridge/package.st @@ -1 +1 @@ -Package { #name : #PythonBridge } +Package { #name : #PythonBridge } From b63dac78fd30a5b3a3f8eb033d9bc3385bb1233e Mon Sep 17 00:00:00 2001 From: Alejandro Infante Date: Fri, 6 Dec 2019 13:46:00 -0300 Subject: [PATCH 02/34] Fix an error on VisualWorks. --- src/PythonBridge/PBMessageBrokerTest.class.st | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PythonBridge/PBMessageBrokerTest.class.st b/src/PythonBridge/PBMessageBrokerTest.class.st index 93ccbb5..e29f01f 100644 --- a/src/PythonBridge/PBMessageBrokerTest.class.st +++ b/src/PythonBridge/PBMessageBrokerTest.class.st @@ -81,9 +81,9 @@ PBMessageBrokerTest >> sendMessageToBroker: dict answerBlock: aBlock [ PBMessageBrokerTest >> sendMessageToBroker: dict answerEquals: ansDict [ | flag | flag := false. - self sendMessageToBroker: dict answerBlock: [ :ansAssoc | + self sendMessageToBroker: dict answerBlock: [ :aDict | flag := true. - self assert: ansAssoc value equals: ansDict ]. + self assert: aDict equals: ansDict ]. self assert: flag ] From c45bd1bb79858a3d7588a0926ac9c2d8535b2f36 Mon Sep 17 00:00:00 2001 From: Alejandro Infante Date: Wed, 11 Dec 2019 07:29:51 -0300 Subject: [PATCH 03/34] Update docs with communication protocol. --- docs/pages/pharo-installation.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/pages/pharo-installation.md b/docs/pages/pharo-installation.md index 4c0abe3..ff7a2b5 100644 --- a/docs/pages/pharo-installation.md +++ b/docs/pages/pharo-installation.md @@ -151,3 +151,13 @@ PBApplication do: [ ] ``` To try this code snippet using KerasBridge replace `PBApplication` -> `Keras` and `PBCF` -> `KCF`. + +## Changing communication protocol +By default, the communication protocol for the bridge is MessagePack through native sockets. To manage which protocol to use we run: +``` +PBPlatform current setSocketMessageBroker. "Set MessagePack over socket protocol" +``` +or +``` +PBPlatform current setHttpMessageBroker. "Set JSON over HTTP protocol" +``` From 94fbd6acfd98db848188b6c35219f167a939f406 Mon Sep 17 00:00:00 2001 From: Alejandro Infante Date: Thu, 19 Dec 2019 07:07:33 -0300 Subject: [PATCH 04/34] Add video --- docs/index.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index de375bd..a02efda 100644 --- a/docs/index.md +++ b/docs/index.md @@ -15,6 +15,8 @@ PythonBridge gives Smalltalk developers the capability of interacting and reusin [Get started now](#getting-started){: .btn .btn-primary .fs-5 .mb-4 .mb-md-0 .mr-2 } [View it on GitHub](https://github.com/ObjectProfile/PythonBridge){: .btn .btn-green .fs-5 .mb-4 .mb-md-0 } + + --- ## Getting started in Pharo @@ -58,4 +60,4 @@ PBApplication do: [ ## Bridges based on PythonBridge -- [KerasBridge](https://objectprofile.github.io/KerasBridge) \ No newline at end of file +- [KerasBridge](https://objectprofile.github.io/KerasBridge) From 68947610a93e5ef8fab39920821720976531c73e Mon Sep 17 00:00:00 2001 From: Alejandro Infante Date: Thu, 19 Dec 2019 13:48:30 -0300 Subject: [PATCH 05/34] Fix problem with video --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index a02efda..d5a2851 100644 --- a/docs/index.md +++ b/docs/index.md @@ -15,7 +15,7 @@ PythonBridge gives Smalltalk developers the capability of interacting and reusin [Get started now](#getting-started){: .btn .btn-primary .fs-5 .mb-4 .mb-md-0 .mr-2 } [View it on GitHub](https://github.com/ObjectProfile/PythonBridge){: .btn .btn-green .fs-5 .mb-4 .mb-md-0 } - + --- From 0f156765274fc33edbe8a51f973303d3bdf7dcbc Mon Sep 17 00:00:00 2001 From: Alejandro Infante Date: Tue, 21 Jan 2020 17:31:39 -0300 Subject: [PATCH 06/34] Improve cpu usage on message waiting. --- bridge_hooks.py | 1 - flask_platform.py | 13 ++++++++----- msgpack_socket_platform.py | 17 +++++++++++++---- python_bridge.py | 2 -- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/bridge_hooks.py b/bridge_hooks.py index 216f09e..773084d 100644 --- a/bridge_hooks.py +++ b/bridge_hooks.py @@ -1,7 +1,6 @@ from flask import Flask, request import http.client import argparse -import threading import sys import traceback from PythonBridge import bridge_globals diff --git a/flask_platform.py b/flask_platform.py index a8e0332..c2925dc 100644 --- a/flask_platform.py +++ b/flask_platform.py @@ -5,6 +5,7 @@ from PythonBridge import bridge_globals, json_encoder, bridge_utils import sys import logging +import requests class FlaskMsgService: @@ -18,6 +19,8 @@ def __init__(self, port, pharo_port, feed_callback): self.feed_callback = feed_callback self.app = Flask('PythonBridge') self.app.use_reloader=False + self.session = requests.Session() + self.session.trust_env = True @self.app.route("/ENQUEUE", methods=["POST"]) def eval_expression(): @@ -56,11 +59,11 @@ def send_async_message(self, msg): def send_sync_message(self, msg): msg['__sync'] = bridge_utils.random_str() bridge_globals.logger.log("SYNC_MSG: " + json.dumps(msg)) - conn = http.client.HTTPConnection("localhost", str(self.pharo_port)) - conn.request("POST", "/" + msg["type"], json.dumps(msg), { - "Content-type": "application/json", - "Accept": "text/plain"}) - response = str(conn.getresponse().read().decode()) + response = self.session.post( + 'http://localhost:' + str(self.pharo_port) + '/' + msg['type'], + data=json.dumps(msg), + headers={'content-type': 'application/json'}, + allow_redirects=True).content.decode('utf-8') bridge_globals.logger.log("SYNC_ANS: " + response) return json.loads(response) diff --git a/msgpack_socket_platform.py b/msgpack_socket_platform.py index 30beca8..7982f70 100644 --- a/msgpack_socket_platform.py +++ b/msgpack_socket_platform.py @@ -3,6 +3,7 @@ import _thread import threading import time +import sys from PythonBridge import bridge_globals, stoppable_thread, msgpack_serializer from uuid import uuid1 @@ -28,12 +29,20 @@ def set_handler(self, msg_type, async_handler): def prim_handle(self): try: + bridge_globals.logger.log("loop func") data = self.client.recv(2048) - self.unpacker.feed(data) - for msg in self.unpacker: - self.prim_handle_msg(msg) + if len(data) == 0: + time.sleep(0.005) + else: + self.unpacker.feed(data) + for msg in self.unpacker: + bridge_globals.logger.log("prim handle message") + self.prim_handle_msg(msg) except OSError: - self.thread.stop() + bridge_globals.logger.log("OSError: " + str(err)) + self.stop() + sys.exit() + exit(-1) except Exception as err: bridge_globals.logger.log("ERROR message: " + str(err)) diff --git a/python_bridge.py b/python_bridge.py index 38e87e3..e9b1847 100644 --- a/python_bridge.py +++ b/python_bridge.py @@ -127,10 +127,8 @@ def run_bridge(): bridge_globals.pharoPort = args["pharo"] if args["log"]: - print("YES LOG") bridge_globals.logger = Logger() else: - print("NO LOG") bridge_globals.logger = NoLogger() bridge_globals.pyPort = args["port"] bridge_globals.globalCommandList = PythonCommandList() From 92e72d5331a24b06f87a742baf23b84047a6bb36 Mon Sep 17 00:00:00 2001 From: Alejandro Infante Date: Wed, 22 Jan 2020 17:30:43 -0300 Subject: [PATCH 07/34] Add new parcels. --- docs/pages/vw-installation.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/pages/vw-installation.md b/docs/pages/vw-installation.md index 394d98c..161a041 100644 --- a/docs/pages/vw-installation.md +++ b/docs/pages/vw-installation.md @@ -60,7 +60,7 @@ Currently PythonBridge version for VisualWorks is on closed beta. Therefore, we dir := Dialog requestDirectoryName: 'Choose the PythonBridge parcels directory'. dir isEmpty ifTrue: [^ self]. dir:= dir, (String with: Filename separator). -#('JSONReader' 'Sport' 'Swazoo' 'VwPharoPlatform' 'P3Generator' 'PythonBridgeBundle') do: [:fn | | file | +#('HTTP' 'JSONReader' 'Sport' 'Swazoo' 'MessagePack-All' 'VwPharoPlatform' 'P3Generator' 'PythonBridge-VwExtensions' 'PythonBridge' 'PythonBridge-VwPlatform' 'PythonBridge-VwMsgPack') do: [:fn | | file | file := dir, fn, '.pcl'. file asFilename exists ifFalse: [self error: 'Missing parcel!', file asString]. Parcel loadParcelFrom: file asFilename @@ -120,4 +120,4 @@ In case you wish to remove the pipenv environment run: ``` cd c:\PATH\TO\PYTHON\BRIDGE\REPOSITORY pipenv --rm -``` \ No newline at end of file +``` From 2ca0ebb7cae79f04e13b1e23d43068fc37f5124d Mon Sep 17 00:00:00 2001 From: Alejandro Infante Date: Wed, 22 Jan 2020 17:59:58 -0300 Subject: [PATCH 08/34] Fix problem with a parcel name. --- docs/pages/vw-installation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/vw-installation.md b/docs/pages/vw-installation.md index 161a041..3532333 100644 --- a/docs/pages/vw-installation.md +++ b/docs/pages/vw-installation.md @@ -60,7 +60,7 @@ Currently PythonBridge version for VisualWorks is on closed beta. Therefore, we dir := Dialog requestDirectoryName: 'Choose the PythonBridge parcels directory'. dir isEmpty ifTrue: [^ self]. dir:= dir, (String with: Filename separator). -#('HTTP' 'JSONReader' 'Sport' 'Swazoo' 'MessagePack-All' 'VwPharoPlatform' 'P3Generator' 'PythonBridge-VwExtensions' 'PythonBridge' 'PythonBridge-VwPlatform' 'PythonBridge-VwMsgPack') do: [:fn | | file | +#('HTTP' 'JSONReader' 'Sport' 'Swazoo' 'MessagePack-All' 'VwPharoPlatform' 'P3Generator' 'Python-Bridge-VWExtensions' 'PythonBridge' 'PythonBridge-VwPlatform' 'PythonBridge-VwMsgPack') do: [:fn | | file | file := dir, fn, '.pcl'. file asFilename exists ifFalse: [self error: 'Missing parcel!', file asString]. Parcel loadParcelFrom: file asFilename From 44195a578a4326edc7dcc1cf9ec4a73bd0e6c0d4 Mon Sep 17 00:00:00 2001 From: Alexandre Bergel Date: Wed, 22 Jan 2020 19:22:32 -0300 Subject: [PATCH 09/34] Update pharo-installation.md --- docs/pages/pharo-installation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/pharo-installation.md b/docs/pages/pharo-installation.md index ff7a2b5..0d7a5db 100644 --- a/docs/pages/pharo-installation.md +++ b/docs/pages/pharo-installation.md @@ -42,7 +42,7 @@ We suggest using `sudo apt-get install python3.6`, this should avoid most of the ### OSX We suggest to NOT use Homebrew, because we have experienced several issues handling the rest of the dependencies. Instead, we suggest using the installer provided in the Python webpage [https://www.python.org/downloads/release/python-368/](https://www.python.org/downloads/release/python-368/). -To verify python installed correctly just run `python3 --version` and you should get `Python 3.6.8`. +To verify python installed correctly just run `python3 --version` and you should get `Python 3.6.8`. If you have a more recent version, then it is all fine. ## Install Pipenv From 280418c204745fc880302c1b5e87d358dfad5f8f Mon Sep 17 00:00:00 2001 From: Alexandre Bergel Date: Wed, 22 Jan 2020 19:24:14 -0300 Subject: [PATCH 10/34] Update pharo-installation.md --- docs/pages/pharo-installation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/pharo-installation.md b/docs/pages/pharo-installation.md index 0d7a5db..a86bdba 100644 --- a/docs/pages/pharo-installation.md +++ b/docs/pages/pharo-installation.md @@ -46,7 +46,7 @@ To verify python installed correctly just run `python3 --version` and you should ## Install Pipenv -To install Pipenv just use the following Pip instruction `pip install pipenv`, though depending on your python installation you may need to call it with `sudo`. This may happen if you are using Ubuntu or the OSX Homebrew python installation. If the command `pip` is not found, use `pip3` instead. +To install Pipenv just use the following Pip instruction `pip install pipenv` or `pip3 install pipenv` in case you have `pip3` installed and not `pip`, though depending on your python installation you may need to call it with `sudo`. This may happen if you are using Ubuntu or the OSX Homebrew python installation. If the command `pip` is not found, use `pip3` instead. To verify if you have pipenv just run in a terminal `pipenv --version`, it should print something like `pipenv, version 2018.11.26`. We strongly suggest you to upgrade your pipenv version if it is older than 2018.11.26, because it has important bugfixes and performance improvements. To upgrade it just run `pip install pipenv --upgrade`. From ce7a7f720b845865edba46e0a928fb5dfe9a356a Mon Sep 17 00:00:00 2001 From: bergel Date: Wed, 22 Jan 2020 19:39:52 -0300 Subject: [PATCH 11/34] Added some error messages --- .../PBPharoPlatform.class.st | 2 +- src/PythonBridge/Character.extension.st | 22 +- src/PythonBridge/Collection.extension.st | 12 +- src/PythonBridge/Dictionary.extension.st | 22 +- src/PythonBridge/False.extension.st | 22 +- src/PythonBridge/Float.extension.st | 22 +- src/PythonBridge/Fraction.extension.st | 22 +- src/PythonBridge/Integer.extension.st | 22 +- src/PythonBridge/Object.extension.st | 12 +- src/PythonBridge/P3GGenerable.extension.st | 22 +- src/PythonBridge/P3GStatement.extension.st | 12 +- src/PythonBridge/PBAbstractAnswer.class.st | 60 +- src/PythonBridge/PBAbstractFinalizer.class.st | 20 +- src/PythonBridge/PBAbstractMessage.class.st | 58 +- .../PBAbstractMessageBroker.class.st | 248 ++++---- src/PythonBridge/PBAbstractProcess.class.st | 238 ++++---- .../PBAbstractSerializerWrapper.class.st | 30 +- .../PBAbstractWeakRegistry.class.st | 30 +- src/PythonBridge/PBAnswer.class.st | 18 +- src/PythonBridge/PBApplication.class.st | 522 ++++++++--------- src/PythonBridge/PBApplicationTest.class.st | 30 +- .../PBApplicationTestResource.class.st | 74 +-- src/PythonBridge/PBAsyncMessage.class.st | 30 +- .../PBAsyncMessageHandler.class.st | 10 +- src/PythonBridge/PBBinding.class.st | 140 ++--- src/PythonBridge/PBBlockFinalizer.class.st | 60 +- src/PythonBridge/PBCF.class.st | 224 ++++---- src/PythonBridge/PBCallbackAnswer.class.st | 48 +- src/PythonBridge/PBCallbackMessage.class.st | 86 +-- src/PythonBridge/PBCommand.class.st | 220 +++---- src/PythonBridge/PBCommandFactory.class.st | 290 +++++----- .../PBCommandFactoryTest.class.st | 104 ++-- src/PythonBridge/PBCommandQueue.class.st | 250 ++++---- src/PythonBridge/PBCommandQueueTest.class.st | 212 +++---- src/PythonBridge/PBCommandTest.class.st | 60 +- .../PBCommunicationError.class.st | 10 +- .../PBCommunicationHandler.class.st | 94 +-- src/PythonBridge/PBConnectionTest.class.st | 130 ++--- src/PythonBridge/PBDeserializeTest.class.st | 140 ++--- src/PythonBridge/PBDeserializer.class.st | 100 ++-- src/PythonBridge/PBDropQueue.class.st | 20 +- .../PBEnqueueCommandMessage.class.st | 154 ++--- src/PythonBridge/PBErrorAnswer.class.st | 48 +- .../PBErrorHandlingAction.class.st | 30 +- src/PythonBridge/PBErrorLog.class.st | 20 +- src/PythonBridge/PBErrorMessage.class.st | 116 ++-- .../PBExcecutionHandlerTest.class.st | 74 +-- src/PythonBridge/PBExecutionHandler.class.st | 384 ++++++------- src/PythonBridge/PBFatalErrorLog.class.st | 10 +- src/PythonBridge/PBHandler.class.st | 86 +-- src/PythonBridge/PBIgnore.class.st | 20 +- src/PythonBridge/PBIsAliveMessage.class.st | 30 +- .../PBJsonSerializerTest.class.st | 128 ++--- src/PythonBridge/PBLog.class.st | 84 +-- src/PythonBridge/PBLoggingHandler.class.st | 58 +- .../PBLoggingHandlerTest.class.st | 64 +-- src/PythonBridge/PBMapper.class.st | 120 ++-- src/PythonBridge/PBMapperFactory.class.st | 116 ++-- src/PythonBridge/PBMapping.class.st | 10 +- src/PythonBridge/PBMessage.class.st | 70 +-- src/PythonBridge/PBMessageBrokerTest.class.st | 542 +++++++++--------- src/PythonBridge/PBMessageHandler.class.st | 108 ++-- .../PBMessageHandlerTest.class.st | 154 ++--- src/PythonBridge/PBMessageTest.class.st | 124 ++-- src/PythonBridge/PBObject.class.st | 316 +++++----- .../PBObjectFinalizationTest.class.st | 116 ++-- src/PythonBridge/PBObjectFinalizer.class.st | 20 +- src/PythonBridge/PBObjectRegistry.class.st | 112 ++-- src/PythonBridge/PBObserver.class.st | 164 +++--- src/PythonBridge/PBPlatform.class.st | 344 +++++------ src/PythonBridge/PBProcessTest.class.st | 112 ++-- src/PythonBridge/PBPromise.class.st | 148 ++--- src/PythonBridge/PBPromiseRegistry.class.st | 90 +-- .../PBPromiseRegistryTest.class.st | 120 ++-- src/PythonBridge/PBProxyObject.class.st | 122 ++-- .../PBPython3GenerationTest.class.st | 74 +-- src/PythonBridge/PBPythonError.class.st | 180 +++--- .../PBPythonErrorHandlingTest.class.st | 10 +- src/PythonBridge/PBPythonHandler.class.st | 80 +-- src/PythonBridge/PBPythonObjectTest.class.st | 92 +-- src/PythonBridge/PBPythonValueTrait.trait.st | 22 +- src/PythonBridge/PBRAnswer.class.st | 48 +- src/PythonBridge/PBRAsyncMessage.class.st | 30 +- src/PythonBridge/PBRMessage.class.st | 56 +- src/PythonBridge/PBRMessageTest.class.st | 102 ++-- src/PythonBridge/PBRStubAnswer.class.st | 54 +- src/PythonBridge/PBRStubMessage.class.st | 72 +-- src/PythonBridge/PBRSyncMessage.class.st | 88 +-- src/PythonBridge/PBRegistryFinalizer.class.st | 112 ++-- src/PythonBridge/PBReplaceCommand.class.st | 62 +- src/PythonBridge/PBRetry.class.st | 10 +- src/PythonBridge/PBSendCommandTest.class.st | 164 +++--- src/PythonBridge/PBSerializationTest.class.st | 52 +- src/PythonBridge/PBSerializeTest.class.st | 62 +- src/PythonBridge/PBSerializer.class.st | 52 +- src/PythonBridge/PBSettings.class.st | 74 +-- .../PBSimpleApplicationTest.class.st | 134 ++--- src/PythonBridge/PBSocketAddress.class.st | 84 +-- src/PythonBridge/PBStubAnswer.class.st | 50 +- src/PythonBridge/PBStubApplication.class.st | 30 +- src/PythonBridge/PBStubMessage.class.st | 94 +-- src/PythonBridge/PBSyncMessage.class.st | 100 ++-- .../PBSyncMessageHandler.class.st | 48 +- src/PythonBridge/PBTestCase.class.st | 166 +++--- src/PythonBridge/PBUiManager.class.st | 30 +- .../PBUpdatePromiseMessage.class.st | 62 +- src/PythonBridge/PBUtils.class.st | 30 +- src/PythonBridge/PBWeakFinalizerTest.class.st | 208 +++---- .../SequenceableCollection.extension.st | 22 +- src/PythonBridge/Set.extension.st | 22 +- src/PythonBridge/True.extension.st | 22 +- src/PythonBridge/UndefinedObject.extension.st | 22 +- src/PythonBridge/package.st | 2 +- 113 files changed, 5292 insertions(+), 5292 deletions(-) diff --git a/src/PythonBridge-Pharo/PBPharoPlatform.class.st b/src/PythonBridge-Pharo/PBPharoPlatform.class.st index fdd2ffa..024332c 100644 --- a/src/PythonBridge-Pharo/PBPharoPlatform.class.st +++ b/src/PythonBridge-Pharo/PBPharoPlatform.class.st @@ -94,7 +94,7 @@ PBPharoPlatform >> folderForApplication: application [ { #category : #utils } PBPharoPlatform >> forceInstallEnvironmentForApp: application [ | proc | - self assert: PBPharoPipenvProcess pipenvPath isEmptyOrNil not. + self assert: PBPharoPipenvProcess pipenvPath isEmptyOrNil not description: 'pipenv is apparently not accessible at a standard location. Please, have a look at the Troubleshooting section of https://objectprofile.github.io/PythonBridge/pages/pharo-installation'. proc := OSSUnixSubprocess new command: '/bin/bash'; addAllEnvVariablesFromParentWithoutOverride; diff --git a/src/PythonBridge/Character.extension.st b/src/PythonBridge/Character.extension.st index 493ee2a..8f93738 100644 --- a/src/PythonBridge/Character.extension.st +++ b/src/PythonBridge/Character.extension.st @@ -1,11 +1,11 @@ -Extension { #name : #Character } - -{ #category : #'*PythonBridge' } -Character >> isPythonGenerable [ - ^ true -] - -{ #category : #'*PythonBridge' } -Character >> isPythonValue [ - ^ true -] +Extension { #name : #Character } + +{ #category : #'*PythonBridge' } +Character >> isPythonGenerable [ + ^ true +] + +{ #category : #'*PythonBridge' } +Character >> isPythonValue [ + ^ true +] diff --git a/src/PythonBridge/Collection.extension.st b/src/PythonBridge/Collection.extension.st index 03b9de8..fd6c18c 100644 --- a/src/PythonBridge/Collection.extension.st +++ b/src/PythonBridge/Collection.extension.st @@ -1,6 +1,6 @@ -Extension { #name : #Collection } - -{ #category : #'*PythonBridge' } -Collection >> ensureDo: aBlock [ - self do: [ :el | aBlock valueUninterruptably ] -] +Extension { #name : #Collection } + +{ #category : #'*PythonBridge' } +Collection >> ensureDo: aBlock [ + self do: [ :el | aBlock valueUninterruptably ] +] diff --git a/src/PythonBridge/Dictionary.extension.st b/src/PythonBridge/Dictionary.extension.st index e1fedb5..10a708c 100644 --- a/src/PythonBridge/Dictionary.extension.st +++ b/src/PythonBridge/Dictionary.extension.st @@ -1,11 +1,11 @@ -Extension { #name : #Dictionary } - -{ #category : #'*PythonBridge' } -Dictionary >> isPythonGenerable [ - ^ true -] - -{ #category : #'*PythonBridge' } -Dictionary >> isPythonValue [ - ^ true -] +Extension { #name : #Dictionary } + +{ #category : #'*PythonBridge' } +Dictionary >> isPythonGenerable [ + ^ true +] + +{ #category : #'*PythonBridge' } +Dictionary >> isPythonValue [ + ^ true +] diff --git a/src/PythonBridge/False.extension.st b/src/PythonBridge/False.extension.st index fc0d62f..d040c29 100644 --- a/src/PythonBridge/False.extension.st +++ b/src/PythonBridge/False.extension.st @@ -1,11 +1,11 @@ -Extension { #name : #False } - -{ #category : #'*PythonBridge' } -False >> isPythonGenerable [ - ^ true -] - -{ #category : #'*PythonBridge' } -False >> isPythonValue [ - ^ true -] +Extension { #name : #False } + +{ #category : #'*PythonBridge' } +False >> isPythonGenerable [ + ^ true +] + +{ #category : #'*PythonBridge' } +False >> isPythonValue [ + ^ true +] diff --git a/src/PythonBridge/Float.extension.st b/src/PythonBridge/Float.extension.st index 83803fb..5c0bbf2 100644 --- a/src/PythonBridge/Float.extension.st +++ b/src/PythonBridge/Float.extension.st @@ -1,11 +1,11 @@ -Extension { #name : #Float } - -{ #category : #'*PythonBridge' } -Float >> isPythonGenerable [ - ^ true -] - -{ #category : #'*PythonBridge' } -Float >> isPythonValue [ - ^ true -] +Extension { #name : #Float } + +{ #category : #'*PythonBridge' } +Float >> isPythonGenerable [ + ^ true +] + +{ #category : #'*PythonBridge' } +Float >> isPythonValue [ + ^ true +] diff --git a/src/PythonBridge/Fraction.extension.st b/src/PythonBridge/Fraction.extension.st index c65cd20..8a5bd2e 100644 --- a/src/PythonBridge/Fraction.extension.st +++ b/src/PythonBridge/Fraction.extension.st @@ -1,11 +1,11 @@ -Extension { #name : #Fraction } - -{ #category : #'*PythonBridge' } -Fraction >> isPythonGenerable [ - ^ true -] - -{ #category : #'*PythonBridge' } -Fraction >> isPythonValue [ - ^ true -] +Extension { #name : #Fraction } + +{ #category : #'*PythonBridge' } +Fraction >> isPythonGenerable [ + ^ true +] + +{ #category : #'*PythonBridge' } +Fraction >> isPythonValue [ + ^ true +] diff --git a/src/PythonBridge/Integer.extension.st b/src/PythonBridge/Integer.extension.st index 6788f37..aa63e8f 100644 --- a/src/PythonBridge/Integer.extension.st +++ b/src/PythonBridge/Integer.extension.st @@ -1,11 +1,11 @@ -Extension { #name : #Integer } - -{ #category : #'*PythonBridge' } -Integer >> isPythonGenerable [ - ^ true -] - -{ #category : #'*PythonBridge' } -Integer >> isPythonValue [ - ^ true -] +Extension { #name : #Integer } + +{ #category : #'*PythonBridge' } +Integer >> isPythonGenerable [ + ^ true +] + +{ #category : #'*PythonBridge' } +Integer >> isPythonValue [ + ^ true +] diff --git a/src/PythonBridge/Object.extension.st b/src/PythonBridge/Object.extension.st index 3a4278b..400f956 100644 --- a/src/PythonBridge/Object.extension.st +++ b/src/PythonBridge/Object.extension.st @@ -1,6 +1,6 @@ -Extension { #name : #Object } - -{ #category : #'*PythonBridge' } -Object >> isPythonGenerable [ - ^ false -] +Extension { #name : #Object } + +{ #category : #'*PythonBridge' } +Object >> isPythonGenerable [ + ^ false +] diff --git a/src/PythonBridge/P3GGenerable.extension.st b/src/PythonBridge/P3GGenerable.extension.st index 6ab5e55..879a751 100644 --- a/src/PythonBridge/P3GGenerable.extension.st +++ b/src/PythonBridge/P3GGenerable.extension.st @@ -1,11 +1,11 @@ -Extension { #name : #P3GGenerable } - -{ #category : #'*PythonBridge' } -P3GGenerable >> isPythonGenerable [ - ^ true -] - -{ #category : #'*PythonBridge' } -P3GGenerable >> isPythonValue [ - ^ true -] +Extension { #name : #P3GGenerable } + +{ #category : #'*PythonBridge' } +P3GGenerable >> isPythonGenerable [ + ^ true +] + +{ #category : #'*PythonBridge' } +P3GGenerable >> isPythonValue [ + ^ true +] diff --git a/src/PythonBridge/P3GStatement.extension.st b/src/PythonBridge/P3GStatement.extension.st index 4ee756e..2b8427a 100644 --- a/src/PythonBridge/P3GStatement.extension.st +++ b/src/PythonBridge/P3GStatement.extension.st @@ -1,6 +1,6 @@ -Extension { #name : #P3GStatement } - -{ #category : #'*PythonBridge' } -P3GStatement >> isPythonValue [ - ^ false -] +Extension { #name : #P3GStatement } + +{ #category : #'*PythonBridge' } +P3GStatement >> isPythonValue [ + ^ false +] diff --git a/src/PythonBridge/PBAbstractAnswer.class.st b/src/PythonBridge/PBAbstractAnswer.class.st index 492dd7b..7d2e04d 100644 --- a/src/PythonBridge/PBAbstractAnswer.class.st +++ b/src/PythonBridge/PBAbstractAnswer.class.st @@ -1,30 +1,30 @@ -Class { - #name : #PBAbstractAnswer, - #superclass : #Object, - #instVars : [ - 'message' - ], - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #'instance creation' } -PBAbstractAnswer class >> answerFor: aMessage [ - ^ self new - message: aMessage; - yourself -] - -{ #category : #accessing } -PBAbstractAnswer >> message [ - ^ message -] - -{ #category : #accessing } -PBAbstractAnswer >> message: anObject [ - message := anObject -] - -{ #category : #accessing } -PBAbstractAnswer >> type [ - ^ message type -] +Class { + #name : #PBAbstractAnswer, + #superclass : #Object, + #instVars : [ + 'message' + ], + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #'instance creation' } +PBAbstractAnswer class >> answerFor: aMessage [ + ^ self new + message: aMessage; + yourself +] + +{ #category : #accessing } +PBAbstractAnswer >> message [ + ^ message +] + +{ #category : #accessing } +PBAbstractAnswer >> message: anObject [ + message := anObject +] + +{ #category : #accessing } +PBAbstractAnswer >> type [ + ^ message type +] diff --git a/src/PythonBridge/PBAbstractFinalizer.class.st b/src/PythonBridge/PBAbstractFinalizer.class.st index bc6dc5f..2919de7 100644 --- a/src/PythonBridge/PBAbstractFinalizer.class.st +++ b/src/PythonBridge/PBAbstractFinalizer.class.st @@ -1,10 +1,10 @@ -Class { - #name : #PBAbstractFinalizer, - #superclass : #Object, - #category : #'PythonBridge-Platform' -} - -{ #category : #finalization } -PBAbstractFinalizer >> finalize [ - self subclassResponsibility -] +Class { + #name : #PBAbstractFinalizer, + #superclass : #Object, + #category : #'PythonBridge-Platform' +} + +{ #category : #finalization } +PBAbstractFinalizer >> finalize [ + self subclassResponsibility +] diff --git a/src/PythonBridge/PBAbstractMessage.class.st b/src/PythonBridge/PBAbstractMessage.class.st index b70d8ef..eb86d88 100644 --- a/src/PythonBridge/PBAbstractMessage.class.st +++ b/src/PythonBridge/PBAbstractMessage.class.st @@ -1,29 +1,29 @@ -Class { - #name : #PBAbstractMessage, - #superclass : #Object, - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #testing } -PBAbstractMessage class >> isReverseMessage [ - "Reverse messages corresponds to messages that start on Python to Pharo. In other words - in reverse direction from normal messages." - self subclassResponsibility -] - -{ #category : #accessing } -PBAbstractMessage class >> type [ - self subclassResponsibility -] - -{ #category : #testing } -PBAbstractMessage >> isReverseMessage [ - "Reverse messages corresponds to messages that start on Python to Pharo. In other words - in reverse direction from normal messages." - ^ self class isReverseMessage -] - -{ #category : #accessing } -PBAbstractMessage >> type [ - ^ self class type -] +Class { + #name : #PBAbstractMessage, + #superclass : #Object, + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #testing } +PBAbstractMessage class >> isReverseMessage [ + "Reverse messages corresponds to messages that start on Python to Pharo. In other words + in reverse direction from normal messages." + self subclassResponsibility +] + +{ #category : #accessing } +PBAbstractMessage class >> type [ + self subclassResponsibility +] + +{ #category : #testing } +PBAbstractMessage >> isReverseMessage [ + "Reverse messages corresponds to messages that start on Python to Pharo. In other words + in reverse direction from normal messages." + ^ self class isReverseMessage +] + +{ #category : #accessing } +PBAbstractMessage >> type [ + ^ self class type +] diff --git a/src/PythonBridge/PBAbstractMessageBroker.class.st b/src/PythonBridge/PBAbstractMessageBroker.class.st index a571759..6db2612 100644 --- a/src/PythonBridge/PBAbstractMessageBroker.class.st +++ b/src/PythonBridge/PBAbstractMessageBroker.class.st @@ -1,124 +1,124 @@ -Class { - #name : #PBAbstractMessageBroker, - #superclass : #Object, - #instVars : [ - 'debugMode', - 'messageCallbacks', - 'settings' - ], - #category : #'PythonBridge-Platform' -} - -{ #category : #accessing } -PBAbstractMessageBroker class >> pythonMethodArg [ - self subclassResponsibility -] - -{ #category : #accessing } -PBAbstractMessageBroker class >> serializer [ - ^ self serializerClass new -] - -{ #category : #accessing } -PBAbstractMessageBroker class >> serializerClass [ - self subclassResponsibility -] - -{ #category : #'as yet unclassified' } -PBAbstractMessageBroker class >> settings: settings [ - ^ self new - settings: settings; - yourself -] - -{ #category : #messaging } -PBAbstractMessageBroker >> addCallback: aBlock messageClass: messageClass [ - messageCallbacks at: messageClass put: aBlock -] - -{ #category : #private } -PBAbstractMessageBroker >> handle: dict reverseMessageClass: msgClass [ - | handler | - (messageCallbacks includesKey: msgClass) ifFalse: [ PBCommunicationError signal ]. - handler := PBMessageHandler - forMessage: (msgClass decodeFrom: dict) - callback: (messageCallbacks at: msgClass). - handler handleMessage. - ^ handler -] - -{ #category : #initialization } -PBAbstractMessageBroker >> initialize [ - super initialize. - messageCallbacks := Dictionary new. - debugMode := false -] - -{ #category : #testing } -PBAbstractMessageBroker >> isRunning [ - self subclassResponsibility -] - -{ #category : #accessing } -PBAbstractMessageBroker >> port [ - ^ settings pharoSocketAddress port -] - -{ #category : #accessing } -PBAbstractMessageBroker >> pythonUri [ - ^ 'http://' , settings pythonSocketAddress printAddress -] - -{ #category : #private } -PBAbstractMessageBroker >> resolveMessageFromType: aType [ - ^ PBAbstractMessage allSubclasses - detect: [ :cls | cls type = aType ] - ifNone: [ Error signal: 'Message ' , aType , ' not understood.' ]. -] - -{ #category : #messaging } -PBAbstractMessageBroker >> sendAsyncMessage: aMessage [ - self subclassResponsibility -] - -{ #category : #messaging } -PBAbstractMessageBroker >> sendMessage: aMessage [ - ^ aMessage isSync - ifTrue: [ self sendSyncMessage: aMessage ] - ifFalse: [ self sendAsyncMessage: aMessage ] -] - -{ #category : #messaging } -PBAbstractMessageBroker >> sendSyncMessage: aMessage [ - self subclassResponsibility -] - -{ #category : #accessing } -PBAbstractMessageBroker >> serializer [ - ^ self class serializer -] - -{ #category : #accessing } -PBAbstractMessageBroker >> setDebugMode [ - debugMode := true. -] - -{ #category : #accessing } -PBAbstractMessageBroker >> settings [ - ^ settings -] - -{ #category : #accessing } -PBAbstractMessageBroker >> settings: anObject [ - settings := anObject -] - -{ #category : #'start-stop' } -PBAbstractMessageBroker >> start [ - self subclassResponsibility -] - -{ #category : #'start-stop' } -PBAbstractMessageBroker >> stop [ - self subclassResponsibility -] +Class { + #name : #PBAbstractMessageBroker, + #superclass : #Object, + #instVars : [ + 'debugMode', + 'messageCallbacks', + 'settings' + ], + #category : #'PythonBridge-Platform' +} + +{ #category : #accessing } +PBAbstractMessageBroker class >> pythonMethodArg [ + self subclassResponsibility +] + +{ #category : #accessing } +PBAbstractMessageBroker class >> serializer [ + ^ self serializerClass new +] + +{ #category : #accessing } +PBAbstractMessageBroker class >> serializerClass [ + self subclassResponsibility +] + +{ #category : #'as yet unclassified' } +PBAbstractMessageBroker class >> settings: settings [ + ^ self new + settings: settings; + yourself +] + +{ #category : #messaging } +PBAbstractMessageBroker >> addCallback: aBlock messageClass: messageClass [ + messageCallbacks at: messageClass put: aBlock +] + +{ #category : #private } +PBAbstractMessageBroker >> handle: dict reverseMessageClass: msgClass [ + | handler | + (messageCallbacks includesKey: msgClass) ifFalse: [ PBCommunicationError signal ]. + handler := PBMessageHandler + forMessage: (msgClass decodeFrom: dict) + callback: (messageCallbacks at: msgClass). + handler handleMessage. + ^ handler +] + +{ #category : #initialization } +PBAbstractMessageBroker >> initialize [ + super initialize. + messageCallbacks := Dictionary new. + debugMode := false +] + +{ #category : #testing } +PBAbstractMessageBroker >> isRunning [ + self subclassResponsibility +] + +{ #category : #accessing } +PBAbstractMessageBroker >> port [ + ^ settings pharoSocketAddress port +] + +{ #category : #accessing } +PBAbstractMessageBroker >> pythonUri [ + ^ 'http://' , settings pythonSocketAddress printAddress +] + +{ #category : #private } +PBAbstractMessageBroker >> resolveMessageFromType: aType [ + ^ PBAbstractMessage allSubclasses + detect: [ :cls | cls type = aType ] + ifNone: [ Error signal: 'Message ' , aType , ' not understood.' ]. +] + +{ #category : #messaging } +PBAbstractMessageBroker >> sendAsyncMessage: aMessage [ + self subclassResponsibility +] + +{ #category : #messaging } +PBAbstractMessageBroker >> sendMessage: aMessage [ + ^ aMessage isSync + ifTrue: [ self sendSyncMessage: aMessage ] + ifFalse: [ self sendAsyncMessage: aMessage ] +] + +{ #category : #messaging } +PBAbstractMessageBroker >> sendSyncMessage: aMessage [ + self subclassResponsibility +] + +{ #category : #accessing } +PBAbstractMessageBroker >> serializer [ + ^ self class serializer +] + +{ #category : #accessing } +PBAbstractMessageBroker >> setDebugMode [ + debugMode := true. +] + +{ #category : #accessing } +PBAbstractMessageBroker >> settings [ + ^ settings +] + +{ #category : #accessing } +PBAbstractMessageBroker >> settings: anObject [ + settings := anObject +] + +{ #category : #'start-stop' } +PBAbstractMessageBroker >> start [ + self subclassResponsibility +] + +{ #category : #'start-stop' } +PBAbstractMessageBroker >> stop [ + self subclassResponsibility +] diff --git a/src/PythonBridge/PBAbstractProcess.class.st b/src/PythonBridge/PBAbstractProcess.class.st index d9be73b..8066e27 100644 --- a/src/PythonBridge/PBAbstractProcess.class.st +++ b/src/PythonBridge/PBAbstractProcess.class.st @@ -1,119 +1,119 @@ -Class { - #name : #PBAbstractProcess, - #superclass : #Object, - #instVars : [ - 'pythonMainFile', - 'debugMode', - 'settings', - 'workingDirectory' - ], - #category : #'PythonBridge-Platform' -} - -{ #category : #accessing } -PBAbstractProcess class >> application: application [ - ^ self - settings: application settings - application: application -] - -{ #category : #accessing } -PBAbstractProcess class >> platform [ - self subclassResponsibility -] - -{ #category : #accessing } -PBAbstractProcess class >> settings: settings application: application [ - ^ self - settings: settings - workingDirectory: (PBPlatform current folderForApplication: application) - debugMode: application class debugMode -] - -{ #category : #accessing } -PBAbstractProcess class >> settings: settings workingDirectory: fileRef [ - ^ self new - settings: settings; - workingDirectory: fileRef; - yourself -] - -{ #category : #accessing } -PBAbstractProcess class >> settings: settings workingDirectory: fileRef debugMode: flag [ - ^ self new - settings: settings; - workingDirectory: fileRef; - debugMode: flag; - yourself -] - -{ #category : #hooks } -PBAbstractProcess class >> workingDirectory [ - ^ self platform folderForApplication: PBApplication -] - -{ #category : #accessing } -PBAbstractProcess >> debugMode [ - ^ debugMode -] - -{ #category : #accessing } -PBAbstractProcess >> debugMode: anObject [ - debugMode := anObject -] - -{ #category : #accessing } -PBAbstractProcess >> errorMessage [ - self subclassResponsibility -] - -{ #category : #initialization } -PBAbstractProcess >> initialize [ - super initialize. - debugMode := false -] - -{ #category : #testing } -PBAbstractProcess >> isRunning [ - self subclassResponsibility -] - -{ #category : #accessing } -PBAbstractProcess >> pythonMainFile [ - ^ pythonMainFile ifNil: [ self workingDirectory / 'start_bridge.py' ] -] - -{ #category : #accessing } -PBAbstractProcess >> pythonMainFile: anObject [ - pythonMainFile := anObject -] - -{ #category : #accessing } -PBAbstractProcess >> settings [ - ^ settings -] - -{ #category : #accessing } -PBAbstractProcess >> settings: anObject [ - settings := anObject -] - -{ #category : #'start-stop' } -PBAbstractProcess >> start [ - self subclassResponsibility -] - -{ #category : #'start-stop' } -PBAbstractProcess >> stop [ - self subclassResponsibility -] - -{ #category : #accessing } -PBAbstractProcess >> workingDirectory [ - ^ workingDirectory -] - -{ #category : #accessing } -PBAbstractProcess >> workingDirectory: anObject [ - workingDirectory := anObject -] +Class { + #name : #PBAbstractProcess, + #superclass : #Object, + #instVars : [ + 'pythonMainFile', + 'debugMode', + 'settings', + 'workingDirectory' + ], + #category : #'PythonBridge-Platform' +} + +{ #category : #accessing } +PBAbstractProcess class >> application: application [ + ^ self + settings: application settings + application: application +] + +{ #category : #accessing } +PBAbstractProcess class >> platform [ + self subclassResponsibility +] + +{ #category : #accessing } +PBAbstractProcess class >> settings: settings application: application [ + ^ self + settings: settings + workingDirectory: (PBPlatform current folderForApplication: application) + debugMode: application class debugMode +] + +{ #category : #accessing } +PBAbstractProcess class >> settings: settings workingDirectory: fileRef [ + ^ self new + settings: settings; + workingDirectory: fileRef; + yourself +] + +{ #category : #accessing } +PBAbstractProcess class >> settings: settings workingDirectory: fileRef debugMode: flag [ + ^ self new + settings: settings; + workingDirectory: fileRef; + debugMode: flag; + yourself +] + +{ #category : #hooks } +PBAbstractProcess class >> workingDirectory [ + ^ self platform folderForApplication: PBApplication +] + +{ #category : #accessing } +PBAbstractProcess >> debugMode [ + ^ debugMode +] + +{ #category : #accessing } +PBAbstractProcess >> debugMode: anObject [ + debugMode := anObject +] + +{ #category : #accessing } +PBAbstractProcess >> errorMessage [ + self subclassResponsibility +] + +{ #category : #initialization } +PBAbstractProcess >> initialize [ + super initialize. + debugMode := false +] + +{ #category : #testing } +PBAbstractProcess >> isRunning [ + self subclassResponsibility +] + +{ #category : #accessing } +PBAbstractProcess >> pythonMainFile [ + ^ pythonMainFile ifNil: [ self workingDirectory / 'start_bridge.py' ] +] + +{ #category : #accessing } +PBAbstractProcess >> pythonMainFile: anObject [ + pythonMainFile := anObject +] + +{ #category : #accessing } +PBAbstractProcess >> settings [ + ^ settings +] + +{ #category : #accessing } +PBAbstractProcess >> settings: anObject [ + settings := anObject +] + +{ #category : #'start-stop' } +PBAbstractProcess >> start [ + self subclassResponsibility +] + +{ #category : #'start-stop' } +PBAbstractProcess >> stop [ + self subclassResponsibility +] + +{ #category : #accessing } +PBAbstractProcess >> workingDirectory [ + ^ workingDirectory +] + +{ #category : #accessing } +PBAbstractProcess >> workingDirectory: anObject [ + workingDirectory := anObject +] diff --git a/src/PythonBridge/PBAbstractSerializerWrapper.class.st b/src/PythonBridge/PBAbstractSerializerWrapper.class.st index cf1c71e..dcd4d8e 100644 --- a/src/PythonBridge/PBAbstractSerializerWrapper.class.st +++ b/src/PythonBridge/PBAbstractSerializerWrapper.class.st @@ -1,15 +1,15 @@ -Class { - #name : #PBAbstractSerializerWrapper, - #superclass : #Object, - #category : #'PythonBridge-Platform' -} - -{ #category : #private } -PBAbstractSerializerWrapper >> deserialize: aString [ - self subclassResponsibility -] - -{ #category : #private } -PBAbstractSerializerWrapper >> serialize: anObject [ - self subclassResponsibility -] +Class { + #name : #PBAbstractSerializerWrapper, + #superclass : #Object, + #category : #'PythonBridge-Platform' +} + +{ #category : #private } +PBAbstractSerializerWrapper >> deserialize: aString [ + self subclassResponsibility +] + +{ #category : #private } +PBAbstractSerializerWrapper >> serialize: anObject [ + self subclassResponsibility +] diff --git a/src/PythonBridge/PBAbstractWeakRegistry.class.st b/src/PythonBridge/PBAbstractWeakRegistry.class.st index 7ec8cc8..92691e2 100644 --- a/src/PythonBridge/PBAbstractWeakRegistry.class.st +++ b/src/PythonBridge/PBAbstractWeakRegistry.class.st @@ -1,15 +1,15 @@ -Class { - #name : #PBAbstractWeakRegistry, - #superclass : #Object, - #category : #'PythonBridge-Platform' -} - -{ #category : #'as yet unclassified' } -PBAbstractWeakRegistry >> destroy [ - self subclassResponsibility -] - -{ #category : #'as yet unclassified' } -PBAbstractWeakRegistry >> registerObject: anObject finalizer: finalizer [ - self subclassResponsibility -] +Class { + #name : #PBAbstractWeakRegistry, + #superclass : #Object, + #category : #'PythonBridge-Platform' +} + +{ #category : #'as yet unclassified' } +PBAbstractWeakRegistry >> destroy [ + self subclassResponsibility +] + +{ #category : #'as yet unclassified' } +PBAbstractWeakRegistry >> registerObject: anObject finalizer: finalizer [ + self subclassResponsibility +] diff --git a/src/PythonBridge/PBAnswer.class.st b/src/PythonBridge/PBAnswer.class.st index fa3e2a7..f202b88 100644 --- a/src/PythonBridge/PBAnswer.class.st +++ b/src/PythonBridge/PBAnswer.class.st @@ -1,9 +1,9 @@ -Class { - #name : #PBAnswer, - #superclass : #PBAbstractAnswer, - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #converting } -PBAnswer >> decode: dict [ -] +Class { + #name : #PBAnswer, + #superclass : #PBAbstractAnswer, + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #converting } +PBAnswer >> decode: dict [ +] diff --git a/src/PythonBridge/PBApplication.class.st b/src/PythonBridge/PBApplication.class.st index 06a0113..0c0e451 100644 --- a/src/PythonBridge/PBApplication.class.st +++ b/src/PythonBridge/PBApplication.class.st @@ -1,261 +1,261 @@ -Class { - #name : #PBApplication, - #superclass : #Object, - #instVars : [ - 'communicationHandler', - 'processHandler', - 'loggingHandler', - 'executionHandler', - 'settings' - ], - #classVars : [ - 'DebugMode' - ], - #classInstVars : [ - 'uniqueInstance' - ], - #category : #'PythonBridge-Global' -} - -{ #category : #accessing } -PBApplication class >> baseApplication [ - ^ PBApplication -] - -{ #category : #debug } -PBApplication class >> debugMode [ - ^ DebugMode ifNil: [ false ] -] - -{ #category : #debug } -PBApplication class >> debugMode: bool [ - ^ DebugMode := bool -] - -{ #category : #'start-stop' } -PBApplication class >> do: aBlockClosure [ - | retVal | - self isRunning ifTrue: [ ^ aBlockClosure value ]. - [ - self start. - retVal := aBlockClosure cull: self uniqueInstance. - self uniqueInstance commandFactory << nil. - self uniqueInstance commandFactory send waitForValue. ] ensure: [ self stop ]. - ^ retVal -] - -{ #category : #testing } -PBApplication class >> isRunning [ - ^ uniqueInstance notNil and: [ uniqueInstance isRunning ] -] - -{ #category : #testing } -PBApplication class >> module [ - ^ self uniqueInstance module -] - -{ #category : #'pipenv setup' } -PBApplication class >> platform [ - ^ PBPlatform current -] - -{ #category : #'python hooks file' } -PBApplication class >> repositoryFileReference [ - ^ self platform folderForApplication: self -] - -{ #category : #instructions } -PBApplication class >> resetUniqueInstance [ - uniqueInstance ifNotNil: [ - [ uniqueInstance stop ] - on: Error - do: [ PBPlatform current uiManager inform: 'Error on reseting unique instance.' ]. ]. - uniqueInstance := nil -] - -{ #category : #instructions } -PBApplication class >> send: obj [ - self assert: self isRunning. - ^ self uniqueInstance send: obj -] - -{ #category : #'start-stop' } -PBApplication class >> start [ - self isRunning ifTrue: [ Error signal: 'Keras already running.' ]. - self stop. - uniqueInstance := self new. - uniqueInstance commandFactory reset. - uniqueInstance start -] - -{ #category : #'start-stop' } -PBApplication class >> stop [ - uniqueInstance ifNotNil: [ - uniqueInstance stop. ]. - uniqueInstance := nil -] - -{ #category : #testing } -PBApplication class >> test [ - self assert: (self do: [ :app | - app commandFactory << (P3GBinaryOperator new - left: 1; - right: 2; - operator: $+; - yourself). - app commandFactory send waitForValue - ]) = 3 -] - -{ #category : #instructions } -PBApplication class >> uniqueInstance [ - ^ uniqueInstance -] - -{ #category : #accessing } -PBApplication class >> uniqueInstance: anObject [ - uniqueInstance := anObject -] - -{ #category : #utils } -PBApplication >> addMapping: pythonType to: pythonFunction [ - self commandFactory - send: (#bridge_globals asP3GI => #msg_service => #addMapping - callWith: (Array with: pythonType with: pythonFunction)) -] - -{ #category : #accessing } -PBApplication >> commandFactory [ - ^ PBCF -] - -{ #category : #accessing } -PBApplication >> communicationHandler [ - ^ communicationHandler -] - -{ #category : #accessing } -PBApplication >> errorMessage [ - "Fetch the error message from the stderr stream, from the processhander" - ^ processHandler errorMessage -] - -{ #category : #accessing } -PBApplication >> executionHandler [ - ^ executionHandler -] - -{ #category : #handlers } -PBApplication >> handlers [ - ^ Array - with: loggingHandler - with: communicationHandler - with: processHandler - with: executionHandler -] - -{ #category : #initialization } -PBApplication >> initialize [ - super initialize. - settings := PBPlatform current defaultSettings. - self initializeHandlers. -] - -{ #category : #initialization } -PBApplication >> initializeHandlers [ - loggingHandler := PBLoggingHandler application: self. - communicationHandler := PBCommunicationHandler application: self. - processHandler := PBPythonHandler application: self. - executionHandler := PBExecutionHandler application: self -] - -{ #category : #testing } -PBApplication >> isPythonReady [ - "Ensures python webserver is ready for receiving commands" - ^ self communicationHandler isPythonReady -] - -{ #category : #testing } -PBApplication >> isRunning [ - ^ self handlers allSatisfy: #isRunning -] - -{ #category : #logging } -PBApplication >> log: aLog [ - self loggingHandler log: aLog -] - -{ #category : #accessing } -PBApplication >> loggingHandler [ - ^ loggingHandler -] - -{ #category : #accessing } -PBApplication >> module [ - self subclassResponsibility -] - -{ #category : #'instance creation' } -PBApplication >> newCommandFactory [ - ^ self executionHandler newCommandFactory -] - -{ #category : #accessing } -PBApplication >> postInitialization [ - -] - -{ #category : #accessing } -PBApplication >> processHandler [ - ^ processHandler -] - -{ #category : #'as yet unclassified' } -PBApplication >> registerObject: aPythonObject [ - self executionHandler registerObject: aPythonObject -] - -{ #category : #instructions } -PBApplication >> send: aCommand [ - self isRunning ifFalse: [ Error signal: 'Bridge not running.' ]. - ^ executionHandler sendCommand: aCommand -] - -{ #category : #accessing } -PBApplication >> settings [ - ^ settings -] - -{ #category : #accessing } -PBApplication >> settings: anObject [ - settings := anObject -] - -{ #category : #accessing } -PBApplication >> start [ - self handlers do: #start. - self commandFactory reset. - self waitInitialization. - self postInitialization. - self commandFactory send. -] - -{ #category : #'as yet unclassified' } -PBApplication >> stop [ - self handlers select: #notNil thenDo: #stop -] - -{ #category : #'as yet unclassified' } -PBApplication >> waitInitialization [ - "Timeout of 10 seconds and try every 0.5 seconds" - 1 to: 10 by: 0.5 do: [ :t | - self isPythonReady - ifTrue: [ ^ self ] - ifFalse: [ (Delay forMilliseconds: 500) wait ] ]. - Error signal: 'Python application initialization failed!' - " - Print the result of executing the following line: - - self errorMessage - " -] +Class { + #name : #PBApplication, + #superclass : #Object, + #instVars : [ + 'communicationHandler', + 'processHandler', + 'loggingHandler', + 'executionHandler', + 'settings' + ], + #classVars : [ + 'DebugMode' + ], + #classInstVars : [ + 'uniqueInstance' + ], + #category : #'PythonBridge-Global' +} + +{ #category : #accessing } +PBApplication class >> baseApplication [ + ^ PBApplication +] + +{ #category : #debug } +PBApplication class >> debugMode [ + ^ DebugMode ifNil: [ false ] +] + +{ #category : #debug } +PBApplication class >> debugMode: bool [ + ^ DebugMode := bool +] + +{ #category : #'start-stop' } +PBApplication class >> do: aBlockClosure [ + | retVal | + self isRunning ifTrue: [ ^ aBlockClosure value ]. + [ + self start. + retVal := aBlockClosure cull: self uniqueInstance. + self uniqueInstance commandFactory << nil. + self uniqueInstance commandFactory send waitForValue. ] ensure: [ self stop ]. + ^ retVal +] + +{ #category : #testing } +PBApplication class >> isRunning [ + ^ uniqueInstance notNil and: [ uniqueInstance isRunning ] +] + +{ #category : #testing } +PBApplication class >> module [ + ^ self uniqueInstance module +] + +{ #category : #'pipenv setup' } +PBApplication class >> platform [ + ^ PBPlatform current +] + +{ #category : #'python hooks file' } +PBApplication class >> repositoryFileReference [ + ^ self platform folderForApplication: self +] + +{ #category : #instructions } +PBApplication class >> resetUniqueInstance [ + uniqueInstance ifNotNil: [ + [ uniqueInstance stop ] + on: Error + do: [ PBPlatform current uiManager inform: 'Error on reseting unique instance.' ]. ]. + uniqueInstance := nil +] + +{ #category : #instructions } +PBApplication class >> send: obj [ + self assert: self isRunning. + ^ self uniqueInstance send: obj +] + +{ #category : #'start-stop' } +PBApplication class >> start [ + self isRunning ifTrue: [ Error signal: 'Keras already running.' ]. + self stop. + uniqueInstance := self new. + uniqueInstance commandFactory reset. + uniqueInstance start +] + +{ #category : #'start-stop' } +PBApplication class >> stop [ + uniqueInstance ifNotNil: [ + uniqueInstance stop. ]. + uniqueInstance := nil +] + +{ #category : #testing } +PBApplication class >> test [ + self assert: (self do: [ :app | + app commandFactory << (P3GBinaryOperator new + left: 1; + right: 2; + operator: $+; + yourself). + app commandFactory send waitForValue + ]) = 3 +] + +{ #category : #instructions } +PBApplication class >> uniqueInstance [ + ^ uniqueInstance +] + +{ #category : #accessing } +PBApplication class >> uniqueInstance: anObject [ + uniqueInstance := anObject +] + +{ #category : #utils } +PBApplication >> addMapping: pythonType to: pythonFunction [ + self commandFactory + send: (#bridge_globals asP3GI => #msg_service => #addMapping + callWith: (Array with: pythonType with: pythonFunction)) +] + +{ #category : #accessing } +PBApplication >> commandFactory [ + ^ PBCF +] + +{ #category : #accessing } +PBApplication >> communicationHandler [ + ^ communicationHandler +] + +{ #category : #accessing } +PBApplication >> errorMessage [ + "Fetch the error message from the stderr stream, from the processhander" + ^ processHandler errorMessage +] + +{ #category : #accessing } +PBApplication >> executionHandler [ + ^ executionHandler +] + +{ #category : #handlers } +PBApplication >> handlers [ + ^ Array + with: loggingHandler + with: communicationHandler + with: processHandler + with: executionHandler +] + +{ #category : #initialization } +PBApplication >> initialize [ + super initialize. + settings := PBPlatform current defaultSettings. + self initializeHandlers. +] + +{ #category : #initialization } +PBApplication >> initializeHandlers [ + loggingHandler := PBLoggingHandler application: self. + communicationHandler := PBCommunicationHandler application: self. + processHandler := PBPythonHandler application: self. + executionHandler := PBExecutionHandler application: self +] + +{ #category : #testing } +PBApplication >> isPythonReady [ + "Ensures python webserver is ready for receiving commands" + ^ self communicationHandler isPythonReady +] + +{ #category : #testing } +PBApplication >> isRunning [ + ^ self handlers allSatisfy: #isRunning +] + +{ #category : #logging } +PBApplication >> log: aLog [ + self loggingHandler log: aLog +] + +{ #category : #accessing } +PBApplication >> loggingHandler [ + ^ loggingHandler +] + +{ #category : #accessing } +PBApplication >> module [ + self subclassResponsibility +] + +{ #category : #'instance creation' } +PBApplication >> newCommandFactory [ + ^ self executionHandler newCommandFactory +] + +{ #category : #accessing } +PBApplication >> postInitialization [ + +] + +{ #category : #accessing } +PBApplication >> processHandler [ + ^ processHandler +] + +{ #category : #'as yet unclassified' } +PBApplication >> registerObject: aPythonObject [ + self executionHandler registerObject: aPythonObject +] + +{ #category : #instructions } +PBApplication >> send: aCommand [ + self isRunning ifFalse: [ Error signal: 'Bridge not running.' ]. + ^ executionHandler sendCommand: aCommand +] + +{ #category : #accessing } +PBApplication >> settings [ + ^ settings +] + +{ #category : #accessing } +PBApplication >> settings: anObject [ + settings := anObject +] + +{ #category : #accessing } +PBApplication >> start [ + self handlers do: #start. + self commandFactory reset. + self waitInitialization. + self postInitialization. + self commandFactory send. +] + +{ #category : #'as yet unclassified' } +PBApplication >> stop [ + self handlers select: #notNil thenDo: #stop +] + +{ #category : #'as yet unclassified' } +PBApplication >> waitInitialization [ + "Timeout of 10 seconds and try every 0.5 seconds" + 1 to: 10 by: 0.5 do: [ :t | + self isPythonReady + ifTrue: [ ^ self ] + ifFalse: [ (Delay forMilliseconds: 500) wait ] ]. + Error signal: 'Python application initialization failed! You should try to manually install the Pipenv environment. Have a look at the section "Manually creating Pipenv environment" in https://objectprofile.github.io/PythonBridge/pages/pharo-installation'. + " + Print the result of executing the following line: + + self errorMessage + " +] diff --git a/src/PythonBridge/PBApplicationTest.class.st b/src/PythonBridge/PBApplicationTest.class.st index 2dfe826..1ef4584 100644 --- a/src/PythonBridge/PBApplicationTest.class.st +++ b/src/PythonBridge/PBApplicationTest.class.st @@ -1,15 +1,15 @@ -Class { - #name : #PBApplicationTest, - #superclass : #PBTestCase, - #category : #'PythonBridge-Tests' -} - -{ #category : #accessing } -PBApplicationTest class >> appResource [ - ^ PBApplicationTestResource -] - -{ #category : #initialization } -PBApplicationTest >> applicationClass [ - ^ PBApplication -] +Class { + #name : #PBApplicationTest, + #superclass : #PBTestCase, + #category : #'PythonBridge-Tests' +} + +{ #category : #accessing } +PBApplicationTest class >> appResource [ + ^ PBApplicationTestResource +] + +{ #category : #initialization } +PBApplicationTest >> applicationClass [ + ^ PBApplication +] diff --git a/src/PythonBridge/PBApplicationTestResource.class.st b/src/PythonBridge/PBApplicationTestResource.class.st index c22f9f2..fab5c19 100644 --- a/src/PythonBridge/PBApplicationTestResource.class.st +++ b/src/PythonBridge/PBApplicationTestResource.class.st @@ -1,37 +1,37 @@ -Class { - #name : #PBApplicationTestResource, - #superclass : #TestResource, - #instVars : [ - 'application' - ], - #category : #'PythonBridge-Tests' -} - -{ #category : #initialization } -PBApplicationTestResource >> app [ - ^ self application -] - -{ #category : #initialization } -PBApplicationTestResource >> application [ - ^ application -] - -{ #category : #initialization } -PBApplicationTestResource >> applicationClass [ - ^ PBApplication -] - -{ #category : #initialization } -PBApplicationTestResource >> setUp [ - super setUp. - self applicationClass stop. - self applicationClass start. - application := self applicationClass uniqueInstance -] - -{ #category : #initialization } -PBApplicationTestResource >> tearDown [ - self applicationClass stop. - super tearDown. -] +Class { + #name : #PBApplicationTestResource, + #superclass : #TestResource, + #instVars : [ + 'application' + ], + #category : #'PythonBridge-Tests' +} + +{ #category : #initialization } +PBApplicationTestResource >> app [ + ^ self application +] + +{ #category : #initialization } +PBApplicationTestResource >> application [ + ^ application +] + +{ #category : #initialization } +PBApplicationTestResource >> applicationClass [ + ^ PBApplication +] + +{ #category : #initialization } +PBApplicationTestResource >> setUp [ + super setUp. + self applicationClass stop. + self applicationClass start. + application := self applicationClass uniqueInstance +] + +{ #category : #initialization } +PBApplicationTestResource >> tearDown [ + self applicationClass stop. + super tearDown. +] diff --git a/src/PythonBridge/PBAsyncMessage.class.st b/src/PythonBridge/PBAsyncMessage.class.st index 56fc828..ccf18f6 100644 --- a/src/PythonBridge/PBAsyncMessage.class.st +++ b/src/PythonBridge/PBAsyncMessage.class.st @@ -1,15 +1,15 @@ -Class { - #name : #PBAsyncMessage, - #superclass : #PBMessage, - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #accessing } -PBAsyncMessage class >> type [ - ^ #ASYNC -] - -{ #category : #testing } -PBAsyncMessage >> isSync [ - ^ false -] +Class { + #name : #PBAsyncMessage, + #superclass : #PBMessage, + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #accessing } +PBAsyncMessage class >> type [ + ^ #ASYNC +] + +{ #category : #testing } +PBAsyncMessage >> isSync [ + ^ false +] diff --git a/src/PythonBridge/PBAsyncMessageHandler.class.st b/src/PythonBridge/PBAsyncMessageHandler.class.st index 985d4e0..69ace7c 100644 --- a/src/PythonBridge/PBAsyncMessageHandler.class.st +++ b/src/PythonBridge/PBAsyncMessageHandler.class.st @@ -1,5 +1,5 @@ -Class { - #name : #PBAsyncMessageHandler, - #superclass : #PBMessageHandler, - #category : #'PythonBridge-Platform' -} +Class { + #name : #PBAsyncMessageHandler, + #superclass : #PBMessageHandler, + #category : #'PythonBridge-Platform' +} diff --git a/src/PythonBridge/PBBinding.class.st b/src/PythonBridge/PBBinding.class.st index 7949243..2efdcc1 100644 --- a/src/PythonBridge/PBBinding.class.st +++ b/src/PythonBridge/PBBinding.class.st @@ -1,70 +1,70 @@ -Class { - #name : #PBBinding, - #superclass : #Object, - #instVars : [ - 'object', - 'key' - ], - #category : #'PythonBridge-Execution' -} - -{ #category : #'instance creation' } -PBBinding class >> key: aKey wrap: anObject [ - ^ self new - key: aKey; - object: anObject; - yourself -] - -{ #category : #'instance creation' } -PBBinding class >> wrap: anObject [ - ^ self new - object: anObject; - yourself -] - -{ #category : #initialization } -PBBinding >> initialize [ - super initialize. - key := PBUtils newP3VariableName -] - -{ #category : #testing } -PBBinding >> isPythonGenerable [ - ^ true -] - -{ #category : #testing } -PBBinding >> isPythonValue [ - ^ true -] - -{ #category : #accessing } -PBBinding >> key [ - ^ key -] - -{ #category : #accessing } -PBBinding >> key: anObject [ - key := anObject -] - -{ #category : #accessing } -PBBinding >> object [ - ^ object -] - -{ #category : #accessing } -PBBinding >> object: anObject [ - object := anObject -] - -{ #category : #'instance creation' } -PBBinding >> pythonVariable [ - ^ key asP3GI -] - -{ #category : #testing } -PBBinding >> writePython3On: aStream [ - self pythonVariable writePython3On: aStream -] +Class { + #name : #PBBinding, + #superclass : #Object, + #instVars : [ + 'object', + 'key' + ], + #category : #'PythonBridge-Execution' +} + +{ #category : #'instance creation' } +PBBinding class >> key: aKey wrap: anObject [ + ^ self new + key: aKey; + object: anObject; + yourself +] + +{ #category : #'instance creation' } +PBBinding class >> wrap: anObject [ + ^ self new + object: anObject; + yourself +] + +{ #category : #initialization } +PBBinding >> initialize [ + super initialize. + key := PBUtils newP3VariableName +] + +{ #category : #testing } +PBBinding >> isPythonGenerable [ + ^ true +] + +{ #category : #testing } +PBBinding >> isPythonValue [ + ^ true +] + +{ #category : #accessing } +PBBinding >> key [ + ^ key +] + +{ #category : #accessing } +PBBinding >> key: anObject [ + key := anObject +] + +{ #category : #accessing } +PBBinding >> object [ + ^ object +] + +{ #category : #accessing } +PBBinding >> object: anObject [ + object := anObject +] + +{ #category : #'instance creation' } +PBBinding >> pythonVariable [ + ^ key asP3GI +] + +{ #category : #testing } +PBBinding >> writePython3On: aStream [ + self pythonVariable writePython3On: aStream +] diff --git a/src/PythonBridge/PBBlockFinalizer.class.st b/src/PythonBridge/PBBlockFinalizer.class.st index d87dbcf..f479902 100644 --- a/src/PythonBridge/PBBlockFinalizer.class.st +++ b/src/PythonBridge/PBBlockFinalizer.class.st @@ -1,30 +1,30 @@ -Class { - #name : #PBBlockFinalizer, - #superclass : #PBAbstractFinalizer, - #instVars : [ - 'block' - ], - #category : #'PythonBridge-Platform' -} - -{ #category : #accessing } -PBBlockFinalizer class >> block: aBlock [ - ^ self new - block: aBlock; - yourself -] - -{ #category : #accessing } -PBBlockFinalizer >> block [ - ^ block -] - -{ #category : #accessing } -PBBlockFinalizer >> block: anObject [ - block := anObject -] - -{ #category : #finalization } -PBBlockFinalizer >> finalize [ - ^ block value -] +Class { + #name : #PBBlockFinalizer, + #superclass : #PBAbstractFinalizer, + #instVars : [ + 'block' + ], + #category : #'PythonBridge-Platform' +} + +{ #category : #accessing } +PBBlockFinalizer class >> block: aBlock [ + ^ self new + block: aBlock; + yourself +] + +{ #category : #accessing } +PBBlockFinalizer >> block [ + ^ block +] + +{ #category : #accessing } +PBBlockFinalizer >> block: anObject [ + block := anObject +] + +{ #category : #finalization } +PBBlockFinalizer >> finalize [ + ^ block value +] diff --git a/src/PythonBridge/PBCF.class.st b/src/PythonBridge/PBCF.class.st index b581352..473df56 100644 --- a/src/PythonBridge/PBCF.class.st +++ b/src/PythonBridge/PBCF.class.st @@ -1,112 +1,112 @@ -Class { - #name : #PBCF, - #superclass : #Object, - #classInstVars : [ - 'current' - ], - #category : #'PythonBridge-Global' -} - -{ #category : #'as yet unclassified' } -PBCF class >> << aPythonStatement [ - ^ self current << aPythonStatement -] - -{ #category : #'as yet unclassified' } -PBCF class >> addBinding: aBinding [ - ^ self current addBinding: aBinding -] - -{ #category : #'as yet unclassified' } -PBCF class >> addObserver: anObserver [ - ^ self current addObserver: anObserver -] - -{ #category : #'as yet unclassified' } -PBCF class >> append: aPythonStatement [ - ^ self current append: aPythonStatement -] - -{ #category : #initialization } -PBCF class >> application [ - ^ self applicationClass uniqueInstance -] - -{ #category : #initialization } -PBCF class >> applicationClass [ - ^ PBApplication -] - -{ #category : #'as yet unclassified' } -PBCF class >> bindingAt: varName put: anObject [ - ^ self current bindingAt: varName put: anObject -] - -{ #category : #'as yet unclassified' } -PBCF class >> bindingWrap: anObject [ - ^ self current bindingWrap: anObject -] - -{ #category : #'as yet unclassified' } -PBCF class >> buildCommand [ - | command | - command := self current buildCommand. - self reset. - ^ command -] - -{ #category : #accessing } -PBCF class >> current [ - ^ current -] - -{ #category : #accessing } -PBCF class >> current: cf [ - current := cf -] - -{ #category : #'reflective operations' } -PBCF class >> doesNotUnderstand: aMessage [ - ^ aMessage sendTo: self current -] - -{ #category : #'instance creation' } -PBCF class >> newCommandFactory [ - ^ self application newCommandFactory -] - -{ #category : #'as yet unclassified' } -PBCF class >> observerFromCallback: aBlock [ - ^ self current observerFromCallback: aBlock -] - -{ #category : #accessing } -PBCF class >> reset [ - current := self newCommandFactory -] - -{ #category : #'old api' } -PBCF class >> send [ - ^ self application send: self buildCommand -] - -{ #category : #'old api' } -PBCF class >> send: aPythonStatement [ - self << aPythonStatement. - ^ self send -] - -{ #category : #'old api' } -PBCF class >> sendAndWait [ - ^ self send waitForValue -] - -{ #category : #'old api' } -PBCF class >> sendAndWait: aPythonStatement [ - ^ (self send: aPythonStatement) waitForValue -] - -{ #category : #'as yet unclassified' } -PBCF class >> transformBlock: aBlock [ - ^ self current transformBlock: aBlock -] +Class { + #name : #PBCF, + #superclass : #Object, + #classInstVars : [ + 'current' + ], + #category : #'PythonBridge-Global' +} + +{ #category : #'as yet unclassified' } +PBCF class >> << aPythonStatement [ + ^ self current << aPythonStatement +] + +{ #category : #'as yet unclassified' } +PBCF class >> addBinding: aBinding [ + ^ self current addBinding: aBinding +] + +{ #category : #'as yet unclassified' } +PBCF class >> addObserver: anObserver [ + ^ self current addObserver: anObserver +] + +{ #category : #'as yet unclassified' } +PBCF class >> append: aPythonStatement [ + ^ self current append: aPythonStatement +] + +{ #category : #initialization } +PBCF class >> application [ + ^ self applicationClass uniqueInstance +] + +{ #category : #initialization } +PBCF class >> applicationClass [ + ^ PBApplication +] + +{ #category : #'as yet unclassified' } +PBCF class >> bindingAt: varName put: anObject [ + ^ self current bindingAt: varName put: anObject +] + +{ #category : #'as yet unclassified' } +PBCF class >> bindingWrap: anObject [ + ^ self current bindingWrap: anObject +] + +{ #category : #'as yet unclassified' } +PBCF class >> buildCommand [ + | command | + command := self current buildCommand. + self reset. + ^ command +] + +{ #category : #accessing } +PBCF class >> current [ + ^ current +] + +{ #category : #accessing } +PBCF class >> current: cf [ + current := cf +] + +{ #category : #'reflective operations' } +PBCF class >> doesNotUnderstand: aMessage [ + ^ aMessage sendTo: self current +] + +{ #category : #'instance creation' } +PBCF class >> newCommandFactory [ + ^ self application newCommandFactory +] + +{ #category : #'as yet unclassified' } +PBCF class >> observerFromCallback: aBlock [ + ^ self current observerFromCallback: aBlock +] + +{ #category : #accessing } +PBCF class >> reset [ + current := self newCommandFactory +] + +{ #category : #'old api' } +PBCF class >> send [ + ^ self application send: self buildCommand +] + +{ #category : #'old api' } +PBCF class >> send: aPythonStatement [ + self << aPythonStatement. + ^ self send +] + +{ #category : #'old api' } +PBCF class >> sendAndWait [ + ^ self send waitForValue +] + +{ #category : #'old api' } +PBCF class >> sendAndWait: aPythonStatement [ + ^ (self send: aPythonStatement) waitForValue +] + +{ #category : #'as yet unclassified' } +PBCF class >> transformBlock: aBlock [ + ^ self current transformBlock: aBlock +] diff --git a/src/PythonBridge/PBCallbackAnswer.class.st b/src/PythonBridge/PBCallbackAnswer.class.st index 04b57c8..18bf9d0 100644 --- a/src/PythonBridge/PBCallbackAnswer.class.st +++ b/src/PythonBridge/PBCallbackAnswer.class.st @@ -1,24 +1,24 @@ -Class { - #name : #PBCallbackAnswer, - #superclass : #PBRAnswer, - #instVars : [ - 'value' - ], - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #encoding } -PBCallbackAnswer >> privateEncode: dict [ - super privateEncode: dict. - dict at: #value put: value -] - -{ #category : #accessing } -PBCallbackAnswer >> value [ - ^ value -] - -{ #category : #accessing } -PBCallbackAnswer >> value: anObject [ - value := anObject -] +Class { + #name : #PBCallbackAnswer, + #superclass : #PBRAnswer, + #instVars : [ + 'value' + ], + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #encoding } +PBCallbackAnswer >> privateEncode: dict [ + super privateEncode: dict. + dict at: #value put: value +] + +{ #category : #accessing } +PBCallbackAnswer >> value [ + ^ value +] + +{ #category : #accessing } +PBCallbackAnswer >> value: anObject [ + value := anObject +] diff --git a/src/PythonBridge/PBCallbackMessage.class.st b/src/PythonBridge/PBCallbackMessage.class.st index 5f05e05..930654f 100644 --- a/src/PythonBridge/PBCallbackMessage.class.st +++ b/src/PythonBridge/PBCallbackMessage.class.st @@ -1,43 +1,43 @@ -Class { - #name : #PBCallbackMessage, - #superclass : #PBRSyncMessage, - #instVars : [ - 'commandId', - 'observerId', - 'value' - ], - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #accessing } -PBCallbackMessage class >> answerClass [ - ^ PBCallbackAnswer -] - -{ #category : #accessing } -PBCallbackMessage class >> type [ - ^ #CALLBACK -] - -{ #category : #accessing } -PBCallbackMessage >> commandId [ - ^ commandId -] - -{ #category : #accessing } -PBCallbackMessage >> observerId [ - ^ observerId -] - -{ #category : #'as yet unclassified' } -PBCallbackMessage >> privateDecode: dict [ - super privateDecode: dict. - commandId := dict at: #commandId. - observerId := dict at: #observerId. - value := dict at: #value -] - -{ #category : #accessing } -PBCallbackMessage >> value [ - ^ value -] +Class { + #name : #PBCallbackMessage, + #superclass : #PBRSyncMessage, + #instVars : [ + 'commandId', + 'observerId', + 'value' + ], + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #accessing } +PBCallbackMessage class >> answerClass [ + ^ PBCallbackAnswer +] + +{ #category : #accessing } +PBCallbackMessage class >> type [ + ^ #CALLBACK +] + +{ #category : #accessing } +PBCallbackMessage >> commandId [ + ^ commandId +] + +{ #category : #accessing } +PBCallbackMessage >> observerId [ + ^ observerId +] + +{ #category : #'as yet unclassified' } +PBCallbackMessage >> privateDecode: dict [ + super privateDecode: dict. + commandId := dict at: #commandId. + observerId := dict at: #observerId. + value := dict at: #value +] + +{ #category : #accessing } +PBCallbackMessage >> value [ + ^ value +] diff --git a/src/PythonBridge/PBCommand.class.st b/src/PythonBridge/PBCommand.class.st index eef043e..df888f3 100644 --- a/src/PythonBridge/PBCommand.class.st +++ b/src/PythonBridge/PBCommand.class.st @@ -1,110 +1,110 @@ -Class { - #name : #PBCommand, - #superclass : #Object, - #instVars : [ - 'id', - 'instructions', - 'bindings', - 'observers', - 'promise', - 'transformBlock' - ], - #category : #'PythonBridge-Execution' -} - -{ #category : #accessing } -PBCommand >> bindings [ - ^ bindings -] - -{ #category : #accessing } -PBCommand >> bindings: bindingCol [ - bindings := bindingCol -] - -{ #category : #accessing } -PBCommand >> bindingsDictionary [ - ^ self bindings asDictionary -] - -{ #category : #accessing } -PBCommand >> getObserver: observerId [ - ^ observers detect: [ :obs | obs id = observerId ] -] - -{ #category : #accessing } -PBCommand >> id [ - ^ id -] - -{ #category : #accessing } -PBCommand >> id: anObject [ - id := anObject -] - -{ #category : #initialization } -PBCommand >> initialize [ - super initialize. - id := PBPlatform current newRandomName. - bindings := #(). - observers := #(). - instructions := OrderedCollection new. - transformBlock := #yourself -] - -{ #category : #accessing } -PBCommand >> instructions [ - ^ instructions -] - -{ #category : #accessing } -PBCommand >> instructions: anObject [ - instructions := anObject -] - -{ #category : #testing } -PBCommand >> isValid [ - ^ [ self id isString and: [ - (self bindings allSatisfy: [ :assoc | assoc key isString ]) and: [ - self observers allSatisfy: [ :obs | obs callback isBlock ] ] ] ] on: Error do: [ false ] -] - -{ #category : #accessing } -PBCommand >> observers [ - ^ observers -] - -{ #category : #accessing } -PBCommand >> observers: anObject [ - observers := anObject -] - -{ #category : #accessing } -PBCommand >> promise [ - ^ promise -] - -{ #category : #accessing } -PBCommand >> promise: anObject [ - promise := anObject -] - -{ #category : #'as yet unclassified' } -PBCommand >> pythonCode [ - | py3CodeStream | - py3CodeStream := String new writeStream. - self instructions do: [ :instr | - instr writePython3On: py3CodeStream. - py3CodeStream << String lf ]. - ^ py3CodeStream contents -] - -{ #category : #accessing } -PBCommand >> transformBlock [ - ^ transformBlock -] - -{ #category : #accessing } -PBCommand >> transformBlock: anObject [ - transformBlock := anObject -] +Class { + #name : #PBCommand, + #superclass : #Object, + #instVars : [ + 'id', + 'instructions', + 'bindings', + 'observers', + 'promise', + 'transformBlock' + ], + #category : #'PythonBridge-Execution' +} + +{ #category : #accessing } +PBCommand >> bindings [ + ^ bindings +] + +{ #category : #accessing } +PBCommand >> bindings: bindingCol [ + bindings := bindingCol +] + +{ #category : #accessing } +PBCommand >> bindingsDictionary [ + ^ self bindings asDictionary +] + +{ #category : #accessing } +PBCommand >> getObserver: observerId [ + ^ observers detect: [ :obs | obs id = observerId ] +] + +{ #category : #accessing } +PBCommand >> id [ + ^ id +] + +{ #category : #accessing } +PBCommand >> id: anObject [ + id := anObject +] + +{ #category : #initialization } +PBCommand >> initialize [ + super initialize. + id := PBPlatform current newRandomName. + bindings := #(). + observers := #(). + instructions := OrderedCollection new. + transformBlock := #yourself +] + +{ #category : #accessing } +PBCommand >> instructions [ + ^ instructions +] + +{ #category : #accessing } +PBCommand >> instructions: anObject [ + instructions := anObject +] + +{ #category : #testing } +PBCommand >> isValid [ + ^ [ self id isString and: [ + (self bindings allSatisfy: [ :assoc | assoc key isString ]) and: [ + self observers allSatisfy: [ :obs | obs callback isBlock ] ] ] ] on: Error do: [ false ] +] + +{ #category : #accessing } +PBCommand >> observers [ + ^ observers +] + +{ #category : #accessing } +PBCommand >> observers: anObject [ + observers := anObject +] + +{ #category : #accessing } +PBCommand >> promise [ + ^ promise +] + +{ #category : #accessing } +PBCommand >> promise: anObject [ + promise := anObject +] + +{ #category : #'as yet unclassified' } +PBCommand >> pythonCode [ + | py3CodeStream | + py3CodeStream := String new writeStream. + self instructions do: [ :instr | + instr writePython3On: py3CodeStream. + py3CodeStream << String lf ]. + ^ py3CodeStream contents +] + +{ #category : #accessing } +PBCommand >> transformBlock [ + ^ transformBlock +] + +{ #category : #accessing } +PBCommand >> transformBlock: anObject [ + transformBlock := anObject +] diff --git a/src/PythonBridge/PBCommandFactory.class.st b/src/PythonBridge/PBCommandFactory.class.st index 08bb87c..eeb332b 100644 --- a/src/PythonBridge/PBCommandFactory.class.st +++ b/src/PythonBridge/PBCommandFactory.class.st @@ -1,145 +1,145 @@ -Class { - #name : #PBCommandFactory, - #superclass : #Object, - #instVars : [ - 'application', - 'bindingsDictionary', - 'observers', - 'transformBlock', - 'command', - 'instructions' - ], - #category : #'PythonBridge-Execution' -} - -{ #category : #streaming } -PBCommandFactory >> << aPythonStatement [ - instructions add: aPythonStatement -] - -{ #category : #bindings } -PBCommandFactory >> addBinding: aBinding [ - bindingsDictionary at: aBinding pythonVariable name put: aBinding object. - ^ aBinding -] - -{ #category : #observers } -PBCommandFactory >> addObserver: anObserver [ - observers add: anObserver. - ^ anObserver -] - -{ #category : #streaming } -PBCommandFactory >> append: aPythonStatement [ - instructions add: aPythonStatement -] - -{ #category : #accessing } -PBCommandFactory >> application [ - ^ application -] - -{ #category : #accessing } -PBCommandFactory >> application: anObject [ - application := anObject -] - -{ #category : #bindings } -PBCommandFactory >> bindingAt: varName put: anObject [ - bindingsDictionary at: varName put: anObject. - ^ PBBinding key: varName wrap: anObject -] - -{ #category : #bindings } -PBCommandFactory >> bindingWrap: anObject [ - ^ self addBinding: (PBBinding wrap: anObject) -] - -{ #category : #send } -PBCommandFactory >> buildCommand [ - | finishedCommand | - finishedCommand := command - instructions: self instructionsWithNotifyAtEnd; - bindings: bindingsDictionary associations; - observers: observers; - transformBlock: transformBlock; - yourself. - self initialize. - ^ finishedCommand -] - -{ #category : #accessing } -PBCommandFactory >> decorateTransform: aBlock [ - | previousBlock | - previousBlock := transformBlock. - ^ transformBlock := [ :obj | aBlock value: (previousBlock value: obj) ] -] - -{ #category : #initialization } -PBCommandFactory >> initialize [ - super initialize. - self reset -] - -{ #category : #accessing } -PBCommandFactory >> instructionsWithNotifyAtEnd [ - | instructionsCopy | - instructionsCopy := instructions copy. - instructionsCopy ifEmpty: [ instructionsCopy := OrderedCollection with: nil ]. - instructionsCopy last isPythonValue ifFalse: [ - instructionsCopy := instructionsCopy asOrderedCollection. - instructionsCopy add: nil ]. - instructionsCopy - at: instructionsCopy size - put: (self setNotifyToInstruction: instructionsCopy last). - ^ instructionsCopy -] - -{ #category : #observers } -PBCommandFactory >> observerFromCallback: aBlock [ - | observer | - observer := (PBObserver callback: aBlock) - command: command; - yourself. - ^ self addObserver: observer -] - -{ #category : #initialization } -PBCommandFactory >> reset [ - instructions := OrderedCollection new. - bindingsDictionary := Dictionary new. - observers := OrderedCollection new. - command := PBCommand new. - transformBlock := #yourself -] - -{ #category : #send } -PBCommandFactory >> send [ - ^ self sendCommand -] - -{ #category : #send } -PBCommandFactory >> sendAndWait [ - ^ self sendCommand waitForValue -] - -{ #category : #send } -PBCommandFactory >> sendCommand [ - ^ self application send: self buildCommand -] - -{ #category : #initialization } -PBCommandFactory >> setNotifyToInstruction: aP3gInstruction [ - ^ 'notify' asP3GIdentifier - callWith: (Array with: aP3gInstruction with: command id) -] - -{ #category : #accessing } -PBCommandFactory >> transformBlock [ - ^ transformBlock -] - -{ #category : #accessing } -PBCommandFactory >> transformBlock: anObject [ - transformBlock := anObject -] +Class { + #name : #PBCommandFactory, + #superclass : #Object, + #instVars : [ + 'application', + 'bindingsDictionary', + 'observers', + 'transformBlock', + 'command', + 'instructions' + ], + #category : #'PythonBridge-Execution' +} + +{ #category : #streaming } +PBCommandFactory >> << aPythonStatement [ + instructions add: aPythonStatement +] + +{ #category : #bindings } +PBCommandFactory >> addBinding: aBinding [ + bindingsDictionary at: aBinding pythonVariable name put: aBinding object. + ^ aBinding +] + +{ #category : #observers } +PBCommandFactory >> addObserver: anObserver [ + observers add: anObserver. + ^ anObserver +] + +{ #category : #streaming } +PBCommandFactory >> append: aPythonStatement [ + instructions add: aPythonStatement +] + +{ #category : #accessing } +PBCommandFactory >> application [ + ^ application +] + +{ #category : #accessing } +PBCommandFactory >> application: anObject [ + application := anObject +] + +{ #category : #bindings } +PBCommandFactory >> bindingAt: varName put: anObject [ + bindingsDictionary at: varName put: anObject. + ^ PBBinding key: varName wrap: anObject +] + +{ #category : #bindings } +PBCommandFactory >> bindingWrap: anObject [ + ^ self addBinding: (PBBinding wrap: anObject) +] + +{ #category : #send } +PBCommandFactory >> buildCommand [ + | finishedCommand | + finishedCommand := command + instructions: self instructionsWithNotifyAtEnd; + bindings: bindingsDictionary associations; + observers: observers; + transformBlock: transformBlock; + yourself. + self initialize. + ^ finishedCommand +] + +{ #category : #accessing } +PBCommandFactory >> decorateTransform: aBlock [ + | previousBlock | + previousBlock := transformBlock. + ^ transformBlock := [ :obj | aBlock value: (previousBlock value: obj) ] +] + +{ #category : #initialization } +PBCommandFactory >> initialize [ + super initialize. + self reset +] + +{ #category : #accessing } +PBCommandFactory >> instructionsWithNotifyAtEnd [ + | instructionsCopy | + instructionsCopy := instructions copy. + instructionsCopy ifEmpty: [ instructionsCopy := OrderedCollection with: nil ]. + instructionsCopy last isPythonValue ifFalse: [ + instructionsCopy := instructionsCopy asOrderedCollection. + instructionsCopy add: nil ]. + instructionsCopy + at: instructionsCopy size + put: (self setNotifyToInstruction: instructionsCopy last). + ^ instructionsCopy +] + +{ #category : #observers } +PBCommandFactory >> observerFromCallback: aBlock [ + | observer | + observer := (PBObserver callback: aBlock) + command: command; + yourself. + ^ self addObserver: observer +] + +{ #category : #initialization } +PBCommandFactory >> reset [ + instructions := OrderedCollection new. + bindingsDictionary := Dictionary new. + observers := OrderedCollection new. + command := PBCommand new. + transformBlock := #yourself +] + +{ #category : #send } +PBCommandFactory >> send [ + ^ self sendCommand +] + +{ #category : #send } +PBCommandFactory >> sendAndWait [ + ^ self sendCommand waitForValue +] + +{ #category : #send } +PBCommandFactory >> sendCommand [ + ^ self application send: self buildCommand +] + +{ #category : #initialization } +PBCommandFactory >> setNotifyToInstruction: aP3gInstruction [ + ^ 'notify' asP3GIdentifier + callWith: (Array with: aP3gInstruction with: command id) +] + +{ #category : #accessing } +PBCommandFactory >> transformBlock [ + ^ transformBlock +] + +{ #category : #accessing } +PBCommandFactory >> transformBlock: anObject [ + transformBlock := anObject +] diff --git a/src/PythonBridge/PBCommandFactoryTest.class.st b/src/PythonBridge/PBCommandFactoryTest.class.st index d60127b..4da673a 100644 --- a/src/PythonBridge/PBCommandFactoryTest.class.st +++ b/src/PythonBridge/PBCommandFactoryTest.class.st @@ -1,52 +1,52 @@ -Class { - #name : #PBCommandFactoryTest, - #superclass : #TestCase, - #instVars : [ - 'factory' - ], - #category : #'PythonBridge-Tests' -} - -{ #category : #initialization } -PBCommandFactoryTest >> setUp [ - factory := PBCommandFactory new -] - -{ #category : #tests } -PBCommandFactoryTest >> testBuildEmptyCommand [ - | command | - command := factory buildCommand. - self assert: command instructions size equals: 1. - self assert: command instructions first class equals: P3GCall. - self assert: command instructions first target name equals: 'notify'. - self assert: command instructions first positionalArguments first equals: nil. - self assert: command bindings isEmpty -] - -{ #category : #tests } -PBCommandFactoryTest >> testBuildFullCommand [ - | command instructions | - factory << (P3GString string: 'foo'). - factory bindingAt: #myVar put: 3. - command := factory buildCommand. - instructions := command instructions. - self assert: command instructions first positionalArguments first string equals: 'foo'. - self assert: (command bindingsDictionary at: #myVar) equals: 3 -] - -{ #category : #tests } -PBCommandFactoryTest >> testBuildSimpleCommand [ - | command instructions | - factory << (P3GString string: 'foo'). - command := factory buildCommand. - instructions := command instructions. - self assert: command instructions first positionalArguments first string equals: 'foo'. -] - -{ #category : #tests } -PBCommandFactoryTest >> testBuildWithObservers [ - | command | - factory observerFromCallback: [ 32 ]. - command := factory buildCommand. - self assert: command observers first callback value equals: 32. -] +Class { + #name : #PBCommandFactoryTest, + #superclass : #TestCase, + #instVars : [ + 'factory' + ], + #category : #'PythonBridge-Tests' +} + +{ #category : #initialization } +PBCommandFactoryTest >> setUp [ + factory := PBCommandFactory new +] + +{ #category : #tests } +PBCommandFactoryTest >> testBuildEmptyCommand [ + | command | + command := factory buildCommand. + self assert: command instructions size equals: 1. + self assert: command instructions first class equals: P3GCall. + self assert: command instructions first target name equals: 'notify'. + self assert: command instructions first positionalArguments first equals: nil. + self assert: command bindings isEmpty +] + +{ #category : #tests } +PBCommandFactoryTest >> testBuildFullCommand [ + | command instructions | + factory << (P3GString string: 'foo'). + factory bindingAt: #myVar put: 3. + command := factory buildCommand. + instructions := command instructions. + self assert: command instructions first positionalArguments first string equals: 'foo'. + self assert: (command bindingsDictionary at: #myVar) equals: 3 +] + +{ #category : #tests } +PBCommandFactoryTest >> testBuildSimpleCommand [ + | command instructions | + factory << (P3GString string: 'foo'). + command := factory buildCommand. + instructions := command instructions. + self assert: command instructions first positionalArguments first string equals: 'foo'. +] + +{ #category : #tests } +PBCommandFactoryTest >> testBuildWithObservers [ + | command | + factory observerFromCallback: [ 32 ]. + command := factory buildCommand. + self assert: command observers first callback value equals: 32. +] diff --git a/src/PythonBridge/PBCommandQueue.class.st b/src/PythonBridge/PBCommandQueue.class.st index 94e356b..16a6f62 100644 --- a/src/PythonBridge/PBCommandQueue.class.st +++ b/src/PythonBridge/PBCommandQueue.class.st @@ -1,125 +1,125 @@ -Class { - #name : #PBCommandQueue, - #superclass : #Object, - #instVars : [ - 'currentIndex', - 'innerCollection', - 'executionHandler' - ], - #category : #'PythonBridge-Execution' -} - -{ #category : #accessing } -PBCommandQueue class >> executionHandler: aHandler [ - ^ self new - executionHandler: aHandler; - yourself -] - -{ #category : #accessing } -PBCommandQueue >> cleanIndex: anIndex [ - self debugMode ifTrue: [ ^ self ]. - currentIndex := currentIndex - 1. - innerCollection removeAt: anIndex -] - -{ #category : #accessing } -PBCommandQueue >> completedCommands [ - ^ innerCollection first: currentIndex -] - -{ #category : #accessing } -PBCommandQueue >> currentCommand [ - self isFinished ifTrue: [ ^ nil ]. - ^ innerCollection at: currentIndex -] - -{ #category : #accessing } -PBCommandQueue >> debugMode [ - ^ PBApplication debugMode -] - -{ #category : #accessing } -PBCommandQueue >> enqueueCommand: aCommand [ - innerCollection add: aCommand -] - -{ #category : #accessing } -PBCommandQueue >> excecutionHandler [ - ^ executionHandler -] - -{ #category : #accessing } -PBCommandQueue >> executionHandler [ - ^ executionHandler -] - -{ #category : #accessing } -PBCommandQueue >> executionHandler: anObject [ - executionHandler := anObject -] - -{ #category : #accessing } -PBCommandQueue >> finishCommand: aCommand [ - ^ self finishCommandId: aCommand id -] - -{ #category : #accessing } -PBCommandQueue >> finishCommandId: id [ - | commandIndex | - self currentCommand ifNotNil: [ :command | - command id = id - ifTrue: [ - self cleanIndex: currentIndex. - currentIndex := currentIndex + 1. - ^ true ] ]. - commandIndex := innerCollection detectIndex: [ :command | command id = id ]. - commandIndex > currentIndex - ifTrue: [ - currentIndex := commandIndex + 1. - self log: (PBErrorLog message: 'Out of sync command queue. Pharo is delayed.') ] - ifFalse: [ - self log: (PBErrorLog message: 'Out of sync command queue. Python is delayed.') ]. - self cleanIndex: commandIndex. - ^ false -] - -{ #category : #accessing } -PBCommandQueue >> getCommand: aCommandId [ - ^ innerCollection detect: [ :command | command id = aCommandId ] -] - -{ #category : #initialization } -PBCommandQueue >> initialize [ - super initialize. - innerCollection := OrderedCollection new. - currentIndex := 1 -] - -{ #category : #accessing } -PBCommandQueue >> isFinished [ - ^ innerCollection size < currentIndex -] - -{ #category : #accessing } -PBCommandQueue >> list [ - ^ innerCollection -] - -{ #category : #accessing } -PBCommandQueue >> nextCommand [ - | nextCommandIndex | - nextCommandIndex := currentIndex + 1. - innerCollection size < nextCommandIndex ifTrue: [ ^ nil ]. - ^ innerCollection at: nextCommandIndex -] - -{ #category : #accessing } -PBCommandQueue >> queue [ - ^ self waitingCommands -] - -{ #category : #accessing } -PBCommandQueue >> waitingCommands [ - ^ innerCollection allButFirst: currentIndex -] +Class { + #name : #PBCommandQueue, + #superclass : #Object, + #instVars : [ + 'currentIndex', + 'innerCollection', + 'executionHandler' + ], + #category : #'PythonBridge-Execution' +} + +{ #category : #accessing } +PBCommandQueue class >> executionHandler: aHandler [ + ^ self new + executionHandler: aHandler; + yourself +] + +{ #category : #accessing } +PBCommandQueue >> cleanIndex: anIndex [ + self debugMode ifTrue: [ ^ self ]. + currentIndex := currentIndex - 1. + innerCollection removeAt: anIndex +] + +{ #category : #accessing } +PBCommandQueue >> completedCommands [ + ^ innerCollection first: currentIndex +] + +{ #category : #accessing } +PBCommandQueue >> currentCommand [ + self isFinished ifTrue: [ ^ nil ]. + ^ innerCollection at: currentIndex +] + +{ #category : #accessing } +PBCommandQueue >> debugMode [ + ^ PBApplication debugMode +] + +{ #category : #accessing } +PBCommandQueue >> enqueueCommand: aCommand [ + innerCollection add: aCommand +] + +{ #category : #accessing } +PBCommandQueue >> excecutionHandler [ + ^ executionHandler +] + +{ #category : #accessing } +PBCommandQueue >> executionHandler [ + ^ executionHandler +] + +{ #category : #accessing } +PBCommandQueue >> executionHandler: anObject [ + executionHandler := anObject +] + +{ #category : #accessing } +PBCommandQueue >> finishCommand: aCommand [ + ^ self finishCommandId: aCommand id +] + +{ #category : #accessing } +PBCommandQueue >> finishCommandId: id [ + | commandIndex | + self currentCommand ifNotNil: [ :command | + command id = id + ifTrue: [ + self cleanIndex: currentIndex. + currentIndex := currentIndex + 1. + ^ true ] ]. + commandIndex := innerCollection detectIndex: [ :command | command id = id ]. + commandIndex > currentIndex + ifTrue: [ + currentIndex := commandIndex + 1. + self log: (PBErrorLog message: 'Out of sync command queue. Pharo is delayed.') ] + ifFalse: [ + self log: (PBErrorLog message: 'Out of sync command queue. Python is delayed.') ]. + self cleanIndex: commandIndex. + ^ false +] + +{ #category : #accessing } +PBCommandQueue >> getCommand: aCommandId [ + ^ innerCollection detect: [ :command | command id = aCommandId ] +] + +{ #category : #initialization } +PBCommandQueue >> initialize [ + super initialize. + innerCollection := OrderedCollection new. + currentIndex := 1 +] + +{ #category : #accessing } +PBCommandQueue >> isFinished [ + ^ innerCollection size < currentIndex +] + +{ #category : #accessing } +PBCommandQueue >> list [ + ^ innerCollection +] + +{ #category : #accessing } +PBCommandQueue >> nextCommand [ + | nextCommandIndex | + nextCommandIndex := currentIndex + 1. + innerCollection size < nextCommandIndex ifTrue: [ ^ nil ]. + ^ innerCollection at: nextCommandIndex +] + +{ #category : #accessing } +PBCommandQueue >> queue [ + ^ self waitingCommands +] + +{ #category : #accessing } +PBCommandQueue >> waitingCommands [ + ^ innerCollection allButFirst: currentIndex +] diff --git a/src/PythonBridge/PBCommandQueueTest.class.st b/src/PythonBridge/PBCommandQueueTest.class.st index 292c378..ade0938 100644 --- a/src/PythonBridge/PBCommandQueueTest.class.st +++ b/src/PythonBridge/PBCommandQueueTest.class.st @@ -1,106 +1,106 @@ -Class { - #name : #PBCommandQueueTest, - #superclass : #TestCase, - #instVars : [ - 'queue', - 'app' - ], - #category : #'PythonBridge-Tests' -} - -{ #category : #initialization } -PBCommandQueueTest >> setUp [ - | execHandler | - app := PBStubApplication new. - execHandler := PBExecutionHandler basicNew - application: app; - yourself. - queue := PBCommandQueue executionHandler: execHandler -] - -{ #category : #tests } -PBCommandQueueTest >> testCleaningCommand [ - | cc1 cc2 | - cc1 := PBCommand new. - cc2 := PBCommand new. - queue enqueueCommand: cc1. - queue enqueueCommand: cc2. - self assert: (queue finishCommand: cc1). - self assert: queue list size equals: 1. - self assert: (queue finishCommand: cc2). - self assert: queue isFinished -] - -{ #category : #tests } -PBCommandQueueTest >> testEmptyQueue [ - self assert: queue list isEmpty. - self assert: queue isFinished. - self assert: queue currentCommand isNil -] - -{ #category : #tests } -PBCommandQueueTest >> testEnqueue [ - | c | - c := PBCommand new. - queue enqueueCommand: c. - self assert: queue list size equals: 1. - self assert: queue currentCommand equals: c. - -] - -{ #category : #tests } -PBCommandQueueTest >> testFinishCommand [ - | cc | - cc := PBCommand new. - queue enqueueCommand: cc. - self assert: (queue finishCommand: cc). - self assert: queue isFinished -] - -{ #category : #tests } -PBCommandQueueTest >> testFinishCommand2 [ - | cc | - cc := PBCommand new. - queue enqueueCommand: cc. - queue enqueueCommand: PBCommand new. - self assert: (queue finishCommand: cc). - self deny: queue isFinished -] - -{ #category : #tests } -PBCommandQueueTest >> testFinishNotFoundCommand [ - self - should: [ queue finishCommandId: 'aa' ] - raise: Error -] - -{ #category : #tests } -PBCommandQueueTest >> testFinishOutOfSync1Command [ - | cc1 cc2 | - cc1 := PBCommand new. - cc2 := PBCommand new. - queue enqueueCommand: cc1. - queue enqueueCommand: cc2. - self deny: (queue finishCommand: cc2). - self assert: queue isFinished -] - -{ #category : #tests } -PBCommandQueueTest >> testFinishOutOfSync2Command [ - | cc1 cc2 | - cc1 := PBCommand new. - cc2 := PBCommand new. - queue enqueueCommand: cc1. - queue enqueueCommand: cc2. - self deny: (queue finishCommand: cc2). - self deny: (queue finishCommand: cc1). - self assert: queue isFinished -] - -{ #category : #tests } -PBCommandQueueTest >> testNotFoundCommand [ - queue enqueueCommand: PBCommand new. - self - should: [ queue finishCommandId: 'aa' ] - raise: Error -] +Class { + #name : #PBCommandQueueTest, + #superclass : #TestCase, + #instVars : [ + 'queue', + 'app' + ], + #category : #'PythonBridge-Tests' +} + +{ #category : #initialization } +PBCommandQueueTest >> setUp [ + | execHandler | + app := PBStubApplication new. + execHandler := PBExecutionHandler basicNew + application: app; + yourself. + queue := PBCommandQueue executionHandler: execHandler +] + +{ #category : #tests } +PBCommandQueueTest >> testCleaningCommand [ + | cc1 cc2 | + cc1 := PBCommand new. + cc2 := PBCommand new. + queue enqueueCommand: cc1. + queue enqueueCommand: cc2. + self assert: (queue finishCommand: cc1). + self assert: queue list size equals: 1. + self assert: (queue finishCommand: cc2). + self assert: queue isFinished +] + +{ #category : #tests } +PBCommandQueueTest >> testEmptyQueue [ + self assert: queue list isEmpty. + self assert: queue isFinished. + self assert: queue currentCommand isNil +] + +{ #category : #tests } +PBCommandQueueTest >> testEnqueue [ + | c | + c := PBCommand new. + queue enqueueCommand: c. + self assert: queue list size equals: 1. + self assert: queue currentCommand equals: c. + +] + +{ #category : #tests } +PBCommandQueueTest >> testFinishCommand [ + | cc | + cc := PBCommand new. + queue enqueueCommand: cc. + self assert: (queue finishCommand: cc). + self assert: queue isFinished +] + +{ #category : #tests } +PBCommandQueueTest >> testFinishCommand2 [ + | cc | + cc := PBCommand new. + queue enqueueCommand: cc. + queue enqueueCommand: PBCommand new. + self assert: (queue finishCommand: cc). + self deny: queue isFinished +] + +{ #category : #tests } +PBCommandQueueTest >> testFinishNotFoundCommand [ + self + should: [ queue finishCommandId: 'aa' ] + raise: Error +] + +{ #category : #tests } +PBCommandQueueTest >> testFinishOutOfSync1Command [ + | cc1 cc2 | + cc1 := PBCommand new. + cc2 := PBCommand new. + queue enqueueCommand: cc1. + queue enqueueCommand: cc2. + self deny: (queue finishCommand: cc2). + self assert: queue isFinished +] + +{ #category : #tests } +PBCommandQueueTest >> testFinishOutOfSync2Command [ + | cc1 cc2 | + cc1 := PBCommand new. + cc2 := PBCommand new. + queue enqueueCommand: cc1. + queue enqueueCommand: cc2. + self deny: (queue finishCommand: cc2). + self deny: (queue finishCommand: cc1). + self assert: queue isFinished +] + +{ #category : #tests } +PBCommandQueueTest >> testNotFoundCommand [ + queue enqueueCommand: PBCommand new. + self + should: [ queue finishCommandId: 'aa' ] + raise: Error +] diff --git a/src/PythonBridge/PBCommandTest.class.st b/src/PythonBridge/PBCommandTest.class.st index 76d7659..2a37b7c 100644 --- a/src/PythonBridge/PBCommandTest.class.st +++ b/src/PythonBridge/PBCommandTest.class.st @@ -1,30 +1,30 @@ -Class { - #name : #PBCommandTest, - #superclass : #TestCase, - #category : #'PythonBridge-Tests' -} - -{ #category : #tests } -PBCommandTest >> testNewCommandHasEmtptyBindings [ - | command | - command := PBCommand new. - self assert: command id isString. - self assert: command id notEmpty. - self assert: command bindings equals: #(). -] - -{ #category : #tests } -PBCommandTest >> testNotValidBindingsKeyNotString [ - | command | - command := PBCommand new. - command bindings: { 33 -> 'bar' }. - self deny: command isValid -] - -{ #category : #tests } -PBCommandTest >> testNotValidBindingsNotAssoc [ - | command | - command := PBCommand new. - command bindings: { '33' -> 'bar'. 'foo' }. - self deny: command isValid -] +Class { + #name : #PBCommandTest, + #superclass : #TestCase, + #category : #'PythonBridge-Tests' +} + +{ #category : #tests } +PBCommandTest >> testNewCommandHasEmtptyBindings [ + | command | + command := PBCommand new. + self assert: command id isString. + self assert: command id notEmpty. + self assert: command bindings equals: #(). +] + +{ #category : #tests } +PBCommandTest >> testNotValidBindingsKeyNotString [ + | command | + command := PBCommand new. + command bindings: { 33 -> 'bar' }. + self deny: command isValid +] + +{ #category : #tests } +PBCommandTest >> testNotValidBindingsNotAssoc [ + | command | + command := PBCommand new. + command bindings: { '33' -> 'bar'. 'foo' }. + self deny: command isValid +] diff --git a/src/PythonBridge/PBCommunicationError.class.st b/src/PythonBridge/PBCommunicationError.class.st index ba36855..3bd5886 100644 --- a/src/PythonBridge/PBCommunicationError.class.st +++ b/src/PythonBridge/PBCommunicationError.class.st @@ -1,5 +1,5 @@ -Class { - #name : #PBCommunicationError, - #superclass : #Error, - #category : #'PythonBridge-Platform' -} +Class { + #name : #PBCommunicationError, + #superclass : #Error, + #category : #'PythonBridge-Platform' +} diff --git a/src/PythonBridge/PBCommunicationHandler.class.st b/src/PythonBridge/PBCommunicationHandler.class.st index a5506a5..a191cec 100644 --- a/src/PythonBridge/PBCommunicationHandler.class.st +++ b/src/PythonBridge/PBCommunicationHandler.class.st @@ -1,47 +1,47 @@ -Class { - #name : #PBCommunicationHandler, - #superclass : #PBHandler, - #instVars : [ - 'messageBroker' - ], - #category : #'PythonBridge-Core' -} - -{ #category : #adding } -PBCommunicationHandler >> addHandler: aBlock forMessageClass: messageClass [ - ^ messageBroker addCallback: aBlock messageClass: messageClass -] - -{ #category : #initialization } -PBCommunicationHandler >> initializeHandler [ - super initializeHandler. - messageBroker := PBPlatform current messageBroker: self application settings -] - -{ #category : #testing } -PBCommunicationHandler >> isPythonReady [ - | semaphore ans | - semaphore := Semaphore new. - [ ans := [self sendMessage: PBIsAliveMessage new. - true ] - on: PBCommunicationError - do: [ :e | false ]. - semaphore signal ] forkAt: Processor lowIOPriority. - semaphore waitTimeoutMSecs: 100. - ^ ans notNil and: ans -] - -{ #category : #adding } -PBCommunicationHandler >> sendMessage: aMessage [ - ^ messageBroker sendMessage: aMessage -] - -{ #category : #accessing } -PBCommunicationHandler >> start [ - ^ messageBroker start -] - -{ #category : #accessing } -PBCommunicationHandler >> stop [ - ^ messageBroker stop -] +Class { + #name : #PBCommunicationHandler, + #superclass : #PBHandler, + #instVars : [ + 'messageBroker' + ], + #category : #'PythonBridge-Core' +} + +{ #category : #adding } +PBCommunicationHandler >> addHandler: aBlock forMessageClass: messageClass [ + ^ messageBroker addCallback: aBlock messageClass: messageClass +] + +{ #category : #initialization } +PBCommunicationHandler >> initializeHandler [ + super initializeHandler. + messageBroker := PBPlatform current messageBroker: self application settings +] + +{ #category : #testing } +PBCommunicationHandler >> isPythonReady [ + | semaphore ans | + semaphore := Semaphore new. + [ ans := [self sendMessage: PBIsAliveMessage new. + true ] + on: PBCommunicationError + do: [ :e | false ]. + semaphore signal ] forkAt: Processor lowIOPriority. + semaphore waitTimeoutMSecs: 100. + ^ ans notNil and: ans +] + +{ #category : #adding } +PBCommunicationHandler >> sendMessage: aMessage [ + ^ messageBroker sendMessage: aMessage +] + +{ #category : #accessing } +PBCommunicationHandler >> start [ + ^ messageBroker start +] + +{ #category : #accessing } +PBCommunicationHandler >> stop [ + ^ messageBroker stop +] diff --git a/src/PythonBridge/PBConnectionTest.class.st b/src/PythonBridge/PBConnectionTest.class.st index f67b61b..29d2d09 100644 --- a/src/PythonBridge/PBConnectionTest.class.st +++ b/src/PythonBridge/PBConnectionTest.class.st @@ -1,65 +1,65 @@ -Class { - #name : #PBConnectionTest, - #superclass : #TestCase, - #instVars : [ - 'application', - 'oldApplication', - 'oldApp', - 'oldCF' - ], - #category : #'PythonBridge-Tests' -} - -{ #category : #running } -PBConnectionTest >> setUp [ - oldApp := PBApplication uniqueInstance. - oldCF := PBCF current. - PBCF current: nil. - application := PBApplication new. - PBApplication uniqueInstance: application -] - -{ #category : #running } -PBConnectionTest >> tearDown [ - application stop. - PBApplication uniqueInstance: oldApp. - PBCF current: oldCF -] - -{ #category : #tests } -PBConnectionTest >> testNotRunning [ - self deny: application isRunning -] - -{ #category : #tests } -PBConnectionTest >> testSimpleExecution [ - self deny: application isRunning. - application start. - application send: - (PBCommand new instructions: - (Array with: (P3GBinaryOperator new - left: 1; - right: 2; - operator: $+; - yourself))). - application stop. - (Delay forMilliseconds: 150) wait. - self should: [ application send: - (PBCommand new instructions: - (Array with: (P3GBinaryOperator new - left: 1; - right: 2; - operator: $+; - yourself))) ] raise: Error. -] - -{ #category : #tests } -PBConnectionTest >> testStartStopProcess [ - self deny: application isRunning. - application start. - self assert: application processHandler isRunning. - application stop. - (Delay forMilliseconds: 150) wait. - self deny: application isRunning. - self deny: application processHandler isRunning -] +Class { + #name : #PBConnectionTest, + #superclass : #TestCase, + #instVars : [ + 'application', + 'oldApplication', + 'oldApp', + 'oldCF' + ], + #category : #'PythonBridge-Tests' +} + +{ #category : #running } +PBConnectionTest >> setUp [ + oldApp := PBApplication uniqueInstance. + oldCF := PBCF current. + PBCF current: nil. + application := PBApplication new. + PBApplication uniqueInstance: application +] + +{ #category : #running } +PBConnectionTest >> tearDown [ + application stop. + PBApplication uniqueInstance: oldApp. + PBCF current: oldCF +] + +{ #category : #tests } +PBConnectionTest >> testNotRunning [ + self deny: application isRunning +] + +{ #category : #tests } +PBConnectionTest >> testSimpleExecution [ + self deny: application isRunning. + application start. + application send: + (PBCommand new instructions: + (Array with: (P3GBinaryOperator new + left: 1; + right: 2; + operator: $+; + yourself))). + application stop. + (Delay forMilliseconds: 150) wait. + self should: [ application send: + (PBCommand new instructions: + (Array with: (P3GBinaryOperator new + left: 1; + right: 2; + operator: $+; + yourself))) ] raise: Error. +] + +{ #category : #tests } +PBConnectionTest >> testStartStopProcess [ + self deny: application isRunning. + application start. + self assert: application processHandler isRunning. + application stop. + (Delay forMilliseconds: 150) wait. + self deny: application isRunning. + self deny: application processHandler isRunning +] diff --git a/src/PythonBridge/PBDeserializeTest.class.st b/src/PythonBridge/PBDeserializeTest.class.st index 405b964..03ece53 100644 --- a/src/PythonBridge/PBDeserializeTest.class.st +++ b/src/PythonBridge/PBDeserializeTest.class.st @@ -1,70 +1,70 @@ -Class { - #name : #PBDeserializeTest, - #superclass : #TestCase, - #instVars : [ - 'mapper' - ], - #category : #'PythonBridge-Tests' -} - -{ #category : #running } -PBDeserializeTest >> application [ - ^ 'FOO' -] - -{ #category : #running } -PBDeserializeTest >> deserialize: anObject [ - ^ self deserializer deserialize: anObject -] - -{ #category : #running } -PBDeserializeTest >> deserializer [ - ^ mapper deserializer - serializerWrapper: PBPlatform current class httpMessageBrokerClass serializer; - yourself -] - -{ #category : #running } -PBDeserializeTest >> setUp [ - super setUp. - mapper := PBMapperFactory forExecutionHandler: self stubExecutionHandler -] - -{ #category : #running } -PBDeserializeTest >> stubExecutionHandler [ - ^ PBExecutionHandler new - application: self application; - yourself -] - -{ #category : #tests } -PBDeserializeTest >> testDeserializeArray [ - self assert: (self deserialize: '[33,"foo"]') equals: #(33 'foo') -] - -{ #category : #tests } -PBDeserializeTest >> testDeserializeNull [ - self assert: (self deserialize: 'null') equals: nil -] - -{ #category : #tests } -PBDeserializeTest >> testDeserializeProxy [ - | proxy | - proxy := self deserialize: '{"__pyclass__":"MyClass","__pyid__":"abcde12345"}'. - self assert: proxy pythonClass equals: #MyClass. - self assert: proxy application equals: self deserializer application. - self assert: proxy application equals: 'FOO'. - self assert: proxy pythonVariable equals: 'abcde12345' asP3GI -] - -{ #category : #tests } -PBDeserializeTest >> testDeserializeProxyInArray [ - | proxy arr | - arr := self deserialize: '[{"__pyclass__":"MyClass","__pyid__":"abcde12345"}]'. - self assert: arr size equals: 1. - proxy := arr first. - self assert: proxy pythonClass equals: #MyClass. - self assert: proxy application equals: self deserializer application. - self assert: proxy application equals: 'FOO'. - self assert: proxy pythonVariable equals: 'abcde12345' asP3GI -] +Class { + #name : #PBDeserializeTest, + #superclass : #TestCase, + #instVars : [ + 'mapper' + ], + #category : #'PythonBridge-Tests' +} + +{ #category : #running } +PBDeserializeTest >> application [ + ^ 'FOO' +] + +{ #category : #running } +PBDeserializeTest >> deserialize: anObject [ + ^ self deserializer deserialize: anObject +] + +{ #category : #running } +PBDeserializeTest >> deserializer [ + ^ mapper deserializer + serializerWrapper: PBPlatform current class httpMessageBrokerClass serializer; + yourself +] + +{ #category : #running } +PBDeserializeTest >> setUp [ + super setUp. + mapper := PBMapperFactory forExecutionHandler: self stubExecutionHandler +] + +{ #category : #running } +PBDeserializeTest >> stubExecutionHandler [ + ^ PBExecutionHandler new + application: self application; + yourself +] + +{ #category : #tests } +PBDeserializeTest >> testDeserializeArray [ + self assert: (self deserialize: '[33,"foo"]') equals: #(33 'foo') +] + +{ #category : #tests } +PBDeserializeTest >> testDeserializeNull [ + self assert: (self deserialize: 'null') equals: nil +] + +{ #category : #tests } +PBDeserializeTest >> testDeserializeProxy [ + | proxy | + proxy := self deserialize: '{"__pyclass__":"MyClass","__pyid__":"abcde12345"}'. + self assert: proxy pythonClass equals: #MyClass. + self assert: proxy application equals: self deserializer application. + self assert: proxy application equals: 'FOO'. + self assert: proxy pythonVariable equals: 'abcde12345' asP3GI +] + +{ #category : #tests } +PBDeserializeTest >> testDeserializeProxyInArray [ + | proxy arr | + arr := self deserialize: '[{"__pyclass__":"MyClass","__pyid__":"abcde12345"}]'. + self assert: arr size equals: 1. + proxy := arr first. + self assert: proxy pythonClass equals: #MyClass. + self assert: proxy application equals: self deserializer application. + self assert: proxy application equals: 'FOO'. + self assert: proxy pythonVariable equals: 'abcde12345' asP3GI +] diff --git a/src/PythonBridge/PBDeserializer.class.st b/src/PythonBridge/PBDeserializer.class.st index 64f3a0b..3540dd3 100644 --- a/src/PythonBridge/PBDeserializer.class.st +++ b/src/PythonBridge/PBDeserializer.class.st @@ -1,50 +1,50 @@ -Class { - #name : #PBDeserializer, - #superclass : #PBMapper, - #category : #'PythonBridge-Serialization' -} - -{ #category : #'private protocol' } -PBDeserializer class >> deserialize: anObject [ - ^ self new - deserialize: anObject -] - -{ #category : #'private protocol' } -PBDeserializer >> application [ - ^ self executionHandler application -] - -{ #category : #'private protocol' } -PBDeserializer >> buildProxyFor: rawObject [ - | proxy | - proxy := PBProxyObject - pythonClass: (rawObject at: #__pyclass__) - pythonVar: (rawObject at: #__pyid__) asP3GI - application: self application. - self executionHandler registerObject: proxy. - ^ proxy -] - -{ #category : #'private protocol' } -PBDeserializer >> deserialize: str [ - ^ self privateDeserialize: (serializerWrapper deserialize: str). -] - -{ #category : #'private protocol' } -PBDeserializer >> objectRegistry [ - ^ self executionHandler objectRegistry -] - -{ #category : #'private protocol' } -PBDeserializer >> privateDeserialize: rawObj [ - rawObj isCollection ifFalse: [ ^ rawObj ]. - rawObj isDictionary and: [ (rawObj includesKey: #__pyid__) - ifTrue: [ ^ self reifyProxyFor: rawObj ] ]. - ^ rawObj collect: [ :elem | self privateDeserialize: elem ] -] - -{ #category : #'private protocol' } -PBDeserializer >> reifyProxyFor: rawObj [ - ^ self objectRegistry resolve: (rawObj at: #__pyid__) ifAbsent: [ self buildProxyFor: rawObj ] -] +Class { + #name : #PBDeserializer, + #superclass : #PBMapper, + #category : #'PythonBridge-Serialization' +} + +{ #category : #'private protocol' } +PBDeserializer class >> deserialize: anObject [ + ^ self new + deserialize: anObject +] + +{ #category : #'private protocol' } +PBDeserializer >> application [ + ^ self executionHandler application +] + +{ #category : #'private protocol' } +PBDeserializer >> buildProxyFor: rawObject [ + | proxy | + proxy := PBProxyObject + pythonClass: (rawObject at: #__pyclass__) + pythonVar: (rawObject at: #__pyid__) asP3GI + application: self application. + self executionHandler registerObject: proxy. + ^ proxy +] + +{ #category : #'private protocol' } +PBDeserializer >> deserialize: str [ + ^ self privateDeserialize: (serializerWrapper deserialize: str). +] + +{ #category : #'private protocol' } +PBDeserializer >> objectRegistry [ + ^ self executionHandler objectRegistry +] + +{ #category : #'private protocol' } +PBDeserializer >> privateDeserialize: rawObj [ + rawObj isCollection ifFalse: [ ^ rawObj ]. + rawObj isDictionary and: [ (rawObj includesKey: #__pyid__) + ifTrue: [ ^ self reifyProxyFor: rawObj ] ]. + ^ rawObj collect: [ :elem | self privateDeserialize: elem ] +] + +{ #category : #'private protocol' } +PBDeserializer >> reifyProxyFor: rawObj [ + ^ self objectRegistry resolve: (rawObj at: #__pyid__) ifAbsent: [ self buildProxyFor: rawObj ] +] diff --git a/src/PythonBridge/PBDropQueue.class.st b/src/PythonBridge/PBDropQueue.class.st index 35e355c..9c35838 100644 --- a/src/PythonBridge/PBDropQueue.class.st +++ b/src/PythonBridge/PBDropQueue.class.st @@ -1,10 +1,10 @@ -Class { - #name : #PBDropQueue, - #superclass : #PBErrorHandlingAction, - #category : #'PythonBridge-ErrorHandling' -} - -{ #category : #'as yet unclassified' } -PBDropQueue >> actionSymbol [ - ^ #'DROP_QUEUE' -] +Class { + #name : #PBDropQueue, + #superclass : #PBErrorHandlingAction, + #category : #'PythonBridge-ErrorHandling' +} + +{ #category : #'as yet unclassified' } +PBDropQueue >> actionSymbol [ + ^ #'DROP_QUEUE' +] diff --git a/src/PythonBridge/PBEnqueueCommandMessage.class.st b/src/PythonBridge/PBEnqueueCommandMessage.class.st index d8678b9..2d46cfd 100644 --- a/src/PythonBridge/PBEnqueueCommandMessage.class.st +++ b/src/PythonBridge/PBEnqueueCommandMessage.class.st @@ -1,77 +1,77 @@ -Class { - #name : #PBEnqueueCommandMessage, - #superclass : #PBAsyncMessage, - #instVars : [ - 'commandId', - 'statements', - 'bindings' - ], - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #'as yet unclassified' } -PBEnqueueCommandMessage class >> commandId: commandId statements: statements bindings: bindings [ - ^ self new - commandId: commandId; - statements: statements; - bindings: bindings; - yourself -] - -{ #category : #'as yet unclassified' } -PBEnqueueCommandMessage class >> type [ - ^ 'ENQUEUE' -] - -{ #category : #adding } -PBEnqueueCommandMessage >> addBinding: assoc [ - bindings add: assoc -] - -{ #category : #adding } -PBEnqueueCommandMessage >> addBindings: assocs [ - assocs do: [ :assoc | self addBinding: assoc ] -] - -{ #category : #accessing } -PBEnqueueCommandMessage >> bindings [ - ^ bindings -] - -{ #category : #accessing } -PBEnqueueCommandMessage >> bindings: anObject [ - bindings := anObject -] - -{ #category : #accessing } -PBEnqueueCommandMessage >> commandId [ - ^ commandId -] - -{ #category : #accessing } -PBEnqueueCommandMessage >> commandId: anObject [ - commandId := anObject -] - -{ #category : #adding } -PBEnqueueCommandMessage >> initialize [ - super initialize. - bindings := Dictionary new -] - -{ #category : #adding } -PBEnqueueCommandMessage >> privateEncode: dict [ - dict at: #commandId put: commandId. - dict at: #statements put: statements. - dict at: #bindings put: bindings -] - -{ #category : #accessing } -PBEnqueueCommandMessage >> statements [ - ^ statements -] - -{ #category : #accessing } -PBEnqueueCommandMessage >> statements: anObject [ - statements := anObject -] +Class { + #name : #PBEnqueueCommandMessage, + #superclass : #PBAsyncMessage, + #instVars : [ + 'commandId', + 'statements', + 'bindings' + ], + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #'as yet unclassified' } +PBEnqueueCommandMessage class >> commandId: commandId statements: statements bindings: bindings [ + ^ self new + commandId: commandId; + statements: statements; + bindings: bindings; + yourself +] + +{ #category : #'as yet unclassified' } +PBEnqueueCommandMessage class >> type [ + ^ 'ENQUEUE' +] + +{ #category : #adding } +PBEnqueueCommandMessage >> addBinding: assoc [ + bindings add: assoc +] + +{ #category : #adding } +PBEnqueueCommandMessage >> addBindings: assocs [ + assocs do: [ :assoc | self addBinding: assoc ] +] + +{ #category : #accessing } +PBEnqueueCommandMessage >> bindings [ + ^ bindings +] + +{ #category : #accessing } +PBEnqueueCommandMessage >> bindings: anObject [ + bindings := anObject +] + +{ #category : #accessing } +PBEnqueueCommandMessage >> commandId [ + ^ commandId +] + +{ #category : #accessing } +PBEnqueueCommandMessage >> commandId: anObject [ + commandId := anObject +] + +{ #category : #adding } +PBEnqueueCommandMessage >> initialize [ + super initialize. + bindings := Dictionary new +] + +{ #category : #adding } +PBEnqueueCommandMessage >> privateEncode: dict [ + dict at: #commandId put: commandId. + dict at: #statements put: statements. + dict at: #bindings put: bindings +] + +{ #category : #accessing } +PBEnqueueCommandMessage >> statements [ + ^ statements +] + +{ #category : #accessing } +PBEnqueueCommandMessage >> statements: anObject [ + statements := anObject +] diff --git a/src/PythonBridge/PBErrorAnswer.class.st b/src/PythonBridge/PBErrorAnswer.class.st index 517c10b..afa8666 100644 --- a/src/PythonBridge/PBErrorAnswer.class.st +++ b/src/PythonBridge/PBErrorAnswer.class.st @@ -1,24 +1,24 @@ -Class { - #name : #PBErrorAnswer, - #superclass : #PBRAnswer, - #instVars : [ - 'handlingAction' - ], - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #accessing } -PBErrorAnswer >> handlingAction [ - ^ handlingAction -] - -{ #category : #accessing } -PBErrorAnswer >> handlingAction: anObject [ - handlingAction := anObject -] - -{ #category : #encoding } -PBErrorAnswer >> privateEncode: dict [ - super privateEncode: dict. - dict at: #action put: handlingAction encodeAsDictionary -] +Class { + #name : #PBErrorAnswer, + #superclass : #PBRAnswer, + #instVars : [ + 'handlingAction' + ], + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #accessing } +PBErrorAnswer >> handlingAction [ + ^ handlingAction +] + +{ #category : #accessing } +PBErrorAnswer >> handlingAction: anObject [ + handlingAction := anObject +] + +{ #category : #encoding } +PBErrorAnswer >> privateEncode: dict [ + super privateEncode: dict. + dict at: #action put: handlingAction encodeAsDictionary +] diff --git a/src/PythonBridge/PBErrorHandlingAction.class.st b/src/PythonBridge/PBErrorHandlingAction.class.st index d8b14cd..5b34e51 100644 --- a/src/PythonBridge/PBErrorHandlingAction.class.st +++ b/src/PythonBridge/PBErrorHandlingAction.class.st @@ -1,15 +1,15 @@ -Class { - #name : #PBErrorHandlingAction, - #superclass : #Object, - #category : #'PythonBridge-ErrorHandling' -} - -{ #category : #'as yet unclassified' } -PBErrorHandlingAction >> actionSymbol [ - self subclassResponsibility -] - -{ #category : #'as yet unclassified' } -PBErrorHandlingAction >> encodeAsDictionary [ - ^ { #action -> self actionSymbol } asDictionary -] +Class { + #name : #PBErrorHandlingAction, + #superclass : #Object, + #category : #'PythonBridge-ErrorHandling' +} + +{ #category : #'as yet unclassified' } +PBErrorHandlingAction >> actionSymbol [ + self subclassResponsibility +] + +{ #category : #'as yet unclassified' } +PBErrorHandlingAction >> encodeAsDictionary [ + ^ { #action -> self actionSymbol } asDictionary +] diff --git a/src/PythonBridge/PBErrorLog.class.st b/src/PythonBridge/PBErrorLog.class.st index f6cb89e..62fd9fb 100644 --- a/src/PythonBridge/PBErrorLog.class.st +++ b/src/PythonBridge/PBErrorLog.class.st @@ -1,10 +1,10 @@ -Class { - #name : #PBErrorLog, - #superclass : #PBLog, - #category : #'PythonBridge-Logs' -} - -{ #category : #testing } -PBErrorLog >> isError [ - ^ true -] +Class { + #name : #PBErrorLog, + #superclass : #PBLog, + #category : #'PythonBridge-Logs' +} + +{ #category : #testing } +PBErrorLog >> isError [ + ^ true +] diff --git a/src/PythonBridge/PBErrorMessage.class.st b/src/PythonBridge/PBErrorMessage.class.st index eb3525f..0c700aa 100644 --- a/src/PythonBridge/PBErrorMessage.class.st +++ b/src/PythonBridge/PBErrorMessage.class.st @@ -1,58 +1,58 @@ -Class { - #name : #PBErrorMessage, - #superclass : #PBRSyncMessage, - #instVars : [ - 'commandId', - 'errorMessage', - 'trace' - ], - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #accessing } -PBErrorMessage class >> answerClass [ - ^ PBErrorAnswer -] - -{ #category : #accessing } -PBErrorMessage class >> type [ - ^ #ERR -] - -{ #category : #accessing } -PBErrorMessage >> commandId [ - ^ commandId -] - -{ #category : #accessing } -PBErrorMessage >> commandId: anObject [ - commandId := anObject -] - -{ #category : #accessing } -PBErrorMessage >> errorMessage [ - ^ errorMessage -] - -{ #category : #accessing } -PBErrorMessage >> errorMessage: anObject [ - errorMessage := anObject -] - -{ #category : #'as yet unclassified' } -PBErrorMessage >> privateDecode: dict [ - super privateDecode: dict. - commandId := dict at: #commandId. - errorMessage := dict at: #errMsg. - trace := dict at: #trace -] - -{ #category : #accessing } -PBErrorMessage >> trace [ - ^ trace -] - -{ #category : #accessing } -PBErrorMessage >> trace: anObject [ - trace := anObject -] +Class { + #name : #PBErrorMessage, + #superclass : #PBRSyncMessage, + #instVars : [ + 'commandId', + 'errorMessage', + 'trace' + ], + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #accessing } +PBErrorMessage class >> answerClass [ + ^ PBErrorAnswer +] + +{ #category : #accessing } +PBErrorMessage class >> type [ + ^ #ERR +] + +{ #category : #accessing } +PBErrorMessage >> commandId [ + ^ commandId +] + +{ #category : #accessing } +PBErrorMessage >> commandId: anObject [ + commandId := anObject +] + +{ #category : #accessing } +PBErrorMessage >> errorMessage [ + ^ errorMessage +] + +{ #category : #accessing } +PBErrorMessage >> errorMessage: anObject [ + errorMessage := anObject +] + +{ #category : #'as yet unclassified' } +PBErrorMessage >> privateDecode: dict [ + super privateDecode: dict. + commandId := dict at: #commandId. + errorMessage := dict at: #errMsg. + trace := dict at: #trace +] + +{ #category : #accessing } +PBErrorMessage >> trace [ + ^ trace +] + +{ #category : #accessing } +PBErrorMessage >> trace: anObject [ + trace := anObject +] diff --git a/src/PythonBridge/PBExcecutionHandlerTest.class.st b/src/PythonBridge/PBExcecutionHandlerTest.class.st index 918381a..808430f 100644 --- a/src/PythonBridge/PBExcecutionHandlerTest.class.st +++ b/src/PythonBridge/PBExcecutionHandlerTest.class.st @@ -1,37 +1,37 @@ -Class { - #name : #PBExcecutionHandlerTest, - #superclass : #TestCase, - #instVars : [ - 'execHandler', - 'commandFactory' - ], - #category : #'PythonBridge-Tests' -} - -{ #category : #initialization } -PBExcecutionHandlerTest >> setUp [ - | app | - app := PBStubApplication new. - execHandler := PBExecutionHandler new - application: app; - yourself. - commandFactory := PBCommandFactory new. -] - -{ #category : #accessing } -PBExcecutionHandlerTest >> testJSONSerializeEncodeBindings [ - | message | - commandFactory bindingAt: #foo put: #(). - message := execHandler buildMessageFromCommand: commandFactory buildCommand. - self assert: (message bindings at: #foo) equals: (execHandler serialize: #()). - self deny: (message bindings at: #foo) = #() -] - -{ #category : #accessing } -PBExcecutionHandlerTest >> testSerializeEncodeBindings [ - | message | - commandFactory bindingAt: #foo put: #(). - message := execHandler buildMessageFromCommand: commandFactory buildCommand. - self assert: (message bindings at: #foo) equals: (execHandler serialize: #()). - self deny: (message bindings at: #foo) = #() -] +Class { + #name : #PBExcecutionHandlerTest, + #superclass : #TestCase, + #instVars : [ + 'execHandler', + 'commandFactory' + ], + #category : #'PythonBridge-Tests' +} + +{ #category : #initialization } +PBExcecutionHandlerTest >> setUp [ + | app | + app := PBStubApplication new. + execHandler := PBExecutionHandler new + application: app; + yourself. + commandFactory := PBCommandFactory new. +] + +{ #category : #accessing } +PBExcecutionHandlerTest >> testJSONSerializeEncodeBindings [ + | message | + commandFactory bindingAt: #foo put: #(). + message := execHandler buildMessageFromCommand: commandFactory buildCommand. + self assert: (message bindings at: #foo) equals: (execHandler serialize: #()). + self deny: (message bindings at: #foo) = #() +] + +{ #category : #accessing } +PBExcecutionHandlerTest >> testSerializeEncodeBindings [ + | message | + commandFactory bindingAt: #foo put: #(). + message := execHandler buildMessageFromCommand: commandFactory buildCommand. + self assert: (message bindings at: #foo) equals: (execHandler serialize: #()). + self deny: (message bindings at: #foo) = #() +] diff --git a/src/PythonBridge/PBExecutionHandler.class.st b/src/PythonBridge/PBExecutionHandler.class.st index 3389c9a..fb58fb1 100644 --- a/src/PythonBridge/PBExecutionHandler.class.st +++ b/src/PythonBridge/PBExecutionHandler.class.st @@ -1,192 +1,192 @@ -Class { - #name : #PBExecutionHandler, - #superclass : #PBHandler, - #instVars : [ - 'commandQueue', - 'weakRegistry', - 'objectRegistry', - 'promiseRegistry', - 'mapperFactory' - ], - #category : #'PythonBridge-Execution' -} - -{ #category : #'private protocol' } -PBExecutionHandler >> buildMessageFromCommand: command [ - | message | - message := PBEnqueueCommandMessage - commandId: command id - statements: command pythonCode - bindings: (command bindings asDictionary collect: [ :obj | self serialize: obj ]). - message addBinding: #pharoCommandId -> (self serialize: command id). - ^ message -] - -{ #category : #'private protocol' } -PBExecutionHandler >> communicationHandler [ - ^ self application communicationHandler -] - -{ #category : #'private protocol' } -PBExecutionHandler >> deserialize: anObject [ - ^ mapperFactory deserializer deserialize: anObject -] - -{ #category : #'private protocol' } -PBExecutionHandler >> getObserverAtCommandId: commandId id: observerId [ - ^ (commandQueue getCommand: commandId) getObserver: observerId -] - -{ #category : #initialization } -PBExecutionHandler >> initialize [ - super initialize. - commandQueue := PBCommandQueue new. - mapperFactory := PBMapperFactory forExecutionHandler: self. - promiseRegistry := PBPromiseRegistry new. - weakRegistry := PBPlatform current weakRegistry. - objectRegistry := PBObjectRegistry new -] - -{ #category : #initialization } -PBExecutionHandler >> initializeHandler [ - self communicationHandler - addHandler: [ :msg | self notifyHandler: msg ] forMessageClass: PBUpdatePromiseMessage; - addHandler: [ :msg | self notifyErrorHandler: msg ] forMessageClass: PBErrorMessage; - addHandler: [ :msg | self notifyCallbackHandler: msg ] forMessageClass: PBCallbackMessage -] - -{ #category : #'private protocol' } -PBExecutionHandler >> mapperFactory [ - ^ mapperFactory -] - -{ #category : #'as yet unclassified' } -PBExecutionHandler >> newCommandFactory [ - ^ PBCommandFactory new - application: self application; - yourself -] - -{ #category : #handlers } -PBExecutionHandler >> notifyCallbackHandler: msg [ - | val serialization | - val := self - signalObserver: (self getObserverAtCommandId: msg commandId id: msg observerId) - withValue: (self deserialize: msg value). - serialization := [ self serialize: val ] on: Error do: [ :err | - self application log: err printString. - self serialize: nil ]. - ^ msg createAnswer - value: serialization; - yourself -] - -{ #category : #handlers } -PBExecutionHandler >> notifyErrorHandler: errorMsg [ - | error | - error := PBPythonError new - application: self application; - command: (commandQueue getCommand: errorMsg commandId); - errorMessage: errorMsg errorMessage; - trace: errorMsg trace; - yourself. - self safeTriggerDebugger: error. - ^ errorMsg createAnswer - handlingAction: error proceedAction; - yourself -] - -{ #category : #handlers } -PBExecutionHandler >> notifyHandler: updatePromiseMsg [ - self - updatePromiseId: updatePromiseMsg promiseId - with: (self deserialize: updatePromiseMsg value) -] - -{ #category : #initialization } -PBExecutionHandler >> objectRegistry [ - ^ objectRegistry -] - -{ #category : #'private protocol' } -PBExecutionHandler >> primitiveSendCommand: command [ - ^ self communicationHandler sendMessage: (self buildMessageFromCommand: command) -] - -{ #category : #'as yet unclassified' } -PBExecutionHandler >> registerObject: aPythonObject [ - objectRegistry registerObject: aPythonObject. - weakRegistry - registerObject: aPythonObject - finalizer: (PBRegistryFinalizer - pythonVariable: aPythonObject pythonVariable - executionHandler: self) -] - -{ #category : #'private protocol' } -PBExecutionHandler >> registerPromiseForCommand: aCommand [ - | promise | - promise := PBPromise new - id: aCommand id; - transformBlock: aCommand transformBlock; - yourself. - aCommand promise: promise. - promiseRegistry addPromise: promise. - ^ promise -] - -{ #category : #'as yet unclassified' } -PBExecutionHandler >> safeTriggerDebugger: error [ - | sem | - sem := Semaphore new. - [ [ self triggerDebugger: error ] ensure: [ sem signal ] ] - on: PBPythonError fork: [ :e | PBPlatform current uiManager spawnDebuggerOnException: e ]. - sem wait. - ^ error proceedAction: error defaultProceedAction -] - -{ #category : #'private protocol' } -PBExecutionHandler >> sendCommand: command [ - | promise | - self assert: command isValid. - commandQueue enqueueCommand: command. - promise := self registerPromiseForCommand: command. - self primitiveSendCommand: command. - ^ promise -] - -{ #category : #'private protocol' } -PBExecutionHandler >> serialize: anObject [ - ^ mapperFactory serializer serialize: anObject -] - -{ #category : #'private protocol' } -PBExecutionHandler >> signalObserver: observer withValue: object [ - ^ observer pharoNotify: object -] - -{ #category : #accessing } -PBExecutionHandler >> stop [ - super stop. - weakRegistry destroy -] - -{ #category : #'as yet unclassified' } -PBExecutionHandler >> triggerDebugger: pythonError [ - "This method is called when an error rised on Python execution." - "Inspect error to review the Command that caused the error. - For ignoring error: - pythonError proceedAction: PBIgnore new - For aborting: - pythonError proceedAction: PBDropQueue new - For replacing the command that caused the error: - pythonError proceedAction: P3ReplaceCommandAction new newCommand: **Your crafted command** - To execute your action you just need to 'Proceed' in the debugger." - pythonError signal. -] - -{ #category : #'private protocol' } -PBExecutionHandler >> updatePromiseId: id with: anObject [ - commandQueue finishCommandId: id. - promiseRegistry removeAndSignalPromiseId: id with: anObject -] +Class { + #name : #PBExecutionHandler, + #superclass : #PBHandler, + #instVars : [ + 'commandQueue', + 'weakRegistry', + 'objectRegistry', + 'promiseRegistry', + 'mapperFactory' + ], + #category : #'PythonBridge-Execution' +} + +{ #category : #'private protocol' } +PBExecutionHandler >> buildMessageFromCommand: command [ + | message | + message := PBEnqueueCommandMessage + commandId: command id + statements: command pythonCode + bindings: (command bindings asDictionary collect: [ :obj | self serialize: obj ]). + message addBinding: #pharoCommandId -> (self serialize: command id). + ^ message +] + +{ #category : #'private protocol' } +PBExecutionHandler >> communicationHandler [ + ^ self application communicationHandler +] + +{ #category : #'private protocol' } +PBExecutionHandler >> deserialize: anObject [ + ^ mapperFactory deserializer deserialize: anObject +] + +{ #category : #'private protocol' } +PBExecutionHandler >> getObserverAtCommandId: commandId id: observerId [ + ^ (commandQueue getCommand: commandId) getObserver: observerId +] + +{ #category : #initialization } +PBExecutionHandler >> initialize [ + super initialize. + commandQueue := PBCommandQueue new. + mapperFactory := PBMapperFactory forExecutionHandler: self. + promiseRegistry := PBPromiseRegistry new. + weakRegistry := PBPlatform current weakRegistry. + objectRegistry := PBObjectRegistry new +] + +{ #category : #initialization } +PBExecutionHandler >> initializeHandler [ + self communicationHandler + addHandler: [ :msg | self notifyHandler: msg ] forMessageClass: PBUpdatePromiseMessage; + addHandler: [ :msg | self notifyErrorHandler: msg ] forMessageClass: PBErrorMessage; + addHandler: [ :msg | self notifyCallbackHandler: msg ] forMessageClass: PBCallbackMessage +] + +{ #category : #'private protocol' } +PBExecutionHandler >> mapperFactory [ + ^ mapperFactory +] + +{ #category : #'as yet unclassified' } +PBExecutionHandler >> newCommandFactory [ + ^ PBCommandFactory new + application: self application; + yourself +] + +{ #category : #handlers } +PBExecutionHandler >> notifyCallbackHandler: msg [ + | val serialization | + val := self + signalObserver: (self getObserverAtCommandId: msg commandId id: msg observerId) + withValue: (self deserialize: msg value). + serialization := [ self serialize: val ] on: Error do: [ :err | + self application log: err printString. + self serialize: nil ]. + ^ msg createAnswer + value: serialization; + yourself +] + +{ #category : #handlers } +PBExecutionHandler >> notifyErrorHandler: errorMsg [ + | error | + error := PBPythonError new + application: self application; + command: (commandQueue getCommand: errorMsg commandId); + errorMessage: errorMsg errorMessage; + trace: errorMsg trace; + yourself. + self safeTriggerDebugger: error. + ^ errorMsg createAnswer + handlingAction: error proceedAction; + yourself +] + +{ #category : #handlers } +PBExecutionHandler >> notifyHandler: updatePromiseMsg [ + self + updatePromiseId: updatePromiseMsg promiseId + with: (self deserialize: updatePromiseMsg value) +] + +{ #category : #initialization } +PBExecutionHandler >> objectRegistry [ + ^ objectRegistry +] + +{ #category : #'private protocol' } +PBExecutionHandler >> primitiveSendCommand: command [ + ^ self communicationHandler sendMessage: (self buildMessageFromCommand: command) +] + +{ #category : #'as yet unclassified' } +PBExecutionHandler >> registerObject: aPythonObject [ + objectRegistry registerObject: aPythonObject. + weakRegistry + registerObject: aPythonObject + finalizer: (PBRegistryFinalizer + pythonVariable: aPythonObject pythonVariable + executionHandler: self) +] + +{ #category : #'private protocol' } +PBExecutionHandler >> registerPromiseForCommand: aCommand [ + | promise | + promise := PBPromise new + id: aCommand id; + transformBlock: aCommand transformBlock; + yourself. + aCommand promise: promise. + promiseRegistry addPromise: promise. + ^ promise +] + +{ #category : #'as yet unclassified' } +PBExecutionHandler >> safeTriggerDebugger: error [ + | sem | + sem := Semaphore new. + [ [ self triggerDebugger: error ] ensure: [ sem signal ] ] + on: PBPythonError fork: [ :e | PBPlatform current uiManager spawnDebuggerOnException: e ]. + sem wait. + ^ error proceedAction: error defaultProceedAction +] + +{ #category : #'private protocol' } +PBExecutionHandler >> sendCommand: command [ + | promise | + self assert: command isValid. + commandQueue enqueueCommand: command. + promise := self registerPromiseForCommand: command. + self primitiveSendCommand: command. + ^ promise +] + +{ #category : #'private protocol' } +PBExecutionHandler >> serialize: anObject [ + ^ mapperFactory serializer serialize: anObject +] + +{ #category : #'private protocol' } +PBExecutionHandler >> signalObserver: observer withValue: object [ + ^ observer pharoNotify: object +] + +{ #category : #accessing } +PBExecutionHandler >> stop [ + super stop. + weakRegistry destroy +] + +{ #category : #'as yet unclassified' } +PBExecutionHandler >> triggerDebugger: pythonError [ + "This method is called when an error rised on Python execution." + "Inspect error to review the Command that caused the error. + For ignoring error: + pythonError proceedAction: PBIgnore new + For aborting: + pythonError proceedAction: PBDropQueue new + For replacing the command that caused the error: + pythonError proceedAction: P3ReplaceCommandAction new newCommand: **Your crafted command** + To execute your action you just need to 'Proceed' in the debugger." + pythonError signal. +] + +{ #category : #'private protocol' } +PBExecutionHandler >> updatePromiseId: id with: anObject [ + commandQueue finishCommandId: id. + promiseRegistry removeAndSignalPromiseId: id with: anObject +] diff --git a/src/PythonBridge/PBFatalErrorLog.class.st b/src/PythonBridge/PBFatalErrorLog.class.st index dfcde82..9097e76 100644 --- a/src/PythonBridge/PBFatalErrorLog.class.st +++ b/src/PythonBridge/PBFatalErrorLog.class.st @@ -1,5 +1,5 @@ -Class { - #name : #PBFatalErrorLog, - #superclass : #PBErrorLog, - #category : #'PythonBridge-Logs' -} +Class { + #name : #PBFatalErrorLog, + #superclass : #PBErrorLog, + #category : #'PythonBridge-Logs' +} diff --git a/src/PythonBridge/PBHandler.class.st b/src/PythonBridge/PBHandler.class.st index 0894a2e..ce950af 100644 --- a/src/PythonBridge/PBHandler.class.st +++ b/src/PythonBridge/PBHandler.class.st @@ -1,43 +1,43 @@ -Class { - #name : #PBHandler, - #superclass : #Object, - #instVars : [ - 'application' - ], - #category : #'PythonBridge-Core' -} - -{ #category : #'as yet unclassified' } -PBHandler class >> application: anApplication [ - ^ self new - application: anApplication; - initializeHandler; - yourself -] - -{ #category : #accessing } -PBHandler >> application [ - ^ application -] - -{ #category : #accessing } -PBHandler >> application: anObject [ - application := anObject -] - -{ #category : #initialization } -PBHandler >> initializeHandler [ -] - -{ #category : #testing } -PBHandler >> isRunning [ - ^ true -] - -{ #category : #accessing } -PBHandler >> start [ -] - -{ #category : #accessing } -PBHandler >> stop [ -] +Class { + #name : #PBHandler, + #superclass : #Object, + #instVars : [ + 'application' + ], + #category : #'PythonBridge-Core' +} + +{ #category : #'as yet unclassified' } +PBHandler class >> application: anApplication [ + ^ self new + application: anApplication; + initializeHandler; + yourself +] + +{ #category : #accessing } +PBHandler >> application [ + ^ application +] + +{ #category : #accessing } +PBHandler >> application: anObject [ + application := anObject +] + +{ #category : #initialization } +PBHandler >> initializeHandler [ +] + +{ #category : #testing } +PBHandler >> isRunning [ + ^ true +] + +{ #category : #accessing } +PBHandler >> start [ +] + +{ #category : #accessing } +PBHandler >> stop [ +] diff --git a/src/PythonBridge/PBIgnore.class.st b/src/PythonBridge/PBIgnore.class.st index da08714..ea40057 100644 --- a/src/PythonBridge/PBIgnore.class.st +++ b/src/PythonBridge/PBIgnore.class.st @@ -1,10 +1,10 @@ -Class { - #name : #PBIgnore, - #superclass : #PBErrorHandlingAction, - #category : #'PythonBridge-ErrorHandling' -} - -{ #category : #'as yet unclassified' } -PBIgnore >> actionSymbol [ - ^ #'IGNORE' -] +Class { + #name : #PBIgnore, + #superclass : #PBErrorHandlingAction, + #category : #'PythonBridge-ErrorHandling' +} + +{ #category : #'as yet unclassified' } +PBIgnore >> actionSymbol [ + ^ #'IGNORE' +] diff --git a/src/PythonBridge/PBIsAliveMessage.class.st b/src/PythonBridge/PBIsAliveMessage.class.st index 8f49514..d00676c 100644 --- a/src/PythonBridge/PBIsAliveMessage.class.st +++ b/src/PythonBridge/PBIsAliveMessage.class.st @@ -1,15 +1,15 @@ -Class { - #name : #PBIsAliveMessage, - #superclass : #PBSyncMessage, - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #accessing } -PBIsAliveMessage class >> answerClass [ - ^ PBAnswer -] - -{ #category : #accessing } -PBIsAliveMessage class >> type [ - ^ #IS_ALIVE -] +Class { + #name : #PBIsAliveMessage, + #superclass : #PBSyncMessage, + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #accessing } +PBIsAliveMessage class >> answerClass [ + ^ PBAnswer +] + +{ #category : #accessing } +PBIsAliveMessage class >> type [ + ^ #IS_ALIVE +] diff --git a/src/PythonBridge/PBJsonSerializerTest.class.st b/src/PythonBridge/PBJsonSerializerTest.class.st index c135e4a..99e344e 100644 --- a/src/PythonBridge/PBJsonSerializerTest.class.st +++ b/src/PythonBridge/PBJsonSerializerTest.class.st @@ -1,64 +1,64 @@ -Class { - #name : #PBJsonSerializerTest, - #superclass : #TestCase, - #instVars : [ - 'serializer' - ], - #category : #'PythonBridge-Platform' -} - -{ #category : #testing } -PBJsonSerializerTest class >> isAbstract [ - ^ self == PBJsonSerializerTest -] - -{ #category : #asserting } -PBJsonSerializerTest >> assertDeserialize: aString equals: anObject [ - self assert: (serializer deserialize: aString) equals: anObject -] - -{ #category : #asserting } -PBJsonSerializerTest >> assertSerialize: anObject equals: aString [ - self assert: (serializer serialize: anObject) equals: aString -] - -{ #category : #running } -PBJsonSerializerTest >> jsonSerializerClass [ - self subclassResponsibility -] - -{ #category : #running } -PBJsonSerializerTest >> setUp [ - super setUp. - serializer := self jsonSerializerClass new -] - -{ #category : #tests } -PBJsonSerializerTest >> testDeserializeArray [ - self assertDeserialize: '[33,"foo"]' equals: #(33 'foo') -] - -{ #category : #tests } -PBJsonSerializerTest >> testDeserializeNestedArrays [ - self assertDeserialize: '[33,["foo","bar"]]' equals: #(33 #('foo' 'bar')) -] - -{ #category : #tests } -PBJsonSerializerTest >> testDeserializeNil [ - self assertDeserialize: 'null' equals: nil -] - -{ #category : #tests } -PBJsonSerializerTest >> testSerializeArray [ - self assertSerialize: #(33 'foo') equals: '[33,"foo"]' -] - -{ #category : #tests } -PBJsonSerializerTest >> testSerializeNestedArrays [ - self assertSerialize: #(33 #('foo' 'bar')) equals: '[33,["foo","bar"]]' -] - -{ #category : #tests } -PBJsonSerializerTest >> testSerializeNil [ - self assertSerialize: nil equals: 'null' -] +Class { + #name : #PBJsonSerializerTest, + #superclass : #TestCase, + #instVars : [ + 'serializer' + ], + #category : #'PythonBridge-Platform' +} + +{ #category : #testing } +PBJsonSerializerTest class >> isAbstract [ + ^ self == PBJsonSerializerTest +] + +{ #category : #asserting } +PBJsonSerializerTest >> assertDeserialize: aString equals: anObject [ + self assert: (serializer deserialize: aString) equals: anObject +] + +{ #category : #asserting } +PBJsonSerializerTest >> assertSerialize: anObject equals: aString [ + self assert: (serializer serialize: anObject) equals: aString +] + +{ #category : #running } +PBJsonSerializerTest >> jsonSerializerClass [ + self subclassResponsibility +] + +{ #category : #running } +PBJsonSerializerTest >> setUp [ + super setUp. + serializer := self jsonSerializerClass new +] + +{ #category : #tests } +PBJsonSerializerTest >> testDeserializeArray [ + self assertDeserialize: '[33,"foo"]' equals: #(33 'foo') +] + +{ #category : #tests } +PBJsonSerializerTest >> testDeserializeNestedArrays [ + self assertDeserialize: '[33,["foo","bar"]]' equals: #(33 #('foo' 'bar')) +] + +{ #category : #tests } +PBJsonSerializerTest >> testDeserializeNil [ + self assertDeserialize: 'null' equals: nil +] + +{ #category : #tests } +PBJsonSerializerTest >> testSerializeArray [ + self assertSerialize: #(33 'foo') equals: '[33,"foo"]' +] + +{ #category : #tests } +PBJsonSerializerTest >> testSerializeNestedArrays [ + self assertSerialize: #(33 #('foo' 'bar')) equals: '[33,["foo","bar"]]' +] + +{ #category : #tests } +PBJsonSerializerTest >> testSerializeNil [ + self assertSerialize: nil equals: 'null' +] diff --git a/src/PythonBridge/PBLog.class.st b/src/PythonBridge/PBLog.class.st index 3d18f6c..43f491e 100644 --- a/src/PythonBridge/PBLog.class.st +++ b/src/PythonBridge/PBLog.class.st @@ -1,42 +1,42 @@ -Class { - #name : #PBLog, - #superclass : #Object, - #instVars : [ - 'message' - ], - #category : #'PythonBridge-Logs' -} - -{ #category : #accessing } -PBLog class >> message: aString [ - ^ self new - message: aString; - yourself -] - -{ #category : #testing } -PBLog >> isError [ - ^ false -] - -{ #category : #accessing } -PBLog >> message [ - ^ message -] - -{ #category : #accessing } -PBLog >> message: anObject [ - message := anObject -] - -{ #category : #printing } -PBLog >> printOn: str [ - message - ifNil: [ super printOn: str ] - ifNotNil: [ - str - << self class name; - << ': '; - << message; - cr ] -] +Class { + #name : #PBLog, + #superclass : #Object, + #instVars : [ + 'message' + ], + #category : #'PythonBridge-Logs' +} + +{ #category : #accessing } +PBLog class >> message: aString [ + ^ self new + message: aString; + yourself +] + +{ #category : #testing } +PBLog >> isError [ + ^ false +] + +{ #category : #accessing } +PBLog >> message [ + ^ message +] + +{ #category : #accessing } +PBLog >> message: anObject [ + message := anObject +] + +{ #category : #printing } +PBLog >> printOn: str [ + message + ifNil: [ super printOn: str ] + ifNotNil: [ + str + << self class name; + << ': '; + << message; + cr ] +] diff --git a/src/PythonBridge/PBLoggingHandler.class.st b/src/PythonBridge/PBLoggingHandler.class.st index 50eb56b..73da321 100644 --- a/src/PythonBridge/PBLoggingHandler.class.st +++ b/src/PythonBridge/PBLoggingHandler.class.st @@ -1,29 +1,29 @@ -Class { - #name : #PBLoggingHandler, - #superclass : #PBHandler, - #instVars : [ - 'logs' - ], - #category : #'PythonBridge-Core' -} - -{ #category : #accessing } -PBLoggingHandler >> errorLogs [ - ^ logs select: #isError -] - -{ #category : #initialization } -PBLoggingHandler >> initialize [ - super initialize. - logs := OrderedCollection new -] - -{ #category : #log } -PBLoggingHandler >> log: aLog [ - logs add: aLog -] - -{ #category : #accessing } -PBLoggingHandler >> logs [ - ^ logs -] +Class { + #name : #PBLoggingHandler, + #superclass : #PBHandler, + #instVars : [ + 'logs' + ], + #category : #'PythonBridge-Core' +} + +{ #category : #accessing } +PBLoggingHandler >> errorLogs [ + ^ logs select: #isError +] + +{ #category : #initialization } +PBLoggingHandler >> initialize [ + super initialize. + logs := OrderedCollection new +] + +{ #category : #log } +PBLoggingHandler >> log: aLog [ + logs add: aLog +] + +{ #category : #accessing } +PBLoggingHandler >> logs [ + ^ logs +] diff --git a/src/PythonBridge/PBLoggingHandlerTest.class.st b/src/PythonBridge/PBLoggingHandlerTest.class.st index e492716..cfec1f7 100644 --- a/src/PythonBridge/PBLoggingHandlerTest.class.st +++ b/src/PythonBridge/PBLoggingHandlerTest.class.st @@ -1,32 +1,32 @@ -Class { - #name : #PBLoggingHandlerTest, - #superclass : #TestCase, - #instVars : [ - 'logger' - ], - #category : #'PythonBridge-Tests' -} - -{ #category : #'as yet unclassified' } -PBLoggingHandlerTest >> logs [ - ^ logger logs -] - -{ #category : #initialization } -PBLoggingHandlerTest >> setUp [ - logger := PBLoggingHandler new -] - -{ #category : #tests } -PBLoggingHandlerTest >> testAddLog [ - logger log: (PBLog message: 'Foo'). - self assert: logger logs first message equals: 'Foo' -] - -{ #category : #tests } -PBLoggingHandlerTest >> testErrorLog [ - logger log: (PBLog message: 'Foo'). - self assert: logger errorLogs isEmpty. - logger log: (PBErrorLog message: 'Bar'). - self assert: logger errorLogs first message equals: 'Bar'. -] +Class { + #name : #PBLoggingHandlerTest, + #superclass : #TestCase, + #instVars : [ + 'logger' + ], + #category : #'PythonBridge-Tests' +} + +{ #category : #'as yet unclassified' } +PBLoggingHandlerTest >> logs [ + ^ logger logs +] + +{ #category : #initialization } +PBLoggingHandlerTest >> setUp [ + logger := PBLoggingHandler new +] + +{ #category : #tests } +PBLoggingHandlerTest >> testAddLog [ + logger log: (PBLog message: 'Foo'). + self assert: logger logs first message equals: 'Foo' +] + +{ #category : #tests } +PBLoggingHandlerTest >> testErrorLog [ + logger log: (PBLog message: 'Foo'). + self assert: logger errorLogs isEmpty. + logger log: (PBErrorLog message: 'Bar'). + self assert: logger errorLogs first message equals: 'Bar'. +] diff --git a/src/PythonBridge/PBMapper.class.st b/src/PythonBridge/PBMapper.class.st index 2060bf2..12086fe 100644 --- a/src/PythonBridge/PBMapper.class.st +++ b/src/PythonBridge/PBMapper.class.st @@ -1,60 +1,60 @@ -Class { - #name : #PBMapper, - #superclass : #Object, - #instVars : [ - 'mappings', - 'serializerWrapper', - 'executionHandler', - 'application' - ], - #category : #'PythonBridge-Serialization' -} - -{ #category : #'as yet unclassified' } -PBMapper class >> mappings: mappings executionHandler: handler [ - ^ self new - mappings: mappings; - executionHandler: handler; - yourself -] - -{ #category : #accessing } -PBMapper >> application [ - ^ executionHandler application -] - -{ #category : #accessing } -PBMapper >> application: anObject [ - application := anObject -] - -{ #category : #accessing } -PBMapper >> executionHandler [ - ^ executionHandler -] - -{ #category : #accessing } -PBMapper >> executionHandler: anObject [ - executionHandler := anObject -] - -{ #category : #initialization } -PBMapper >> initialize [ - super initialize. - serializerWrapper := PBPlatform current serializer -] - -{ #category : #accessing } -PBMapper >> mappings [ - ^ mappings -] - -{ #category : #accessing } -PBMapper >> mappings: anObject [ - mappings := anObject -] - -{ #category : #accessing } -PBMapper >> serializerWrapper: anObject [ - serializerWrapper := anObject -] +Class { + #name : #PBMapper, + #superclass : #Object, + #instVars : [ + 'mappings', + 'serializerWrapper', + 'executionHandler', + 'application' + ], + #category : #'PythonBridge-Serialization' +} + +{ #category : #'as yet unclassified' } +PBMapper class >> mappings: mappings executionHandler: handler [ + ^ self new + mappings: mappings; + executionHandler: handler; + yourself +] + +{ #category : #accessing } +PBMapper >> application [ + ^ executionHandler application +] + +{ #category : #accessing } +PBMapper >> application: anObject [ + application := anObject +] + +{ #category : #accessing } +PBMapper >> executionHandler [ + ^ executionHandler +] + +{ #category : #accessing } +PBMapper >> executionHandler: anObject [ + executionHandler := anObject +] + +{ #category : #initialization } +PBMapper >> initialize [ + super initialize. + serializerWrapper := PBPlatform current serializer +] + +{ #category : #accessing } +PBMapper >> mappings [ + ^ mappings +] + +{ #category : #accessing } +PBMapper >> mappings: anObject [ + mappings := anObject +] + +{ #category : #accessing } +PBMapper >> serializerWrapper: anObject [ + serializerWrapper := anObject +] diff --git a/src/PythonBridge/PBMapperFactory.class.st b/src/PythonBridge/PBMapperFactory.class.st index 8bbb7f4..b2890b5 100644 --- a/src/PythonBridge/PBMapperFactory.class.st +++ b/src/PythonBridge/PBMapperFactory.class.st @@ -1,58 +1,58 @@ -Class { - #name : #PBMapperFactory, - #superclass : #Object, - #instVars : [ - 'executionHandler', - 'serializationMappings', - 'deserializationMappings' - ], - #category : #'PythonBridge-Serialization' -} - -{ #category : #'as yet unclassified' } -PBMapperFactory class >> forExecutionHandler: handler [ - ^ self new - executionHandler: handler; - yourself -] - -{ #category : #initialization } -PBMapperFactory >> deserializer [ - ^ self deserializerClass - mappings: serializationMappings - executionHandler: executionHandler -] - -{ #category : #initialization } -PBMapperFactory >> deserializerClass [ - ^ PBDeserializer -] - -{ #category : #accessing } -PBMapperFactory >> executionHandler [ - ^ executionHandler -] - -{ #category : #accessing } -PBMapperFactory >> executionHandler: anObject [ - executionHandler := anObject -] - -{ #category : #initialization } -PBMapperFactory >> initialize [ - super initialize. - serializationMappings := OrderedCollection new. - deserializationMappings := OrderedCollection new -] - -{ #category : #initialization } -PBMapperFactory >> serializer [ - ^ self serializerClass - mappings: serializationMappings - executionHandler: executionHandler -] - -{ #category : #initialization } -PBMapperFactory >> serializerClass [ - ^ PBSerializer -] +Class { + #name : #PBMapperFactory, + #superclass : #Object, + #instVars : [ + 'executionHandler', + 'serializationMappings', + 'deserializationMappings' + ], + #category : #'PythonBridge-Serialization' +} + +{ #category : #'as yet unclassified' } +PBMapperFactory class >> forExecutionHandler: handler [ + ^ self new + executionHandler: handler; + yourself +] + +{ #category : #initialization } +PBMapperFactory >> deserializer [ + ^ self deserializerClass + mappings: serializationMappings + executionHandler: executionHandler +] + +{ #category : #initialization } +PBMapperFactory >> deserializerClass [ + ^ PBDeserializer +] + +{ #category : #accessing } +PBMapperFactory >> executionHandler [ + ^ executionHandler +] + +{ #category : #accessing } +PBMapperFactory >> executionHandler: anObject [ + executionHandler := anObject +] + +{ #category : #initialization } +PBMapperFactory >> initialize [ + super initialize. + serializationMappings := OrderedCollection new. + deserializationMappings := OrderedCollection new +] + +{ #category : #initialization } +PBMapperFactory >> serializer [ + ^ self serializerClass + mappings: serializationMappings + executionHandler: executionHandler +] + +{ #category : #initialization } +PBMapperFactory >> serializerClass [ + ^ PBSerializer +] diff --git a/src/PythonBridge/PBMapping.class.st b/src/PythonBridge/PBMapping.class.st index 032d1c5..77f3944 100644 --- a/src/PythonBridge/PBMapping.class.st +++ b/src/PythonBridge/PBMapping.class.st @@ -1,5 +1,5 @@ -Class { - #name : #PBMapping, - #superclass : #Object, - #category : #'PythonBridge-Serialization' -} +Class { + #name : #PBMapping, + #superclass : #Object, + #category : #'PythonBridge-Serialization' +} diff --git a/src/PythonBridge/PBMessage.class.st b/src/PythonBridge/PBMessage.class.st index 1bfd6a2..a67d4f2 100644 --- a/src/PythonBridge/PBMessage.class.st +++ b/src/PythonBridge/PBMessage.class.st @@ -1,35 +1,35 @@ -Class { - #name : #PBMessage, - #superclass : #PBAbstractMessage, - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #testing } -PBMessage class >> isReverseMessage [ - "Reverse messages corresponds to messages that start on Python to Pharo. In other words - in reverse direction from normal messages." - ^ false -] - -{ #category : #accessing } -PBMessage class >> type [ - ^ #MSG -] - -{ #category : #encoding } -PBMessage >> encode [ - | dict | - dict := Dictionary new. - dict at: #type put: self type. - self privateEncode: dict. - ^ dict -] - -{ #category : #testing } -PBMessage >> isSync [ - self subclassResponsibility -] - -{ #category : #encoding } -PBMessage >> privateEncode: dict [ -] +Class { + #name : #PBMessage, + #superclass : #PBAbstractMessage, + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #testing } +PBMessage class >> isReverseMessage [ + "Reverse messages corresponds to messages that start on Python to Pharo. In other words + in reverse direction from normal messages." + ^ false +] + +{ #category : #accessing } +PBMessage class >> type [ + ^ #MSG +] + +{ #category : #encoding } +PBMessage >> encode [ + | dict | + dict := Dictionary new. + dict at: #type put: self type. + self privateEncode: dict. + ^ dict +] + +{ #category : #testing } +PBMessage >> isSync [ + self subclassResponsibility +] + +{ #category : #encoding } +PBMessage >> privateEncode: dict [ +] diff --git a/src/PythonBridge/PBMessageBrokerTest.class.st b/src/PythonBridge/PBMessageBrokerTest.class.st index e29f01f..7ed7016 100644 --- a/src/PythonBridge/PBMessageBrokerTest.class.st +++ b/src/PythonBridge/PBMessageBrokerTest.class.st @@ -1,271 +1,271 @@ -Class { - #name : #PBMessageBrokerTest, - #superclass : #TestCase, - #instVars : [ - 'broker', - 'handlerBlock', - 'handlerException', - 'settings' - ], - #category : #'PythonBridge-Platform' -} - -{ #category : #testing } -PBMessageBrokerTest class >> isAbstract [ - ^ self == PBMessageBrokerTest -] - -{ #category : #accessing } -PBMessageBrokerTest >> answer: aDictionary [ - self subclassResponsibility -] - -{ #category : #utils } -PBMessageBrokerTest >> assertCommunicationError: aBlock [ - self should: aBlock raise: PBCommunicationError -] - -{ #category : #accessing } -PBMessageBrokerTest >> brokerUri [ - ^ 'http://' , settings pharoSocketAddress printAddress -] - -{ #category : #initialization } -PBMessageBrokerTest >> buildAndStartStubServer [ - self subclassResponsibility -] - -{ #category : #running } -PBMessageBrokerTest >> defaultSettings [ - ^ PBSettings - pharoSocketAddress: (PBSocketAddress ipOrName: 'localhost' port: 6538) - pythonSocketAddress: (PBSocketAddress ipOrName: 'localhost' port: 6539) -] - -{ #category : #utils } -PBMessageBrokerTest >> errorResponse [ -] - -{ #category : #hooks } -PBMessageBrokerTest >> for: messageClass setCallback: aBlock [ - ^ broker addCallback: aBlock messageClass: messageClass -] - -{ #category : #initialization } -PBMessageBrokerTest >> initialize [ - super initialize. - handlerBlock := [ :r | ] -] - -{ #category : #hooks } -PBMessageBrokerTest >> messageBrokerClass [ - self subclassResponsibility -] - -{ #category : #accessing } -PBMessageBrokerTest >> pythonUri [ - ^ 'http://' , settings pythonSocketAddress printAddress -] - -{ #category : #utils } -PBMessageBrokerTest >> sendMessageToBroker: dict [ - self subclassResponsibility -] - -{ #category : #utils } -PBMessageBrokerTest >> sendMessageToBroker: dict answerBlock: aBlock [ - self subclassResponsibility -] - -{ #category : #utils } -PBMessageBrokerTest >> sendMessageToBroker: dict answerEquals: ansDict [ - | flag | - flag := false. - self sendMessageToBroker: dict answerBlock: [ :aDict | - flag := true. - self assert: aDict equals: ansDict ]. - self assert: flag -] - -{ #category : #accessing } -PBMessageBrokerTest >> setHandler: aBlock [ - handlerBlock := aBlock -] - -{ #category : #running } -PBMessageBrokerTest >> setUp [ - super setUp. - settings := self defaultSettings. - broker := self messageBrokerClass settings: settings. - broker start. - self buildAndStartStubServer. - self sleepAWhile -] - -{ #category : #utils } -PBMessageBrokerTest >> sleepAWhile [ - "Sleeping for a while so the async message has a chance to perform a change." - self subclassResponsibility -] - -{ #category : #running } -PBMessageBrokerTest >> stopStubServer [ - self subclassResponsibility -] - -{ #category : #running } -PBMessageBrokerTest >> tearDown [ - broker ifNotNil: [ broker stop ]. - self stopStubServer -] - -{ #category : #tests } -PBMessageBrokerTest >> testEnqueueCommandMessage [ - | flag msg | - flag := false. - msg := PBEnqueueCommandMessage - commandId: '7365' - statements: 'foo().cat()' - bindings: { #foo -> 42 . #bar -> 'zork' } asDictionary. - self setHandler: [ :assoc | | bindings | - self assert: assoc key equals: PBEnqueueCommandMessage type. - self assert: assoc value size equals: 4. - self assert: (assoc value at: 'type') equals: PBEnqueueCommandMessage type. - self assert: (assoc value at: 'commandId') equals: '7365'. - self assert: (assoc value at: 'statements') equals: 'foo().cat()'. - bindings := assoc value at: 'bindings'. - self assert: bindings size equals: 2. - self assert: (bindings at: 'foo') equals: 42. - self assert: (bindings at: 'bar') equals: 'zork'. - flag := true ]. - broker sendMessage: msg. - self sleepAWhile. - self assert: flag -] - -{ #category : #tests } -PBMessageBrokerTest >> testErrorOnCallback [ - | flag | - flag := false. - self for: PBRSyncMessage setCallback: [ :msg | - Error signal. - flag := true ]. - self assertCommunicationError: [ - self - sendMessageToBroker: { - #type -> PBRSyncMessage type. - #__sync -> 'foobar' } asDictionary - answerBlock: [ ] ]. - self deny: flag -] - -{ #category : #tests } -PBMessageBrokerTest >> testEvalAnswer [ - | flag | - flag := false. - self for: PBUpdatePromiseMessage setCallback: [ :msg | - self assert: msg type equals: PBUpdatePromiseMessage type. - self assert: msg value equals: 'foobar'. - self assert: msg promiseId equals: '4fcb36d'. - flag := true ]. - self sendMessageToBroker: { - #type -> PBUpdatePromiseMessage type. - #id -> '4fcb36d'. - #value -> 'foobar' } asDictionary. - self assert: flag -] - -{ #category : #tests } -PBMessageBrokerTest >> testIsAliveMessage [ - | flag msg | - flag := false. - self setHandler: [ :assoc | - self assert: assoc key equals: PBIsAliveMessage type. - self assert: assoc value associations size equals: 2. - self assert: (assoc value at: #type) equals: PBIsAliveMessage type. - self assert: (assoc value at: #__sync) equals: msg syncId. - flag := true. - self answer: { #type -> PBIsAliveMessage type. #__sync -> msg syncId } asDictionary ]. - msg := PBIsAliveMessage new. - broker sendMessage: msg. - self assert: flag -] - -{ #category : #tests } -PBMessageBrokerTest >> testIsRunning [ - self assert: broker isRunning -] - -{ #category : #tests } -PBMessageBrokerTest >> testRMessageWithParams [ - | flag | - flag := false. - self for: PBCallbackMessage setCallback: [ :msg | - flag := true. - self assert: msg type equals: PBCallbackMessage type. - self assert: msg commandId equals: 10. - self assert: msg observerId equals: 'foo'. - self assert: msg value equals: 'lalala'. - self assert: msg syncId equals: 'zork'. - msg createAnswer - value: 13; - yourself ]. - self - sendMessageToBroker: { - #type -> PBCallbackMessage type. - #commandId -> 10. - #observerId -> 'foo'. - #value -> 'lalala'. - #__sync -> 'zork' } asDictionary - answerEquals: { - #type -> PBCallbackMessage type. - #value -> 13. - #__sync -> 'zork' } asDictionary. - self assert: flag. -] - -{ #category : #tests } -PBMessageBrokerTest >> testRSyncMessage [ - | flag | - flag := false. - self for: PBRSyncMessage setCallback: [ :msg | - flag := true. - msg createAnswer ]. - self - sendMessageToBroker: { - #type -> PBRSyncMessage type. - #__sync -> 'foobar' } asDictionary - answerEquals: { - #type -> PBRSyncMessage type. - #__sync -> 'foobar' } asDictionary. - self assert: flag. -] - -{ #category : #tests } -PBMessageBrokerTest >> testSyncMessage [ - | flag msg ans | - flag := false. - self setHandler: [ :assoc | - self assert: assoc key equals: PBSyncMessage type. - self assert: assoc value associations size equals: 2. - self assert: (assoc value at: #type) equals: PBSyncMessage type. - self assert: (assoc value at: #__sync) equals: msg syncId. - flag := true. - self answer: { #type -> PBSyncMessage type . #__sync -> msg syncId } asDictionary ]. - msg := PBSyncMessage new. - ans := broker sendMessage: msg. - self assert: ans message equals: msg. - self assert: flag -] - -{ #category : #tests } -PBMessageBrokerTest >> testWrongRouteAnswer [ - | flag | - flag := false. - self for: PBCallbackMessage setCallback: [ :dict | - flag := true ]. - self assertCommunicationError: [ self sendMessageToBroker: { - #type -> PBRSyncMessage type. - #__sync -> 'foobar' } asDictionary ]. - self deny: flag -] +Class { + #name : #PBMessageBrokerTest, + #superclass : #TestCase, + #instVars : [ + 'broker', + 'handlerBlock', + 'handlerException', + 'settings' + ], + #category : #'PythonBridge-Platform' +} + +{ #category : #testing } +PBMessageBrokerTest class >> isAbstract [ + ^ self == PBMessageBrokerTest +] + +{ #category : #accessing } +PBMessageBrokerTest >> answer: aDictionary [ + self subclassResponsibility +] + +{ #category : #utils } +PBMessageBrokerTest >> assertCommunicationError: aBlock [ + self should: aBlock raise: PBCommunicationError +] + +{ #category : #accessing } +PBMessageBrokerTest >> brokerUri [ + ^ 'http://' , settings pharoSocketAddress printAddress +] + +{ #category : #initialization } +PBMessageBrokerTest >> buildAndStartStubServer [ + self subclassResponsibility +] + +{ #category : #running } +PBMessageBrokerTest >> defaultSettings [ + ^ PBSettings + pharoSocketAddress: (PBSocketAddress ipOrName: 'localhost' port: 6538) + pythonSocketAddress: (PBSocketAddress ipOrName: 'localhost' port: 6539) +] + +{ #category : #utils } +PBMessageBrokerTest >> errorResponse [ +] + +{ #category : #hooks } +PBMessageBrokerTest >> for: messageClass setCallback: aBlock [ + ^ broker addCallback: aBlock messageClass: messageClass +] + +{ #category : #initialization } +PBMessageBrokerTest >> initialize [ + super initialize. + handlerBlock := [ :r | ] +] + +{ #category : #hooks } +PBMessageBrokerTest >> messageBrokerClass [ + self subclassResponsibility +] + +{ #category : #accessing } +PBMessageBrokerTest >> pythonUri [ + ^ 'http://' , settings pythonSocketAddress printAddress +] + +{ #category : #utils } +PBMessageBrokerTest >> sendMessageToBroker: dict [ + self subclassResponsibility +] + +{ #category : #utils } +PBMessageBrokerTest >> sendMessageToBroker: dict answerBlock: aBlock [ + self subclassResponsibility +] + +{ #category : #utils } +PBMessageBrokerTest >> sendMessageToBroker: dict answerEquals: ansDict [ + | flag | + flag := false. + self sendMessageToBroker: dict answerBlock: [ :aDict | + flag := true. + self assert: aDict equals: ansDict ]. + self assert: flag +] + +{ #category : #accessing } +PBMessageBrokerTest >> setHandler: aBlock [ + handlerBlock := aBlock +] + +{ #category : #running } +PBMessageBrokerTest >> setUp [ + super setUp. + settings := self defaultSettings. + broker := self messageBrokerClass settings: settings. + broker start. + self buildAndStartStubServer. + self sleepAWhile +] + +{ #category : #utils } +PBMessageBrokerTest >> sleepAWhile [ + "Sleeping for a while so the async message has a chance to perform a change." + self subclassResponsibility +] + +{ #category : #running } +PBMessageBrokerTest >> stopStubServer [ + self subclassResponsibility +] + +{ #category : #running } +PBMessageBrokerTest >> tearDown [ + broker ifNotNil: [ broker stop ]. + self stopStubServer +] + +{ #category : #tests } +PBMessageBrokerTest >> testEnqueueCommandMessage [ + | flag msg | + flag := false. + msg := PBEnqueueCommandMessage + commandId: '7365' + statements: 'foo().cat()' + bindings: { #foo -> 42 . #bar -> 'zork' } asDictionary. + self setHandler: [ :assoc | | bindings | + self assert: assoc key equals: PBEnqueueCommandMessage type. + self assert: assoc value size equals: 4. + self assert: (assoc value at: 'type') equals: PBEnqueueCommandMessage type. + self assert: (assoc value at: 'commandId') equals: '7365'. + self assert: (assoc value at: 'statements') equals: 'foo().cat()'. + bindings := assoc value at: 'bindings'. + self assert: bindings size equals: 2. + self assert: (bindings at: 'foo') equals: 42. + self assert: (bindings at: 'bar') equals: 'zork'. + flag := true ]. + broker sendMessage: msg. + self sleepAWhile. + self assert: flag +] + +{ #category : #tests } +PBMessageBrokerTest >> testErrorOnCallback [ + | flag | + flag := false. + self for: PBRSyncMessage setCallback: [ :msg | + Error signal. + flag := true ]. + self assertCommunicationError: [ + self + sendMessageToBroker: { + #type -> PBRSyncMessage type. + #__sync -> 'foobar' } asDictionary + answerBlock: [ ] ]. + self deny: flag +] + +{ #category : #tests } +PBMessageBrokerTest >> testEvalAnswer [ + | flag | + flag := false. + self for: PBUpdatePromiseMessage setCallback: [ :msg | + self assert: msg type equals: PBUpdatePromiseMessage type. + self assert: msg value equals: 'foobar'. + self assert: msg promiseId equals: '4fcb36d'. + flag := true ]. + self sendMessageToBroker: { + #type -> PBUpdatePromiseMessage type. + #id -> '4fcb36d'. + #value -> 'foobar' } asDictionary. + self assert: flag +] + +{ #category : #tests } +PBMessageBrokerTest >> testIsAliveMessage [ + | flag msg | + flag := false. + self setHandler: [ :assoc | + self assert: assoc key equals: PBIsAliveMessage type. + self assert: assoc value associations size equals: 2. + self assert: (assoc value at: #type) equals: PBIsAliveMessage type. + self assert: (assoc value at: #__sync) equals: msg syncId. + flag := true. + self answer: { #type -> PBIsAliveMessage type. #__sync -> msg syncId } asDictionary ]. + msg := PBIsAliveMessage new. + broker sendMessage: msg. + self assert: flag +] + +{ #category : #tests } +PBMessageBrokerTest >> testIsRunning [ + self assert: broker isRunning +] + +{ #category : #tests } +PBMessageBrokerTest >> testRMessageWithParams [ + | flag | + flag := false. + self for: PBCallbackMessage setCallback: [ :msg | + flag := true. + self assert: msg type equals: PBCallbackMessage type. + self assert: msg commandId equals: 10. + self assert: msg observerId equals: 'foo'. + self assert: msg value equals: 'lalala'. + self assert: msg syncId equals: 'zork'. + msg createAnswer + value: 13; + yourself ]. + self + sendMessageToBroker: { + #type -> PBCallbackMessage type. + #commandId -> 10. + #observerId -> 'foo'. + #value -> 'lalala'. + #__sync -> 'zork' } asDictionary + answerEquals: { + #type -> PBCallbackMessage type. + #value -> 13. + #__sync -> 'zork' } asDictionary. + self assert: flag. +] + +{ #category : #tests } +PBMessageBrokerTest >> testRSyncMessage [ + | flag | + flag := false. + self for: PBRSyncMessage setCallback: [ :msg | + flag := true. + msg createAnswer ]. + self + sendMessageToBroker: { + #type -> PBRSyncMessage type. + #__sync -> 'foobar' } asDictionary + answerEquals: { + #type -> PBRSyncMessage type. + #__sync -> 'foobar' } asDictionary. + self assert: flag. +] + +{ #category : #tests } +PBMessageBrokerTest >> testSyncMessage [ + | flag msg ans | + flag := false. + self setHandler: [ :assoc | + self assert: assoc key equals: PBSyncMessage type. + self assert: assoc value associations size equals: 2. + self assert: (assoc value at: #type) equals: PBSyncMessage type. + self assert: (assoc value at: #__sync) equals: msg syncId. + flag := true. + self answer: { #type -> PBSyncMessage type . #__sync -> msg syncId } asDictionary ]. + msg := PBSyncMessage new. + ans := broker sendMessage: msg. + self assert: ans message equals: msg. + self assert: flag +] + +{ #category : #tests } +PBMessageBrokerTest >> testWrongRouteAnswer [ + | flag | + flag := false. + self for: PBCallbackMessage setCallback: [ :dict | + flag := true ]. + self assertCommunicationError: [ self sendMessageToBroker: { + #type -> PBRSyncMessage type. + #__sync -> 'foobar' } asDictionary ]. + self deny: flag +] diff --git a/src/PythonBridge/PBMessageHandler.class.st b/src/PythonBridge/PBMessageHandler.class.st index aad669b..06c79ed 100644 --- a/src/PythonBridge/PBMessageHandler.class.st +++ b/src/PythonBridge/PBMessageHandler.class.st @@ -1,54 +1,54 @@ -Class { - #name : #PBMessageHandler, - #superclass : #Object, - #instVars : [ - 'message', - 'callback' - ], - #category : #'PythonBridge-Platform' -} - -{ #category : #'as yet unclassified' } -PBMessageHandler class >> forMessage: msg callback: block [ - ^ (self handlerClassForMessage: msg) new - message: msg; - callback: block; - yourself -] - -{ #category : #'as yet unclassified' } -PBMessageHandler class >> handlerClassForMessage: msg [ - ^ msg isSync - ifTrue: [ PBSyncMessageHandler ] - ifFalse: [ PBAsyncMessageHandler ] -] - -{ #category : #accessing } -PBMessageHandler >> callback [ - ^ callback -] - -{ #category : #accessing } -PBMessageHandler >> callback: anObject [ - callback := anObject -] - -{ #category : #accessing } -PBMessageHandler >> handleMessage [ - callback value: message -] - -{ #category : #accessing } -PBMessageHandler >> message [ - ^ message -] - -{ #category : #accessing } -PBMessageHandler >> message: anObject [ - message := anObject -] - -{ #category : #asserting } -PBMessageHandler >> shouldAnswer [ - ^ false -] +Class { + #name : #PBMessageHandler, + #superclass : #Object, + #instVars : [ + 'message', + 'callback' + ], + #category : #'PythonBridge-Platform' +} + +{ #category : #'as yet unclassified' } +PBMessageHandler class >> forMessage: msg callback: block [ + ^ (self handlerClassForMessage: msg) new + message: msg; + callback: block; + yourself +] + +{ #category : #'as yet unclassified' } +PBMessageHandler class >> handlerClassForMessage: msg [ + ^ msg isSync + ifTrue: [ PBSyncMessageHandler ] + ifFalse: [ PBAsyncMessageHandler ] +] + +{ #category : #accessing } +PBMessageHandler >> callback [ + ^ callback +] + +{ #category : #accessing } +PBMessageHandler >> callback: anObject [ + callback := anObject +] + +{ #category : #accessing } +PBMessageHandler >> handleMessage [ + callback value: message +] + +{ #category : #accessing } +PBMessageHandler >> message [ + ^ message +] + +{ #category : #accessing } +PBMessageHandler >> message: anObject [ + message := anObject +] + +{ #category : #asserting } +PBMessageHandler >> shouldAnswer [ + ^ false +] diff --git a/src/PythonBridge/PBMessageHandlerTest.class.st b/src/PythonBridge/PBMessageHandlerTest.class.st index 6d60215..09a1c6b 100644 --- a/src/PythonBridge/PBMessageHandlerTest.class.st +++ b/src/PythonBridge/PBMessageHandlerTest.class.st @@ -1,77 +1,77 @@ -Class { - #name : #PBMessageHandlerTest, - #superclass : #TestCase, - #category : #'PythonBridge-Platform' -} - -{ #category : #tests } -PBMessageHandlerTest >> testAsyncMessage [ - | flag msg handler | - flag := false. - msg := PBAsyncMessage new. - handler := PBMessageHandler - forMessage: msg - callback: [ :aMsg | - self assert: msg equals: aMsg. - flag := true ]. - self deny: flag. - handler handleMessage. - self deny: handler shouldAnswer. - self assert: flag. - self should: [ handler answer ] raise: Error -] - -{ #category : #tests } -PBMessageHandlerTest >> testRAsyncMessage [ - | flag msg handler | - flag := false. - msg := PBRAsyncMessage new. - handler := PBMessageHandler - forMessage: msg - callback: [ :aMsg | - self assert: msg equals: aMsg. - flag := true ]. - self deny: flag. - handler handleMessage. - self deny: handler shouldAnswer. - self assert: flag. - self should: [ handler answer ] raise: Error -] - -{ #category : #tests } -PBMessageHandlerTest >> testRSyncMessage [ - | flag msg handler ans | - flag := false. - ans := nil. - msg := PBRSyncMessage new. - handler := PBMessageHandler - forMessage: msg - callback: [ :aMsg | - self assert: msg equals: aMsg. - flag := true. - ans := msg createAnswer ]. - self deny: flag. - handler handleMessage. - self assert: handler shouldAnswer. - self assert: flag. - self assert: handler answer equals: ans -] - -{ #category : #tests } -PBMessageHandlerTest >> testSyncMessage [ - | flag msg handler ans | - flag := false. - ans := nil. - msg := PBSyncMessage new. - handler := PBMessageHandler - forMessage: msg - callback: [ :aMsg | - self assert: msg equals: aMsg. - flag := true. - ans := msg createAnswer ]. - self deny: flag. - handler handleMessage. - self assert: handler shouldAnswer. - self assert: flag. - self assert: handler answer equals: ans -] +Class { + #name : #PBMessageHandlerTest, + #superclass : #TestCase, + #category : #'PythonBridge-Platform' +} + +{ #category : #tests } +PBMessageHandlerTest >> testAsyncMessage [ + | flag msg handler | + flag := false. + msg := PBAsyncMessage new. + handler := PBMessageHandler + forMessage: msg + callback: [ :aMsg | + self assert: msg equals: aMsg. + flag := true ]. + self deny: flag. + handler handleMessage. + self deny: handler shouldAnswer. + self assert: flag. + self should: [ handler answer ] raise: Error +] + +{ #category : #tests } +PBMessageHandlerTest >> testRAsyncMessage [ + | flag msg handler | + flag := false. + msg := PBRAsyncMessage new. + handler := PBMessageHandler + forMessage: msg + callback: [ :aMsg | + self assert: msg equals: aMsg. + flag := true ]. + self deny: flag. + handler handleMessage. + self deny: handler shouldAnswer. + self assert: flag. + self should: [ handler answer ] raise: Error +] + +{ #category : #tests } +PBMessageHandlerTest >> testRSyncMessage [ + | flag msg handler ans | + flag := false. + ans := nil. + msg := PBRSyncMessage new. + handler := PBMessageHandler + forMessage: msg + callback: [ :aMsg | + self assert: msg equals: aMsg. + flag := true. + ans := msg createAnswer ]. + self deny: flag. + handler handleMessage. + self assert: handler shouldAnswer. + self assert: flag. + self assert: handler answer equals: ans +] + +{ #category : #tests } +PBMessageHandlerTest >> testSyncMessage [ + | flag msg handler ans | + flag := false. + ans := nil. + msg := PBSyncMessage new. + handler := PBMessageHandler + forMessage: msg + callback: [ :aMsg | + self assert: msg equals: aMsg. + flag := true. + ans := msg createAnswer ]. + self deny: flag. + handler handleMessage. + self assert: handler shouldAnswer. + self assert: flag. + self assert: handler answer equals: ans +] diff --git a/src/PythonBridge/PBMessageTest.class.st b/src/PythonBridge/PBMessageTest.class.st index 533672d..b1447e1 100644 --- a/src/PythonBridge/PBMessageTest.class.st +++ b/src/PythonBridge/PBMessageTest.class.st @@ -1,62 +1,62 @@ -Class { - #name : #PBMessageTest, - #superclass : #TestCase, - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #tests } -PBMessageTest >> stubMessage [ - ^ PBStubMessage new - ivar1: #foo; - ivar2: #(3 #bar); - yourself -] - -{ #category : #tests } -PBMessageTest >> testDecodeAnswer [ - | msg dict ans | - msg := self stubMessage. - dict := { - (#type -> #STUB). - (#ivar1 -> #foo). - (#ivar2f -> 3). - (#ivar2r -> #(#zork)). - (#__sync -> msg syncId)} asDictionary. - ans := msg createAnswer decode: dict. - self assert: ans ivar1 equals: #foo. - self assert: ans ivar2 equals: #(3 #zork). -] - -{ #category : #tests } -PBMessageTest >> testDecodeBaseMessage [ - self - assert: (PBSyncMessage new createAnswer decode: { #type -> #MSG } asDictionary) class - equals: PBAnswer -] - -{ #category : #tests } -PBMessageTest >> testEncodeBaseMessage [ - self - assert: PBMessage new encode - equals: { #type -> #MSG } asDictionary -] - -{ #category : #tests } -PBMessageTest >> testEncodeMessage [ - | msg dict | - msg := self stubMessage. - dict := { - (#type -> #STUB). - (#ivar1 -> #foo). - (#ivar2f -> 3). - (#ivar2r -> #(#bar)). - (#__sync -> msg syncId)} asDictionary. - self assert: msg encode equals: dict -] - -{ #category : #tests } -PBMessageTest >> testNoDuplicatedTypes [ - | messageClasses | - messageClasses := PBAbstractMessage allSubclasses. - self assert: (messageClasses collect: #type) asSet size equals: messageClasses size -] +Class { + #name : #PBMessageTest, + #superclass : #TestCase, + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #tests } +PBMessageTest >> stubMessage [ + ^ PBStubMessage new + ivar1: #foo; + ivar2: #(3 #bar); + yourself +] + +{ #category : #tests } +PBMessageTest >> testDecodeAnswer [ + | msg dict ans | + msg := self stubMessage. + dict := { + (#type -> #STUB). + (#ivar1 -> #foo). + (#ivar2f -> 3). + (#ivar2r -> #(#zork)). + (#__sync -> msg syncId)} asDictionary. + ans := msg createAnswer decode: dict. + self assert: ans ivar1 equals: #foo. + self assert: ans ivar2 equals: #(3 #zork). +] + +{ #category : #tests } +PBMessageTest >> testDecodeBaseMessage [ + self + assert: (PBSyncMessage new createAnswer decode: { #type -> #MSG } asDictionary) class + equals: PBAnswer +] + +{ #category : #tests } +PBMessageTest >> testEncodeBaseMessage [ + self + assert: PBMessage new encode + equals: { #type -> #MSG } asDictionary +] + +{ #category : #tests } +PBMessageTest >> testEncodeMessage [ + | msg dict | + msg := self stubMessage. + dict := { + (#type -> #STUB). + (#ivar1 -> #foo). + (#ivar2f -> 3). + (#ivar2r -> #(#bar)). + (#__sync -> msg syncId)} asDictionary. + self assert: msg encode equals: dict +] + +{ #category : #tests } +PBMessageTest >> testNoDuplicatedTypes [ + | messageClasses | + messageClasses := PBAbstractMessage allSubclasses. + self assert: (messageClasses collect: #type) asSet size equals: messageClasses size +] diff --git a/src/PythonBridge/PBObject.class.st b/src/PythonBridge/PBObject.class.st index ee7ab39..fc33543 100644 --- a/src/PythonBridge/PBObject.class.st +++ b/src/PythonBridge/PBObject.class.st @@ -1,158 +1,158 @@ -Class { - #name : #PBObject, - #superclass : #Object, - #traits : 'P3GAttributeAccess + P3GCallable', - #classTraits : 'P3GAttributeAccess classTrait + P3GCallable classTrait', - #instVars : [ - 'pythonVariable' - ], - #category : #'PythonBridge-Core' -} - -{ #category : #'instance creation' } -PBObject class >> fromProxy: aProxy [ - | obj | - obj := self new. - obj pythonVariable: aProxy pythonVariable. - self assert: obj pythonClass asString = aProxy pythonVariable. - ^ obj -] - -{ #category : #'instance creation' } -PBObject class >> fromPythonReference: pythonVar [ - ^ super new - pythonVariable: pythonVar; - yourself. -] - -{ #category : #'instance creation' } -PBObject class >> newPythonVar [ - ^ PBPlatform current newRandomName asP3GIdentifier -] - -{ #category : #initialization } -PBObject >> application [ - ^ self applicationClass uniqueInstance -] - -{ #category : #initialization } -PBObject >> applicationClass [ - self class == PBObject ifTrue: [ ^ PBApplication ]. - self subclassResponsibility -] - -{ #category : #'as yet unclassified' } -PBObject >> basicCreateObject [ - self basicCreateObjectArgs: #() -] - -{ #category : #'as yet unclassified' } -PBObject >> basicCreateObjectArgs: posArgs [ - self basicCreateObjectArgs: posArgs nameArgs: Dictionary new -] - -{ #category : #'as yet unclassified' } -PBObject >> basicCreateObjectArgs: posArgs nameArgs: nameArgs [ - ^ self basicCreateObjectExpr: - (self pythonConstructor - callWith: posArgs - with: nameArgs asDictionary) -] - -{ #category : #'as yet unclassified' } -PBObject >> basicCreateObjectExpr: anExpression [ - | varName | - self isCreated ifTrue: [ ^ self ]. - varName := self newPythonVar. - pythonVariable := varName. - self application commandFactory << ( - self registerIdPyExpression: anExpression). - self registerObject. - self application commandFactory send. -] - -{ #category : #'as yet unclassified' } -PBObject >> createObject [ - self subclassResponsibility -] - -{ #category : #'as yet unclassified' } -PBObject >> ensureCreateObject [ - self isCreated ifFalse: [ self createObject ] -] - -{ #category : #accessing } -PBObject >> id [ - ^ pythonVariable name -] - -{ #category : #'as yet unclassified' } -PBObject >> isCreated [ - ^ pythonVariable notNil -] - -{ #category : #p3generator } -PBObject >> isPythonGenerable [ - ^ true -] - -{ #category : #p3generator } -PBObject >> isPythonValue [ - ^ true -] - -{ #category : #accessing } -PBObject >> module [ - ^ self applicationClass module -] - -{ #category : #'instance creation' } -PBObject >> newPythonVar [ - ^ self class newPythonVar -] - -{ #category : #'as yet unclassified' } -PBObject >> pythonClass [ - self subclassResponsibility -] - -{ #category : #'as yet unclassified' } -PBObject >> pythonClassName [ - ^ self pythonClass attributeIdentifier name -] - -{ #category : #'as yet unclassified' } -PBObject >> pythonConstructor [ - ^ self pythonClass -] - -{ #category : #'as yet unclassified' } -PBObject >> pythonRegistryExpression [ - ^ #registry callWith: #() -] - -{ #category : #accessing } -PBObject >> pythonVariable [ - ^ pythonVariable -] - -{ #category : #'as yet unclassified' } -PBObject >> registerIdPyExpression: objExpr [ - ^ self pythonRegistryExpression => #register_with_id callWith: (Array with: objExpr with: self id) -] - -{ #category : #'as yet unclassified' } -PBObject >> registerObject [ - self application registerObject: self -] - -{ #category : #'as yet unclassified' } -PBObject >> resolveIdPyExpression [ - ^ self pythonRegistryExpression => #resolve callWith: (Array with: self id) -] - -{ #category : #'as yet unclassified' } -PBObject >> writePython3On: aStream [ - self assert: self isCreated. - self resolveIdPyExpression writePython3On: aStream -] +Class { + #name : #PBObject, + #superclass : #Object, + #traits : 'P3GAttributeAccess + P3GCallable', + #classTraits : 'P3GAttributeAccess classTrait + P3GCallable classTrait', + #instVars : [ + 'pythonVariable' + ], + #category : #'PythonBridge-Core' +} + +{ #category : #'instance creation' } +PBObject class >> fromProxy: aProxy [ + | obj | + obj := self new. + obj pythonVariable: aProxy pythonVariable. + self assert: obj pythonClass asString = aProxy pythonVariable. + ^ obj +] + +{ #category : #'instance creation' } +PBObject class >> fromPythonReference: pythonVar [ + ^ super new + pythonVariable: pythonVar; + yourself. +] + +{ #category : #'instance creation' } +PBObject class >> newPythonVar [ + ^ PBPlatform current newRandomName asP3GIdentifier +] + +{ #category : #initialization } +PBObject >> application [ + ^ self applicationClass uniqueInstance +] + +{ #category : #initialization } +PBObject >> applicationClass [ + self class == PBObject ifTrue: [ ^ PBApplication ]. + self subclassResponsibility +] + +{ #category : #'as yet unclassified' } +PBObject >> basicCreateObject [ + self basicCreateObjectArgs: #() +] + +{ #category : #'as yet unclassified' } +PBObject >> basicCreateObjectArgs: posArgs [ + self basicCreateObjectArgs: posArgs nameArgs: Dictionary new +] + +{ #category : #'as yet unclassified' } +PBObject >> basicCreateObjectArgs: posArgs nameArgs: nameArgs [ + ^ self basicCreateObjectExpr: + (self pythonConstructor + callWith: posArgs + with: nameArgs asDictionary) +] + +{ #category : #'as yet unclassified' } +PBObject >> basicCreateObjectExpr: anExpression [ + | varName | + self isCreated ifTrue: [ ^ self ]. + varName := self newPythonVar. + pythonVariable := varName. + self application commandFactory << ( + self registerIdPyExpression: anExpression). + self registerObject. + self application commandFactory send. +] + +{ #category : #'as yet unclassified' } +PBObject >> createObject [ + self subclassResponsibility +] + +{ #category : #'as yet unclassified' } +PBObject >> ensureCreateObject [ + self isCreated ifFalse: [ self createObject ] +] + +{ #category : #accessing } +PBObject >> id [ + ^ pythonVariable name +] + +{ #category : #'as yet unclassified' } +PBObject >> isCreated [ + ^ pythonVariable notNil +] + +{ #category : #p3generator } +PBObject >> isPythonGenerable [ + ^ true +] + +{ #category : #p3generator } +PBObject >> isPythonValue [ + ^ true +] + +{ #category : #accessing } +PBObject >> module [ + ^ self applicationClass module +] + +{ #category : #'instance creation' } +PBObject >> newPythonVar [ + ^ self class newPythonVar +] + +{ #category : #'as yet unclassified' } +PBObject >> pythonClass [ + self subclassResponsibility +] + +{ #category : #'as yet unclassified' } +PBObject >> pythonClassName [ + ^ self pythonClass attributeIdentifier name +] + +{ #category : #'as yet unclassified' } +PBObject >> pythonConstructor [ + ^ self pythonClass +] + +{ #category : #'as yet unclassified' } +PBObject >> pythonRegistryExpression [ + ^ #registry callWith: #() +] + +{ #category : #accessing } +PBObject >> pythonVariable [ + ^ pythonVariable +] + +{ #category : #'as yet unclassified' } +PBObject >> registerIdPyExpression: objExpr [ + ^ self pythonRegistryExpression => #register_with_id callWith: (Array with: objExpr with: self id) +] + +{ #category : #'as yet unclassified' } +PBObject >> registerObject [ + self application registerObject: self +] + +{ #category : #'as yet unclassified' } +PBObject >> resolveIdPyExpression [ + ^ self pythonRegistryExpression => #resolve callWith: (Array with: self id) +] + +{ #category : #'as yet unclassified' } +PBObject >> writePython3On: aStream [ + self assert: self isCreated. + self resolveIdPyExpression writePython3On: aStream +] diff --git a/src/PythonBridge/PBObjectFinalizationTest.class.st b/src/PythonBridge/PBObjectFinalizationTest.class.st index 76fb9a9..eb012ab 100644 --- a/src/PythonBridge/PBObjectFinalizationTest.class.st +++ b/src/PythonBridge/PBObjectFinalizationTest.class.st @@ -1,58 +1,58 @@ -Class { - #name : #PBObjectFinalizationTest, - #superclass : #PBApplicationTest, - #instVars : [ - 'debugMode' - ], - #category : #'PythonBridge-Tests' -} - -{ #category : #asserting } -PBObjectFinalizationTest >> idInRegistry: anId [ - ^ self registryExpression => #hasId callWith: (Array with: anId) -] - -{ #category : #initialization } -PBObjectFinalizationTest >> setUp [ - super setUp. - debugMode := PBApplication debugMode. - PBApplication debugMode: false. -] - -{ #category : #initialization } -PBObjectFinalizationTest >> tearDown [ - PBApplication debugMode: debugMode. - super tearDown -] - -{ #category : #tests } -PBObjectFinalizationTest >> testCreateObjectAndGcItBeforeSending [ - "Bug when the object is garbage collected before sending the command to python, this trigger the gc in Python of an object that hasnt yer been created nor registered. Now we fixed this enforcing the message send in the basicCreateObject, though another way is to registering the object to the command with a hard-reference." - PBObject new basicCreateObjectExpr: 5.5. - Smalltalk garbageCollect. - Smalltalk garbageCollect. - self assert: true -] - -{ #category : #tests } -PBObjectFinalizationTest >> testGCSimpleObj [ - | obj id | - obj := PBObject new basicCreateObjectExpr: 5.5. - id := obj id. - self cf << obj. - self assert: self cfSend waitForValue equals: 5.5. - self assertExpression: (self idInRegistry: id) equals: true. - obj := nil. - Smalltalk garbageCollect. - Smalltalk garbageCollect. - self assertExpression: (self idInRegistry: id) equals: false. -] - -{ #category : #tests } -PBObjectFinalizationTest >> testSimpleCreateObjectFromExpr [ - | obj | - obj := PBObject new basicCreateObjectExpr: 5.5. - self cf << obj. - self assert: self cfSend waitForValue equals: 5.5. - self assertExpression: (self resolveId: obj id) equals: 5.5 -] +Class { + #name : #PBObjectFinalizationTest, + #superclass : #PBApplicationTest, + #instVars : [ + 'debugMode' + ], + #category : #'PythonBridge-Tests' +} + +{ #category : #asserting } +PBObjectFinalizationTest >> idInRegistry: anId [ + ^ self registryExpression => #hasId callWith: (Array with: anId) +] + +{ #category : #initialization } +PBObjectFinalizationTest >> setUp [ + super setUp. + debugMode := PBApplication debugMode. + PBApplication debugMode: false. +] + +{ #category : #initialization } +PBObjectFinalizationTest >> tearDown [ + PBApplication debugMode: debugMode. + super tearDown +] + +{ #category : #tests } +PBObjectFinalizationTest >> testCreateObjectAndGcItBeforeSending [ + "Bug when the object is garbage collected before sending the command to python, this trigger the gc in Python of an object that hasnt yer been created nor registered. Now we fixed this enforcing the message send in the basicCreateObject, though another way is to registering the object to the command with a hard-reference." + PBObject new basicCreateObjectExpr: 5.5. + Smalltalk garbageCollect. + Smalltalk garbageCollect. + self assert: true +] + +{ #category : #tests } +PBObjectFinalizationTest >> testGCSimpleObj [ + | obj id | + obj := PBObject new basicCreateObjectExpr: 5.5. + id := obj id. + self cf << obj. + self assert: self cfSend waitForValue equals: 5.5. + self assertExpression: (self idInRegistry: id) equals: true. + obj := nil. + Smalltalk garbageCollect. + Smalltalk garbageCollect. + self assertExpression: (self idInRegistry: id) equals: false. +] + +{ #category : #tests } +PBObjectFinalizationTest >> testSimpleCreateObjectFromExpr [ + | obj | + obj := PBObject new basicCreateObjectExpr: 5.5. + self cf << obj. + self assert: self cfSend waitForValue equals: 5.5. + self assertExpression: (self resolveId: obj id) equals: 5.5 +] diff --git a/src/PythonBridge/PBObjectFinalizer.class.st b/src/PythonBridge/PBObjectFinalizer.class.st index d6e2a8b..4f04fcd 100644 --- a/src/PythonBridge/PBObjectFinalizer.class.st +++ b/src/PythonBridge/PBObjectFinalizer.class.st @@ -1,10 +1,10 @@ -Class { - #name : #PBObjectFinalizer, - #superclass : #Object, - #category : #'PythonBridge-Platform' -} - -{ #category : #finalization } -PBObjectFinalizer >> finalize [ - self subclassResponsibility -] +Class { + #name : #PBObjectFinalizer, + #superclass : #Object, + #category : #'PythonBridge-Platform' +} + +{ #category : #finalization } +PBObjectFinalizer >> finalize [ + self subclassResponsibility +] diff --git a/src/PythonBridge/PBObjectRegistry.class.st b/src/PythonBridge/PBObjectRegistry.class.st index 01db2d5..027eddf 100644 --- a/src/PythonBridge/PBObjectRegistry.class.st +++ b/src/PythonBridge/PBObjectRegistry.class.st @@ -1,56 +1,56 @@ -Class { - #name : #PBObjectRegistry, - #superclass : #Object, - #instVars : [ - 'objectTable', - 'semaphore', - 'idTable' - ], - #category : #'PythonBridge-Execution' -} - -{ #category : #'as yet unclassified' } -PBObjectRegistry >> hasId: anId [ - ^ semaphore critical: [ idTable includesKey: anId ] -] - -{ #category : #'as yet unclassified' } -PBObjectRegistry >> idTable [ - ^ idTable -] - -{ #category : #'as yet unclassified' } -PBObjectRegistry >> initialize [ - super initialize. - idTable := WeakValueDictionary new. - semaphore := Semaphore forMutualExclusion -] - -{ #category : #'as yet unclassified' } -PBObjectRegistry >> registerObject: anObject [ - semaphore critical: [ - idTable at: anObject id put: anObject ] -] - -{ #category : #'as yet unclassified' } -PBObjectRegistry >> resolve: anId [ - ^ semaphore critical: [ idTable at: anId ] -] - -{ #category : #'as yet unclassified' } -PBObjectRegistry >> resolve: anId ifAbsent: aBlock [ - | obj | - obj := semaphore critical: [ idTable at: anId ifAbsent: [ nil ] ]. - ^ obj ifNil: aBlock. - -] - -{ #category : #'as yet unclassified' } -PBObjectRegistry >> unregisterId: anId [ - semaphore critical: [ idTable removeKey: anId ] -] - -{ #category : #'as yet unclassified' } -PBObjectRegistry >> unregisterObject: anObject [ - semaphore critical: [ idTable removeKey: anObject id ] -] +Class { + #name : #PBObjectRegistry, + #superclass : #Object, + #instVars : [ + 'objectTable', + 'semaphore', + 'idTable' + ], + #category : #'PythonBridge-Execution' +} + +{ #category : #'as yet unclassified' } +PBObjectRegistry >> hasId: anId [ + ^ semaphore critical: [ idTable includesKey: anId ] +] + +{ #category : #'as yet unclassified' } +PBObjectRegistry >> idTable [ + ^ idTable +] + +{ #category : #'as yet unclassified' } +PBObjectRegistry >> initialize [ + super initialize. + idTable := WeakValueDictionary new. + semaphore := Semaphore forMutualExclusion +] + +{ #category : #'as yet unclassified' } +PBObjectRegistry >> registerObject: anObject [ + semaphore critical: [ + idTable at: anObject id put: anObject ] +] + +{ #category : #'as yet unclassified' } +PBObjectRegistry >> resolve: anId [ + ^ semaphore critical: [ idTable at: anId ] +] + +{ #category : #'as yet unclassified' } +PBObjectRegistry >> resolve: anId ifAbsent: aBlock [ + | obj | + obj := semaphore critical: [ idTable at: anId ifAbsent: [ nil ] ]. + ^ obj ifNil: aBlock. + +] + +{ #category : #'as yet unclassified' } +PBObjectRegistry >> unregisterId: anId [ + semaphore critical: [ idTable removeKey: anId ] +] + +{ #category : #'as yet unclassified' } +PBObjectRegistry >> unregisterObject: anObject [ + semaphore critical: [ idTable removeKey: anObject id ] +] diff --git a/src/PythonBridge/PBObserver.class.st b/src/PythonBridge/PBObserver.class.st index 82f5316..278f4b2 100644 --- a/src/PythonBridge/PBObserver.class.st +++ b/src/PythonBridge/PBObserver.class.st @@ -1,82 +1,82 @@ -Class { - #name : #PBObserver, - #superclass : #Object, - #traits : 'P3GCallable', - #classTraits : 'P3GCallable classTrait', - #instVars : [ - 'id', - 'callback', - 'command' - ], - #category : #'PythonBridge-Execution' -} - -{ #category : #accessing } -PBObserver class >> callback: aBlock [ - ^ self new - callback: aBlock; - yourself -] - -{ #category : #accessing } -PBObserver >> callback [ - ^ callback -] - -{ #category : #accessing } -PBObserver >> callback: anObject [ - callback := anObject -] - -{ #category : #accessing } -PBObserver >> command [ - ^ command -] - -{ #category : #accessing } -PBObserver >> command: anObject [ - command := anObject -] - -{ #category : #accessing } -PBObserver >> id [ - ^ id -] - -{ #category : #initialization } -PBObserver >> initialize [ - super initialize. - id := PBUtils newP3VariableName -] - -{ #category : #testing } -PBObserver >> isPythonGenerable [ - ^ true -] - -{ #category : #testing } -PBObserver >> isPythonValue [ - ^ true -] - -{ #category : #'error handling' } -PBObserver >> pharoNotify: anObject [ - ^ callback cull: anObject -] - -{ #category : #'error handling' } -PBObserver >> pythonNotify [ - ^ self pythonNotify: nil -] - -{ #category : #'error handling' } -PBObserver >> pythonNotify: anObject [ - ^ self callWith: (Array with: anObject) -] - -{ #category : #testing } -PBObserver >> writePython3On: aStream [ - (#observer asP3GI callWith: (Array - with: self command id - with: self id)) writePython3On: aStream -] +Class { + #name : #PBObserver, + #superclass : #Object, + #traits : 'P3GCallable', + #classTraits : 'P3GCallable classTrait', + #instVars : [ + 'id', + 'callback', + 'command' + ], + #category : #'PythonBridge-Execution' +} + +{ #category : #accessing } +PBObserver class >> callback: aBlock [ + ^ self new + callback: aBlock; + yourself +] + +{ #category : #accessing } +PBObserver >> callback [ + ^ callback +] + +{ #category : #accessing } +PBObserver >> callback: anObject [ + callback := anObject +] + +{ #category : #accessing } +PBObserver >> command [ + ^ command +] + +{ #category : #accessing } +PBObserver >> command: anObject [ + command := anObject +] + +{ #category : #accessing } +PBObserver >> id [ + ^ id +] + +{ #category : #initialization } +PBObserver >> initialize [ + super initialize. + id := PBUtils newP3VariableName +] + +{ #category : #testing } +PBObserver >> isPythonGenerable [ + ^ true +] + +{ #category : #testing } +PBObserver >> isPythonValue [ + ^ true +] + +{ #category : #'error handling' } +PBObserver >> pharoNotify: anObject [ + ^ callback cull: anObject +] + +{ #category : #'error handling' } +PBObserver >> pythonNotify [ + ^ self pythonNotify: nil +] + +{ #category : #'error handling' } +PBObserver >> pythonNotify: anObject [ + ^ self callWith: (Array with: anObject) +] + +{ #category : #testing } +PBObserver >> writePython3On: aStream [ + (#observer asP3GI callWith: (Array + with: self command id + with: self id)) writePython3On: aStream +] diff --git a/src/PythonBridge/PBPlatform.class.st b/src/PythonBridge/PBPlatform.class.st index c0658e9..83237e5 100644 --- a/src/PythonBridge/PBPlatform.class.st +++ b/src/PythonBridge/PBPlatform.class.st @@ -1,172 +1,172 @@ -Class { - #name : #PBPlatform, - #superclass : #Object, - #instVars : [ - 'msgBrokerStrategy', - 'processStrategy' - ], - #classVars : [ - 'Current' - ], - #category : #'PythonBridge-Platform' -} - -{ #category : #accessing } -PBPlatform class >> current [ - ^ Current ifNil: [ Current := self getConcretePlatform new ] -] - -{ #category : #accessing } -PBPlatform class >> current: aPlatform [ - Current := aPlatform -] - -{ #category : #utils } -PBPlatform class >> getConcretePlatform [ - ^ (self allSubclasses reject: #isAbstract) - inject: nil - into: [ :candidate :next | - candidate - ifNil: [ next ] - ifNotNil: [ - candidate priority > next priority - ifTrue: [ candidate ] - ifFalse: [ next ] ] ] -] - -{ #category : #hooks } -PBPlatform class >> globalPythonProcessClass [ - self subclassResponsibility -] - -{ #category : #hooks } -PBPlatform class >> httpMessageBrokerClass [ - self subclassResponsibility -] - -{ #category : #testing } -PBPlatform class >> isAbstract [ - ^ self name = 'PBPlatform' asSymbol -] - -{ #category : #hooks } -PBPlatform class >> manualProcessClass [ - self subclassResponsibility -] - -{ #category : #hooks } -PBPlatform class >> pipenvProcessClass [ - self subclassResponsibility -] - -{ #category : #accessing } -PBPlatform class >> platform [ - ^ self current -] - -{ #category : #private } -PBPlatform class >> priority [ - ^ -547835385 -] - -{ #category : #hooks } -PBPlatform class >> socketMessageBrokerClass [ - self subclassResponsibility -] - -{ #category : #hooks } -PBPlatform class >> uiManagerClass [ - self subclassResponsibility -] - -{ #category : #hooks } -PBPlatform class >> weakRegistryClass [ - self subclassResponsibility -] - -{ #category : #'message broker strategy' } -PBPlatform >> defaultMessageBrokerClass [ - ^ self class httpMessageBrokerClass -] - -{ #category : #utils } -PBPlatform >> defaultSettings [ - ^ PBSettings - pharoSocketAddress: (PBSocketAddress ipOrName: 'localhost' port: (7000 + 99 atRandom)) - pythonSocketAddress: (PBSocketAddress ipOrName: 'localhost' port: (6900 + 99 atRandom)) -] - -{ #category : #hooks } -PBPlatform >> ensureEnvironmentForApp: anApplication [ - self subclassResponsibility -] - -{ #category : #hooks } -PBPlatform >> folderForApplication: application [ - self subclassResponsibility -] - -{ #category : #'module creation' } -PBPlatform >> messageBroker: settings [ - ^ self messageBrokerStrategy settings: settings -] - -{ #category : #'message broker strategy' } -PBPlatform >> messageBrokerStrategy [ - ^ msgBrokerStrategy ifNil: [ ^ self defaultMessageBrokerClass ] -] - -{ #category : #'message broker strategy' } -PBPlatform >> messageBrokerStrategy: msgBrokerCls [ - msgBrokerStrategy := msgBrokerCls -] - -{ #category : #utils } -PBPlatform >> newRandomName [ - self subclassResponsibility -] - -{ #category : #'module creation' } -PBPlatform >> process: application [ - ^ self processStrategy application: application -] - -{ #category : #'process strategy' } -PBPlatform >> processStrategy [ - ^ processStrategy ifNil: [ ^ self class pipenvProcessClass ] -] - -{ #category : #'process strategy' } -PBPlatform >> processStrategy: processCls [ - processStrategy := processCls -] - -{ #category : #'accessing modules' } -PBPlatform >> serializer [ - ^ self messageBrokerStrategy serializer -] - -{ #category : #'message broker strategy' } -PBPlatform >> setHttpMessageBroker [ - self messageBrokerStrategy: self class httpMessageBrokerClass -] - -{ #category : #'process strategy' } -PBPlatform >> setPipenvProcess [ - self processStrategy: self class pipenvProcessClass -] - -{ #category : #'message broker strategy' } -PBPlatform >> setSocketMessageBroker [ - self messageBrokerStrategy: self class socketMessageBrokerClass -] - -{ #category : #'module creation' } -PBPlatform >> uiManager [ - ^ self class uiManagerClass new -] - -{ #category : #'module creation' } -PBPlatform >> weakRegistry [ - ^ self class weakRegistryClass new -] +Class { + #name : #PBPlatform, + #superclass : #Object, + #instVars : [ + 'msgBrokerStrategy', + 'processStrategy' + ], + #classVars : [ + 'Current' + ], + #category : #'PythonBridge-Platform' +} + +{ #category : #accessing } +PBPlatform class >> current [ + ^ Current ifNil: [ Current := self getConcretePlatform new ] +] + +{ #category : #accessing } +PBPlatform class >> current: aPlatform [ + Current := aPlatform +] + +{ #category : #utils } +PBPlatform class >> getConcretePlatform [ + ^ (self allSubclasses reject: #isAbstract) + inject: nil + into: [ :candidate :next | + candidate + ifNil: [ next ] + ifNotNil: [ + candidate priority > next priority + ifTrue: [ candidate ] + ifFalse: [ next ] ] ] +] + +{ #category : #hooks } +PBPlatform class >> globalPythonProcessClass [ + self subclassResponsibility +] + +{ #category : #hooks } +PBPlatform class >> httpMessageBrokerClass [ + self subclassResponsibility +] + +{ #category : #testing } +PBPlatform class >> isAbstract [ + ^ self name = 'PBPlatform' asSymbol +] + +{ #category : #hooks } +PBPlatform class >> manualProcessClass [ + self subclassResponsibility +] + +{ #category : #hooks } +PBPlatform class >> pipenvProcessClass [ + self subclassResponsibility +] + +{ #category : #accessing } +PBPlatform class >> platform [ + ^ self current +] + +{ #category : #private } +PBPlatform class >> priority [ + ^ -547835385 +] + +{ #category : #hooks } +PBPlatform class >> socketMessageBrokerClass [ + self subclassResponsibility +] + +{ #category : #hooks } +PBPlatform class >> uiManagerClass [ + self subclassResponsibility +] + +{ #category : #hooks } +PBPlatform class >> weakRegistryClass [ + self subclassResponsibility +] + +{ #category : #'message broker strategy' } +PBPlatform >> defaultMessageBrokerClass [ + ^ self class httpMessageBrokerClass +] + +{ #category : #utils } +PBPlatform >> defaultSettings [ + ^ PBSettings + pharoSocketAddress: (PBSocketAddress ipOrName: 'localhost' port: (7000 + 99 atRandom)) + pythonSocketAddress: (PBSocketAddress ipOrName: 'localhost' port: (6900 + 99 atRandom)) +] + +{ #category : #hooks } +PBPlatform >> ensureEnvironmentForApp: anApplication [ + self subclassResponsibility +] + +{ #category : #hooks } +PBPlatform >> folderForApplication: application [ + self subclassResponsibility +] + +{ #category : #'module creation' } +PBPlatform >> messageBroker: settings [ + ^ self messageBrokerStrategy settings: settings +] + +{ #category : #'message broker strategy' } +PBPlatform >> messageBrokerStrategy [ + ^ msgBrokerStrategy ifNil: [ ^ self defaultMessageBrokerClass ] +] + +{ #category : #'message broker strategy' } +PBPlatform >> messageBrokerStrategy: msgBrokerCls [ + msgBrokerStrategy := msgBrokerCls +] + +{ #category : #utils } +PBPlatform >> newRandomName [ + self subclassResponsibility +] + +{ #category : #'module creation' } +PBPlatform >> process: application [ + ^ self processStrategy application: application +] + +{ #category : #'process strategy' } +PBPlatform >> processStrategy [ + ^ processStrategy ifNil: [ ^ self class pipenvProcessClass ] +] + +{ #category : #'process strategy' } +PBPlatform >> processStrategy: processCls [ + processStrategy := processCls +] + +{ #category : #'accessing modules' } +PBPlatform >> serializer [ + ^ self messageBrokerStrategy serializer +] + +{ #category : #'message broker strategy' } +PBPlatform >> setHttpMessageBroker [ + self messageBrokerStrategy: self class httpMessageBrokerClass +] + +{ #category : #'process strategy' } +PBPlatform >> setPipenvProcess [ + self processStrategy: self class pipenvProcessClass +] + +{ #category : #'message broker strategy' } +PBPlatform >> setSocketMessageBroker [ + self messageBrokerStrategy: self class socketMessageBrokerClass +] + +{ #category : #'module creation' } +PBPlatform >> uiManager [ + ^ self class uiManagerClass new +] + +{ #category : #'module creation' } +PBPlatform >> weakRegistry [ + ^ self class weakRegistryClass new +] diff --git a/src/PythonBridge/PBProcessTest.class.st b/src/PythonBridge/PBProcessTest.class.st index 25727f2..29af69f 100644 --- a/src/PythonBridge/PBProcessTest.class.st +++ b/src/PythonBridge/PBProcessTest.class.st @@ -1,56 +1,56 @@ -Class { - #name : #PBProcessTest, - #superclass : #TestCase, - #instVars : [ - 'process', - 'tmpPythonFile' - ], - #category : #'PythonBridge-Platform' -} - -{ #category : #testing } -PBProcessTest class >> isAbstract [ - ^ self == PBProcessTest -] - -{ #category : #running } -PBProcessTest >> defaultSettings [ - ^ PBSettings - pharoSocketAddress: (PBSocketAddress ipOrName: 'localhost' port: 6538) - pythonSocketAddress: (PBSocketAddress ipOrName: 'localhost' port: 6539) -] - -{ #category : #running } -PBProcessTest >> defaultTmpFile [ - self subclassResponsibility -] - -{ #category : #hooks } -PBProcessTest >> processClass [ - self subclassResponsibility -] - -{ #category : #running } -PBProcessTest >> setUp [ - super setUp. - process := self processClass - settings: self defaultSettings - workingDirectory: self processClass workingDirectory. - process pythonMainFile: self defaultTmpFile -] - -{ #category : #running } -PBProcessTest >> tearDown [ - process stop. - super tearDown -] - -{ #category : #running } -PBProcessTest >> testStartStopProcess [ - self deny: process isRunning. - process start. - self assert: process isRunning. - process stop. - (Delay forMilliseconds: 150) wait. - self deny: process isRunning -] +Class { + #name : #PBProcessTest, + #superclass : #TestCase, + #instVars : [ + 'process', + 'tmpPythonFile' + ], + #category : #'PythonBridge-Platform' +} + +{ #category : #testing } +PBProcessTest class >> isAbstract [ + ^ self == PBProcessTest +] + +{ #category : #running } +PBProcessTest >> defaultSettings [ + ^ PBSettings + pharoSocketAddress: (PBSocketAddress ipOrName: 'localhost' port: 6538) + pythonSocketAddress: (PBSocketAddress ipOrName: 'localhost' port: 6539) +] + +{ #category : #running } +PBProcessTest >> defaultTmpFile [ + self subclassResponsibility +] + +{ #category : #hooks } +PBProcessTest >> processClass [ + self subclassResponsibility +] + +{ #category : #running } +PBProcessTest >> setUp [ + super setUp. + process := self processClass + settings: self defaultSettings + workingDirectory: self processClass workingDirectory. + process pythonMainFile: self defaultTmpFile +] + +{ #category : #running } +PBProcessTest >> tearDown [ + process stop. + super tearDown +] + +{ #category : #running } +PBProcessTest >> testStartStopProcess [ + self deny: process isRunning. + process start. + self assert: process isRunning. + process stop. + (Delay forMilliseconds: 150) wait. + self deny: process isRunning +] diff --git a/src/PythonBridge/PBPromise.class.st b/src/PythonBridge/PBPromise.class.st index d00eab8..3d867be 100644 --- a/src/PythonBridge/PBPromise.class.st +++ b/src/PythonBridge/PBPromise.class.st @@ -1,74 +1,74 @@ -Class { - #name : #PBPromise, - #superclass : #Object, - #instVars : [ - 'id', - 'semaphore', - 'transformBlock', - 'value' - ], - #category : #'PythonBridge-Execution' -} - -{ #category : #accessing } -PBPromise class >> id: id [ - ^ self new - id: id; - yourself -] - -{ #category : #accessing } -PBPromise >> id [ - ^ id -] - -{ #category : #accessing } -PBPromise >> id: anObject [ - id := anObject -] - -{ #category : #initialization } -PBPromise >> initialize [ - super initialize. - semaphore := Semaphore new. - value := nil. - transformBlock := #yourself -] - -{ #category : #signalling } -PBPromise >> isSignaled [ - ^ semaphore isSignaled -] - -{ #category : #signalling } -PBPromise >> signalAll [ - 1 to: semaphore size + 20 do: [ :s | semaphore signal ] -] - -{ #category : #signalling } -PBPromise >> signalWithValue: anObject [ - value := transformBlock value: anObject. - self signalAll. -] - -{ #category : #accessing } -PBPromise >> transformBlock [ - ^ transformBlock -] - -{ #category : #accessing } -PBPromise >> transformBlock: anObject [ - transformBlock := anObject -] - -{ #category : #signalling } -PBPromise >> value [ - ^ value -] - -{ #category : #signalling } -PBPromise >> waitForValue [ - self isSignaled ifTrue: [ ^ self value ]. - semaphore wait. - ^ self value -] +Class { + #name : #PBPromise, + #superclass : #Object, + #instVars : [ + 'id', + 'semaphore', + 'transformBlock', + 'value' + ], + #category : #'PythonBridge-Execution' +} + +{ #category : #accessing } +PBPromise class >> id: id [ + ^ self new + id: id; + yourself +] + +{ #category : #accessing } +PBPromise >> id [ + ^ id +] + +{ #category : #accessing } +PBPromise >> id: anObject [ + id := anObject +] + +{ #category : #initialization } +PBPromise >> initialize [ + super initialize. + semaphore := Semaphore new. + value := nil. + transformBlock := #yourself +] + +{ #category : #signalling } +PBPromise >> isSignaled [ + ^ semaphore isSignaled +] + +{ #category : #signalling } +PBPromise >> signalAll [ + 1 to: semaphore size + 20 do: [ :s | semaphore signal ] +] + +{ #category : #signalling } +PBPromise >> signalWithValue: anObject [ + value := transformBlock value: anObject. + self signalAll. +] + +{ #category : #accessing } +PBPromise >> transformBlock [ + ^ transformBlock +] + +{ #category : #accessing } +PBPromise >> transformBlock: anObject [ + transformBlock := anObject +] + +{ #category : #signalling } +PBPromise >> value [ + ^ value +] + +{ #category : #signalling } +PBPromise >> waitForValue [ + self isSignaled ifTrue: [ ^ self value ]. + semaphore wait. + ^ self value +] diff --git a/src/PythonBridge/PBPromiseRegistry.class.st b/src/PythonBridge/PBPromiseRegistry.class.st index 5d295f1..52d6161 100644 --- a/src/PythonBridge/PBPromiseRegistry.class.st +++ b/src/PythonBridge/PBPromiseRegistry.class.st @@ -1,45 +1,45 @@ -Class { - #name : #PBPromiseRegistry, - #superclass : #Object, - #instVars : [ - 'promiseTable', - 'semaphore' - ], - #category : #'PythonBridge-Execution' -} - -{ #category : #adding } -PBPromiseRegistry >> addPromise: aPromise [ - semaphore critical: [ promiseTable at: aPromise id put: aPromise ] -] - -{ #category : #initialization } -PBPromiseRegistry >> initialize [ - super initialize. - promiseTable := Dictionary new. - semaphore := Semaphore forMutualExclusion -] - -{ #category : #'private - testing' } -PBPromiseRegistry >> promiseTable [ - ^ promiseTable -] - -{ #category : #adding } -PBPromiseRegistry >> removeAndSignalPromiseId: id with: anObject [ - self signalPromiseId: id with: anObject. - self removePromiseId: id -] - -{ #category : #adding } -PBPromiseRegistry >> removePromiseId: id [ - semaphore critical: [ promiseTable removeKey: id ] -] - -{ #category : #adding } -PBPromiseRegistry >> signalPromiseId: id with: anObject [ - | promise | - semaphore critical: [ - promise := promiseTable at: id. - promise signalWithValue: anObject ] -] +Class { + #name : #PBPromiseRegistry, + #superclass : #Object, + #instVars : [ + 'promiseTable', + 'semaphore' + ], + #category : #'PythonBridge-Execution' +} + +{ #category : #adding } +PBPromiseRegistry >> addPromise: aPromise [ + semaphore critical: [ promiseTable at: aPromise id put: aPromise ] +] + +{ #category : #initialization } +PBPromiseRegistry >> initialize [ + super initialize. + promiseTable := Dictionary new. + semaphore := Semaphore forMutualExclusion +] + +{ #category : #'private - testing' } +PBPromiseRegistry >> promiseTable [ + ^ promiseTable +] + +{ #category : #adding } +PBPromiseRegistry >> removeAndSignalPromiseId: id with: anObject [ + self signalPromiseId: id with: anObject. + self removePromiseId: id +] + +{ #category : #adding } +PBPromiseRegistry >> removePromiseId: id [ + semaphore critical: [ promiseTable removeKey: id ] +] + +{ #category : #adding } +PBPromiseRegistry >> signalPromiseId: id with: anObject [ + | promise | + semaphore critical: [ + promise := promiseTable at: id. + promise signalWithValue: anObject ] +] diff --git a/src/PythonBridge/PBPromiseRegistryTest.class.st b/src/PythonBridge/PBPromiseRegistryTest.class.st index d3af20a..9d723e1 100644 --- a/src/PythonBridge/PBPromiseRegistryTest.class.st +++ b/src/PythonBridge/PBPromiseRegistryTest.class.st @@ -1,60 +1,60 @@ -Class { - #name : #PBPromiseRegistryTest, - #superclass : #TestCase, - #instVars : [ - 'registry' - ], - #category : #'PythonBridge-Tests' -} - -{ #category : #initialization } -PBPromiseRegistryTest >> setUp [ - registry := PBPromiseRegistry new -] - -{ #category : #initialization } -PBPromiseRegistryTest >> testAddPromise [ - registry addPromise: (PBPromise id: '123'). - self assert: registry promiseTable size equals: 1. - self assert: registry promiseTable anyOne id equals: '123' -] - -{ #category : #initialization } -PBPromiseRegistryTest >> testRemovePromiseId [ - registry addPromise: (PBPromise id: '123'). - registry removePromiseId: '123'. - self assert: registry promiseTable size equals: 0 -] - -{ #category : #initialization } -PBPromiseRegistryTest >> testSignalPromise [ - | semaphore flag promise | - semaphore := Semaphore new. - flag := false. - promise := (PBPromise id: '123'). - registry addPromise: promise. - [ - self assert: promise waitForValue equals: #foo. - flag := true. - semaphore signal. ] fork. - registry signalPromiseId: '123' with: #foo. - semaphore wait. - self assert: flag -] - -{ #category : #initialization } -PBPromiseRegistryTest >> testSignalPromiseWithTransformBlock [ - | semaphore flag promise | - semaphore := Semaphore new. - flag := false. - promise := (PBPromise id: '123') - transformBlock: [ :obj | 55 ]. - registry addPromise: promise. - [ - self assert: promise waitForValue equals: 55. - flag := true. - semaphore signal. ] fork. - registry signalPromiseId: '123' with: #foo. - semaphore wait. - self assert: flag -] +Class { + #name : #PBPromiseRegistryTest, + #superclass : #TestCase, + #instVars : [ + 'registry' + ], + #category : #'PythonBridge-Tests' +} + +{ #category : #initialization } +PBPromiseRegistryTest >> setUp [ + registry := PBPromiseRegistry new +] + +{ #category : #initialization } +PBPromiseRegistryTest >> testAddPromise [ + registry addPromise: (PBPromise id: '123'). + self assert: registry promiseTable size equals: 1. + self assert: registry promiseTable anyOne id equals: '123' +] + +{ #category : #initialization } +PBPromiseRegistryTest >> testRemovePromiseId [ + registry addPromise: (PBPromise id: '123'). + registry removePromiseId: '123'. + self assert: registry promiseTable size equals: 0 +] + +{ #category : #initialization } +PBPromiseRegistryTest >> testSignalPromise [ + | semaphore flag promise | + semaphore := Semaphore new. + flag := false. + promise := (PBPromise id: '123'). + registry addPromise: promise. + [ + self assert: promise waitForValue equals: #foo. + flag := true. + semaphore signal. ] fork. + registry signalPromiseId: '123' with: #foo. + semaphore wait. + self assert: flag +] + +{ #category : #initialization } +PBPromiseRegistryTest >> testSignalPromiseWithTransformBlock [ + | semaphore flag promise | + semaphore := Semaphore new. + flag := false. + promise := (PBPromise id: '123') + transformBlock: [ :obj | 55 ]. + registry addPromise: promise. + [ + self assert: promise waitForValue equals: 55. + flag := true. + semaphore signal. ] fork. + registry signalPromiseId: '123' with: #foo. + semaphore wait. + self assert: flag +] diff --git a/src/PythonBridge/PBProxyObject.class.st b/src/PythonBridge/PBProxyObject.class.st index 76e9468..b7ac03e 100644 --- a/src/PythonBridge/PBProxyObject.class.st +++ b/src/PythonBridge/PBProxyObject.class.st @@ -1,61 +1,61 @@ -Class { - #name : #PBProxyObject, - #superclass : #PBObject, - #instVars : [ - 'pythonClass', - 'application' - ], - #category : #'PythonBridge-Core' -} - -{ #category : #'as yet unclassified' } -PBProxyObject class >> pythonClass: pythonClass pythonVar: pyVar application: application [ - ^ self new - pythonVariable: pyVar; - pythonClass: pythonClass; - application: application; - yourself -] - -{ #category : #accessing } -PBProxyObject >> application [ - ^ application -] - -{ #category : #accessing } -PBProxyObject >> application: anObject [ - application := anObject -] - -{ #category : #accessing } -PBProxyObject >> applicationClass [ - ^ self application class -] - -{ #category : #hooks } -PBProxyObject >> createObject [ - self shouldNotImplement -] - -{ #category : #printing } -PBProxyObject >> printOn: str [ - str - << (pythonClass asString first isVowel ifTrue: ['an '] ifFalse: ['a ']); - << pythonClass asString; - << ' (Proxy)' -] - -{ #category : #accessing } -PBProxyObject >> pythonClass [ - ^ pythonClass -] - -{ #category : #accessing } -PBProxyObject >> pythonClass: anObject [ - pythonClass := anObject -] - -{ #category : #accessing } -PBProxyObject >> pythonVariable: pyVar [ - pythonVariable := pyVar -] +Class { + #name : #PBProxyObject, + #superclass : #PBObject, + #instVars : [ + 'pythonClass', + 'application' + ], + #category : #'PythonBridge-Core' +} + +{ #category : #'as yet unclassified' } +PBProxyObject class >> pythonClass: pythonClass pythonVar: pyVar application: application [ + ^ self new + pythonVariable: pyVar; + pythonClass: pythonClass; + application: application; + yourself +] + +{ #category : #accessing } +PBProxyObject >> application [ + ^ application +] + +{ #category : #accessing } +PBProxyObject >> application: anObject [ + application := anObject +] + +{ #category : #accessing } +PBProxyObject >> applicationClass [ + ^ self application class +] + +{ #category : #hooks } +PBProxyObject >> createObject [ + self shouldNotImplement +] + +{ #category : #printing } +PBProxyObject >> printOn: str [ + str + << (pythonClass asString first isVowel ifTrue: ['an '] ifFalse: ['a ']); + << pythonClass asString; + << ' (Proxy)' +] + +{ #category : #accessing } +PBProxyObject >> pythonClass [ + ^ pythonClass +] + +{ #category : #accessing } +PBProxyObject >> pythonClass: anObject [ + pythonClass := anObject +] + +{ #category : #accessing } +PBProxyObject >> pythonVariable: pyVar [ + pythonVariable := pyVar +] diff --git a/src/PythonBridge/PBPython3GenerationTest.class.st b/src/PythonBridge/PBPython3GenerationTest.class.st index 655ee8e..e328abd 100644 --- a/src/PythonBridge/PBPython3GenerationTest.class.st +++ b/src/PythonBridge/PBPython3GenerationTest.class.st @@ -1,37 +1,37 @@ -Class { - #name : #PBPython3GenerationTest, - #superclass : #TestCase, - #category : #'PythonBridge-Tests' -} - -{ #category : #'as yet unclassified' } -PBPython3GenerationTest >> getPythonCode: aPythonExpression [ - ^ self getPythonCodeUsingStream: [ :str | aPythonExpression writePython3On: str ] -] - -{ #category : #'as yet unclassified' } -PBPython3GenerationTest >> getPythonCodeUsingStream: aBlock [ - | stream | - stream := String new writeStream. - aBlock value: stream. - ^ stream contents -] - -{ #category : #tests } -PBPython3GenerationTest >> testBinding [ - | binding | - binding := PBBinding wrap: 32. - self - assert: (self getPythonCode: binding) - equals: binding key -] - -{ #category : #tests } -PBPython3GenerationTest >> testObserverNotify [ - | obs | - obs := PBObserver callback: [ 32 ]. - obs command: PBCommand new. - self - assert: (self getPythonCode: (obs pythonNotify: 'foobar')) - equals: 'observer(''' , obs command id , ''',''' , obs id , ''')(''foobar'')' -] +Class { + #name : #PBPython3GenerationTest, + #superclass : #TestCase, + #category : #'PythonBridge-Tests' +} + +{ #category : #'as yet unclassified' } +PBPython3GenerationTest >> getPythonCode: aPythonExpression [ + ^ self getPythonCodeUsingStream: [ :str | aPythonExpression writePython3On: str ] +] + +{ #category : #'as yet unclassified' } +PBPython3GenerationTest >> getPythonCodeUsingStream: aBlock [ + | stream | + stream := String new writeStream. + aBlock value: stream. + ^ stream contents +] + +{ #category : #tests } +PBPython3GenerationTest >> testBinding [ + | binding | + binding := PBBinding wrap: 32. + self + assert: (self getPythonCode: binding) + equals: binding key +] + +{ #category : #tests } +PBPython3GenerationTest >> testObserverNotify [ + | obs | + obs := PBObserver callback: [ 32 ]. + obs command: PBCommand new. + self + assert: (self getPythonCode: (obs pythonNotify: 'foobar')) + equals: 'observer(''' , obs command id , ''',''' , obs id , ''')(''foobar'')' +] diff --git a/src/PythonBridge/PBPythonError.class.st b/src/PythonBridge/PBPythonError.class.st index 3eb0fe8..b8eb2a0 100644 --- a/src/PythonBridge/PBPythonError.class.st +++ b/src/PythonBridge/PBPythonError.class.st @@ -1,90 +1,90 @@ -Class { - #name : #PBPythonError, - #superclass : #Notification, - #instVars : [ - 'command', - 'errorMessage', - 'application', - 'proceedAction', - 'trace' - ], - #category : #'PythonBridge-ErrorHandling' -} - -{ #category : #accessing } -PBPythonError >> application [ - ^ application -] - -{ #category : #accessing } -PBPythonError >> application: anObject [ - application := anObject -] - -{ #category : #accessing } -PBPythonError >> command [ - ^ command -] - -{ #category : #accessing } -PBPythonError >> command: anObject [ - command := anObject -] - -{ #category : #accessing } -PBPythonError >> defaultAction [ - "No one has handled this error, but now give them a chance to decide how to debug it. If none handle this either then open debugger (see UnhandedError-defaultAction)" - - ^ PBPlatform current uiManager spawnDebuggerOnException: self -] - -{ #category : #'as yet unclassified' } -PBPythonError >> defaultProceedAction [ - ^ PBDropQueue new -] - -{ #category : #accessing } -PBPythonError >> errorMessage [ - ^ errorMessage -] - -{ #category : #accessing } -PBPythonError >> errorMessage: anObject [ - errorMessage := anObject -] - -{ #category : #initialization } -PBPythonError >> initialize [ - super initialize. - proceedAction := self defaultProceedAction -] - -{ #category : #accessing } -PBPythonError >> isResumable [ - ^ true -] - -{ #category : #accessing } -PBPythonError >> messageText [ - ^ errorMessage -] - -{ #category : #accessing } -PBPythonError >> proceedAction [ - ^ proceedAction -] - -{ #category : #accessing } -PBPythonError >> proceedAction: anObject [ - proceedAction := anObject -] - -{ #category : #tracing } -PBPythonError >> trace [ - ^ trace -] - -{ #category : #tracing } -PBPythonError >> trace: aTrace [ - trace := aTrace -] +Class { + #name : #PBPythonError, + #superclass : #Notification, + #instVars : [ + 'command', + 'errorMessage', + 'application', + 'proceedAction', + 'trace' + ], + #category : #'PythonBridge-ErrorHandling' +} + +{ #category : #accessing } +PBPythonError >> application [ + ^ application +] + +{ #category : #accessing } +PBPythonError >> application: anObject [ + application := anObject +] + +{ #category : #accessing } +PBPythonError >> command [ + ^ command +] + +{ #category : #accessing } +PBPythonError >> command: anObject [ + command := anObject +] + +{ #category : #accessing } +PBPythonError >> defaultAction [ + "No one has handled this error, but now give them a chance to decide how to debug it. If none handle this either then open debugger (see UnhandedError-defaultAction)" + + ^ PBPlatform current uiManager spawnDebuggerOnException: self +] + +{ #category : #'as yet unclassified' } +PBPythonError >> defaultProceedAction [ + ^ PBDropQueue new +] + +{ #category : #accessing } +PBPythonError >> errorMessage [ + ^ errorMessage +] + +{ #category : #accessing } +PBPythonError >> errorMessage: anObject [ + errorMessage := anObject +] + +{ #category : #initialization } +PBPythonError >> initialize [ + super initialize. + proceedAction := self defaultProceedAction +] + +{ #category : #accessing } +PBPythonError >> isResumable [ + ^ true +] + +{ #category : #accessing } +PBPythonError >> messageText [ + ^ errorMessage +] + +{ #category : #accessing } +PBPythonError >> proceedAction [ + ^ proceedAction +] + +{ #category : #accessing } +PBPythonError >> proceedAction: anObject [ + proceedAction := anObject +] + +{ #category : #tracing } +PBPythonError >> trace [ + ^ trace +] + +{ #category : #tracing } +PBPythonError >> trace: aTrace [ + trace := aTrace +] diff --git a/src/PythonBridge/PBPythonErrorHandlingTest.class.st b/src/PythonBridge/PBPythonErrorHandlingTest.class.st index 13aa0c6..acfc570 100644 --- a/src/PythonBridge/PBPythonErrorHandlingTest.class.st +++ b/src/PythonBridge/PBPythonErrorHandlingTest.class.st @@ -1,5 +1,5 @@ -Class { - #name : #PBPythonErrorHandlingTest, - #superclass : #PBApplicationTest, - #category : #'PythonBridge-Tests' -} +Class { + #name : #PBPythonErrorHandlingTest, + #superclass : #PBApplicationTest, + #category : #'PythonBridge-Tests' +} diff --git a/src/PythonBridge/PBPythonHandler.class.st b/src/PythonBridge/PBPythonHandler.class.st index a955663..04d70d4 100644 --- a/src/PythonBridge/PBPythonHandler.class.st +++ b/src/PythonBridge/PBPythonHandler.class.st @@ -1,40 +1,40 @@ -Class { - #name : #PBPythonHandler, - #superclass : #PBHandler, - #instVars : [ - 'process' - ], - #category : #'PythonBridge-Core' -} - -{ #category : #accessing } -PBPythonHandler >> errorMessage [ - ^ process errorMessage -] - -{ #category : #initialization } -PBPythonHandler >> initializeHandler [ - super initializeHandler. - process := PBPlatform current process: self application -] - -{ #category : #testing } -PBPythonHandler >> isRunning [ - ^ process isRunning -] - -{ #category : #accessing } -PBPythonHandler >> platform [ - ^ PBPlatform current -] - -{ #category : #testing } -PBPythonHandler >> start [ - self platform ensureEnvironmentForApp: self application. - ^ process start -] - -{ #category : #testing } -PBPythonHandler >> stop [ - ^ process stop -] +Class { + #name : #PBPythonHandler, + #superclass : #PBHandler, + #instVars : [ + 'process' + ], + #category : #'PythonBridge-Core' +} + +{ #category : #accessing } +PBPythonHandler >> errorMessage [ + ^ process errorMessage +] + +{ #category : #initialization } +PBPythonHandler >> initializeHandler [ + super initializeHandler. + process := PBPlatform current process: self application +] + +{ #category : #testing } +PBPythonHandler >> isRunning [ + ^ process isRunning +] + +{ #category : #accessing } +PBPythonHandler >> platform [ + ^ PBPlatform current +] + +{ #category : #testing } +PBPythonHandler >> start [ + self platform ensureEnvironmentForApp: self application. + ^ process start +] + +{ #category : #testing } +PBPythonHandler >> stop [ + ^ process stop +] diff --git a/src/PythonBridge/PBPythonObjectTest.class.st b/src/PythonBridge/PBPythonObjectTest.class.st index efdb228..87dbef6 100644 --- a/src/PythonBridge/PBPythonObjectTest.class.st +++ b/src/PythonBridge/PBPythonObjectTest.class.st @@ -1,46 +1,46 @@ -Class { - #name : #PBPythonObjectTest, - #superclass : #PBApplicationTest, - #category : #'PythonBridge-Tests' -} - -{ #category : #tests } -PBPythonObjectTest >> setUp [ - super setUp. - self cf << (#PythonBridge asP3GI => #object_registry) import -] - -{ #category : #tests } -PBPythonObjectTest >> stubPythonObjectExpression [ - ^ #PythonBridge asP3GI => #object_registry => #Registry callWith: #() -] - -{ #category : #tests } -PBPythonObjectTest >> testProxyIdentity [ - | obj | - self cf << self stubPythonObjectExpression. - obj := self cfSend waitForValue. - self assert: obj class equals: PBProxyObject. - self assertInstanceClass: obj name: 'Registry'. - self cf << (self resolveId: obj id). - self assert: self cfSend waitForValue equals: obj -] - -{ #category : #tests } -PBPythonObjectTest >> testSimpleObjectIdentity [ - | obj | - obj := PBObject new basicCreateObjectExpr: self stubPythonObjectExpression. - self cf << obj. - self assert: self cfSend waitForValue equals: obj. - self assertExpression: (self resolveId: obj id) equals: obj -] - -{ #category : #tests } -PBPythonObjectTest >> testSimpleProxy [ - | obj | - self cf << self stubPythonObjectExpression. - obj := self cfSend waitForValue. - self assert: obj class equals: PBProxyObject. - self assertInstanceClass: obj name: 'Registry'. - self assertExpression: (obj => #hasId callWith: #(0)) equals: false -] +Class { + #name : #PBPythonObjectTest, + #superclass : #PBApplicationTest, + #category : #'PythonBridge-Tests' +} + +{ #category : #tests } +PBPythonObjectTest >> setUp [ + super setUp. + self cf << (#PythonBridge asP3GI => #object_registry) import +] + +{ #category : #tests } +PBPythonObjectTest >> stubPythonObjectExpression [ + ^ #PythonBridge asP3GI => #object_registry => #Registry callWith: #() +] + +{ #category : #tests } +PBPythonObjectTest >> testProxyIdentity [ + | obj | + self cf << self stubPythonObjectExpression. + obj := self cfSend waitForValue. + self assert: obj class equals: PBProxyObject. + self assertInstanceClass: obj name: 'Registry'. + self cf << (self resolveId: obj id). + self assert: self cfSend waitForValue equals: obj +] + +{ #category : #tests } +PBPythonObjectTest >> testSimpleObjectIdentity [ + | obj | + obj := PBObject new basicCreateObjectExpr: self stubPythonObjectExpression. + self cf << obj. + self assert: self cfSend waitForValue equals: obj. + self assertExpression: (self resolveId: obj id) equals: obj +] + +{ #category : #tests } +PBPythonObjectTest >> testSimpleProxy [ + | obj | + self cf << self stubPythonObjectExpression. + obj := self cfSend waitForValue. + self assert: obj class equals: PBProxyObject. + self assertInstanceClass: obj name: 'Registry'. + self assertExpression: (obj => #hasId callWith: #(0)) equals: false +] diff --git a/src/PythonBridge/PBPythonValueTrait.trait.st b/src/PythonBridge/PBPythonValueTrait.trait.st index 3930a7c..795a274 100644 --- a/src/PythonBridge/PBPythonValueTrait.trait.st +++ b/src/PythonBridge/PBPythonValueTrait.trait.st @@ -1,11 +1,11 @@ -Trait { - #name : #PBPythonValueTrait, - #traits : 'P3GAttributeAccess', - #classTraits : 'P3GAttributeAccess classTrait', - #category : #'PythonBridge-P3Generator' -} - -{ #category : #testing } -PBPythonValueTrait >> isPythonValue [ - ^ true -] +Trait { + #name : #PBPythonValueTrait, + #traits : 'P3GAttributeAccess', + #classTraits : 'P3GAttributeAccess classTrait', + #category : #'PythonBridge-P3Generator' +} + +{ #category : #testing } +PBPythonValueTrait >> isPythonValue [ + ^ true +] diff --git a/src/PythonBridge/PBRAnswer.class.st b/src/PythonBridge/PBRAnswer.class.st index eba8aa2..392067b 100644 --- a/src/PythonBridge/PBRAnswer.class.st +++ b/src/PythonBridge/PBRAnswer.class.st @@ -1,24 +1,24 @@ -Class { - #name : #PBRAnswer, - #superclass : #PBAbstractAnswer, - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #encoding } -PBRAnswer >> encode [ - | dict | - dict := Dictionary new. - dict at: #type put: self type. - self privateEncode: dict. - ^ dict -] - -{ #category : #encoding } -PBRAnswer >> privateEncode: dict [ - dict at: #__sync put: self syncId -] - -{ #category : #writing } -PBRAnswer >> syncId [ - ^ message syncId -] +Class { + #name : #PBRAnswer, + #superclass : #PBAbstractAnswer, + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #encoding } +PBRAnswer >> encode [ + | dict | + dict := Dictionary new. + dict at: #type put: self type. + self privateEncode: dict. + ^ dict +] + +{ #category : #encoding } +PBRAnswer >> privateEncode: dict [ + dict at: #__sync put: self syncId +] + +{ #category : #writing } +PBRAnswer >> syncId [ + ^ message syncId +] diff --git a/src/PythonBridge/PBRAsyncMessage.class.st b/src/PythonBridge/PBRAsyncMessage.class.st index fb66893..45c6ac2 100644 --- a/src/PythonBridge/PBRAsyncMessage.class.st +++ b/src/PythonBridge/PBRAsyncMessage.class.st @@ -1,15 +1,15 @@ -Class { - #name : #PBRAsyncMessage, - #superclass : #PBRMessage, - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #accessing } -PBRAsyncMessage class >> type [ - ^ #RASYNC -] - -{ #category : #testing } -PBRAsyncMessage >> isSync [ - ^ false -] +Class { + #name : #PBRAsyncMessage, + #superclass : #PBRMessage, + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #accessing } +PBRAsyncMessage class >> type [ + ^ #RASYNC +] + +{ #category : #testing } +PBRAsyncMessage >> isSync [ + ^ false +] diff --git a/src/PythonBridge/PBRMessage.class.st b/src/PythonBridge/PBRMessage.class.st index 54a95e9..87bce7e 100644 --- a/src/PythonBridge/PBRMessage.class.st +++ b/src/PythonBridge/PBRMessage.class.st @@ -1,28 +1,28 @@ -Class { - #name : #PBRMessage, - #superclass : #PBAbstractMessage, - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #actions } -PBRMessage class >> decodeFrom: aDict [ - ^ self new - privateDecode: aDict; - yourself -] - -{ #category : #testing } -PBRMessage class >> isReverseMessage [ - "Reverse messages corresponds to messages that start on Python to Pharo. In other words - in reverse direction from normal messages." - ^ true -] - -{ #category : #accessing } -PBRMessage class >> type [ - ^ #RMSG -] - -{ #category : #'as yet unclassified' } -PBRMessage >> privateDecode: aDict [ -] +Class { + #name : #PBRMessage, + #superclass : #PBAbstractMessage, + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #actions } +PBRMessage class >> decodeFrom: aDict [ + ^ self new + privateDecode: aDict; + yourself +] + +{ #category : #testing } +PBRMessage class >> isReverseMessage [ + "Reverse messages corresponds to messages that start on Python to Pharo. In other words + in reverse direction from normal messages." + ^ true +] + +{ #category : #accessing } +PBRMessage class >> type [ + ^ #RMSG +] + +{ #category : #'as yet unclassified' } +PBRMessage >> privateDecode: aDict [ +] diff --git a/src/PythonBridge/PBRMessageTest.class.st b/src/PythonBridge/PBRMessageTest.class.st index a9fe5aa..f6c63f6 100644 --- a/src/PythonBridge/PBRMessageTest.class.st +++ b/src/PythonBridge/PBRMessageTest.class.st @@ -1,51 +1,51 @@ -Class { - #name : #PBRMessageTest, - #superclass : #TestCase, - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #tests } -PBRMessageTest >> stubDict [ - ^ {#type -> #RSTUB . - #ivar1 -> #foo . - #ivar2f -> 3 . - #ivar2r -> #(#bar) . - #__sync -> 'ab45d3' - } asDictionary -] - -{ #category : #tests } -PBRMessageTest >> testDecodeRMessage [ - | msg | - msg := PBRMessage decodeFrom: { #type -> #RMSG } asDictionary. - self assert: msg class equals: PBRMessage. - self assert: msg type equals: #RMSG -] - -{ #category : #tests } -PBRMessageTest >> testDecodeRStubMessage [ - | msg | - msg := PBRStubMessage decodeFrom: self stubDict. - self assert: msg ivar1 equals: #foo. - self assert: msg ivar2 equals: #(3 #bar). - self assert: msg syncId equals: 'ab45d3' -] - -{ #category : #tests } -PBRMessageTest >> testEncodeRAnswer [ - | msg ans | - msg := PBRSyncMessage decodeFrom: { #type -> #RSYNC . #__sync -> 'abcde1234' } asDictionary. - ans := msg createAnswer. - self assert: ans syncId equals: 'abcde1234'. - self assert: ans encode equals: { #type -> #RSYNC . #__sync -> 'abcde1234' } asDictionary -] - -{ #category : #tests } -PBRMessageTest >> testEncodeRStubAnswer [ - | msg ans | - msg := PBRStubMessage decodeFrom: self stubDict. - ans := msg createAnswer. - ans ivar1: #foo. - ans ivar2: #(3 #bar). - self assert: ans encode equals: self stubDict -] +Class { + #name : #PBRMessageTest, + #superclass : #TestCase, + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #tests } +PBRMessageTest >> stubDict [ + ^ {#type -> #RSTUB . + #ivar1 -> #foo . + #ivar2f -> 3 . + #ivar2r -> #(#bar) . + #__sync -> 'ab45d3' + } asDictionary +] + +{ #category : #tests } +PBRMessageTest >> testDecodeRMessage [ + | msg | + msg := PBRMessage decodeFrom: { #type -> #RMSG } asDictionary. + self assert: msg class equals: PBRMessage. + self assert: msg type equals: #RMSG +] + +{ #category : #tests } +PBRMessageTest >> testDecodeRStubMessage [ + | msg | + msg := PBRStubMessage decodeFrom: self stubDict. + self assert: msg ivar1 equals: #foo. + self assert: msg ivar2 equals: #(3 #bar). + self assert: msg syncId equals: 'ab45d3' +] + +{ #category : #tests } +PBRMessageTest >> testEncodeRAnswer [ + | msg ans | + msg := PBRSyncMessage decodeFrom: { #type -> #RSYNC . #__sync -> 'abcde1234' } asDictionary. + ans := msg createAnswer. + self assert: ans syncId equals: 'abcde1234'. + self assert: ans encode equals: { #type -> #RSYNC . #__sync -> 'abcde1234' } asDictionary +] + +{ #category : #tests } +PBRMessageTest >> testEncodeRStubAnswer [ + | msg ans | + msg := PBRStubMessage decodeFrom: self stubDict. + ans := msg createAnswer. + ans ivar1: #foo. + ans ivar2: #(3 #bar). + self assert: ans encode equals: self stubDict +] diff --git a/src/PythonBridge/PBRStubAnswer.class.st b/src/PythonBridge/PBRStubAnswer.class.st index a7d0835..593378c 100644 --- a/src/PythonBridge/PBRStubAnswer.class.st +++ b/src/PythonBridge/PBRStubAnswer.class.st @@ -1,27 +1,27 @@ -Class { - #name : #PBRStubAnswer, - #superclass : #PBRAnswer, - #instVars : [ - 'ivar1', - 'ivar2' - ], - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #accessing } -PBRStubAnswer >> ivar1: anObject [ - ivar1 := anObject -] - -{ #category : #accessing } -PBRStubAnswer >> ivar2: anObject [ - ivar2 := anObject -] - -{ #category : #encoding } -PBRStubAnswer >> privateEncode: dict [ - super privateEncode: dict. - dict at: #ivar1 put: ivar1. - dict at: #ivar2f put: ivar2 first. - dict at: #ivar2r put: ivar2 allButFirst. -] +Class { + #name : #PBRStubAnswer, + #superclass : #PBRAnswer, + #instVars : [ + 'ivar1', + 'ivar2' + ], + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #accessing } +PBRStubAnswer >> ivar1: anObject [ + ivar1 := anObject +] + +{ #category : #accessing } +PBRStubAnswer >> ivar2: anObject [ + ivar2 := anObject +] + +{ #category : #encoding } +PBRStubAnswer >> privateEncode: dict [ + super privateEncode: dict. + dict at: #ivar1 put: ivar1. + dict at: #ivar2f put: ivar2 first. + dict at: #ivar2r put: ivar2 allButFirst. +] diff --git a/src/PythonBridge/PBRStubMessage.class.st b/src/PythonBridge/PBRStubMessage.class.st index 4a055b5..467e664 100644 --- a/src/PythonBridge/PBRStubMessage.class.st +++ b/src/PythonBridge/PBRStubMessage.class.st @@ -1,36 +1,36 @@ -Class { - #name : #PBRStubMessage, - #superclass : #PBRSyncMessage, - #instVars : [ - 'ivar1', - 'ivar2' - ], - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #accessing } -PBRStubMessage class >> answerClass [ - ^ PBRStubAnswer -] - -{ #category : #accessing } -PBRStubMessage class >> type [ - ^ #RSTUB -] - -{ #category : #accessing } -PBRStubMessage >> ivar1 [ - ^ ivar1 -] - -{ #category : #accessing } -PBRStubMessage >> ivar2 [ - ^ ivar2 -] - -{ #category : #'as yet unclassified' } -PBRStubMessage >> privateDecode: dict [ - super privateDecode: dict. - ivar1 := dict at: #ivar1. - ivar2 := {dict at: #ivar2f} , (dict at: #ivar2r) -] +Class { + #name : #PBRStubMessage, + #superclass : #PBRSyncMessage, + #instVars : [ + 'ivar1', + 'ivar2' + ], + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #accessing } +PBRStubMessage class >> answerClass [ + ^ PBRStubAnswer +] + +{ #category : #accessing } +PBRStubMessage class >> type [ + ^ #RSTUB +] + +{ #category : #accessing } +PBRStubMessage >> ivar1 [ + ^ ivar1 +] + +{ #category : #accessing } +PBRStubMessage >> ivar2 [ + ^ ivar2 +] + +{ #category : #'as yet unclassified' } +PBRStubMessage >> privateDecode: dict [ + super privateDecode: dict. + ivar1 := dict at: #ivar1. + ivar2 := {dict at: #ivar2f} , (dict at: #ivar2r) +] diff --git a/src/PythonBridge/PBRSyncMessage.class.st b/src/PythonBridge/PBRSyncMessage.class.st index 40cb68b..90a04ef 100644 --- a/src/PythonBridge/PBRSyncMessage.class.st +++ b/src/PythonBridge/PBRSyncMessage.class.st @@ -1,44 +1,44 @@ -Class { - #name : #PBRSyncMessage, - #superclass : #PBRMessage, - #instVars : [ - 'syncId' - ], - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #accessing } -PBRSyncMessage class >> answerClass [ - ^ PBRAnswer -] - -{ #category : #accessing } -PBRSyncMessage class >> type [ - ^ #RSYNC -] - -{ #category : #accessing } -PBRSyncMessage >> answerClass [ - ^ self class answerClass -] - -{ #category : #accessing } -PBRSyncMessage >> createAnswer [ - ^ self answerClass answerFor: self -] - -{ #category : #testing } -PBRSyncMessage >> isSync [ - ^ true -] - -{ #category : #'as yet unclassified' } -PBRSyncMessage >> privateDecode: dict [ - super privateDecode: dict. - syncId := dict at: #__sync -] - -{ #category : #accessing } -PBRSyncMessage >> syncId [ - ^ syncId -] +Class { + #name : #PBRSyncMessage, + #superclass : #PBRMessage, + #instVars : [ + 'syncId' + ], + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #accessing } +PBRSyncMessage class >> answerClass [ + ^ PBRAnswer +] + +{ #category : #accessing } +PBRSyncMessage class >> type [ + ^ #RSYNC +] + +{ #category : #accessing } +PBRSyncMessage >> answerClass [ + ^ self class answerClass +] + +{ #category : #accessing } +PBRSyncMessage >> createAnswer [ + ^ self answerClass answerFor: self +] + +{ #category : #testing } +PBRSyncMessage >> isSync [ + ^ true +] + +{ #category : #'as yet unclassified' } +PBRSyncMessage >> privateDecode: dict [ + super privateDecode: dict. + syncId := dict at: #__sync +] + +{ #category : #accessing } +PBRSyncMessage >> syncId [ + ^ syncId +] diff --git a/src/PythonBridge/PBRegistryFinalizer.class.st b/src/PythonBridge/PBRegistryFinalizer.class.st index d596e88..afc9286 100644 --- a/src/PythonBridge/PBRegistryFinalizer.class.st +++ b/src/PythonBridge/PBRegistryFinalizer.class.st @@ -1,56 +1,56 @@ -Class { - #name : #PBRegistryFinalizer, - #superclass : #PBAbstractFinalizer, - #instVars : [ - 'pythonVariable', - 'executionHandler' - ], - #category : #'PythonBridge-Execution' -} - -{ #category : #accessing } -PBRegistryFinalizer class >> pythonVariable: aPythonVariable executionHandler: executionHandler [ - ^ self new - pythonVariable: aPythonVariable; - executionHandler: executionHandler - yourself -] - -{ #category : #accessing } -PBRegistryFinalizer >> executionHandler [ - ^ executionHandler -] - -{ #category : #accessing } -PBRegistryFinalizer >> executionHandler: anObject [ - executionHandler := anObject -] - -{ #category : #finalization } -PBRegistryFinalizer >> finalize [ - | cf | - executionHandler isRunning ifFalse: [ ^ self ]. - cf := executionHandler newCommandFactory. - cf << (self removeId: pythonVariable name). - cf send. -] - -{ #category : #accessing } -PBRegistryFinalizer >> pythonVariable [ - ^ pythonVariable -] - -{ #category : #accessing } -PBRegistryFinalizer >> pythonVariable: anObject [ - pythonVariable := anObject -] - -{ #category : #asserting } -PBRegistryFinalizer >> registryExpression [ - ^ #registry callWith: #() -] - -{ #category : #asserting } -PBRegistryFinalizer >> removeId: anId [ - ^ self registryExpression => #clean callWith: (Array with: anId) -] +Class { + #name : #PBRegistryFinalizer, + #superclass : #PBAbstractFinalizer, + #instVars : [ + 'pythonVariable', + 'executionHandler' + ], + #category : #'PythonBridge-Execution' +} + +{ #category : #accessing } +PBRegistryFinalizer class >> pythonVariable: aPythonVariable executionHandler: executionHandler [ + ^ self new + pythonVariable: aPythonVariable; + executionHandler: executionHandler + yourself +] + +{ #category : #accessing } +PBRegistryFinalizer >> executionHandler [ + ^ executionHandler +] + +{ #category : #accessing } +PBRegistryFinalizer >> executionHandler: anObject [ + executionHandler := anObject +] + +{ #category : #finalization } +PBRegistryFinalizer >> finalize [ + | cf | + executionHandler isRunning ifFalse: [ ^ self ]. + cf := executionHandler newCommandFactory. + cf << (self removeId: pythonVariable name). + cf send. +] + +{ #category : #accessing } +PBRegistryFinalizer >> pythonVariable [ + ^ pythonVariable +] + +{ #category : #accessing } +PBRegistryFinalizer >> pythonVariable: anObject [ + pythonVariable := anObject +] + +{ #category : #asserting } +PBRegistryFinalizer >> registryExpression [ + ^ #registry callWith: #() +] + +{ #category : #asserting } +PBRegistryFinalizer >> removeId: anId [ + ^ self registryExpression => #clean callWith: (Array with: anId) +] diff --git a/src/PythonBridge/PBReplaceCommand.class.st b/src/PythonBridge/PBReplaceCommand.class.st index cf3bb7f..2a10f31 100644 --- a/src/PythonBridge/PBReplaceCommand.class.st +++ b/src/PythonBridge/PBReplaceCommand.class.st @@ -1,31 +1,31 @@ -Class { - #name : #PBReplaceCommand, - #superclass : #PBErrorHandlingAction, - #instVars : [ - 'newCommand' - ], - #category : #'PythonBridge-ErrorHandling' -} - -{ #category : #'as yet unclassified' } -PBReplaceCommand >> actionSymbol [ - ^ #'REPLACE_COMMAND' -] - -{ #category : #'as yet unclassified' } -PBReplaceCommand >> encodeAsDictionary [ - | response | - response := super encodeAsDictionary. - response at: #command put: newCommand encodeAsDictionary. - ^ response -] - -{ #category : #accessing } -PBReplaceCommand >> newCommand [ - ^ newCommand -] - -{ #category : #accessing } -PBReplaceCommand >> newCommand: anObject [ - newCommand := anObject -] +Class { + #name : #PBReplaceCommand, + #superclass : #PBErrorHandlingAction, + #instVars : [ + 'newCommand' + ], + #category : #'PythonBridge-ErrorHandling' +} + +{ #category : #'as yet unclassified' } +PBReplaceCommand >> actionSymbol [ + ^ #'REPLACE_COMMAND' +] + +{ #category : #'as yet unclassified' } +PBReplaceCommand >> encodeAsDictionary [ + | response | + response := super encodeAsDictionary. + response at: #command put: newCommand encodeAsDictionary. + ^ response +] + +{ #category : #accessing } +PBReplaceCommand >> newCommand [ + ^ newCommand +] + +{ #category : #accessing } +PBReplaceCommand >> newCommand: anObject [ + newCommand := anObject +] diff --git a/src/PythonBridge/PBRetry.class.st b/src/PythonBridge/PBRetry.class.st index 0cb2d80..21b22d9 100644 --- a/src/PythonBridge/PBRetry.class.st +++ b/src/PythonBridge/PBRetry.class.st @@ -1,5 +1,5 @@ -Class { - #name : #PBRetry, - #superclass : #PBErrorHandlingAction, - #category : #'PythonBridge-ErrorHandling' -} +Class { + #name : #PBRetry, + #superclass : #PBErrorHandlingAction, + #category : #'PythonBridge-ErrorHandling' +} diff --git a/src/PythonBridge/PBSendCommandTest.class.st b/src/PythonBridge/PBSendCommandTest.class.st index 15bd605..1d8f1ff 100644 --- a/src/PythonBridge/PBSendCommandTest.class.st +++ b/src/PythonBridge/PBSendCommandTest.class.st @@ -1,82 +1,82 @@ -Class { - #name : #PBSendCommandTest, - #superclass : #PBApplicationTest, - #category : #'PythonBridge-Tests' -} - -{ #category : #tests } -PBSendCommandTest >> testAddBinding [ - | binding | - binding := PBBinding wrap: #((2) 3). - self cf addBinding: binding. - self cf << binding. - self assert: self cfSend waitForValue equals: #((2) 3) -] - -{ #category : #tests } -PBSendCommandTest >> testAddObserver [ - | observer callbackExecuted promiseSem | - promiseSem := Semaphore new. - callbackExecuted := false. - observer := self cf observerFromCallback: [ :obj | - promiseSem wait. - self assert: obj equals: 33. - self deny: promise isSignaled. - callbackExecuted := true ]. - self cf << (observer pythonNotify: 33). - self cf << 2. - self cfSend. - promiseSem signal. - self assert: promise waitForValue equals: 2. - self assert: callbackExecuted -] - -{ #category : #tests } -PBSendCommandTest >> testCallbackReturnValue [ - | observer callbackExecuted promiseSem | - promiseSem := Semaphore new. - callbackExecuted := false. - observer := self cf observerFromCallback: [ :obj | - promiseSem wait. - self assert: obj equals: 33. - self deny: promise isSignaled. - callbackExecuted := true. - 5 ]. - self cf << (observer pythonNotify: 33). - self cfSend. - promiseSem signal. - self assert: promise waitForValue equals: 5. - self assert: callbackExecuted -] - -{ #category : #tests } -PBSendCommandTest >> testInvalidCallbackReturn [ - | observer callbackExecuted promiseSem | - promiseSem := Semaphore new. - callbackExecuted := false. - observer := self cf observerFromCallback: [ :obj | - promiseSem wait. - self assert: obj equals: 33. - self deny: promise isSignaled. - callbackExecuted := true. - self ]. - self cf << (observer pythonNotify: 33). - self cfSend. - promiseSem signal. - self assert: promise waitForValue equals: nil. - self assert: callbackExecuted -] - -{ #category : #tests } -PBSendCommandTest >> testSendAssignAsLastMessage [ - self cf << (#foo asP3GI <- 33). - self cfSend. - self assert: promise waitForValue equals: nil -] - -{ #category : #tests } -PBSendCommandTest >> testSendImportAsLastMessage [ - self cf << #sys asP3GI import. - self cfSend. - self assert: promise waitForValue equals: nil -] +Class { + #name : #PBSendCommandTest, + #superclass : #PBApplicationTest, + #category : #'PythonBridge-Tests' +} + +{ #category : #tests } +PBSendCommandTest >> testAddBinding [ + | binding | + binding := PBBinding wrap: #((2) 3). + self cf addBinding: binding. + self cf << binding. + self assert: self cfSend waitForValue equals: #((2) 3) +] + +{ #category : #tests } +PBSendCommandTest >> testAddObserver [ + | observer callbackExecuted promiseSem | + promiseSem := Semaphore new. + callbackExecuted := false. + observer := self cf observerFromCallback: [ :obj | + promiseSem wait. + self assert: obj equals: 33. + self deny: promise isSignaled. + callbackExecuted := true ]. + self cf << (observer pythonNotify: 33). + self cf << 2. + self cfSend. + promiseSem signal. + self assert: promise waitForValue equals: 2. + self assert: callbackExecuted +] + +{ #category : #tests } +PBSendCommandTest >> testCallbackReturnValue [ + | observer callbackExecuted promiseSem | + promiseSem := Semaphore new. + callbackExecuted := false. + observer := self cf observerFromCallback: [ :obj | + promiseSem wait. + self assert: obj equals: 33. + self deny: promise isSignaled. + callbackExecuted := true. + 5 ]. + self cf << (observer pythonNotify: 33). + self cfSend. + promiseSem signal. + self assert: promise waitForValue equals: 5. + self assert: callbackExecuted +] + +{ #category : #tests } +PBSendCommandTest >> testInvalidCallbackReturn [ + | observer callbackExecuted promiseSem | + promiseSem := Semaphore new. + callbackExecuted := false. + observer := self cf observerFromCallback: [ :obj | + promiseSem wait. + self assert: obj equals: 33. + self deny: promise isSignaled. + callbackExecuted := true. + self ]. + self cf << (observer pythonNotify: 33). + self cfSend. + promiseSem signal. + self assert: promise waitForValue equals: nil. + self assert: callbackExecuted +] + +{ #category : #tests } +PBSendCommandTest >> testSendAssignAsLastMessage [ + self cf << (#foo asP3GI <- 33). + self cfSend. + self assert: promise waitForValue equals: nil +] + +{ #category : #tests } +PBSendCommandTest >> testSendImportAsLastMessage [ + self cf << #sys asP3GI import. + self cfSend. + self assert: promise waitForValue equals: nil +] diff --git a/src/PythonBridge/PBSerializationTest.class.st b/src/PythonBridge/PBSerializationTest.class.st index fd6fef0..b22aba8 100644 --- a/src/PythonBridge/PBSerializationTest.class.st +++ b/src/PythonBridge/PBSerializationTest.class.st @@ -1,26 +1,26 @@ -Class { - #name : #PBSerializationTest, - #superclass : #PBApplicationTest, - #category : #'PythonBridge-Tests' -} - -{ #category : #tests } -PBSerializationTest >> testSendAndRetrieveFloat [ - self cf << 2.2. - self cfSend. - self assert: promise waitForValue equals: 2.2. -] - -{ #category : #tests } -PBSerializationTest >> testSendAndRetrieveInteger [ - self cf << 2. - self cfSend. - self assert: promise waitForValue equals: 2. -] - -{ #category : #tests } -PBSerializationTest >> testSendAndRetrieveNil [ - self cf << nil. - self cfSend. - self assert: promise waitForValue equals: nil -] +Class { + #name : #PBSerializationTest, + #superclass : #PBApplicationTest, + #category : #'PythonBridge-Tests' +} + +{ #category : #tests } +PBSerializationTest >> testSendAndRetrieveFloat [ + self cf << 2.2. + self cfSend. + self assert: promise waitForValue equals: 2.2. +] + +{ #category : #tests } +PBSerializationTest >> testSendAndRetrieveInteger [ + self cf << 2. + self cfSend. + self assert: promise waitForValue equals: 2. +] + +{ #category : #tests } +PBSerializationTest >> testSendAndRetrieveNil [ + self cf << nil. + self cfSend. + self assert: promise waitForValue equals: nil +] diff --git a/src/PythonBridge/PBSerializeTest.class.st b/src/PythonBridge/PBSerializeTest.class.st index b984cfc..7eb5c0e 100644 --- a/src/PythonBridge/PBSerializeTest.class.st +++ b/src/PythonBridge/PBSerializeTest.class.st @@ -1,31 +1,31 @@ -Class { - #name : #PBSerializeTest, - #superclass : #TestCase, - #instVars : [ - 'mapper' - ], - #category : #'PythonBridge-Tests' -} - -{ #category : #tests } -PBSerializeTest >> serializer [ - ^ mapper serializer - serializerWrapper: PBPlatform current class httpMessageBrokerClass serializer; - yourself -] - -{ #category : #tests } -PBSerializeTest >> setUp [ - super setUp. - mapper := PBMapperFactory forExecutionHandler: self -] - -{ #category : #tests } -PBSerializeTest >> testSerializeArray [ - self assert: (self serializer serialize: #(33 'foo')) equals: '[33,"foo"]' -] - -{ #category : #tests } -PBSerializeTest >> testSerializeNil [ - self assert: (self serializer serialize: nil) equals: 'null' -] +Class { + #name : #PBSerializeTest, + #superclass : #TestCase, + #instVars : [ + 'mapper' + ], + #category : #'PythonBridge-Tests' +} + +{ #category : #tests } +PBSerializeTest >> serializer [ + ^ mapper serializer + serializerWrapper: PBPlatform current class httpMessageBrokerClass serializer; + yourself +] + +{ #category : #tests } +PBSerializeTest >> setUp [ + super setUp. + mapper := PBMapperFactory forExecutionHandler: self +] + +{ #category : #tests } +PBSerializeTest >> testSerializeArray [ + self assert: (self serializer serialize: #(33 'foo')) equals: '[33,"foo"]' +] + +{ #category : #tests } +PBSerializeTest >> testSerializeNil [ + self assert: (self serializer serialize: nil) equals: 'null' +] diff --git a/src/PythonBridge/PBSerializer.class.st b/src/PythonBridge/PBSerializer.class.st index 21a8cd3..edb8599 100644 --- a/src/PythonBridge/PBSerializer.class.st +++ b/src/PythonBridge/PBSerializer.class.st @@ -1,26 +1,26 @@ -Class { - #name : #PBSerializer, - #superclass : #PBMapper, - #category : #'PythonBridge-Serialization' -} - -{ #category : #private } -PBSerializer class >> deserialize: anObject [ - ^ PBDeserializer deserialize: anObject -] - -{ #category : #private } -PBSerializer class >> deserialize: anObject forApplication: application [ - ^ PBDeserializer deserialize: anObject forApplication: application -] - -{ #category : #private } -PBSerializer class >> serialize: anObject [ - ^ self new - serialize: anObject -] - -{ #category : #api } -PBSerializer >> serialize: anObject [ - ^ serializerWrapper serialize: anObject -] +Class { + #name : #PBSerializer, + #superclass : #PBMapper, + #category : #'PythonBridge-Serialization' +} + +{ #category : #private } +PBSerializer class >> deserialize: anObject [ + ^ PBDeserializer deserialize: anObject +] + +{ #category : #private } +PBSerializer class >> deserialize: anObject forApplication: application [ + ^ PBDeserializer deserialize: anObject forApplication: application +] + +{ #category : #private } +PBSerializer class >> serialize: anObject [ + ^ self new + serialize: anObject +] + +{ #category : #api } +PBSerializer >> serialize: anObject [ + ^ serializerWrapper serialize: anObject +] diff --git a/src/PythonBridge/PBSettings.class.st b/src/PythonBridge/PBSettings.class.st index 5418f66..f2c7ca0 100644 --- a/src/PythonBridge/PBSettings.class.st +++ b/src/PythonBridge/PBSettings.class.st @@ -1,37 +1,37 @@ -Class { - #name : #PBSettings, - #superclass : #Object, - #instVars : [ - 'pharoSocketAddress', - 'pythonSocketAddress' - ], - #category : #'PythonBridge-Platform' -} - -{ #category : #'as yet unclassified' } -PBSettings class >> pharoSocketAddress: pharoSocketAddress pythonSocketAddress: pythonSocketAddress [ - ^ self new - pharoSocketAddress: pharoSocketAddress; - pythonSocketAddress: pythonSocketAddress; - yourself -] - -{ #category : #accessing } -PBSettings >> pharoSocketAddress [ - ^ pharoSocketAddress -] - -{ #category : #accessing } -PBSettings >> pharoSocketAddress: anObject [ - pharoSocketAddress := anObject -] - -{ #category : #accessing } -PBSettings >> pythonSocketAddress [ - ^ pythonSocketAddress -] - -{ #category : #accessing } -PBSettings >> pythonSocketAddress: anObject [ - pythonSocketAddress := anObject -] +Class { + #name : #PBSettings, + #superclass : #Object, + #instVars : [ + 'pharoSocketAddress', + 'pythonSocketAddress' + ], + #category : #'PythonBridge-Platform' +} + +{ #category : #'as yet unclassified' } +PBSettings class >> pharoSocketAddress: pharoSocketAddress pythonSocketAddress: pythonSocketAddress [ + ^ self new + pharoSocketAddress: pharoSocketAddress; + pythonSocketAddress: pythonSocketAddress; + yourself +] + +{ #category : #accessing } +PBSettings >> pharoSocketAddress [ + ^ pharoSocketAddress +] + +{ #category : #accessing } +PBSettings >> pharoSocketAddress: anObject [ + pharoSocketAddress := anObject +] + +{ #category : #accessing } +PBSettings >> pythonSocketAddress [ + ^ pythonSocketAddress +] + +{ #category : #accessing } +PBSettings >> pythonSocketAddress: anObject [ + pythonSocketAddress := anObject +] diff --git a/src/PythonBridge/PBSimpleApplicationTest.class.st b/src/PythonBridge/PBSimpleApplicationTest.class.st index 9aed354..ca35cc6 100644 --- a/src/PythonBridge/PBSimpleApplicationTest.class.st +++ b/src/PythonBridge/PBSimpleApplicationTest.class.st @@ -1,67 +1,67 @@ -Class { - #name : #PBSimpleApplicationTest, - #superclass : #PBApplicationTest, - #category : #'PythonBridge-Tests' -} - -{ #category : #tests } -PBSimpleApplicationTest >> testDoubleRetrieveValue [ - | promise | - self cf << (P3GBinaryOperator new - left: 1; - right: 2; - operator: $+; - yourself). - promise := self cf send. - self assert: promise waitForValue equals: 3. - self cf << (P3GBinaryOperator new - left: 3; - right: 4; - operator: $*; - yourself). - promise := self cf send. - self assert: promise waitForValue equals: 12 -] - -{ #category : #tests } -PBSimpleApplicationTest >> testSimpleLambda [ - self cf << ((P3GLambda - argument: #a asP3GI - expression: #a asP3GI + 1) callWith: #( 2 )). - self assert: self cf send waitForValue equals: 3 -] - -{ #category : #tests } -PBSimpleApplicationTest >> testSimpleMapping [ - | obj type | - obj := self cf sendAndWait: #bridge_globals asP3GI => #msg_service. - type := self cf sendAndWait: (#type asP3GI callWith: (Array with: obj)). - self application addMapping: type to: (P3GLambda - argument: #x asP3GI - expression: 'STRING!!'). - self assert: (self cf sendAndWait: obj) equals: 'STRING!!' -] - -{ #category : #tests } -PBSimpleApplicationTest >> testSimpleRetrieveSameValue [ - | promise | - self cf << (P3GBinaryOperator new - left: 1; - right: 2; - operator: $+; - yourself). - promise := self cf send. - self assert: promise waitForValue equals: 3 -] - -{ #category : #tests } -PBSimpleApplicationTest >> testSimpleRetrieveSameValue2 [ - | promise | - self cf << (P3GBinaryOperator new - left: 3; - right: 4; - operator: $*; - yourself). - promise := self cf send. - self assert: promise waitForValue equals: 12 -] +Class { + #name : #PBSimpleApplicationTest, + #superclass : #PBApplicationTest, + #category : #'PythonBridge-Tests' +} + +{ #category : #tests } +PBSimpleApplicationTest >> testDoubleRetrieveValue [ + | promise | + self cf << (P3GBinaryOperator new + left: 1; + right: 2; + operator: $+; + yourself). + promise := self cf send. + self assert: promise waitForValue equals: 3. + self cf << (P3GBinaryOperator new + left: 3; + right: 4; + operator: $*; + yourself). + promise := self cf send. + self assert: promise waitForValue equals: 12 +] + +{ #category : #tests } +PBSimpleApplicationTest >> testSimpleLambda [ + self cf << ((P3GLambda + argument: #a asP3GI + expression: #a asP3GI + 1) callWith: #( 2 )). + self assert: self cf send waitForValue equals: 3 +] + +{ #category : #tests } +PBSimpleApplicationTest >> testSimpleMapping [ + | obj type | + obj := self cf sendAndWait: #bridge_globals asP3GI => #msg_service. + type := self cf sendAndWait: (#type asP3GI callWith: (Array with: obj)). + self application addMapping: type to: (P3GLambda + argument: #x asP3GI + expression: 'STRING!!'). + self assert: (self cf sendAndWait: obj) equals: 'STRING!!' +] + +{ #category : #tests } +PBSimpleApplicationTest >> testSimpleRetrieveSameValue [ + | promise | + self cf << (P3GBinaryOperator new + left: 1; + right: 2; + operator: $+; + yourself). + promise := self cf send. + self assert: promise waitForValue equals: 3 +] + +{ #category : #tests } +PBSimpleApplicationTest >> testSimpleRetrieveSameValue2 [ + | promise | + self cf << (P3GBinaryOperator new + left: 3; + right: 4; + operator: $*; + yourself). + promise := self cf send. + self assert: promise waitForValue equals: 12 +] diff --git a/src/PythonBridge/PBSocketAddress.class.st b/src/PythonBridge/PBSocketAddress.class.st index 5e643a0..c220a0e 100644 --- a/src/PythonBridge/PBSocketAddress.class.st +++ b/src/PythonBridge/PBSocketAddress.class.st @@ -1,42 +1,42 @@ -Class { - #name : #PBSocketAddress, - #superclass : #Object, - #instVars : [ - 'ipOrName', - 'port' - ], - #category : #'PythonBridge-Platform' -} - -{ #category : #'as yet unclassified' } -PBSocketAddress class >> ipOrName: ipOrName port: aPort [ - ^ self new - ipOrName: ipOrName; - port: aPort; - yourself -] - -{ #category : #accessing } -PBSocketAddress >> ipOrName [ - ^ ipOrName -] - -{ #category : #accessing } -PBSocketAddress >> ipOrName: anObject [ - ipOrName := anObject -] - -{ #category : #accessing } -PBSocketAddress >> port [ - ^ port -] - -{ #category : #accessing } -PBSocketAddress >> port: anObject [ - port := anObject -] - -{ #category : #printing } -PBSocketAddress >> printAddress [ - ^ ipOrName , ':' , port asString -] +Class { + #name : #PBSocketAddress, + #superclass : #Object, + #instVars : [ + 'ipOrName', + 'port' + ], + #category : #'PythonBridge-Platform' +} + +{ #category : #'as yet unclassified' } +PBSocketAddress class >> ipOrName: ipOrName port: aPort [ + ^ self new + ipOrName: ipOrName; + port: aPort; + yourself +] + +{ #category : #accessing } +PBSocketAddress >> ipOrName [ + ^ ipOrName +] + +{ #category : #accessing } +PBSocketAddress >> ipOrName: anObject [ + ipOrName := anObject +] + +{ #category : #accessing } +PBSocketAddress >> port [ + ^ port +] + +{ #category : #accessing } +PBSocketAddress >> port: anObject [ + port := anObject +] + +{ #category : #printing } +PBSocketAddress >> printAddress [ + ^ ipOrName , ':' , port asString +] diff --git a/src/PythonBridge/PBStubAnswer.class.st b/src/PythonBridge/PBStubAnswer.class.st index 636a7f7..534506b 100644 --- a/src/PythonBridge/PBStubAnswer.class.st +++ b/src/PythonBridge/PBStubAnswer.class.st @@ -1,25 +1,25 @@ -Class { - #name : #PBStubAnswer, - #superclass : #PBAnswer, - #instVars : [ - 'ivar1', - 'ivar2' - ], - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #converting } -PBStubAnswer >> decode: dict [ - ivar1 := dict at: #ivar1. - ivar2 := { dict at: #ivar2f } , (dict at: #ivar2r) -] - -{ #category : #accessing } -PBStubAnswer >> ivar1 [ - ^ ivar1 -] - -{ #category : #accessing } -PBStubAnswer >> ivar2 [ - ^ ivar2 -] +Class { + #name : #PBStubAnswer, + #superclass : #PBAnswer, + #instVars : [ + 'ivar1', + 'ivar2' + ], + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #converting } +PBStubAnswer >> decode: dict [ + ivar1 := dict at: #ivar1. + ivar2 := { dict at: #ivar2f } , (dict at: #ivar2r) +] + +{ #category : #accessing } +PBStubAnswer >> ivar1 [ + ^ ivar1 +] + +{ #category : #accessing } +PBStubAnswer >> ivar2 [ + ^ ivar2 +] diff --git a/src/PythonBridge/PBStubApplication.class.st b/src/PythonBridge/PBStubApplication.class.st index 7ad1e23..0f3ac25 100644 --- a/src/PythonBridge/PBStubApplication.class.st +++ b/src/PythonBridge/PBStubApplication.class.st @@ -1,15 +1,15 @@ -Class { - #name : #PBStubApplication, - #superclass : #PBApplication, - #category : #'PythonBridge-Tests' -} - -{ #category : #initialization } -PBStubApplication >> handlers [ - ^ Array with: loggingHandler -] - -{ #category : #initialization } -PBStubApplication >> initializeHandlers [ - loggingHandler := PBLoggingHandler application: self. -] +Class { + #name : #PBStubApplication, + #superclass : #PBApplication, + #category : #'PythonBridge-Tests' +} + +{ #category : #initialization } +PBStubApplication >> handlers [ + ^ Array with: loggingHandler +] + +{ #category : #initialization } +PBStubApplication >> initializeHandlers [ + loggingHandler := PBLoggingHandler application: self. +] diff --git a/src/PythonBridge/PBStubMessage.class.st b/src/PythonBridge/PBStubMessage.class.st index 804163b..fbeac62 100644 --- a/src/PythonBridge/PBStubMessage.class.st +++ b/src/PythonBridge/PBStubMessage.class.st @@ -1,47 +1,47 @@ -Class { - #name : #PBStubMessage, - #superclass : #PBSyncMessage, - #instVars : [ - 'ivar1', - 'ivar2' - ], - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #accessing } -PBStubMessage class >> answerClass [ - ^ PBStubAnswer -] - -{ #category : #accessing } -PBStubMessage class >> type [ - ^ #STUB -] - -{ #category : #accessing } -PBStubMessage >> ivar1 [ - ^ ivar1 -] - -{ #category : #accessing } -PBStubMessage >> ivar1: anObject [ - ivar1 := anObject -] - -{ #category : #accessing } -PBStubMessage >> ivar2 [ - ^ ivar2 -] - -{ #category : #accessing } -PBStubMessage >> ivar2: anObject [ - ivar2 := anObject -] - -{ #category : #encode } -PBStubMessage >> privateEncode: aDict [ - super privateEncode: aDict. - aDict at: #ivar1 put: ivar1. - aDict at: #ivar2f put: ivar2 first. - aDict at: #ivar2r put: ivar2 allButFirst. -] +Class { + #name : #PBStubMessage, + #superclass : #PBSyncMessage, + #instVars : [ + 'ivar1', + 'ivar2' + ], + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #accessing } +PBStubMessage class >> answerClass [ + ^ PBStubAnswer +] + +{ #category : #accessing } +PBStubMessage class >> type [ + ^ #STUB +] + +{ #category : #accessing } +PBStubMessage >> ivar1 [ + ^ ivar1 +] + +{ #category : #accessing } +PBStubMessage >> ivar1: anObject [ + ivar1 := anObject +] + +{ #category : #accessing } +PBStubMessage >> ivar2 [ + ^ ivar2 +] + +{ #category : #accessing } +PBStubMessage >> ivar2: anObject [ + ivar2 := anObject +] + +{ #category : #encode } +PBStubMessage >> privateEncode: aDict [ + super privateEncode: aDict. + aDict at: #ivar1 put: ivar1. + aDict at: #ivar2f put: ivar2 first. + aDict at: #ivar2r put: ivar2 allButFirst. +] diff --git a/src/PythonBridge/PBSyncMessage.class.st b/src/PythonBridge/PBSyncMessage.class.st index 76c4a61..0fc4fd3 100644 --- a/src/PythonBridge/PBSyncMessage.class.st +++ b/src/PythonBridge/PBSyncMessage.class.st @@ -1,50 +1,50 @@ -Class { - #name : #PBSyncMessage, - #superclass : #PBMessage, - #instVars : [ - 'syncId' - ], - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #accessing } -PBSyncMessage class >> answerClass [ - ^ PBAnswer -] - -{ #category : #accessing } -PBSyncMessage class >> type [ - ^ #SYNC -] - -{ #category : #accessing } -PBSyncMessage >> answerClass [ - ^ self class answerClass -] - -{ #category : #accessing } -PBSyncMessage >> createAnswer [ - ^ self answerClass answerFor: self -] - -{ #category : #initialization } -PBSyncMessage >> initialize [ - super initialize. - syncId := PBPlatform current newRandomName -] - -{ #category : #testing } -PBSyncMessage >> isSync [ - ^ true -] - -{ #category : #writing } -PBSyncMessage >> privateEncode: aDict [ - super privateEncode: aDict. - aDict at: #__sync put: self syncId -] - -{ #category : #writing } -PBSyncMessage >> syncId [ - ^ syncId -] +Class { + #name : #PBSyncMessage, + #superclass : #PBMessage, + #instVars : [ + 'syncId' + ], + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #accessing } +PBSyncMessage class >> answerClass [ + ^ PBAnswer +] + +{ #category : #accessing } +PBSyncMessage class >> type [ + ^ #SYNC +] + +{ #category : #accessing } +PBSyncMessage >> answerClass [ + ^ self class answerClass +] + +{ #category : #accessing } +PBSyncMessage >> createAnswer [ + ^ self answerClass answerFor: self +] + +{ #category : #initialization } +PBSyncMessage >> initialize [ + super initialize. + syncId := PBPlatform current newRandomName +] + +{ #category : #testing } +PBSyncMessage >> isSync [ + ^ true +] + +{ #category : #writing } +PBSyncMessage >> privateEncode: aDict [ + super privateEncode: aDict. + aDict at: #__sync put: self syncId +] + +{ #category : #writing } +PBSyncMessage >> syncId [ + ^ syncId +] diff --git a/src/PythonBridge/PBSyncMessageHandler.class.st b/src/PythonBridge/PBSyncMessageHandler.class.st index ff6f558..b5c2108 100644 --- a/src/PythonBridge/PBSyncMessageHandler.class.st +++ b/src/PythonBridge/PBSyncMessageHandler.class.st @@ -1,24 +1,24 @@ -Class { - #name : #PBSyncMessageHandler, - #superclass : #PBMessageHandler, - #instVars : [ - 'answer' - ], - #category : #'PythonBridge-Platform' -} - -{ #category : #accessing } -PBSyncMessageHandler >> answer [ - ^ answer -] - -{ #category : #accessing } -PBSyncMessageHandler >> handleMessage [ - answer := callback value: message. - self assert: answer class = message answerClass. -] - -{ #category : #asserting } -PBSyncMessageHandler >> shouldAnswer [ - ^ true -] +Class { + #name : #PBSyncMessageHandler, + #superclass : #PBMessageHandler, + #instVars : [ + 'answer' + ], + #category : #'PythonBridge-Platform' +} + +{ #category : #accessing } +PBSyncMessageHandler >> answer [ + ^ answer +] + +{ #category : #accessing } +PBSyncMessageHandler >> handleMessage [ + answer := callback value: message. + self assert: answer class = message answerClass. +] + +{ #category : #asserting } +PBSyncMessageHandler >> shouldAnswer [ + ^ true +] diff --git a/src/PythonBridge/PBTestCase.class.st b/src/PythonBridge/PBTestCase.class.st index 20af39e..2713cbf 100644 --- a/src/PythonBridge/PBTestCase.class.st +++ b/src/PythonBridge/PBTestCase.class.st @@ -1,83 +1,83 @@ -Class { - #name : #PBTestCase, - #superclass : #TestCase, - #instVars : [ - 'commandFactory', - 'promise' - ], - #category : #'PythonBridge-Tests' -} - -{ #category : #accessing } -PBTestCase class >> appResource [ - self subclassResponsibility -] - -{ #category : #accessing } -PBTestCase class >> resources [ - ^ super resources , (Array with: self appResource) -] - -{ #category : #initialization } -PBTestCase >> app [ - ^ self application -] - -{ #category : #initialization } -PBTestCase >> application [ - ^ self applicationClass uniqueInstance -] - -{ #category : #initialization } -PBTestCase >> applicationClass [ - self subclassResponsibility -] - -{ #category : #asserting } -PBTestCase >> assertClass: cls name: aName [ - self cf << (cls => #__name__). - self assert: self cf send waitForValue equals: aName -] - -{ #category : #asserting } -PBTestCase >> assertExpression: expr equals: aBlockOrValue [ - self cf << expr. - self assert: self cf send waitForValue equals: aBlockOrValue value -] - -{ #category : #asserting } -PBTestCase >> assertInstanceClass: obj name: aName [ - self cf << ((#type asP3GI callWith: (Array with: obj)) => #__name__). - self assert: self cf send waitForValue equals: aName -] - -{ #category : #initialization } -PBTestCase >> cf [ - ^ self commandFactory -] - -{ #category : #initialization } -PBTestCase >> cfSend [ - ^ promise := self cf send -] - -{ #category : #initialization } -PBTestCase >> commandFactory [ - ^ self application commandFactory -] - -{ #category : #asserting } -PBTestCase >> registryExpression [ - ^ #registry callWith: #() -] - -{ #category : #asserting } -PBTestCase >> resolveId: anId [ - ^ self registryExpression => #resolve callWith: (Array with: anId) -] - -{ #category : #running } -PBTestCase >> setUp [ - super setUp. - self cf reset -] +Class { + #name : #PBTestCase, + #superclass : #TestCase, + #instVars : [ + 'commandFactory', + 'promise' + ], + #category : #'PythonBridge-Tests' +} + +{ #category : #accessing } +PBTestCase class >> appResource [ + self subclassResponsibility +] + +{ #category : #accessing } +PBTestCase class >> resources [ + ^ super resources , (Array with: self appResource) +] + +{ #category : #initialization } +PBTestCase >> app [ + ^ self application +] + +{ #category : #initialization } +PBTestCase >> application [ + ^ self applicationClass uniqueInstance +] + +{ #category : #initialization } +PBTestCase >> applicationClass [ + self subclassResponsibility +] + +{ #category : #asserting } +PBTestCase >> assertClass: cls name: aName [ + self cf << (cls => #__name__). + self assert: self cf send waitForValue equals: aName +] + +{ #category : #asserting } +PBTestCase >> assertExpression: expr equals: aBlockOrValue [ + self cf << expr. + self assert: self cf send waitForValue equals: aBlockOrValue value +] + +{ #category : #asserting } +PBTestCase >> assertInstanceClass: obj name: aName [ + self cf << ((#type asP3GI callWith: (Array with: obj)) => #__name__). + self assert: self cf send waitForValue equals: aName +] + +{ #category : #initialization } +PBTestCase >> cf [ + ^ self commandFactory +] + +{ #category : #initialization } +PBTestCase >> cfSend [ + ^ promise := self cf send +] + +{ #category : #initialization } +PBTestCase >> commandFactory [ + ^ self application commandFactory +] + +{ #category : #asserting } +PBTestCase >> registryExpression [ + ^ #registry callWith: #() +] + +{ #category : #asserting } +PBTestCase >> resolveId: anId [ + ^ self registryExpression => #resolve callWith: (Array with: anId) +] + +{ #category : #running } +PBTestCase >> setUp [ + super setUp. + self cf reset +] diff --git a/src/PythonBridge/PBUiManager.class.st b/src/PythonBridge/PBUiManager.class.st index 9ddf317..536b455 100644 --- a/src/PythonBridge/PBUiManager.class.st +++ b/src/PythonBridge/PBUiManager.class.st @@ -1,15 +1,15 @@ -Class { - #name : #PBUiManager, - #superclass : #Object, - #category : #'PythonBridge-Platform' -} - -{ #category : #hooks } -PBUiManager >> notify: aString [ - self subclassResponsibility -] - -{ #category : #hooks } -PBUiManager >> spawnDebuggerOnException: anException [ - self subclassResponsibility -] +Class { + #name : #PBUiManager, + #superclass : #Object, + #category : #'PythonBridge-Platform' +} + +{ #category : #hooks } +PBUiManager >> notify: aString [ + self subclassResponsibility +] + +{ #category : #hooks } +PBUiManager >> spawnDebuggerOnException: anException [ + self subclassResponsibility +] diff --git a/src/PythonBridge/PBUpdatePromiseMessage.class.st b/src/PythonBridge/PBUpdatePromiseMessage.class.st index 70a0e35..55ead90 100644 --- a/src/PythonBridge/PBUpdatePromiseMessage.class.st +++ b/src/PythonBridge/PBUpdatePromiseMessage.class.st @@ -1,31 +1,31 @@ -Class { - #name : #PBUpdatePromiseMessage, - #superclass : #PBRAsyncMessage, - #instVars : [ - 'promiseId', - 'value' - ], - #category : #'PythonBridge-Platform-Messages' -} - -{ #category : #accessing } -PBUpdatePromiseMessage class >> type [ - ^ #EVAL -] - -{ #category : #'as yet unclassified' } -PBUpdatePromiseMessage >> privateDecode: dict [ - super privateDecode: dict. - promiseId := dict at: #id. - value := dict at: #value -] - -{ #category : #accessing } -PBUpdatePromiseMessage >> promiseId [ - ^ promiseId -] - -{ #category : #accessing } -PBUpdatePromiseMessage >> value [ - ^ value -] +Class { + #name : #PBUpdatePromiseMessage, + #superclass : #PBRAsyncMessage, + #instVars : [ + 'promiseId', + 'value' + ], + #category : #'PythonBridge-Platform-Messages' +} + +{ #category : #accessing } +PBUpdatePromiseMessage class >> type [ + ^ #EVAL +] + +{ #category : #'as yet unclassified' } +PBUpdatePromiseMessage >> privateDecode: dict [ + super privateDecode: dict. + promiseId := dict at: #id. + value := dict at: #value +] + +{ #category : #accessing } +PBUpdatePromiseMessage >> promiseId [ + ^ promiseId +] + +{ #category : #accessing } +PBUpdatePromiseMessage >> value [ + ^ value +] diff --git a/src/PythonBridge/PBUtils.class.st b/src/PythonBridge/PBUtils.class.st index cd3eb86..0403a13 100644 --- a/src/PythonBridge/PBUtils.class.st +++ b/src/PythonBridge/PBUtils.class.st @@ -1,15 +1,15 @@ -Class { - #name : #PBUtils, - #superclass : #Object, - #category : #'PythonBridge-Core' -} - -{ #category : #'instance creation' } -PBUtils class >> newP3Variable [ - ^ self newP3VariableName asP3GI -] - -{ #category : #'instance creation' } -PBUtils class >> newP3VariableName [ - ^ PBPlatform current newRandomName -] +Class { + #name : #PBUtils, + #superclass : #Object, + #category : #'PythonBridge-Core' +} + +{ #category : #'instance creation' } +PBUtils class >> newP3Variable [ + ^ self newP3VariableName asP3GI +] + +{ #category : #'instance creation' } +PBUtils class >> newP3VariableName [ + ^ PBPlatform current newRandomName +] diff --git a/src/PythonBridge/PBWeakFinalizerTest.class.st b/src/PythonBridge/PBWeakFinalizerTest.class.st index 9a4443e..6648dd2 100644 --- a/src/PythonBridge/PBWeakFinalizerTest.class.st +++ b/src/PythonBridge/PBWeakFinalizerTest.class.st @@ -1,104 +1,104 @@ -Class { - #name : #PBWeakFinalizerTest, - #superclass : #TestCase, - #instVars : [ - 'weakRegistry', - 'assertCounter' - ], - #category : #'PythonBridge-Platform' -} - -{ #category : #testing } -PBWeakFinalizerTest class >> isAbstract [ - ^ self == PBWeakFinalizerTest -] - -{ #category : #running } -PBWeakFinalizerTest >> assertCount: anInteger [ - self assert: assertCounter equals: anInteger -] - -{ #category : #running } -PBWeakFinalizerTest >> countFinalizer [ - ^ PBBlockFinalizer block: [ assertCounter := assertCounter + 1 ] -] - -{ #category : #running } -PBWeakFinalizerTest >> setUp [ - super setUp. - weakRegistry := self weakRegistryClass new. - assertCounter := 0 -] - -{ #category : #running } -PBWeakFinalizerTest >> tearDown [ - weakRegistry destroy. - super tearDown -] - -{ #category : #running } -PBWeakFinalizerTest >> testBlockFinalizer [ - self assertCount: 0. - self countFinalizer finalize. - self assertCount: 1 -] - -{ #category : #running } -PBWeakFinalizerTest >> testDestroy [ - | obj | - obj := Object new. - weakRegistry registerObject: obj finalizer: self countFinalizer. - weakRegistry destroy. - obj := nil. - self triggerGC. - self assertCount: 0 -] - -{ #category : #running } -PBWeakFinalizerTest >> testGcMultObjects [ - | obj1 obj2 obj3 | - obj1 := Object new. - obj2 := Object new. - obj3 := Object new. - weakRegistry registerObject: obj1 finalizer: self countFinalizer. - weakRegistry registerObject: obj2 finalizer: self countFinalizer. - obj1 := nil. - self triggerGC. - self assertCount: 1. - weakRegistry registerObject: obj3 finalizer: self countFinalizer. - self triggerGC. - self assertCount: 1. - obj2 := nil. - obj3 := nil. - self triggerGC. - self assertCount: 3 -] - -{ #category : #running } -PBWeakFinalizerTest >> testGcObject [ - | obj | - obj := Object new. - weakRegistry registerObject: obj finalizer: self countFinalizer. - obj := nil. - self triggerGC. - self assertCount: 1 -] - -{ #category : #running } -PBWeakFinalizerTest >> testNotGcObject [ - | obj | - obj := Object new. - weakRegistry registerObject: obj finalizer: self countFinalizer. - self triggerGC. - self assertCount: 0 -] - -{ #category : #running } -PBWeakFinalizerTest >> triggerGC [ - self subclassResponsibility -] - -{ #category : #running } -PBWeakFinalizerTest >> weakRegistryClass [ - self subclassResponsibility -] +Class { + #name : #PBWeakFinalizerTest, + #superclass : #TestCase, + #instVars : [ + 'weakRegistry', + 'assertCounter' + ], + #category : #'PythonBridge-Platform' +} + +{ #category : #testing } +PBWeakFinalizerTest class >> isAbstract [ + ^ self == PBWeakFinalizerTest +] + +{ #category : #running } +PBWeakFinalizerTest >> assertCount: anInteger [ + self assert: assertCounter equals: anInteger +] + +{ #category : #running } +PBWeakFinalizerTest >> countFinalizer [ + ^ PBBlockFinalizer block: [ assertCounter := assertCounter + 1 ] +] + +{ #category : #running } +PBWeakFinalizerTest >> setUp [ + super setUp. + weakRegistry := self weakRegistryClass new. + assertCounter := 0 +] + +{ #category : #running } +PBWeakFinalizerTest >> tearDown [ + weakRegistry destroy. + super tearDown +] + +{ #category : #running } +PBWeakFinalizerTest >> testBlockFinalizer [ + self assertCount: 0. + self countFinalizer finalize. + self assertCount: 1 +] + +{ #category : #running } +PBWeakFinalizerTest >> testDestroy [ + | obj | + obj := Object new. + weakRegistry registerObject: obj finalizer: self countFinalizer. + weakRegistry destroy. + obj := nil. + self triggerGC. + self assertCount: 0 +] + +{ #category : #running } +PBWeakFinalizerTest >> testGcMultObjects [ + | obj1 obj2 obj3 | + obj1 := Object new. + obj2 := Object new. + obj3 := Object new. + weakRegistry registerObject: obj1 finalizer: self countFinalizer. + weakRegistry registerObject: obj2 finalizer: self countFinalizer. + obj1 := nil. + self triggerGC. + self assertCount: 1. + weakRegistry registerObject: obj3 finalizer: self countFinalizer. + self triggerGC. + self assertCount: 1. + obj2 := nil. + obj3 := nil. + self triggerGC. + self assertCount: 3 +] + +{ #category : #running } +PBWeakFinalizerTest >> testGcObject [ + | obj | + obj := Object new. + weakRegistry registerObject: obj finalizer: self countFinalizer. + obj := nil. + self triggerGC. + self assertCount: 1 +] + +{ #category : #running } +PBWeakFinalizerTest >> testNotGcObject [ + | obj | + obj := Object new. + weakRegistry registerObject: obj finalizer: self countFinalizer. + self triggerGC. + self assertCount: 0 +] + +{ #category : #running } +PBWeakFinalizerTest >> triggerGC [ + self subclassResponsibility +] + +{ #category : #running } +PBWeakFinalizerTest >> weakRegistryClass [ + self subclassResponsibility +] diff --git a/src/PythonBridge/SequenceableCollection.extension.st b/src/PythonBridge/SequenceableCollection.extension.st index 2222b1d..31137fd 100644 --- a/src/PythonBridge/SequenceableCollection.extension.st +++ b/src/PythonBridge/SequenceableCollection.extension.st @@ -1,11 +1,11 @@ -Extension { #name : #SequenceableCollection } - -{ #category : #'*PythonBridge' } -SequenceableCollection >> isPythonGenerable [ - ^ true -] - -{ #category : #'*PythonBridge' } -SequenceableCollection >> isPythonValue [ - ^ true -] +Extension { #name : #SequenceableCollection } + +{ #category : #'*PythonBridge' } +SequenceableCollection >> isPythonGenerable [ + ^ true +] + +{ #category : #'*PythonBridge' } +SequenceableCollection >> isPythonValue [ + ^ true +] diff --git a/src/PythonBridge/Set.extension.st b/src/PythonBridge/Set.extension.st index 3f0a8eb..d5b9ce6 100644 --- a/src/PythonBridge/Set.extension.st +++ b/src/PythonBridge/Set.extension.st @@ -1,11 +1,11 @@ -Extension { #name : #Set } - -{ #category : #'*PythonBridge' } -Set >> isPythonGenerable [ - ^ true -] - -{ #category : #'*PythonBridge' } -Set >> isPythonValue [ - ^ true -] +Extension { #name : #Set } + +{ #category : #'*PythonBridge' } +Set >> isPythonGenerable [ + ^ true +] + +{ #category : #'*PythonBridge' } +Set >> isPythonValue [ + ^ true +] diff --git a/src/PythonBridge/True.extension.st b/src/PythonBridge/True.extension.st index 07f7eb6..fe1ad98 100644 --- a/src/PythonBridge/True.extension.st +++ b/src/PythonBridge/True.extension.st @@ -1,11 +1,11 @@ -Extension { #name : #True } - -{ #category : #'*PythonBridge' } -True >> isPythonGenerable [ - ^ true -] - -{ #category : #'*PythonBridge' } -True >> isPythonValue [ - ^ true -] +Extension { #name : #True } + +{ #category : #'*PythonBridge' } +True >> isPythonGenerable [ + ^ true +] + +{ #category : #'*PythonBridge' } +True >> isPythonValue [ + ^ true +] diff --git a/src/PythonBridge/UndefinedObject.extension.st b/src/PythonBridge/UndefinedObject.extension.st index 9c1b225..a2af7d4 100644 --- a/src/PythonBridge/UndefinedObject.extension.st +++ b/src/PythonBridge/UndefinedObject.extension.st @@ -1,11 +1,11 @@ -Extension { #name : #UndefinedObject } - -{ #category : #'*PythonBridge' } -UndefinedObject >> isPythonGenerable [ - ^ true -] - -{ #category : #'*PythonBridge' } -UndefinedObject >> isPythonValue [ - ^ true -] +Extension { #name : #UndefinedObject } + +{ #category : #'*PythonBridge' } +UndefinedObject >> isPythonGenerable [ + ^ true +] + +{ #category : #'*PythonBridge' } +UndefinedObject >> isPythonValue [ + ^ true +] diff --git a/src/PythonBridge/package.st b/src/PythonBridge/package.st index 45fd065..3f3c901 100644 --- a/src/PythonBridge/package.st +++ b/src/PythonBridge/package.st @@ -1 +1 @@ -Package { #name : #PythonBridge } +Package { #name : #PythonBridge } From 0d579015624d1e404f9cb064fd3d172157dea125 Mon Sep 17 00:00:00 2001 From: bergel Date: Wed, 22 Jan 2020 19:41:07 -0300 Subject: [PATCH 12/34] --- src/PythonBridge-Pharo/SocketStream.extension.st | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PythonBridge-Pharo/SocketStream.extension.st b/src/PythonBridge-Pharo/SocketStream.extension.st index 311344a..2bef881 100644 --- a/src/PythonBridge-Pharo/SocketStream.extension.st +++ b/src/PythonBridge-Pharo/SocketStream.extension.st @@ -32,8 +32,8 @@ SocketStream >> uint16: anInteger [ (anInteger < 0 or: [ anInteger >= 16r10000 ]) ifTrue: [ self error: 'outside unsigned 16-bit integer range' ]. - self nextPut: (anInteger digitAt: 2). - self nextPut: (anInteger digitAt: 1) + self nextPut: (anInteger byteAt: 2). + self nextPut: (anInteger byteAt: 1) ] { #category : #'*PythonBridge-Pharo' } From 133210a33ac9fa882fcc0d56b76017bb17bc3624 Mon Sep 17 00:00:00 2001 From: Alexandre Bergel Date: Wed, 22 Jan 2020 19:45:52 -0300 Subject: [PATCH 13/34] Update pharo-installation.md --- docs/pages/pharo-installation.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/pages/pharo-installation.md b/docs/pages/pharo-installation.md index a86bdba..fbab666 100644 --- a/docs/pages/pharo-installation.md +++ b/docs/pages/pharo-installation.md @@ -105,7 +105,12 @@ which pipenv ``` Then you must set this path in PythonBridge by running the following script in a Playground: ```smalltalk -PBPipenvPyStrategy pipEnvPath: '/PATH/TO/PIPENV/BINARY' +PBPharoPipenvProcess pipenvPath: '/PATH/TO/PIPENV/BINARY' +``` + +An example of this command could be: +```Smalltalk +PBPharoPipenvProcess pipenvPath: '/Library/Frameworks/Python.framework/Versions/3.7/bin/pipenv' ``` ### Executing PythonBridge in Windows From 064dad41230476bf21d834b243b04bf84a8aafd2 Mon Sep 17 00:00:00 2001 From: Alexandre Bergel Date: Thu, 26 Mar 2020 22:42:42 -0300 Subject: [PATCH 14/34] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 30c4864..a972a6f 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,8 @@ Depending on the internet connection, the script could take a couple of minutes A more in depth guide is present on the official website of this project https://objectprofile.github.io/PythonBridge/. +[Video installation for VisualWorks](https://vimeo.com/401190276) + # Simple test Evaluating the following code in a playground should return `3`: From 38a286d643a416151bdfa4d650d0646b0f038197 Mon Sep 17 00:00:00 2001 From: Alexandre Bergel Date: Thu, 26 Mar 2020 23:17:55 -0300 Subject: [PATCH 15/34] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a972a6f..3de01fd 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Depending on the internet connection, the script could take a couple of minutes A more in depth guide is present on the official website of this project https://objectprofile.github.io/PythonBridge/. -[Video installation for VisualWorks](https://vimeo.com/401190276) +[Video installation for VisualWorks](https://vimeo.com/401196404) # Simple test From 80e9ec0aa551b12058edbcd54f7fd8fb91993c78 Mon Sep 17 00:00:00 2001 From: Alexandre Bergel Date: Mon, 13 Apr 2020 16:24:09 -0400 Subject: [PATCH 16/34] Update vw-installation.md --- docs/pages/vw-installation.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/pages/vw-installation.md b/docs/pages/vw-installation.md index 3532333..4229fad 100644 --- a/docs/pages/vw-installation.md +++ b/docs/pages/vw-installation.md @@ -91,6 +91,10 @@ To create the link you need to execute the following in a shell with ADMINISTRAT mklink /D PythonBridge . ``` +## Update the path of Pipenv +The method `PBVwProcess>>start` contains a hardcoded path to `pipenv.exe`. Update it to the correct path. + + ## Test your installation From 572826ded870cb903c261f5da83f57631b92fb53 Mon Sep 17 00:00:00 2001 From: Alexandre Bergel Date: Fri, 17 Apr 2020 15:46:17 -0400 Subject: [PATCH 17/34] Update pythonCommands.md --- docs/pages/pythonCommands.md | 83 +++++++++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 5 deletions(-) diff --git a/docs/pages/pythonCommands.md b/docs/pages/pythonCommands.md index 774f142..7f6c56f 100644 --- a/docs/pages/pythonCommands.md +++ b/docs/pages/pythonCommands.md @@ -25,7 +25,7 @@ The python statements are created in Pharo by using [Python3Generator](https://g #### Attribute accessing Python objects instance variables and methods are accessible in Python by operator `.`. From Pharo, this operator is defined using `=>` and allow accessing instance variables and invoking methods. ```smalltalk -foo asP3GI => #a "foo.a" +#foo asP3GI => #a "foo.a" ``` #### Method and function invoking @@ -33,12 +33,12 @@ Python functions and methods are called by using `callWith:` and `callWith:with: The `callWith:` method receive as argument a collection of objects which corresponds to the positional arguments of the call. ```smalltalk -foo asP3GI callWith: #(1 2 3) "foo(1,2,3)" +#foo asP3GI callWith: #(1 2 3) "foo(1,2,3)" ``` The `callWith:with:` method receives as first agument a collection of positional arguments and, as second argument, a dictionary of named arguments. ```smalltalk -foo asP3GI +#foo asP3GI callWith: #(1 2 3) with: { #nameArg1 -> 'bar'. @@ -52,14 +52,87 @@ Assignments in python allow you to store objects in globals, temporary variables Assigning the temporary variable `w` with the array `[1,2,3]`. ```smalltalk -foo asP3GI <- #(1 2 3) "foo = [1,2,3]" +#foo asP3GI <- #(1 2 3) "foo = [1,2,3]" ``` Assigning instance variable `a` from object in variable `foo` with the string `'bar'`. ```smalltalk -(foo asP3GI => #a) <- 'bar' "foo.a = 'bar'" +(#foo asP3GI => #a) <- 'bar' "foo.a = 'bar'" ``` + +## Importing an External Module + +PythonBridge can interact with any python modules. Consider the `numpy` Python module, which essential in scientific computing. We will perform the following Python instruction within Smalltalk: `numpy.arange(15).reshape(3, 5)` + +First, we need to augment the Pipenv environment with the `numpy` module. You can simply do it by modifying the `Pipfile` by adding the line `numpy = "*"`. The complete `Pipfile` should be: + +``` +[[source]] +name = "pypi" +url = "https://pypi.org/simple" +verify_ssl = true + +[dev-packages] + +[packages] +flask = "*" +requests = "*" +msgpack = "*" +numpy = "*" + +[requires] +python_version = "3" +``` + +Once the `Pipfile` file modified, the pipenv environment must be upgraded, which can be done using the command line: +``` +pipenv update +``` + +You should see something like: +``` +➜ PythonBridge git:(master) ✗ pipenv update +Running $ pipenv lock then $ pipenv sync. +Locking [dev-packages] dependencies… +Locking [packages] dependencies… +✔ Success! +Updated Pipfile.lock (deca6d)! +Installing dependencies from Pipfile.lock (deca6d)… + 🐍 ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 14/14 — 00:00:07 +To activate this project's virtualenv, run pipenv shell. +Alternatively, run a command inside the virtualenv with pipenv run. +All dependencies are now up-to-date! +``` + +Numpy is now installed in your Pipenv environment, and it is ready to be used from Smalltalk. You can do + +```Smalltalk +PBApplication do: [ + "We import the numpy module" + PBCF << (P3GImport moduleIdentifier: #numpy asP3GI). + + "We construct the Python expression numpy.arange(15).reshape(3, 5)" + r := P3GCall target: (#numpy asP3GI => #arange) positionalArguments: #(15). + PBCF << (P3GCall target: r => #reshape positionalArguments: #(3 5)). + s := PBCF send waitForValue. + + "The variable s points to a Smalltalk wrapper of the Python object" + "We simply execute the Python expression str(s) to obtain a string that represents the numpy object" + PBCF << (P3GCall target: #str asP3GI positionalArguments: { s }). + PBCF send waitForValue. + ]. +``` + +Printing this expression will give: +```Python +[[ 0 1 2 3 4] + [ 5 6 7 8 9] + [10 11 12 13 14]] +``` + +This small example shows how you can augment the Pipenv environment with a new Python module, and how you can access it from Smalltalk. + ## Command Factory Each PythonBridge extension defines its own CommandFactory as a global object. In the case of PythonBridge it's called `PBCF` and in KerasBridge is called `KCF`. From 99a703d5c915ad85a3e7f043ebd2f35ab87dbf5c Mon Sep 17 00:00:00 2001 From: Alexandre Bergel Date: Fri, 17 Apr 2020 15:46:49 -0400 Subject: [PATCH 18/34] Update pythonCommands.md --- docs/pages/pythonCommands.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/pythonCommands.md b/docs/pages/pythonCommands.md index 7f6c56f..a96e3ff 100644 --- a/docs/pages/pythonCommands.md +++ b/docs/pages/pythonCommands.md @@ -124,7 +124,7 @@ PBApplication do: [ ]. ``` -Printing this expression will give: +Printing this expression will result in: ```Python [[ 0 1 2 3 4] [ 5 6 7 8 9] From fe4a27ee994abfd7ac5e72d5bdd494346dafc6f0 Mon Sep 17 00:00:00 2001 From: Alexandre Bergel Date: Fri, 17 Apr 2020 22:40:26 -0400 Subject: [PATCH 19/34] Create tutorial01.md --- docs/pages/tutorial01.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 docs/pages/tutorial01.md diff --git a/docs/pages/tutorial01.md b/docs/pages/tutorial01.md new file mode 100644 index 0000000..b7a1b89 --- /dev/null +++ b/docs/pages/tutorial01.md @@ -0,0 +1,39 @@ +# Tutorial + +This tutorial is a gentle introduction to using PythonBridge. It is written for Pharo, however, it works equally well for VisualWorks. + +The tutorial assumes that you have PythonBridge correctly installed in your Smalltalk environment and have Python and Pipenv installed. If this is not the case, then you should follow the instruction given in https://objectprofile.github.io/PythonBridge/ + +## How do I know if Python and Pipenv are correctly installed? +If you have PythonBridge installed, and you do not know if you Python environment is correctly setup, the easy way to check this is evaluate the following expression: + +```Smalltalk +PBApplication do: [ + PBCF << (P3GBinaryOperator new left: 1; right: 2; operator: $+; yourself). + PBCF send waitForValue ] +``` + +If it returns `3`, then your Python setting is properly installed and you can continue the tutorial. If it does not return 3, but raises en error, then you should revise your Python installation. In case you a VisualWorks user, do not forget to manually set the path to `Pipenv.exe` as specified [here](https://objectprofile.github.io/PythonBridge/pages/vw-installation). + +## Installing the OpenCV Python module + +Before jumping into Smalltalk, we need to make sure that the OpenCV Python library is installed in your Pipenv environment before continuing. You need to open a terminal that points to the `PythonBridge` folder, next to your image. Edit the file called `Pipenv` and add the line `opencv-python = "*"` in the `[packages]` section. You `Pipfile` should be very similar to: + +``` +[[source]] +name = "pypi" +url = "https://pypi.org/simple" +verify_ssl = true + +[dev-packages] + +[packages] +flask = "*" +requests = "*" +msgpack = "*" +opencv-python = "*" + +[requires] +python_version = "3" +``` + From 0d7c98822077312bad9140aa9b79be9263b11b24 Mon Sep 17 00:00:00 2001 From: Alexandre Bergel Date: Fri, 17 Apr 2020 22:55:18 -0400 Subject: [PATCH 20/34] Update tutorial01.md --- docs/pages/tutorial01.md | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/docs/pages/tutorial01.md b/docs/pages/tutorial01.md index b7a1b89..9387906 100644 --- a/docs/pages/tutorial01.md +++ b/docs/pages/tutorial01.md @@ -1,6 +1,6 @@ -# Tutorial +# Tutorial: Using OpenCV from Smalltalk -This tutorial is a gentle introduction to using PythonBridge. It is written for Pharo, however, it works equally well for VisualWorks. +This tutorial is a gentle introduction to using PythonBridge using OpenCV. It is written for Pharo, however, it works equally well for VisualWorks. The tutorial assumes that you have PythonBridge correctly installed in your Smalltalk environment and have Python and Pipenv installed. If this is not the case, then you should follow the instruction given in https://objectprofile.github.io/PythonBridge/ @@ -37,3 +37,32 @@ opencv-python = "*" python_version = "3" ``` +You should then update your pipenv environment. To do so, you should simply execute the `pipenv update` expression. You should see something like: + +``` +➜ PythonBridge git:(master) ✗ pipenv update +Running $ pipenv lock then $ pipenv sync. +Locking [dev-packages] dependencies… +Locking [packages] dependencies… +✔ Success! +Updated Pipfile.lock (bc0ce1)! +Installing dependencies from Pipfile.lock (bc0ce1)… + 🐍 ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 14/14 — 00:00:10 +To activate this project's virtualenv, run pipenv shell. +Alternatively, run a command inside the virtualenv with pipenv run. +All dependencies are now up-to-date! +``` + +You can now close your terminal and stay within the confortable world of Smalltalk. We will not have to use the terminal anymore. + +## Your first OpenCV script + +We will first do some scripting to illustrate the essence of PythonBridge. We will then move into defining a proper application, without having the exposition to Python. + +This tutorial is highly inspired from the [OpenCV online tutorial](https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_gui/py_image_display/py_image_display.html). + +```Smalltalk +PBApplication start. +ref := 'c:\Users\infan\Pictures\pic.png' asFilename. +PBCF sendAndWait: #cv2 asP3GI import. +``` From 4e100e947419daa6782a628a726b85ae7441eec5 Mon Sep 17 00:00:00 2001 From: Alexandre Bergel Date: Fri, 17 Apr 2020 23:39:03 -0400 Subject: [PATCH 21/34] Update tutorial01.md --- docs/pages/tutorial01.md | 115 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 2 deletions(-) diff --git a/docs/pages/tutorial01.md b/docs/pages/tutorial01.md index 9387906..3ca915b 100644 --- a/docs/pages/tutorial01.md +++ b/docs/pages/tutorial01.md @@ -59,10 +59,121 @@ You can now close your terminal and stay within the confortable world of Smallta We will first do some scripting to illustrate the essence of PythonBridge. We will then move into defining a proper application, without having the exposition to Python. -This tutorial is highly inspired from the [OpenCV online tutorial](https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_gui/py_image_display/py_image_display.html). +This tutorial will simply open an image using OpenCV. It is highly inspired from the [OpenCV online tutorial](https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_gui/py_image_display/py_image_display.html). +PythonBridge needs to launch a Python virtual machine and establish a communication channel to it. This is simply done using: ```Smalltalk PBApplication start. -ref := 'c:\Users\infan\Pictures\pic.png' asFilename. +``` + +Starting the Python vm may take a few seconds in some cases. The python code we will execute is the following: + +```Python +import cv2 +img = cv2.imread('/Users/alexandrebergel/Desktop/iss.jpg',0) +cv2.imshow('image',img) +cv2.waitKey(0) +cv2.destroyAllWindows() +``` + +I am here assuming spectacular picture from the [ISS](https://www.esa.int/Science_Exploration/Human_and_Robotic_Exploration/International_Space_Station/Where_is_the_International_Space_Station) is available on my desktop, under the name `iss.jpg`. + +We first need to import OpenCV, using: +```Smalltalk PBCF sendAndWait: #cv2 asP3GI import. ``` + +We load the picture using OpenCV: + +```Smalltalk +ref := '/Users/alexandrebergel/Desktop/iss.jpg'. +img := PBCF sendAndWait: (#cv2 asP3GI => #imread callWith: (Array with: filename)). +``` + +If you print (in Smalltalk), the variable `img` you should see `a ndarray (Proxy)`. OpenCV handle the picture as a numpy structure. Within Smalltalk, we only see a proxy as the image is living within the Python World. Note that we are using the `sendAndWait:` instruction as we wait for the completion of the Python import. + +We can now open the image using: + +```Smalltalk +PBCF send: (#cv2 asP3GI => #imshow callWith: (Array with: 'image' with: img)). +PBCF send: (#cv2 asP3GI => #waitKey callWith: (Array with: 0)). +PBCF send: (#cv2 asP3GI => #destroyAllWindows callWith: (Array new)). +``` + +Note that we simply use `send:` to send the Python commands, as there is no need to wait for their completion. + +We can now close the Python connection: +```Smalltalk +PBApplication stop. +``` + +In theory, there should not be a need to shutdown the Python VM, however, due to a limitation of OpenCV in the way it handles the windows, it is simpler to do so. + +## Applying transformation to an image + +We can apply the OpenCV `cvtColor` [operation](https://docs.opencv.org/2.4/modules/imgproc/doc/miscellaneous_transformations.html#cvtcolor). We will turn a colored picture into gray using an adequate [transformation](https://docs.opencv.org/master/de/d25/imgproc_color_conversions.html#color_convert_rgb_gray). + +The complete script is: + +```Smalltalk +PBApplication start. +filename := '/Users/alexandrebergel/Desktop/iss.jpg'. +PBCF sendAndWait: #cv2 asP3GI import. +img := PBCF sendAndWait: (#cv2 asP3GI => #imread callWith: (Array with: filename)). +gray := PBCF sendAndWait: (#cv2 asP3GI => #cvtColor callWith: (Array with: img with: #cv2 asP3GI => #COLOR_BGR2GRAY)). + +PBCF send: (#cv2 asP3GI => #imshow callWith: (Array with: 'image' with: gray)). +PBCF send: (#cv2 asP3GI => #waitKey callWith: (Array with: 0)). +PBCF send: (#cv2 asP3GI => #destroyAllWindows callWith: (Array new)). + +PBApplication stop. +``` + +## Turning your script into an application + +Obviously, you do not wish to directly face the Python scripting instruction. You can easily turn the script into a small class, titled `ImageViewer`: + +```Smalltalk +Object subclass: #ImageViewer + instanceVariableNames: 'filename' + classVariableNames: '' + package: 'OpenCVExample' +``` + +An accessor to set the image filename: +```Smalltalk +ImageViewer>>filename: aString + filename := aString +``` + +The `show` methods to display the image: + +```Smalltalk +ImageViewer>>show + | img | + PBApplication start. + PBCF sendAndWait: #cv2 asP3GI import. + img := PBCF sendAndWait: (#cv2 asP3GI => #imread callWith: (Array with: filename)). + PBCF send: (#cv2 asP3GI => #imshow callWith: (Array with: 'image' with: img)). + PBCF send: (#cv2 asP3GI => #waitKey callWith: (Array with: 0)). + PBCF send: (#cv2 asP3GI => #destroyAllWindows callWith: (Array new)). + ``` + + And to close the image: +```Smalltalk +ImageViewer>>delete + PBApplication stop +``` + +You can now simply execute the following Smalltalk script, line by line: +```Smalltalk +v := ImageViewer new filename: '/Users/alexandrebergel/Desktop/iss.jpg'. +v show. +v delete +``` + +## What have we seen? + +This short tutorial covers the basic functionalities of our bridge. We used an external Python modules within Smalltalk, and called a few Python functions within Pharo. We then wrapped our application into Smalltalk code to completely hide the Python code construction. + +Have fun! From 8314e376fbb45c815e3256ffebb89e9581604f11 Mon Sep 17 00:00:00 2001 From: Alexandre Bergel Date: Fri, 17 Apr 2020 23:40:20 -0400 Subject: [PATCH 22/34] Update tutorial01.md --- docs/pages/tutorial01.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/pages/tutorial01.md b/docs/pages/tutorial01.md index 3ca915b..265eb92 100644 --- a/docs/pages/tutorial01.md +++ b/docs/pages/tutorial01.md @@ -1,8 +1,6 @@ # Tutorial: Using OpenCV from Smalltalk -This tutorial is a gentle introduction to using PythonBridge using OpenCV. It is written for Pharo, however, it works equally well for VisualWorks. - -The tutorial assumes that you have PythonBridge correctly installed in your Smalltalk environment and have Python and Pipenv installed. If this is not the case, then you should follow the instruction given in https://objectprofile.github.io/PythonBridge/ +This tutorial is a gentle introduction to PythonBridge. We use OpenCV as the running example. The tutorial assumes that you have PythonBridge correctly installed in your Smalltalk environment and have Python and Pipenv installed. If this is not the case, then you should follow the instruction given in https://objectprofile.github.io/PythonBridge/ ## How do I know if Python and Pipenv are correctly installed? If you have PythonBridge installed, and you do not know if you Python environment is correctly setup, the easy way to check this is evaluate the following expression: From 9858178b3499663c2ba273afc0a1a76549948c85 Mon Sep 17 00:00:00 2001 From: Alexandre Bergel Date: Fri, 17 Apr 2020 23:41:52 -0400 Subject: [PATCH 23/34] Update tutorial01.md --- docs/pages/tutorial01.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/pages/tutorial01.md b/docs/pages/tutorial01.md index 265eb92..5885831 100644 --- a/docs/pages/tutorial01.md +++ b/docs/pages/tutorial01.md @@ -35,7 +35,8 @@ opencv-python = "*" python_version = "3" ``` -You should then update your pipenv environment. To do so, you should simply execute the `pipenv update` expression. You should see something like: +Note that you should leave the packages `flask`, `requests`, `msgpack` as they are used by the PythonBridge itself to operate. +Now that we edited the `Pipenv` file, you should then update your pipenv environment. To do so, simply execute the `pipenv update` expression. You should see something like: ``` ➜ PythonBridge git:(master) ✗ pipenv update From fc9f40e12d0bac716db1341213d31b30943ca033 Mon Sep 17 00:00:00 2001 From: Alexandre Bergel Date: Fri, 17 Apr 2020 23:45:33 -0400 Subject: [PATCH 24/34] Update tutorial01.md --- docs/pages/tutorial01.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/pages/tutorial01.md b/docs/pages/tutorial01.md index 5885831..038d53c 100644 --- a/docs/pages/tutorial01.md +++ b/docs/pages/tutorial01.md @@ -65,7 +65,7 @@ PythonBridge needs to launch a Python virtual machine and establish a communicat PBApplication start. ``` -Starting the Python vm may take a few seconds in some cases. The python code we will execute is the following: +Starting the Python Virtual Machine (VM) may take a few seconds in some cases. The python code we will execute is the following: ```Python import cv2 @@ -89,7 +89,7 @@ ref := '/Users/alexandrebergel/Desktop/iss.jpg'. img := PBCF sendAndWait: (#cv2 asP3GI => #imread callWith: (Array with: filename)). ``` -If you print (in Smalltalk), the variable `img` you should see `a ndarray (Proxy)`. OpenCV handle the picture as a numpy structure. Within Smalltalk, we only see a proxy as the image is living within the Python World. Note that we are using the `sendAndWait:` instruction as we wait for the completion of the Python import. +If you print (in Smalltalk), the variable `img` you should see `a ndarray (Proxy)`. OpenCV handles the picture as a numpy structure. Within Smalltalk, we only see a proxy since the image is living within the Python World. Note that we are using the `sendAndWait:` instruction as we wait for the completion of the Python import. We can now open the image using: @@ -106,7 +106,7 @@ We can now close the Python connection: PBApplication stop. ``` -In theory, there should not be a need to shutdown the Python VM, however, due to a limitation of OpenCV in the way it handles the windows, it is simpler to do so. +In theory, we should not need to shutdown the Python VM, however, due to a limitation of OpenCV in the way it handles the windows, it is simpler to do so. ## Applying transformation to an image @@ -130,7 +130,7 @@ PBApplication stop. ## Turning your script into an application -Obviously, you do not wish to directly face the Python scripting instruction. You can easily turn the script into a small class, titled `ImageViewer`: +Obviously, you do not wish to directly face the Python scripting instruction. You can easily turn the script into a small class, titled `ImageViewer`, to completely hide the Python instructions: ```Smalltalk Object subclass: #ImageViewer @@ -156,9 +156,9 @@ ImageViewer>>show PBCF send: (#cv2 asP3GI => #imshow callWith: (Array with: 'image' with: img)). PBCF send: (#cv2 asP3GI => #waitKey callWith: (Array with: 0)). PBCF send: (#cv2 asP3GI => #destroyAllWindows callWith: (Array new)). - ``` +``` - And to close the image: +And to close the image: ```Smalltalk ImageViewer>>delete PBApplication stop From fe4f9703c9b9f4cf3949e0f4a91d47353a2861c1 Mon Sep 17 00:00:00 2001 From: Alexandre Bergel Date: Mon, 20 Apr 2020 21:04:06 -0400 Subject: [PATCH 25/34] Update faq.md --- docs/pages/faq.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/faq.md b/docs/pages/faq.md index b4148da..5caecf9 100644 --- a/docs/pages/faq.md +++ b/docs/pages/faq.md @@ -8,4 +8,4 @@ nav_order: 10 # Configuration {: .no_toc } -Section under work... \ No newline at end of file +Section under construction From 9c48f10ceed87e44bbadf228494346647dce5806 Mon Sep 17 00:00:00 2001 From: Alexandre Bergel Date: Mon, 20 Apr 2020 21:06:09 -0400 Subject: [PATCH 26/34] Update tutorial01.md --- docs/pages/tutorial01.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/pages/tutorial01.md b/docs/pages/tutorial01.md index 038d53c..7252bc3 100644 --- a/docs/pages/tutorial01.md +++ b/docs/pages/tutorial01.md @@ -1,4 +1,18 @@ +--- +layout: default +permalink: /pages/vw-installation +title: Visual Works Installation +nav_order: 3 +--- + # Tutorial: Using OpenCV from Smalltalk +{: .no_toc } + +## Table of contents +{: .no_toc .text-delta } + +1. TOC +{:toc} This tutorial is a gentle introduction to PythonBridge. We use OpenCV as the running example. The tutorial assumes that you have PythonBridge correctly installed in your Smalltalk environment and have Python and Pipenv installed. If this is not the case, then you should follow the instruction given in https://objectprofile.github.io/PythonBridge/ From 3311c03c73a8443c81a781c869d0ac6ae423a03d Mon Sep 17 00:00:00 2001 From: Alexandre Bergel Date: Mon, 20 Apr 2020 21:09:40 -0400 Subject: [PATCH 27/34] Update tutorial01.md --- docs/pages/tutorial01.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/pages/tutorial01.md b/docs/pages/tutorial01.md index 7252bc3..bf43b8c 100644 --- a/docs/pages/tutorial01.md +++ b/docs/pages/tutorial01.md @@ -1,7 +1,7 @@ --- layout: default -permalink: /pages/vw-installation -title: Visual Works Installation +permalink: /pages/tutorial01 +title: Tutorial: Using OpenCV from Smalltalk nav_order: 3 --- From d3e25ea0b7f914c1a6032355f37aa096bb918241 Mon Sep 17 00:00:00 2001 From: Alexandre Bergel Date: Mon, 20 Apr 2020 21:13:35 -0400 Subject: [PATCH 28/34] Update pythonCommands.md --- docs/pages/pythonCommands.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/pythonCommands.md b/docs/pages/pythonCommands.md index a96e3ff..6e660b0 100644 --- a/docs/pages/pythonCommands.md +++ b/docs/pages/pythonCommands.md @@ -119,7 +119,7 @@ PBApplication do: [ "The variable s points to a Smalltalk wrapper of the Python object" "We simply execute the Python expression str(s) to obtain a string that represents the numpy object" - PBCF << (P3GCall target: #str asP3GI positionalArguments: { s }). + PBCF << (P3GCall target: #str asP3GI positionalArguments: (Array with: s )). PBCF send waitForValue. ]. ``` From acdcb16a3c42d88ab317dbb9e269f33292ffdfd6 Mon Sep 17 00:00:00 2001 From: Alexandre Bergel Date: Mon, 20 Apr 2020 21:18:32 -0400 Subject: [PATCH 29/34] Update tutorial01.md --- docs/pages/tutorial01.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/pages/tutorial01.md b/docs/pages/tutorial01.md index bf43b8c..20b0731 100644 --- a/docs/pages/tutorial01.md +++ b/docs/pages/tutorial01.md @@ -16,6 +16,9 @@ nav_order: 3 This tutorial is a gentle introduction to PythonBridge. We use OpenCV as the running example. The tutorial assumes that you have PythonBridge correctly installed in your Smalltalk environment and have Python and Pipenv installed. If this is not the case, then you should follow the instruction given in https://objectprofile.github.io/PythonBridge/ + + + ## How do I know if Python and Pipenv are correctly installed? If you have PythonBridge installed, and you do not know if you Python environment is correctly setup, the easy way to check this is evaluate the following expression: From b6648ad32bcc2e56351b967740bfac34bb039e7b Mon Sep 17 00:00:00 2001 From: Alexandre Bergel Date: Mon, 20 Apr 2020 21:18:58 -0400 Subject: [PATCH 30/34] Update tutorial01.md --- docs/pages/tutorial01.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/tutorial01.md b/docs/pages/tutorial01.md index 20b0731..d4046b9 100644 --- a/docs/pages/tutorial01.md +++ b/docs/pages/tutorial01.md @@ -14,7 +14,7 @@ nav_order: 3 1. TOC {:toc} -This tutorial is a gentle introduction to PythonBridge. We use OpenCV as the running example. The tutorial assumes that you have PythonBridge correctly installed in your Smalltalk environment and have Python and Pipenv installed. If this is not the case, then you should follow the instruction given in https://objectprofile.github.io/PythonBridge/ +This tutorial is a gentle introduction to PythonBridge. We use OpenCV as the running example. The tutorial assumes that you have PythonBridge correctly installed in your Smalltalk environment and have Python and Pipenv installed. If this is not the case, then you should follow the instruction given in [https://objectprofile.github.io/PythonBridge/](https://objectprofile.github.io/PythonBridge/). From 2c7dcbdb8cca4df6a99711c766da3345ab4092b8 Mon Sep 17 00:00:00 2001 From: Alexandre Bergel Date: Mon, 20 Apr 2020 21:23:52 -0400 Subject: [PATCH 31/34] Update pythonCommands.md --- docs/pages/pythonCommands.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/pythonCommands.md b/docs/pages/pythonCommands.md index 6e660b0..1c037dd 100644 --- a/docs/pages/pythonCommands.md +++ b/docs/pages/pythonCommands.md @@ -119,7 +119,7 @@ PBApplication do: [ "The variable s points to a Smalltalk wrapper of the Python object" "We simply execute the Python expression str(s) to obtain a string that represents the numpy object" - PBCF << (P3GCall target: #str asP3GI positionalArguments: (Array with: s )). + PBCF << (P3GCall target: #str asP3GI positionalArguments: (Array with: s)). PBCF send waitForValue. ]. ``` From 068bdb7d5fdf15b03cb75333f744d4a5347e3929 Mon Sep 17 00:00:00 2001 From: Alexandre Bergel Date: Mon, 20 Apr 2020 21:28:38 -0400 Subject: [PATCH 32/34] Update tutorial01.md --- docs/pages/tutorial01.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/pages/tutorial01.md b/docs/pages/tutorial01.md index d4046b9..f8e28c0 100644 --- a/docs/pages/tutorial01.md +++ b/docs/pages/tutorial01.md @@ -16,8 +16,7 @@ nav_order: 3 This tutorial is a gentle introduction to PythonBridge. We use OpenCV as the running example. The tutorial assumes that you have PythonBridge correctly installed in your Smalltalk environment and have Python and Pipenv installed. If this is not the case, then you should follow the instruction given in [https://objectprofile.github.io/PythonBridge/](https://objectprofile.github.io/PythonBridge/). - - +We produced a video describing this tutorial, available [online](https://vimeo.com/409987849). ## How do I know if Python and Pipenv are correctly installed? If you have PythonBridge installed, and you do not know if you Python environment is correctly setup, the easy way to check this is evaluate the following expression: From 80fd4b5c5f7492e7395c4edf1704e5c1dfe6605a Mon Sep 17 00:00:00 2001 From: Alexandre Bergel Date: Mon, 20 Apr 2020 21:31:14 -0400 Subject: [PATCH 33/34] Update tutorial01.md --- docs/pages/tutorial01.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/tutorial01.md b/docs/pages/tutorial01.md index f8e28c0..bfd80fe 100644 --- a/docs/pages/tutorial01.md +++ b/docs/pages/tutorial01.md @@ -2,7 +2,7 @@ layout: default permalink: /pages/tutorial01 title: Tutorial: Using OpenCV from Smalltalk -nav_order: 3 +nav_order: 5 --- # Tutorial: Using OpenCV from Smalltalk From 729ebfc1948fda006d32e16a8bbd47b864a07144 Mon Sep 17 00:00:00 2001 From: Alexandre Bergel Date: Mon, 20 Apr 2020 21:42:04 -0400 Subject: [PATCH 34/34] removed old architecture --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 329a68c..7c7d90d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,9 +4,9 @@ os: - linux smalltalk: - - Pharo-7.0 - - Pharo64-7.0 - Pharo64-8.0 + - Pharo64-9.0 + python: - 3.6 @@ -33,4 +33,4 @@ matrix: # - script: pipenv run python -m unittest discover tests # os: linux # python: 3.7 - \ No newline at end of file +