]> git.phdru.name Git - dotfiles.git/commitdiff
Feat(.vim/python/virtualenv.py): Check major Python version
authorOleg Broytman <phd@phdru.name>
Thu, 18 Jan 2024 12:55:38 +0000 (15:55 +0300)
committerOleg Broytman <phd@phdru.name>
Thu, 18 Jan 2024 12:55:38 +0000 (15:55 +0300)
Do not activate the current virtual environment
if it doesn't correspond to the vim's Python version.

.vim/python/virtualenv.py

index 9341bc79f9663e407650941be798519bd73e4351..ca66bf8854095a10d459ace69cf34b4ac63066bd 100644 (file)
@@ -10,7 +10,13 @@ if virtualenv_dir:
         if not os.path.exists(activate_this):
             continue
         if sys.version_info[0] == 2:
-            execfile(activate_this, dict(__file__=activate_this))
+            if os.path.exists(
+                    os.path.join(virtualenv_dir, 'lib', 'python2.7')):
+                execfile(activate_this,
+                         dict(__file__=activate_this))
         else:
-            exec(open(activate_this, 'r').read(), dict(__file__=activate_this))
+            if not os.path.exists(
+                    os.path.join(virtualenv_dir, 'lib', 'python2.7')):
+                exec(open(activate_this, 'r').read(),
+                     dict(__file__=activate_this))
         break