This repository has been archived by the owner on Jun 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.py
79 lines (61 loc) · 1.68 KB
/
install.py
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import os
import pwd
import subprocess
import os.path
ownerAccount = 590186200215
notebookExtensionName = "@amzn/awsgluenotebooks-extensions"
overridesPathBase = "/settings/overrides.json"
jupiterFolder = "~/.jupyter"
jupiterConfig = "jupyter_notebook_config.py"
def getSytemPrefix():
processOutput = subprocess.run(["jupyter", "lab", "path"], stdout=subprocess.PIPE)
path = processOutput.stdout.split()[2]
decodedPath = path.decode("utf-8")
return decodedPath
def getOverridesPath():
return f"{getSytemPrefix()}/settings/overrides.json"
def getUsername():
return pwd.getpwuid(os.getuid())[0]
def getJupiterConfigPath():
return os.path.expanduser(f"{jupiterFolder}/{jupiterConfig}")
def replaceLine(fileName, lineNum, text):
lines = open(fileName, "r").readlines()
lines[lineNum] = text
out = open(fileName, "w")
out.writelines(lines)
out.close()
def codeArtifactSubProcess(toolName):
return [
"aws",
"codeartifact",
"login",
"--tool",
toolName,
"--repository",
"aws-glue",
"--domain",
"amazon",
"--domain-owner",
str(ownerAccount),
]
subprocess.run(codeArtifactSubProcess("npm"))
subprocess.run(codeArtifactSubProcess("pip"))
subprocess.run(codeArtifactSubProcess("twine"))
subprocess.run(
[
"jupyter",
"labextension",
"install",
notebookExtensionName,
]
)
if os.path.exists(getJupiterConfigPath()):
os.remove(getJupiterConfigPath())
subprocess.run(
[
"jupyter",
"notebook",
"--generate-config",
]
)
replaceLine(getJupiterConfigPath(), 83, "c.NotebookApp.allow_origin = '*'\n\n")