@@ -35,6 +35,21 @@ python3 << endpython3
3535import sys
3636import vim
3737
38+ def _find_python_binary (exec_prefix):
39+ if sys.platform[:3 ] == " win" :
40+ return exec_prefix / ' python.exe'
41+ return exec_prefix / 'bin' / ' python3'
42+
43+ def _find_pip (venv_path):
44+ if sys.platform[:3 ] == " win" :
45+ return venv_path / 'Scripts' / ' pip.exe'
46+ return venv_path / 'bin' / ' pip'
47+
48+ def _find_virtualenv_site_packages (venv_path):
49+ if sys.platform[:3 ] == " win" :
50+ return venv_path / 'Lib' / ' site-packages'
51+ return venv_path / 'Lib' / f ' python{pyver[0]}.{pyver[1]}' / ' site-packages'
52+
3853def _initialize_black_env (upgrade= False):
3954 pyver = sys.version_info[:2 ]
4055 if pyver < (3 , 6 ):
@@ -45,15 +60,13 @@ def _initialize_black_env(upgrade=False):
4560 import subprocess
4661 import venv
4762 virtualenv_path = Path (vim .eval (" g:black_virtualenv" )).expanduser ()
48- virtualenv_site_packages = str (
49- virtualenv_path / 'lib' / f ' python{pyver[0]}.{pyver[1]}' / ' site-packages'
50- )
63+ virtualenv_site_packages = str (_find_virtualenv_site_packages (virtualenv_path))
5164 first_install = False
5265 if not virtualenv_path.is_dir ():
5366 print (' Please wait, one time setup for Black.' )
5467 _executable = sys.executable
5568 try :
56- sys.executable = str (Path (sys.exec_prefix) / 'bin' / ' python3 ' )
69+ sys.executable = str (_find_python_binary ( Path (sys.exec_prefix)) )
5770 print (f ' Creating a virtualenv in {virtualenv_path}...' )
5871 print (' (this path can be customized in .vimrc by setting g:black_virtualenv)' )
5972 venv.create (virtualenv_path, with_pip= True)
@@ -65,7 +78,7 @@ def _initialize_black_env(upgrade=False):
6578 if upgrade:
6679 print (' Upgrading Black with pip...' )
6780 if first_install or upgrade:
68- subprocess.run ([str (virtualenv_path / 'bin' / ' pip ' ), ' install' , ' -U' , ' black' ])
81+ subprocess.run ([str (_find_pip ( virtualenv_path) ), ' install' , ' -U' , ' black' ])
6982 print (' DONE! You are all set, thanks for waiting ✨ 🍰 ✨' )
7083 if first_install:
7184 print (' Pro-tip: to upgrade Black in the future, use the :BlackUpgrade command and restart Vim.\n' )
0 commit comments