Nicer handling of python for typecheck
This commit is contained in:
parent
e608a945de
commit
3662efdf80
@ -82,6 +82,11 @@ def filter_tests_by_module(suite: unittest.TestSuite, *names: str) -> unittest.T
|
|||||||
return filter_tests(suite, q)
|
return filter_tests(suite, q)
|
||||||
|
|
||||||
|
|
||||||
|
@lru_cache
|
||||||
|
def python_for_type_check() -> str:
|
||||||
|
return shutil.which('python') or shutil.which('python3') or 'python'
|
||||||
|
|
||||||
|
|
||||||
def type_check() -> NoReturn:
|
def type_check() -> NoReturn:
|
||||||
from kitty.cli_stub import generate_stub # type:ignore
|
from kitty.cli_stub import generate_stub # type:ignore
|
||||||
|
|
||||||
@ -89,7 +94,7 @@ def type_check() -> NoReturn:
|
|||||||
from kittens.tui.operations_stub import generate_stub # type: ignore
|
from kittens.tui.operations_stub import generate_stub # type: ignore
|
||||||
|
|
||||||
generate_stub()
|
generate_stub()
|
||||||
py = os.environ.get('PYTHON_FOR_TYPE_CHECK') or shutil.which('python') or shutil.which('python3')
|
py = python_for_type_check()
|
||||||
os.execlp(py, py, '-m', 'mypy', '--pretty')
|
os.execlp(py, py, '-m', 'mypy', '--pretty')
|
||||||
|
|
||||||
|
|
||||||
@ -226,16 +231,15 @@ def env_vars(**kw: str) -> Iterator[None]:
|
|||||||
@contextmanager
|
@contextmanager
|
||||||
def env_for_python_tests(report_env: bool = False) -> Iterator[None]:
|
def env_for_python_tests(report_env: bool = False) -> Iterator[None]:
|
||||||
gohome = os.path.expanduser('~/go')
|
gohome = os.path.expanduser('~/go')
|
||||||
python = shutil.which('python') or shutil.which('python3')
|
|
||||||
current_home = os.path.expanduser('~') + os.sep
|
current_home = os.path.expanduser('~') + os.sep
|
||||||
paths = os.environ.get('PATH', '/usr/local/sbin:/usr/local/bin:/usr/bin').split(os.pathsep)
|
paths = os.environ.get('PATH', '/usr/local/sbin:/usr/local/bin:/usr/bin').split(os.pathsep)
|
||||||
path = os.pathsep.join(x for x in paths if not x.startswith(current_home))
|
path = os.pathsep.join(x for x in paths if not x.startswith(current_home))
|
||||||
launcher_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'kitty', 'launcher')
|
launcher_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'kitty', 'launcher')
|
||||||
path = f'{launcher_dir}{os.pathsep}{path}'
|
path = f'{launcher_dir}{os.pathsep}{path}'
|
||||||
|
python_for_type_check()
|
||||||
if os.environ.get('CI') == 'true' or report_env:
|
if os.environ.get('CI') == 'true' or report_env:
|
||||||
print('Using PATH in test environment:', path)
|
print('Using PATH in test environment:', path)
|
||||||
python = shutil.which('python', path=path) or shutil.which('python3', path=path)
|
print('Python:', python_for_type_check())
|
||||||
print('Python:', python)
|
|
||||||
|
|
||||||
with TemporaryDirectory() as tdir, env_vars(
|
with TemporaryDirectory() as tdir, env_vars(
|
||||||
HOME=tdir,
|
HOME=tdir,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user