Creating methods for create virtual envs with python and PyEnv initialization.

This commit is contained in:
ruidajo 2024-09-09 19:36:22 -05:00
parent 97d50c3a40
commit dafde6dda2

View File

@ -4,17 +4,74 @@ Class {
#instVars : [ #instVars : [
'workingDirectory', 'workingDirectory',
'pyVersion', 'pyVersion',
'pyBinLocation' 'pyBinLocation',
'envs'
], ],
#category : #ExtEnvi #category : #ExtEnvi
} }
{ #category : #'as yet unclassified' } { #category : #accessing }
PyEnv >> initialize [ PyEnv >> createDefaultEnv [
super initialize | 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 [ PyEnv >> python3 [
pyVersion := (GtSubprocessWithInMemoryOutput new pyVersion := (GtSubprocessWithInMemoryOutput new
command: 'python3'; command: 'python3';
@ -31,7 +88,9 @@ PyEnv >> python3 [
{ #category : #accessing } { #category : #accessing }
PyEnv >> workingDirectory [ PyEnv >> workingDirectory [
^ workingDirectory ifNil: [ workingDirectory := (FileLocator documents / 'TempPythonEnv') ensureCreateDirectory ] ^ workingDirectory
ifNil: [ workingDirectory := (FileLocator documents / 'ExtEnviPythonEnv')
ensureCreateDirectory ]
] ]
{ #category : #accessing } { #category : #accessing }