From dafde6dda27f9d87e4ee1d4391aec528419cae33 Mon Sep 17 00:00:00 2001 From: ruidajo Date: Mon, 9 Sep 2024 19:36:22 -0500 Subject: [PATCH] Creating methods for create virtual envs with python and PyEnv initialization. --- src/ExtEnvi/PyEnv.class.st | 71 ++++++++++++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 6 deletions(-) diff --git a/src/ExtEnvi/PyEnv.class.st b/src/ExtEnvi/PyEnv.class.st index 089c3b4..6da6ca7 100644 --- a/src/ExtEnvi/PyEnv.class.st +++ b/src/ExtEnvi/PyEnv.class.st @@ -4,17 +4,74 @@ Class { #instVars : [ 'workingDirectory', 'pyVersion', - 'pyBinLocation' + 'pyBinLocation', + 'envs' ], #category : #ExtEnvi } -{ #category : #'as yet unclassified' } -PyEnv >> initialize [ - super initialize +{ #category : #accessing } +PyEnv >> createDefaultEnv [ + | temp | + temp := self workingDirectory. + GtSubprocessWithInMemoryOutput new + workingDirectory: temp; + command: 'python3'; + arguments: #('-m' 'venv' './Env/'); + runAndWait; + stdout. + ^ workingDirectory ] -{ #category : #'as yet unclassified' } +{ #category : #accessing } +PyEnv >> createEnv: aDirEnvName in: aLocation [ + self workingDirectory: aLocation. + GtSubprocessWithInMemoryOutput new + workingDirectory: self workingDirectory; + command: 'python3'; + arguments: {'-m' . 'venv' . aDirEnvName}; + runAndWait; + stdout. + envs at: aDirEnvName put: aLocation / aDirEnvName +] + +{ #category : #accessing } +PyEnv >> envs [ + ^ envs ifNil: [ envs := Dictionary new ] +] + +{ #category : #initalization } +PyEnv >> initialize [ + super initialize. + self python3. + self workingDirectory. + self envs. +] + +{ #category : #accessing } +PyEnv >> install: packageName [ + | wd | + wd := self workingDirectory. + ^ wd +] + +{ #category : #accessing } +PyEnv >> install: aPackageName in: anEnvDirName [ + | bins pip | + (envs includesKey: anEnvDirName) + ifFalse: [ InformDebugger inform: 'Env doesn''t exist'. + ^ self ]. + bins := (envs at: anEnvDirName) / 'bin'. + pip := (bins / 'pip') fullName. + ^ GtSubprocessWithInMemoryOutput new + workingDirectory: workingDirectory; + command: pip; + arguments: #('install' 'instaloader'); + runAndWait; + stdout +] + +{ #category : #accessing } PyEnv >> python3 [ pyVersion := (GtSubprocessWithInMemoryOutput new command: 'python3'; @@ -31,7 +88,9 @@ PyEnv >> python3 [ { #category : #accessing } PyEnv >> workingDirectory [ - ^ workingDirectory ifNil: [ workingDirectory := (FileLocator documents / 'TempPythonEnv') ensureCreateDirectory ] + ^ workingDirectory + ifNil: [ workingDirectory := (FileLocator documents / 'ExtEnviPythonEnv') + ensureCreateDirectory ] ] { #category : #accessing }