mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #756 from pre-commit/venv_spiders
Invoke -mvenv with the original python if in a -mvirtualenv venv
This commit is contained in:
commit
1b92f79941
1 changed files with 33 additions and 1 deletions
|
|
@ -1,14 +1,46 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import os.path
|
||||||
|
|
||||||
from pre_commit.languages import python
|
from pre_commit.languages import python
|
||||||
|
from pre_commit.util import CalledProcessError
|
||||||
from pre_commit.util import cmd_output
|
from pre_commit.util import cmd_output
|
||||||
|
|
||||||
|
|
||||||
ENVIRONMENT_DIR = 'py_venv'
|
ENVIRONMENT_DIR = 'py_venv'
|
||||||
|
|
||||||
|
|
||||||
|
def orig_py_exe(exe): # pragma: no cover (platform specific)
|
||||||
|
"""A -mvenv virtualenv made from a -mvirtualenv virtualenv installs
|
||||||
|
packages to the incorrect location. Attempt to find the _original_ exe
|
||||||
|
and invoke `-mvenv` from there.
|
||||||
|
|
||||||
|
See:
|
||||||
|
- https://github.com/pre-commit/pre-commit/issues/755
|
||||||
|
- https://github.com/pypa/virtualenv/issues/1095
|
||||||
|
- https://bugs.python.org/issue30811
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
prefix_script = 'import sys; print(sys.real_prefix)'
|
||||||
|
_, prefix, _ = cmd_output(exe, '-c', prefix_script)
|
||||||
|
prefix = prefix.strip()
|
||||||
|
except CalledProcessError:
|
||||||
|
# not created from -mvirtualenv
|
||||||
|
return exe
|
||||||
|
|
||||||
|
if os.name == 'nt':
|
||||||
|
expected = os.path.join(prefix, 'python.exe')
|
||||||
|
else:
|
||||||
|
expected = os.path.join(prefix, 'bin', os.path.basename(exe))
|
||||||
|
|
||||||
|
if os.path.exists(expected):
|
||||||
|
return expected
|
||||||
|
else:
|
||||||
|
return exe
|
||||||
|
|
||||||
|
|
||||||
def make_venv(envdir, python):
|
def make_venv(envdir, python):
|
||||||
cmd_output(python, '-mvenv', envdir, cwd='/')
|
cmd_output(orig_py_exe(python), '-mvenv', envdir, cwd='/')
|
||||||
|
|
||||||
|
|
||||||
get_default_version = python.get_default_version
|
get_default_version = python.get_default_version
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue