@@ -15,6 +15,11 @@ export interface PyenvConfig extends ResourceConfig {
1515 // TODO: Add option here to use homebrew to install instead. Default to true. Maybe add option to set default values to resource config.
1616}
1717
18+ // pyenv is a real binary on PATH (unlike nvm, which is a sourced shell function), so every
19+ // command that invokes it must set up PATH inline rather than assuming a prior interactive
20+ // shell already sourced the rc lines added by addPyenvInitialization().
21+ export const PYENV_INIT_INLINE = 'export PYENV_ROOT="$HOME/.pyenv"; [ -d "$PYENV_ROOT/bin" ] && export PATH="$PYENV_ROOT/bin:$PATH"; eval "$(pyenv init -)" 2>/dev/null;' ;
22+
1823const defaultConfig : Partial < PyenvConfig > = {
1924 pythonVersions : [ ] ,
2025}
@@ -60,7 +65,7 @@ export class PyenvResource extends Resource<PyenvConfig> {
6065 override async refresh ( ) : Promise < Partial < PyenvConfig > | null > {
6166 const $ = getPty ( ) ;
6267
63- const pyenvVersion = await $ . spawnSafe ( ' pyenv --version' )
68+ const pyenvVersion = await $ . spawnSafe ( ` ${ PYENV_INIT_INLINE } pyenv --version` , { interactive : true } )
6469 if ( pyenvVersion . status === SpawnStatus . ERROR ) {
6570 return null
6671 }
@@ -101,7 +106,7 @@ export class PyenvResource extends Resource<PyenvConfig> {
101106 override async destroy ( ) : Promise < void > {
102107 const $ = getPty ( ) ;
103108
104- await $ . spawn ( ' rm -rf $(pyenv root)' , { interactive : true } ) ;
109+ await $ . spawn ( ` ${ PYENV_INIT_INLINE } rm -rf $(pyenv root)` , { interactive : true } ) ;
105110 await $ . spawn ( 'rm -rf $HOME/.pyenv' ) ;
106111
107112 await FileUtils . removeLineFromStartupFile ( 'export PYENV_ROOT="$HOME/.pyenv"' )
@@ -120,7 +125,7 @@ export class PyenvResource extends Resource<PyenvConfig> {
120125 // TODO: Need to support bash in addition to zsh here
121126 private async isValidInstall ( ) : Promise < boolean > {
122127 const $ = getPty ( ) ;
123- const { data : doctor } = await $ . spawnSafe ( ' pyenv doctor' , { interactive : true } )
128+ const { data : doctor } = await $ . spawnSafe ( ` ${ PYENV_INIT_INLINE } pyenv doctor` , { interactive : true } )
124129 return doctor . includes ( 'Congratulations! You are ready to build pythons!' ) ;
125130 }
126131}
0 commit comments