diff --git a/spyder/plugins/remoteclient/api/client.py b/spyder/plugins/remoteclient/api/client.py index 352a56e48a9..6fdc097f811 100644 --- a/spyder/plugins/remoteclient/api/client.py +++ b/spyder/plugins/remoteclient/api/client.py @@ -26,6 +26,7 @@ from spyder.plugins.remoteclient.api.ssh import SpyderSSHClient from spyder.plugins.remoteclient.utils.installation import ( get_installer_command, + SERVER_ENV, ) @@ -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 @@ -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: diff --git a/spyder/plugins/remoteclient/api/jupyterhub/__init__.py b/spyder/plugins/remoteclient/api/jupyterhub/__init__.py index 32b77cea1b7..4353c830cf9 100644 --- a/spyder/plugins/remoteclient/api/jupyterhub/__init__.py +++ b/spyder/plugins/remoteclient/api/jupyterhub/__init__.py @@ -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: diff --git a/spyder/plugins/remoteclient/utils/installation.py b/spyder/plugins/remoteclient/utils/installation.py index df1c076f0a5..0a5aa4f80d2 100644 --- a/spyder/plugins/remoteclient/utils/installation.py +++ b/spyder/plugins/remoteclient/utils/installation.py @@ -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}"