Skip to content

Commit 0cf2e03

Browse files
committed
Dotenv location dependent inits
1 parent a3ecc03 commit 0cf2e03

File tree

5 files changed

+28
-9
lines changed

5 files changed

+28
-9
lines changed

example.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
registry_url="https://binder-registry.conp.cloud",
77
gh_user_repo_name = "agahkarakuzu/mriscope",
88
gh_repo_commit_hash = "ae64d9ed17e6ce66ecf94d585d7b68a19a435d70",
9-
binder_image_tag = "489ae0eb0d08fe30e45bc31201524a6570b9b7dd"))
9+
binder_image_tag = "489ae0eb0d08fe30e45bc31201524a6570b9b7dd",
10+
dotenv = "/where/dotenv/is/located"))
1011

1112

1213
hub = JupyterHubLocalSpawner(resources,

myst_libre/rees/rees.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ def __init__(self, rees_dict):
1111
self.gh_user_repo_name = rees_dict['gh_user_repo_name']
1212
self.gh_repo_commit_hash = rees_dict['gh_repo_commit_hash']
1313
self.binder_image_tag = rees_dict['binder_image_tag']
14+
15+
if 'dotenv' in rees_dict.keys():
16+
self.dotenvloc = rees_dict['dotenv']
17+
1418
# Initialize as base to rees
1519
BuildSourceManager.__init__(self)
1620
DockerRegistryClient.__init__(self)

myst_libre/tools/authenticator.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
from myst_libre.abstract_class import AbstractClass
44

55
class Authenticator(AbstractClass):
6-
def __init__(self):
6+
def __init__(self,dotenvloc = '.'):
77
super().__init__()
88
self._auth = {}
9+
self.dotenvloc = dotenvloc
910
self._load_auth_from_env()
1011

1112
def _load_auth_from_env(self):
12-
load_dotenv()
13+
14+
load_dotenv(os.path.join(self.dotenvloc,'.env'))
15+
1316
username = os.getenv('DOCKER_PRIVATE_REGISTRY_USERNAME')
1417
password = os.getenv('DOCKER_PRIVATE_REGISTRY_PASSWORD')
1518

@@ -20,5 +23,8 @@ def _load_auth_from_env(self):
2023
self._auth['username'] = username
2124
self._auth['password'] = password
2225

23-
del os.environ['DOCKER_PRIVATE_REGISTRY_USERNAME']
24-
del os.environ['DOCKER_PRIVATE_REGISTRY_PASSWORD']
26+
try:
27+
del os.environ['DOCKER_PRIVATE_REGISTRY_USERNAME']
28+
del os.environ['DOCKER_PRIVATE_REGISTRY_PASSWORD']
29+
except:
30+
pass

myst_libre/tools/docker_registry_client.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@ class DockerRegistryClient(Authenticator):
2323
def __init__(self, **kwargs):
2424
for key, value in kwargs.items():
2525
setattr(self, key, value)
26-
super().__init__()
26+
27+
if hasattr(self, 'dotenvloc'):
28+
super().__init__(self.dotenvloc)
29+
self.rest_client = RestClient(self.dotenvloc)
30+
else:
31+
super().__init__()
32+
self.rest_client = RestClient()
33+
2734
self.registry_url_bare = self.registry_url.replace("http://", "").replace("https://", "")
2835
self.found_image_name = None
2936
self.found_image_tags = None
3037
self.docker_images = []
31-
self.rest_client = RestClient()
38+
3239

3340
def get_token(self):
3441
"""

myst_libre/tools/rest_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ class RestClient(Authenticator):
1717
Args:
1818
auth (dict): Authentication credentials.
1919
"""
20-
def __init__(self):
21-
super().__init__()
20+
def __init__(self,dotenvloc = '.'):
21+
print(dotenvloc)
22+
super().__init__(dotenvloc)
2223
self.session = requests.Session()
2324
self.session.auth = HTTPBasicAuth(self._auth['username'], self._auth['password'])
2425

0 commit comments

Comments
 (0)