diff --git a/src/algokit/cli/explore.py b/src/algokit/cli/explore.py index 723a91ba..e19bc1e7 100644 --- a/src/algokit/cli/explore.py +++ b/src/algokit/cli/explore.py @@ -1,5 +1,7 @@ +import functools import logging import os +import platform from typing import TypedDict from urllib.parse import urlencode @@ -10,6 +12,21 @@ logger = logging.getLogger(__name__) +@functools.cache +def _is_wsl(v: str = platform.uname().release) -> int: + """ + detects if Python is running in WSL + https://github.com/scivision/detect-windows-subsystem-for-linux + """ + + if v.endswith("-Microsoft"): + return 1 + elif v.endswith("microsoft-standard-WSL2"): + return 2 + + return 0 + + class NetworkConfigurationRequired(TypedDict): algod_url: str indexer_url: str @@ -98,4 +115,9 @@ def get_explore_url(network: str) -> str: def explore_command(network: str) -> None: url = get_explore_url(network) logger.info(f"Opening {network} explorer in your default browser") + if _is_wsl(): + logger.warning( + "WSL detected. Make sure that wslu is installed in order for the cli to open browsers in host OS. " + "Installation instructions: https://wslutiliti.es/wslu/install.html" + ) click.launch(url)