Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Windows support #171

Merged
9 changes: 8 additions & 1 deletion kraken-build/src/kraken/common/findpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ def get_candidates(
if re.match(r"\d+\.\d+\.\d+$", item.name) and item.is_dir():
yield {"path": str(item / "bin" / "python"), "exact_version": item.name}

# pyenv (Windows)
pyenv_versions = (Path(os.getenv('PYENV')) / "versions").expanduser()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pyenv_versions = (Path(os.getenv('PYENV')) / "versions").expanduser()
pyenv_versions = (Path(os.getenv("PYENV")) / "versions").expanduser()

Black will complain about this

if check_pyenv and pyenv_versions.is_dir():
for item in pyenv_versions.iterdir():
if re.match(r"\d+\.\d+\.\d+$", item.name) and item.is_dir():
yield {"path": str(item / "python.exe"), "exact_version": item.name}

yield {"path": sys.executable, "exact_version": ".".join(map(str, sys.version_info[:3]))}


Expand Down Expand Up @@ -192,7 +199,7 @@ def evaluate_candidates(
if version is None:
try:
version = get_python_interpreter_version(str(path))
except (subprocess.CalledProcessError, RuntimeError):
except (subprocess.CalledProcessError, RuntimeError, FileNotFoundError):
logger.debug("Failed to get version for Python interpreter %s", path, exc_info=True)
continue
if cache:
Expand Down
3 changes: 2 additions & 1 deletion kraken-build/src/kraken/std/python/tasks/base_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,6 @@ def execute(self) -> TaskStatus:
logger.warning('%s = "*"', dep)
return TaskStatus.failed("The %s dependencies are missing" % self.python_dependencies)
logger.info("%s", command)
result = sp.call(command, cwd=self.project.directory, env=env)
shell = sys.platform.startswith('win32') # Windows requires shell to find executable in path
result = sp.call(command, cwd=self.project.directory, env=env, shell=shell)
return self.handle_exit_code(result)
13 changes: 11 additions & 2 deletions kraken-build/src/kraken/std/python/tasks/mypy_task.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from __future__ import annotations

from collections.abc import MutableMapping, Sequence
import logging
from pathlib import Path
import sys

from kraken.common import Supplier
from kraken.core import Project, Property
Expand All @@ -10,6 +12,8 @@
from .base_task import EnvironmentAwareDispatchTask


logger = logging.getLogger(__name__)

NiklasRosenstein marked this conversation as resolved.
Show resolved Hide resolved
class MypyTask(EnvironmentAwareDispatchTask):
description = "Static type checking for Python code using Mypy."
python_dependencies = ["mypy"]
Expand All @@ -24,7 +28,12 @@ class MypyTask(EnvironmentAwareDispatchTask):
# EnvironmentAwareDispatchTask

def get_execute_command_v2(self, env: MutableMapping[str, str]) -> list[str]:
entry_point = "dmypy" if self.use_daemon.get() else "mypy"
use_daemon = self.use_daemon.get()
if use_daemon and sys.platform.startswith('win32'):
use_daemon = False
logger.warning("Disable use of mypy daemon due to error in exit code on Windows")

entry_point = "dmypy" if use_daemon else "mypy"

if mypy_pex_bin := self.mypy_pex_bin.get():
# See https://pex.readthedocs.io/en/latest/api/vars.html
Expand All @@ -38,7 +47,7 @@ def get_execute_command_v2(self, env: MutableMapping[str, str]) -> list[str]:
# happens regularly but is hard to detect automatically).

status_file = (self.project.directory / ".dmypy.json").absolute()
if self.use_daemon.get():
if use_daemon:
command += ["--status-file", str(status_file), "run", "--"]
if mypy_pex_bin:
# Have mypy pick up the Python executable from the virtual environment that is activated automatically
Expand Down
Loading