Spaces:
Sleeping
Sleeping
File size: 3,341 Bytes
50f034f |
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# This script guides the user through setting up their env.sh
# if env.sh does not exist. Should have no dependencies other
# than Python standard library.
import shlex
import socket
import subprocess
import textwrap
def run(cmd):
return subprocess.check_output(shlex.split(cmd)).decode("utf-8")
print("1. Setting up Google Cloud access")
print("---------------------------------")
gcloud_authorized = "gs://research-data-raw" in run("gsutil ls")
if not gcloud_authorized:
run("gcloud auth login")
run("gcloud config set project lyrebird-research")
run("gcloud auth configure-docker")
print()
print("2. Setting up Github access")
print("---------------------------")
lines = textwrap.wrap(
"First, let's get your Github token, so all "
"packages can be installed. Create one by going to your "
"Github profile -> Developer settings -> Personal access tokens -> "
"Generate new token. Copy the token below."
)
[print(l) for l in lines]
GITHUB_TOKEN = input("\nGithub token: ") or "undefined"
print()
print("3. Setting up Jupyter and Tensorboard")
print("-------------------------------------")
JUPYTER_TOKEN = input("Password for Jupyter server (default:password): ") or "password"
JUPYTER_PORT = input("Jupyter port to run on (default:8888): ") or "8888"
TENSORBOARD_PORT = input("Tensorboard port to run on (default:6006): ") or "6006"
print()
print("4. Setting up paths.")
print("--------------------")
PATH_TO_RUNS = input("Where runs should go (default:./runs/): ") or "./runs/"
TENSORBOARD_PATH = (
input("Bucket/dir for tensorboard logs (default=PATH_TO_RUNS): ") or PATH_TO_RUNS
)
with open("env/data.sh") as f:
data_script = f.read()
write_to_data_sh = False
if socket.gethostname() not in data_script:
print("Looks like the data path for this machine is not setup.")
PATH_TO_DATA = input(f"Path to data on {socket.gethostname()}: ") or "~/data"
data_command = f"""
if [[ $(hostname) == "{socket.gethostname()}" ]]; then
export PATH_TO_DATA={PATH_TO_DATA}
fi
"""
write_to_data_sh = True
print()
print("5. Setting up Papaya")
print("-----------------------------------------")
PAPAYA_USER_TOKEN = input("Papaya user token: ") or "undefined"
env_script = f"""
source env/alias.sh
source env/data.sh
export GITHUB_TOKEN={GITHUB_TOKEN}
export PAPAYA_USER_TOKEN={PAPAYA_USER_TOKEN}
export HOST_USER_ID=$(id -u)
export HOST_USER_GID=$(id -g)
export JUPYTER_TOKEN={JUPYTER_TOKEN}
export JUPYTER_PORT={JUPYTER_PORT}
export TENSORBOARD_PORT={TENSORBOARD_PORT}
export PATH_TO_RUNS={PATH_TO_RUNS}
export TENSORBOARD_PATH={TENSORBOARD_PATH}
"""
print()
print("6. Potential file contents.")
print("---------------------------")
print("env/env.sh: \n")
print("##################")
print(env_script)
print("##################")
if write_to_data_sh:
data_script += data_command
print("env/data.sh:")
print("##################")
print(data_script)
print("##################")
print()
write_to_files = input("Write to file [yn]? ") or "n"
if write_to_files == "y":
with open("env/env.sh", "w") as f:
f.write(env_script.strip())
with open("env/data.sh", "w") as f:
f.write(data_script.strip())
print()
print("8. Finalize setup.")
print("------------------")
print("Run the following command to complete setup.")
print("source env/env.sh")
|