Skip to content

Commit

Permalink
Merge pull request #22368 from hlouzada/fix-remote-installation
Browse files Browse the repository at this point in the history
PR: Update `spyder-remote-services` installation script (Remote client)
  • Loading branch information
ccordoba12 authored Aug 22, 2024
2 parents ab77b22 + 1031894 commit ad74fce
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 121 deletions.
9 changes: 5 additions & 4 deletions spyder/plugins/remoteclient/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from spyder.plugins.remoteclient.api.ssh import SpyderSSHClient
from spyder.plugins.remoteclient.utils.installation import (
get_installer_command,
SERVER_ENV,
)


Expand Down Expand Up @@ -58,9 +59,9 @@ class SpyderRemoteClient:

_extra_options = ["platform", "id"]

START_SERVER_COMMAND = "/${HOME}/.local/bin/micromamba run -n spyder-remote spyder-remote-server --jupyter-server"
CHECK_SERVER_COMMAND = "/${HOME}/.local/bin/micromamba run -n spyder-remote spyder-remote-server -h"
GET_SERVER_INFO_COMMAND = "/${HOME}/.local/bin/micromamba run -n spyder-remote spyder-remote-server --get-running-info"
START_SERVER_COMMAND = f"/${{HOME}}/.local/bin/micromamba run -n {SERVER_ENV} spyder-server --jupyter-server"
CHECK_SERVER_COMMAND = f"/${{HOME}}/.local/bin/micromamba run -n {SERVER_ENV} spyder-server -h"
GET_SERVER_INFO_COMMAND = f"/${{HOME}}/.local/bin/micromamba run -n {SERVER_ENV} spyder-server --get-running-info"

def __init__(self, conf_id, options: SSHClientOptions, _plugin=None):
self._config_id = conf_id
Expand Down Expand Up @@ -230,7 +231,7 @@ async def get_server_info(self):
)
return None
except asyncssh.ProcessError as err:
self._logger.debug(f"Error getting server infp: {err.stderr}")
self._logger.debug(f"Error getting server info: {err.stderr}")
return None

try:
Expand Down
16 changes: 9 additions & 7 deletions spyder/plugins/remoteclient/api/jupyterhub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,17 +291,19 @@ async def __aexit__(self, exc_type, exc, tb):
await self.session.close()

async def create_kernel(self, kernel_spec=None):
data = {"kernel_spec": kernel_spec} if kernel_spec else None
data = {"name": kernel_spec} if kernel_spec else None

async with self.session.post(
self.api_url / "kernels", json=data
) as response:
data = await response.json()
logger.info(
f'created kernel_spec={kernel_spec} '
f'kernel={data["id"]} for jupyter'
)
return data
if response.status != 201:
logger.error(
f"failed to create kernel_spec={kernel_spec}"
)
raise ValueError(
await response.text()
)
return await response.json()

async def list_kernel_specs(self):
async with self.session.get(self.api_url / "kernelspecs") as response:
Expand Down
123 changes: 13 additions & 110 deletions spyder/plugins/remoteclient/utils/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,122 +4,25 @@
# Licensed under the terms of the MIT License
# (see spyder/__init__.py for details)

import base64
from spyder.plugins.ipythonconsole import SPYDER_KERNELS_VERSION


ENVIROMENT_NAME = "spyder-remote"
PACKAGE_NAME = "spyder-remote-server"
MICROMAMBA_VERSION = "latest"
SERVER_ENTRY_POINT = "spyder-server"
SERVER_ENV = "spyder-remote"
PACKAGE_NAME = "spyder-remote-services"
PACKAGE_VERSION = "0.1.3"

