This repository was archived by the owner on Jan 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.py
More file actions
61 lines (50 loc) · 2 KB
/
entrypoint.py
File metadata and controls
61 lines (50 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import argparse
import os
import subprocess
import sys
import tempfile
import zipfile
from pathlib import Path
from urllib import request
LAYER_REQUIREMENTS_FILE_NAME = "layer.txt"
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("zip_url")
args = parser.parse_args()
zip_url = args.zip_url
with tempfile.TemporaryDirectory() as tmp_dir:
zip_path, _ = request.urlretrieve(zip_url)
with zipfile.ZipFile(zip_path, "r") as zip_ref:
zip_ref.extractall(tmp_dir)
# TODO: remove once we no longer want to support old SDK versions
layer_requirements_file_path = Path(tmp_dir) / LAYER_REQUIREMENTS_FILE_NAME
if os.path.exists(layer_requirements_file_path):
pip_install = [
sys.executable,
"-m",
"pip",
"--quiet",
"--disable-pip-version-check",
"--no-color",
"install",
"--requirement",
LAYER_REQUIREMENTS_FILE_NAME,
]
result = subprocess.run(
pip_install, text=True, check=False, capture_output=True, cwd=tmp_dir
)
if result.returncode != 0:
raise Exception(
f"package instalation failed:\n{result.stdout}\n{result.stderr}"
)
# TODO: Once we remove the build-in layer package from the executor, we should be able to replace
# spawning a new process with the following:
# user_site = site.getusersitepackages()
# if user_site not in sys.path:
# sys.path.append(user_site)
# from layer.executables.runtime import BaseFunctionRuntime
# BaseFunctionRuntime.main()
# For now, spawn a child process as otherwise we end up loading the old version
run = [sys.executable, "-m", "layer.executables.runtime", zip_url]
result = subprocess.run(run, check=False)
exit(result.returncode)