server: use portable python, shim in debugpy

This commit is contained in:
Koushik Dutta
2024-03-06 19:54:57 -08:00
parent 958442b1bd
commit 83f24ebdaa
7 changed files with 52 additions and 16 deletions

View File

@@ -46,6 +46,8 @@ def install_with_pip(
requirements_str: str,
requirements_basename: str,
ignore_error: bool = False,
site_packages: str = None,
target: bool = False,
):
requirementstxt, installed_requirementstxt = get_requirements_files(requirements_basename)
@@ -70,7 +72,7 @@ def install_with_pip(
"install",
"-r",
requirementstxt,
"--prefix",
"--prefix" if not target else "--target",
python_prefix,
]
if pythonVersion:
@@ -80,7 +82,15 @@ def install_with_pip(
# force reinstall even if it exists in system packages.
pipArgs.append("--force-reinstall")
p = subprocess.Popen(pipArgs, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
env = None
if site_packages:
env = dict(os.environ)
PYTHONPATH = env['PYTHONPATH'] or ''
PYTHONPATH += ':' + site_packages
env["PYTHONPATH"] = PYTHONPATH
print("PYTHONPATH", env["PYTHONPATH"])
p = subprocess.Popen(pipArgs, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env)
while True:
line = p.stdout.readline()

View File

@@ -28,10 +28,7 @@ from scrypted_python.scrypted_sdk.types import (Device, DeviceManifest,
ScryptedInterfaceProperty,
Storage)
try:
from typing import TypedDict
except:
from typing_extensions import TypedDict
from typing import TypedDict
import hashlib
import multiprocessing
@@ -43,6 +40,12 @@ import rpc_reader
SCRYPTED_REQUIREMENTS = """
ptpython
wheel
debugpy
""".strip()
SCRYPTED_DEBUGPY_REQUIREMENTS = """
debugpy
""".strip()
@@ -587,6 +590,7 @@ class PluginRemote:
python_prefix, 'requirements.scrypted')
requirements_basename = os.path.join(
python_prefix, 'requirements')
debug_requirements_basename = os.path.join(python_prefix, 'requirements.debug')
optional_requirements_basename = os.path.join(
python_prefix, 'requirements.optional')
@@ -595,12 +599,17 @@ class PluginRemote:
need_pip = need_requirements(requirements_basename, str_requirements)
if not need_pip:
need_pip = need_requirements(scrypted_requirements_basename, SCRYPTED_REQUIREMENTS)
python_debugpy_target = os.environ['SCRYPTED_DEBUGPY_TARGET']
if not need_pip and python_debugpy_target:
need_pip = need_requirements(debug_requirements_basename, SCRYPTED_DEBUGPY_REQUIREMENTS)
if need_pip:
remove_pip_dirs(plugin_volume)
install_with_pip(python_prefix, packageJson, SCRYPTED_REQUIREMENTS, scrypted_requirements_basename, ignore_error=True)
install_with_pip(python_prefix, packageJson, str_requirements, requirements_basename, ignore_error=False)
install_with_pip(python_prefix, packageJson, str_optional_requirements, optional_requirements_basename, ignore_error=True)
if python_debugpy_target:
install_with_pip(python_debugpy_target, packageJson, SCRYPTED_DEBUGPY_REQUIREMENTS, debug_requirements_basename, ignore_error=True, target=True)
else:
print('requirements.txt (up to date)')
print(str_requirements)

View File

@@ -2,15 +2,9 @@ import inspect
import random
import string
import traceback
from asyncio.futures import Future
from typing import Any, Callable, Dict, List, Mapping
try:
from typing import TypedDict
except:
from typing_extensions import TypedDict
import weakref
from asyncio.futures import Future
from typing import Any, Callable, Dict, List, Mapping, TypedDict
jsonSerializable = set()
jsonSerializable.add(float)