@scrypted/server 0.94.9 → 0.94.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,7 +10,6 @@ const os_1 = __importDefault(require("os"));
|
|
10
10
|
const path_1 = __importDefault(require("path"));
|
11
11
|
const rpc_serializer_1 = require("../../rpc-serializer");
|
12
12
|
const child_process_worker_1 = require("./child-process-worker");
|
13
|
-
const plugin_volume_1 = require("../plugin-volume");
|
14
13
|
class PythonRuntimeWorker extends child_process_worker_1.ChildProcessWorker {
|
15
14
|
static {
|
16
15
|
try {
|
@@ -67,18 +66,15 @@ class PythonRuntimeWorker extends child_process_worker_1.ChildProcessWorker {
|
|
67
66
|
}
|
68
67
|
args.push(this.pluginId);
|
69
68
|
const types = require.resolve('@scrypted/types');
|
70
|
-
const
|
71
|
-
const PYTHONPATH = [
|
72
|
-
types.substring(0, types.indexOf('types') + 'types'.length),
|
73
|
-
SCRYPTED_DEBUGPY_TARGET
|
74
|
-
].join(':');
|
69
|
+
const PYTHONPATH = types.substring(0, types.indexOf('types') + 'types'.length);
|
75
70
|
this.worker = child_process_1.default.spawn(pythonPath, args, {
|
76
71
|
// stdin, stdout, stderr, peer in, peer out
|
77
72
|
stdio: ['pipe', 'pipe', 'pipe', 'pipe', 'pipe'],
|
78
73
|
env: Object.assign({
|
74
|
+
// rev this if the base python version or server characterstics change.
|
75
|
+
SCRYPTED_BASE_VERSION: '20240308',
|
79
76
|
PYTHONUNBUFFERED: '1',
|
80
77
|
PYTHONPATH,
|
81
|
-
SCRYPTED_DEBUGPY_TARGET,
|
82
78
|
}, gstEnv, process.env, env),
|
83
79
|
});
|
84
80
|
this.setupWorker();
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"python-worker.js","sourceRoot":"","sources":["../../../src/plugin/runtime/python-worker.ts"],"names":[],"mappings":";;;;;;AAAA,kEAA0C;AAC1C,4CAAoB;AACpB,4CAAoB;AACpB,gDAAwB;AAGxB,yD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,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;YACrB,UAAU,CAAC,cAAc,EAAE,CAAC;QAChC,CAAC,CAAC,CAAC;IACP,CAAC;IAED,IAAI,CAAC,OAAmB,EAAE,MAA2B,EAAE,oBAA0B;QAC7E,IAAI,CAAC;YACD,IAAI,CAAC,IAAI,CAAC,MAAM;gBACZ,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;YACrD,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,oBAAoB,CAAC,CAAC;QACvE,CAAC;QACD,OAAO,CAAC,EAAE,CAAC;YACP,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;QAChB,CAAC;IACL,CAAC;CACJ;AAlHD,kDAkHC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@scrypted/server",
|
3
|
-
"version": "0.94.
|
3
|
+
"version": "0.94.10",
|
4
4
|
"description": "",
|
5
5
|
"dependencies": {
|
6
6
|
"@bjia56/portable-python-3.9": "^0.1.9",
|
@@ -56,6 +56,7 @@
|
|
56
56
|
"main": "dist/scrypted-main-exports.js",
|
57
57
|
"types": "dist/scrypted-main-exports.d.ts",
|
58
58
|
"scripts": {
|
59
|
+
"postinstall": "node scripts/postinstall.js",
|
59
60
|
"preserve": "npm run build",
|
60
61
|
"serve": "node --expose-gc dist/scrypted-main.js",
|
61
62
|
"serve-no-build": "node --expose-gc dist/scrypted-main.js",
|
package/python/plugin_pip.py
CHANGED
@@ -47,7 +47,6 @@ def install_with_pip(
|
|
47
47
|
requirements_basename: str,
|
48
48
|
ignore_error: bool = False,
|
49
49
|
site_packages: str = None,
|
50
|
-
target: bool = False,
|
51
50
|
):
|
52
51
|
requirementstxt, installed_requirementstxt = get_requirements_files(requirements_basename)
|
53
52
|
|
@@ -72,7 +71,7 @@ def install_with_pip(
|
|
72
71
|
"install",
|
73
72
|
"-r",
|
74
73
|
requirementstxt,
|
75
|
-
"--
|
74
|
+
"--target",
|
76
75
|
python_prefix,
|
77
76
|
]
|
78
77
|
if pythonVersion:
|
package/python/plugin_remote.py
CHANGED
@@ -3,10 +3,13 @@ from __future__ import annotations
|
|
3
3
|
import asyncio
|
4
4
|
import base64
|
5
5
|
import gc
|
6
|
+
import hashlib
|
7
|
+
import multiprocessing
|
8
|
+
import multiprocessing.connection
|
6
9
|
import os
|
7
10
|
import platform
|
8
11
|
import shutil
|
9
|
-
|
12
|
+
import ssl
|
10
13
|
import sys
|
11
14
|
import threading
|
12
15
|
import time
|
@@ -17,10 +20,12 @@ from asyncio.futures import Future
|
|
17
20
|
from asyncio.streams import StreamReader, StreamWriter
|
18
21
|
from collections.abc import Mapping
|
19
22
|
from io import StringIO
|
20
|
-
from
|
21
|
-
from typing import Any, Optional, Set, Tuple
|
23
|
+
from typing import Any, Optional, Set, Tuple, TypedDict
|
22
24
|
|
25
|
+
import rpc
|
26
|
+
import rpc_reader
|
23
27
|
import scrypted_python.scrypted_sdk.types
|
28
|
+
from plugin_pip import install_with_pip, need_requirements, remove_pip_dirs
|
24
29
|
from scrypted_python.scrypted_sdk import PluginFork, ScryptedStatic
|
25
30
|
from scrypted_python.scrypted_sdk.types import (Device, DeviceManifest,
|
26
31
|
EventDetails,
|
@@ -28,24 +33,13 @@ from scrypted_python.scrypted_sdk.types import (Device, DeviceManifest,
|
|
28
33
|
ScryptedInterfaceProperty,
|
29
34
|
Storage)
|
30
35
|
|
31
|
-
|
36
|
+
default_create_default_context = ssl.create_default_context
|
37
|
+
def new_create_default_context(*args, **kwargs):
|
38
|
+
capath = os.path.dirname(os.path.dirname(sys.executable)) + "/lib/python3.9/site-packages/pip/_vendor/certifi/cacert.pem"
|
39
|
+
return default_create_default_context(*args, cafile=capath, **kwargs)
|
32
40
|
|
33
|
-
|
34
|
-
|
35
|
-
import multiprocessing.connection
|
36
|
-
|
37
|
-
import rpc
|
38
|
-
import rpc_reader
|
39
|
-
|
40
|
-
|
41
|
-
SCRYPTED_REQUIREMENTS = """
|
42
|
-
ptpython
|
43
|
-
wheel
|
44
|
-
""".strip()
|
45
|
-
|
46
|
-
SCRYPTED_DEBUGPY_REQUIREMENTS = """
|
47
|
-
debugpy
|
48
|
-
""".strip()
|
41
|
+
ssl.create_default_context = new_create_default_context
|
42
|
+
ssl._create_default_https_context = new_create_default_context
|
49
43
|
|
50
44
|
class ClusterObject(TypedDict):
|
51
45
|
id: str
|
@@ -563,16 +557,15 @@ class PluginRemote:
|
|
563
557
|
python_versioned_directory = '%s-%s-%s' % (
|
564
558
|
python_version, platform.system(), platform.machine())
|
565
559
|
SCRYPTED_BASE_VERSION = os.environ.get('SCRYPTED_BASE_VERSION')
|
566
|
-
|
567
|
-
python_versioned_directory += '-' + SCRYPTED_BASE_VERSION
|
560
|
+
python_versioned_directory += '-' + SCRYPTED_BASE_VERSION
|
568
561
|
|
569
|
-
|
562
|
+
pip_target = os.path.join(
|
570
563
|
plugin_volume, python_versioned_directory)
|
571
564
|
|
572
|
-
print('
|
565
|
+
print('pip target: %s' % pip_target)
|
573
566
|
|
574
|
-
if not os.path.exists(
|
575
|
-
os.makedirs(
|
567
|
+
if not os.path.exists(pip_target):
|
568
|
+
os.makedirs(pip_target)
|
576
569
|
|
577
570
|
|
578
571
|
def read_requirements(filename: str) -> str:
|
@@ -584,49 +577,27 @@ class PluginRemote:
|
|
584
577
|
str_optional_requirements = read_requirements('requirements.optional.txt')
|
585
578
|
|
586
579
|
scrypted_requirements_basename = os.path.join(
|
587
|
-
|
580
|
+
pip_target, 'requirements.scrypted')
|
588
581
|
requirements_basename = os.path.join(
|
589
|
-
|
590
|
-
debug_requirements_basename = os.path.join(
|
582
|
+
pip_target, 'requirements')
|
583
|
+
debug_requirements_basename = os.path.join(pip_target, 'requirements.debug')
|
591
584
|
optional_requirements_basename = os.path.join(
|
592
|
-
|
585
|
+
pip_target, 'requirements.optional')
|
593
586
|
|
594
587
|
need_pip = True
|
595
588
|
if str_requirements:
|
596
589
|
need_pip = need_requirements(requirements_basename, str_requirements)
|
597
|
-
if not need_pip:
|
598
|
-
need_pip = need_requirements(scrypted_requirements_basename, SCRYPTED_REQUIREMENTS)
|
599
|
-
python_debugpy_target = os.environ['SCRYPTED_DEBUGPY_TARGET']
|
600
|
-
if not need_pip and python_debugpy_target:
|
601
|
-
need_pip = need_requirements(debug_requirements_basename, SCRYPTED_DEBUGPY_REQUIREMENTS)
|
602
590
|
|
603
591
|
if need_pip:
|
604
592
|
remove_pip_dirs(plugin_volume)
|
605
|
-
install_with_pip(
|
606
|
-
install_with_pip(
|
607
|
-
install_with_pip(python_prefix, packageJson, str_optional_requirements, optional_requirements_basename, ignore_error=True)
|
608
|
-
if python_debugpy_target:
|
609
|
-
install_with_pip(python_debugpy_target, packageJson, SCRYPTED_DEBUGPY_REQUIREMENTS, debug_requirements_basename, ignore_error=True, target=True)
|
593
|
+
install_with_pip(pip_target, packageJson, str_requirements, requirements_basename, ignore_error=False)
|
594
|
+
install_with_pip(pip_target, packageJson, str_optional_requirements, optional_requirements_basename, ignore_error=True)
|
610
595
|
else:
|
611
596
|
print('requirements.txt (up to date)')
|
612
597
|
print(str_requirements)
|
613
598
|
|
614
599
|
sys.path.insert(0, zipPath)
|
615
|
-
|
616
|
-
# local/lib/dist-packages seen on python3.10 on ubuntu.
|
617
|
-
# TODO: find a way to programatically get this value, or switch to venv.
|
618
|
-
dist_packages = os.path.join(
|
619
|
-
python_prefix, 'local', 'lib', python_version, 'dist-packages')
|
620
|
-
if os.path.exists(dist_packages):
|
621
|
-
site_packages = dist_packages
|
622
|
-
else:
|
623
|
-
site_packages = os.path.join(
|
624
|
-
python_prefix, 'lib', python_version, 'site-packages')
|
625
|
-
else:
|
626
|
-
site_packages = os.path.join(
|
627
|
-
python_prefix, 'Lib', 'site-packages')
|
628
|
-
print('site-packages: %s' % site_packages)
|
629
|
-
sys.path.insert(0, site_packages)
|
600
|
+
sys.path.insert(0, pip_target)
|
630
601
|
else:
|
631
602
|
zip = zipfile.ZipFile(options['filename'])
|
632
603
|
|
@@ -81,18 +81,15 @@ export class PythonRuntimeWorker extends ChildProcessWorker {
|
|
81
81
|
args.push(this.pluginId);
|
82
82
|
|
83
83
|
const types = require.resolve('@scrypted/types');
|
84
|
-
const
|
85
|
-
const PYTHONPATH = [
|
86
|
-
types.substring(0, types.indexOf('types') + 'types'.length),
|
87
|
-
SCRYPTED_DEBUGPY_TARGET
|
88
|
-
].join(':');
|
84
|
+
const PYTHONPATH = types.substring(0, types.indexOf('types') + 'types'.length);
|
89
85
|
this.worker = child_process.spawn(pythonPath, args, {
|
90
86
|
// stdin, stdout, stderr, peer in, peer out
|
91
87
|
stdio: ['pipe', 'pipe', 'pipe', 'pipe', 'pipe'],
|
92
88
|
env: Object.assign({
|
89
|
+
// rev this if the base python version or server characterstics change.
|
90
|
+
SCRYPTED_BASE_VERSION: '20240308',
|
93
91
|
PYTHONUNBUFFERED: '1',
|
94
92
|
PYTHONPATH,
|
95
|
-
SCRYPTED_DEBUGPY_TARGET,
|
96
93
|
}, gstEnv, process.env, env),
|
97
94
|
});
|
98
95
|
|