Skip to content

Commit 062f975

Browse files
author
Seb Boving
committed
Support adding an /etc/host entry for the data proxy, if asked.
1 parent a364dfe commit 062f975

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

patches/sitecustomize.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,27 @@
55
import torch
66
import os
77

8+
_HOST_FILE = "/etc/hosts"
9+
810
kaggle_proxy_token = os.getenv("KAGGLE_DATA_PROXY_TOKEN")
911
if kaggle_proxy_token:
1012
from google.auth import credentials
1113
from google.cloud import bigquery
1214
from google.cloud.bigquery._http import Connection
1315

16+
host_entry = os.getenv("KAGGLE_DATA_PROXY_HOST_ENTRY")
17+
if host_entry:
18+
host_entry = host_entry.strip()
19+
with open(_HOST_FILE, "r") as host_file:
20+
for line in host_file:
21+
if line.strip() == host_entry:
22+
break
23+
else:
24+
with open(_HOST_FILE, "a") as host_file_append:
25+
host_file_append.write("\n" # Just in case it wasn't newline terminated.
26+
+ host_entry
27+
+ "\n")
28+
1429
Connection.API_BASE_URL = os.getenv("KAGGLE_DATA_PROXY_URL")
1530
Connection._EXTRA_HEADERS["X-KAGGLE-PROXY-DATA"] = kaggle_proxy_token
1631

0 commit comments

Comments
 (0)