Skip to content

Commit

Permalink
paquo: warn windows users in case we detect a microsoft store python
Browse files Browse the repository at this point in the history
Closes #67

This adds a warning on Windows in case we detect a Microsoft Store
Python installation. Since paquo on windows works with the MS Store
Python and QuPath versions >=0.2.1,<=0.2.3 this warning can be disabled
via a config setting.
  • Loading branch information
ap-- committed Jan 5, 2022
1 parent 1e8b2b8 commit 738db66
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
2 changes: 2 additions & 0 deletions paquo/.paquo.defaults.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ safe_truncate = true
mock_backend = false
# only show paquo errors on cli
cli_force_log_level_error = true
# on windows warn about microsoft store python
warn_microsoft_store_python = true
33 changes: 31 additions & 2 deletions paquo/jpype_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
import platform
import re
import shlex
import sys
from contextlib import contextmanager
from itertools import chain
from pathlib import Path
from textwrap import dedent
from typing import Tuple, List, Optional, Callable, Union, Iterable, Any, Dict
from warnings import warn

import jpype
from packaging.version import parse
Expand Down Expand Up @@ -142,8 +145,10 @@ def qupath_jvm_info_from_qupath_dir(qupath_dir: Path, jvm_options: List[str]) ->
_QUPATH_VERSION: Union[Version, LegacyVersion, None] = None


def start_jvm(finder: Optional[Callable[..., QuPathJVMInfo]] = None,
finder_kwargs: Optional[Dict[str, Any]] = None) -> Union[Version, LegacyVersion, None]:
def start_jvm(
finder: Optional[Callable[..., QuPathJVMInfo]] = None,
finder_kwargs: Optional[Dict[str, Any]] = None,
) -> Union[Version, LegacyVersion, None]:
"""start the jvm via jpype
This is automatically called at import of `paquo.java`.
Expand Down Expand Up @@ -176,6 +181,30 @@ def patched_env():
finally:
os.environ.clear()
os.environ.update(_old)

# the above workaround doesn't fix the issue for python versions installed
# via the Microsoft Store. Let's warn users that this might cause problems
def is_windows_store_python() -> bool:
parts = Path(sys.base_exec_prefix).parts
try:
idx = parts.index("WindowsApps")
except ValueError:
return False
try:
return parts[idx + 1].startswith("PythonSoftwareFoundation")
except IndexError:
return False

if finder_kwargs.pop("warn_microsoft_store_python", True) and is_windows_store_python():
msg = dedent("""\
MicrosoftStore Python installation detected
Your Python version seems to be installed via the MicrosoftStore.
If paquo crashes with a EXCEPTION_ACCESS_VIOLATION try installing Python from https://www.python.org
To silence this warning set the following in your .paquo.toml configfile:
>>> warn_microsoft_store_python = false <<<
""")
warn(msg, stacklevel=2)

else:
patched_env = nullcontext

Expand Down

0 comments on commit 738db66

Please sign in to comment.