Skip to content

Commit 158c224

Browse files
committed
Add PBApplication>>installModule:
1 parent f698e35 commit 158c224

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/PythonBridge-Pharo/PBPharoPipenvProcess.class.st

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,36 @@ PBPharoPipenvProcess >> initialize [
106106
self setDefaultEnvironmentVariables
107107
]
108108

109+
{ #category : #utils }
110+
PBPharoPipenvProcess >> installModule: aString in: aPBApplication [
111+
"Install the supplied module using `pipenv run pip install aString`"
112+
| pipenvPath proc arguments stdoutStream stderrStream |
113+
114+
pipenvPath := aPBApplication settings pipenvPath ifNil: [ self class pipenvPath ].
115+
arguments := { 'run'. 'pip'. 'install'. aString. }.
116+
stdoutStream := String new writeStream.
117+
stderrStream := String new writeStream.
118+
proc := OSSUnixSubprocess new
119+
command: pipenvPath fullName;
120+
arguments: arguments;
121+
workingDirectory: aPBApplication workingDirectory fullName;
122+
addAllEnvVariablesFromParentWithoutOverride;
123+
terminateOnShutdown;
124+
redirectStdout;
125+
redirectStderr;
126+
yourself.
127+
environmentVariables associationsDo: [ :assoc |
128+
proc environmentAt: assoc key put: assoc value ].
129+
proc run.
130+
proc
131+
waitForExitPollingEvery: (Delay forMilliseconds: 500)
132+
doing: [ :aProcess :outStream :errStream |
133+
stdoutStream nextPutAll: outStream upToEnd.
134+
stderrStream nextPutAll: errStream upToEnd ].
135+
proc isSuccess ifFalse:
136+
[ self error: 'Unable to install module:', aString asString ].
137+
]
138+
109139
{ #category : #testing }
110140
PBPharoPipenvProcess >> isRunning [
111141
^ process

src/PythonBridge/PBApplication.class.st

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ PBApplication >> initializeHandlers [
180180
executionHandler := PBExecutionHandler application: self
181181
]
182182

183+
{ #category : #utils }
184+
PBApplication >> installModule: aString [
185+
"Install the supplied module using `pipenv run pip install aString`"
186+
187+
PBPharoPipenvProcess new installModule: aString in: self
188+
]
189+
183190
{ #category : #testing }
184191
PBApplication >> isPythonReady [
185192
"Ensures python webserver is ready for receiving commands"

0 commit comments

Comments
 (0)