MICROMAMBA_INSTALLER_SH = f"""
#!/bin/bash
VERSION="{MICROMAMBA_VERSION}"
BIN_FOLDER="${{HOME}}/.local/bin"
PREFIX_LOCATION="${{HOME}}/micromamba"
# Computing artifact location
case "$(uname)" in
Linux)
PLATFORM="linux" ;;
Darwin)
PLATFORM="osx" ;;
*NT*)
PLATFORM="win" ;;
esac
ARCH="$(uname -m)"
case "$ARCH" in
aarch64|ppc64le|arm64)
;; # pass
*)
ARCH="64" ;;
esac
case "$PLATFORM-$ARCH" in
linux-aarch64|linux-ppc64le|linux-64|osx-arm64|osx-64|win-64)
;; # pass
*)
echo "Failed to detect your OS" >&2
exit 1
;;
esac
RELEASE_URL="https://github.com/mamba-org/micromamba-releases/releases/${{VERSION}}/download/micromamba-${{PLATFORM}}-${{ARCH}}"
# Downloading artifact
mkdir -p "${{BIN_FOLDER}}"
if hash curl >/dev/null 2>&1; then
curl "${{RELEASE_URL}}" -o "${{BIN_FOLDER}}/micromamba" -fsSL --compressed ${{CURL_OPTS:-}}
elif hash wget >/dev/null 2>&1; then
wget ${{WGET_OPTS:-}} -qO "${{BIN_FOLDER}}/micromamba" "${{RELEASE_URL}}"
else
echo "Neither curl nor wget was found" >&2
exit 1
fi
chmod +x "${{BIN_FOLDER}}/micromamba"
# Activate micromamba shell hook
eval "$("${{BIN_FOLDER}}/micromamba" shell hook --shell bash)"
git clone https://github.com/spyder-ide/spyder-remote-server
cd spyder-remote-server
micromamba create -y -n {ENVIROMENT_NAME} -f environment.yml
# Activate the environment
micromamba activate {ENVIROMENT_NAME}
# Install the spyder-remote-server package
#pip install {PACKAGE_NAME}
poetry install
"""


MICROMAMBA_INSTALLER_PS = f"""
# check if VERSION env variable is set, otherwise use "latest"
$VERSION = "{MICROMAMBA_VERSION}"
$RELEASE_URL="https://github.com/mamba-org/micromamba-releases/releases/$VERSION/download/micromamba-win-64"
Write-Output "Downloading micromamba from $RELEASE_URL"
curl.exe -L -o micromamba.exe $RELEASE_URL
New-Item -ItemType Directory -Force -Path $Env:LocalAppData\micromamba | out-null
$MAMBA_INSTALL_PATH = Join-Path -Path $Env:LocalAppData -ChildPAth micromamba\micromamba.exe
Write-Output "`nInstalling micromamba to $Env:LocalAppData\micromamba`n"
Move-Item -Force micromamba.exe $MAMBA_INSTALL_PATH | out-null
# Add micromamba to PATH if the folder is not already in the PATH variable
$PATH = [Environment]::GetEnvironmentVariable("Path", "User")
if ($PATH -notlike "*$Env:LocalAppData\micromamba*") {{
Write-Output "Adding $MAMBA_INSTALL_PATH to PATH`n"
[Environment]::SetEnvironmentVariable("Path", "$Env:LocalAppData\micromamba;" + [Environment]::GetEnvironmentVariable("Path", "User"), "User")
}} else {{
Write-Output "$MAMBA_INSTALL_PATH is already in PATH`n"
}}"""
ENCODING = "utf-8"

SCRIPT_URL = (
f"https://raw.githubusercontent.com/spyder-ide/{PACKAGE_NAME}/master/scripts"
)

def get_installer_command(platform: str) -> str:
if platform == "win":
script = MICROMAMBA_INSTALLER_PS
encoding = "utf-16le"
command = "powershell.exe -EncodedCommand {}"
else:
script = MICROMAMBA_INSTALLER_SH
encoding = "utf-8"
command = "echo {} | base64 --decode | /bin/bash"
raise NotImplementedError("Windows is not supported yet")

return command.format(
base64.b64encode(script.encode(encoding)).decode(encoding)
return (
f'"${{SHELL}}" <(curl -L {SCRIPT_URL}/installer.sh) '
f'"{PACKAGE_VERSION}" "{SPYDER_KERNELS_VERSION}"'
)


def get_enviroment_command(platform: str) -> str:
if platform == "win":
return f"micromamba activate {ENVIROMENT_NAME}"
else:
return f"source micromamba activate {ENVIROMENT_NAME}"

0 comments on commit ad74fce

Please sign in to comment.