mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #1363 from pre-commit/broken_symlinks_healthy
mark a python environment as unhealthy if python goes missing
This commit is contained in:
commit
58a16bcf57
2 changed files with 18 additions and 2 deletions
|
|
@ -158,10 +158,12 @@ def py_interface(
|
||||||
yield
|
yield
|
||||||
|
|
||||||
def healthy(prefix: Prefix, language_version: str) -> bool:
|
def healthy(prefix: Prefix, language_version: str) -> bool:
|
||||||
|
envdir = helpers.environment_dir(_dir, language_version)
|
||||||
|
exe_name = 'python.exe' if sys.platform == 'win32' else 'python'
|
||||||
|
py_exe = prefix.path(bin_dir(envdir), exe_name)
|
||||||
with in_env(prefix, language_version):
|
with in_env(prefix, language_version):
|
||||||
retcode, _, _ = cmd_output_b(
|
retcode, _, _ = cmd_output_b(
|
||||||
'python', '-c',
|
py_exe, '-c', 'import ctypes, datetime, io, os, ssl, weakref',
|
||||||
'import ctypes, datetime, io, os, ssl, weakref',
|
|
||||||
cwd='/',
|
cwd='/',
|
||||||
retcode=None,
|
retcode=None,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -59,3 +59,17 @@ def test_healthy_types_py_in_cwd(tmpdir):
|
||||||
# even if a `types.py` file exists, should still be healthy
|
# even if a `types.py` file exists, should still be healthy
|
||||||
tmpdir.join('types.py').ensure()
|
tmpdir.join('types.py').ensure()
|
||||||
assert python.healthy(prefix, C.DEFAULT) is True
|
assert python.healthy(prefix, C.DEFAULT) is True
|
||||||
|
|
||||||
|
|
||||||
|
def test_healthy_python_goes_missing(tmpdir):
|
||||||
|
with tmpdir.as_cwd():
|
||||||
|
prefix = tmpdir.join('prefix').ensure_dir()
|
||||||
|
prefix.join('setup.py').write('import setuptools; setuptools.setup()')
|
||||||
|
prefix = Prefix(str(prefix))
|
||||||
|
python.install_environment(prefix, C.DEFAULT, ())
|
||||||
|
|
||||||
|
exe_name = 'python' if sys.platform != 'win32' else 'python.exe'
|
||||||
|
py_exe = prefix.path(python.bin_dir('py_env-default'), exe_name)
|
||||||
|
os.remove(py_exe)
|
||||||
|
|
||||||
|
assert python.healthy(prefix, C.DEFAULT) is False
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue