added function to activate a virtualenv if there is any in the directory of the python files
This commit is contained in:
		
							parent
							
								
									6bf6e6ad1e
								
							
						
					
					
						commit
						bf71ea8fba
					
				| 
						 | 
					@ -38,3 +38,26 @@ let g:ale_fixers = {
 | 
				
			||||||
\   '*': ['remove_trailing_lines', 'trim_whitespace'],
 | 
					\   '*': ['remove_trailing_lines', 'trim_whitespace'],
 | 
				
			||||||
\   'python': ['black', 'add_blank_lines_for_python_control_statements'],
 | 
					\   'python': ['black', 'add_blank_lines_for_python_control_statements'],
 | 
				
			||||||
\}
 | 
					\}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function! LoadVirtualEnv()
 | 
				
			||||||
 | 
					  if filereadable('./.venv/bin/activate')
 | 
				
			||||||
 | 
					    let g:virtualenv_path = getcwd() . '/.venv/bin/python'
 | 
				
			||||||
 | 
					    let g:python3_host_prog = g:virtualenv_path
 | 
				
			||||||
 | 
					    echo "Loaded virtual environment: " . g:virtualenv_path
 | 
				
			||||||
 | 
					  elseif filereadable('./venv/bin/activate')
 | 
				
			||||||
 | 
					    let g:virtualenv_path = getcwd() . '/venv/bin/python'
 | 
				
			||||||
 | 
					    let g:python3_host_prog = g:virtualenv_path
 | 
				
			||||||
 | 
					    echo "Loaded virtual environment: " . g:virtualenv_path
 | 
				
			||||||
 | 
					  else
 | 
				
			||||||
 | 
					    " If no virtualenv is found, fall back to the default Python
 | 
				
			||||||
 | 
					    " Check if variables exist before unsetting them
 | 
				
			||||||
 | 
					    if exists('g:virtualenv_path')
 | 
				
			||||||
 | 
					      unlet g:virtualenv_path
 | 
				
			||||||
 | 
					    endif
 | 
				
			||||||
 | 
					    if exists('g:python3_host_prog')
 | 
				
			||||||
 | 
					      unlet g:python3_host_prog
 | 
				
			||||||
 | 
					    endif
 | 
				
			||||||
 | 
					  endif
 | 
				
			||||||
 | 
					endfunction
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					autocmd BufEnter * call LoadVirtualEnv()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue