Skip to content

Commit ae3386e

Browse files
committed
more logs
1 parent 95d2088 commit ae3386e

File tree

3 files changed

+39
-26
lines changed

3 files changed

+39
-26
lines changed

myst_libre/builders/myst_builder.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ def build(self,*args,user=None,group=None):
3131
self.cprint(f'Starting MyST build {self.hub.jh_url}','yellow')
3232
else:
3333
self.cprint(f'Starting MyST build no exec.','yellow')
34-
self.myst_client.build('build',*args,user=user,group=group)
34+
logs = self.myst_client.build('build',*args,user=user,group=group)
35+
return logs

myst_libre/tools/jupyter_hub_local_spawner.py

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ def _is_port_in_use(self, port):
6868
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
6969
return s.connect_ex(('127.0.0.1', port)) == 0
7070

71-
def spawn_jupyter_hub(self,jb_build_command=None):
71+
def spawn_jupyter_hub(self, jb_build_command=None):
7272
"""
7373
Spawn a JupyterHub instance.
7474
"""
75+
output_logs = [] # Collect logs and cprints here
7576
self.port = self.find_open_port()
7677
h = blake2b(digest_size=20)
7778
h.update(os.urandom(20))
@@ -96,8 +97,8 @@ def spawn_jupyter_hub(self,jb_build_command=None):
9697

9798
if self.rees.dataset_name:
9899
self.rees.repo2data_download(self.host_data_parent_dir)
99-
mnt_vol = {f'{os.path.join(self.host_data_parent_dir,self.rees.dataset_name)}': {'bind': os.path.join(self.container_data_mount_dir,self.rees.dataset_name), 'mode': 'ro'},
100-
self.rees.build_dir: {'bind': f'{self.container_build_source_mount_dir}', 'mode': 'rw'}}
100+
mnt_vol = {f'{os.path.join(self.host_data_parent_dir, self.rees.dataset_name)}': {'bind': os.path.join(self.container_data_mount_dir, self.rees.dataset_name), 'mode': 'ro'},
101+
self.rees.build_dir: {'bind': f'{self.container_build_source_mount_dir}', 'mode': 'rw'}}
101102
else:
102103
mnt_vol = {self.rees.build_dir: {'bind': f'{self.container_build_source_mount_dir}', 'mode': 'rw'}}
103104

@@ -107,33 +108,46 @@ def spawn_jupyter_hub(self,jb_build_command=None):
107108
self.container = self.rees.docker_client.containers.run(
108109
self.rees.docker_image,
109110
ports={f'{self.port}/tcp': self.port},
110-
environment={"JUPYTER_TOKEN": f'{self.jh_token}',"port": f'{self.port}',"JUPYTER_BASE_URL": f'{self.jh_url}'},
111-
entrypoint= this_entrypoint,
111+
environment={"JUPYTER_TOKEN": f'{self.jh_token}', "port": f'{self.port}', "JUPYTER_BASE_URL": f'{self.jh_url}'},
112+
entrypoint=this_entrypoint,
112113
volumes=mnt_vol,
113114
detach=True)
114115
logging.info(f'Jupyter hub is {self.container.status}')
115-
self.cprint(f'␤[Status]', 'light_grey')
116-
self.cprint(f' ├─────── ⏺ running', 'green')
117-
self.cprint(f' └─────── Container {self.container.short_id} {self.container.name}', 'green')
118-
self.cprint(f' ℹ Run the following commands in the terminal if you are debugging locally:', 'yellow')
119-
self.cprint(f' port=\"{self.port}\"', 'cyan')
120-
self.cprint(f' export JUPYTER_BASE_URL=\"{self.jh_url}\"', 'cyan')
121-
self.cprint(f' export JUPYTER_TOKEN=\"{self.jh_token}\"', 'cyan')
122-
self.cprint(f'␤[Resources]', 'light_grey')
123-
self.cprint(f' ├── MyST repository', 'magenta')
124-
self.cprint(f' │ ├───────── ✸ {self.rees.gh_user_repo_name}','light_blue')
125-
self.cprint(f' │ ├───────── ⎌ {self.rees.gh_repo_commit_hash}','light_blue')
126-
self.cprint(f" │ └───────── ⏲ {self.rees.repo_commit_info['datetime']}: {self.rees.repo_commit_info['message']}".replace('\n', ''),'light_blue')
127-
self.cprint(f' └── Docker container', 'magenta')
128-
self.cprint(f' ├───────── ✸ {self.rees.pull_image_name}','light_blue')
129-
self.cprint(f' ├───────── ⎌ {self.rees.binder_image_tag}','light_blue')
130-
self.cprint(f" ├───────── ⏲ {self.rees.binder_commit_info['datetime']}: {self.rees.binder_commit_info['message']}".replace('\n', ''),'light_blue')
116+
117+
# Use the helper function to log and print messages
118+
def log_and_print(message, color=None):
119+
output_logs.append(message)
120+
if color:
121+
self.cprint(message, color)
122+
else:
123+
print(message)
124+
125+
# Collecting and printing output
126+
log_and_print('␤[Status]', 'light_grey')
127+
log_and_print(' ├─────── ⏺ running', 'green')
128+
log_and_print(f' └─────── Container {self.container.short_id} {self.container.name}', 'green')
129+
log_and_print(' ℹ Run the following commands in the terminal if you are debugging locally:', 'yellow')
130+
log_and_print(f' port="{self.port}"', 'cyan')
131+
log_and_print(f' export JUPYTER_BASE_URL="{self.jh_url}"', 'cyan')
132+
log_and_print(f' export JUPYTER_TOKEN="{self.jh_token}"', 'cyan')
133+
log_and_print('␤[Resources]', 'light_grey')
134+
log_and_print(' ├── MyST repository', 'magenta')
135+
log_and_print(f' │ ├───────── ✸ {self.rees.gh_user_repo_name}', 'light_blue')
136+
log_and_print(f' │ ├───────── ⎌ {self.rees.gh_repo_commit_hash}', 'light_blue')
137+
log_and_print(f" │ └───────── ⏲ {self.rees.repo_commit_info['datetime']}: {self.rees.repo_commit_info['message']}".replace('\n', ''), 'light_blue')
138+
log_and_print(' └── Docker container', 'magenta')
139+
log_and_print(f' ├───────── ✸ {self.rees.pull_image_name}', 'light_blue')
140+
log_and_print(f' ├───────── ⎌ {self.rees.binder_image_tag}', 'light_blue')
141+
log_and_print(f" ├───────── ⏲ {self.rees.binder_commit_info['datetime']}: {self.rees.binder_commit_info['message']}".replace('\n', ''), 'light_blue')
131142
if self.rees.binder_image_name:
132-
self.cprint(f' └───────── ℹ Using NeuroLibre base image {self.rees.binder_image_name}','yellow')
143+
log_and_print(f' └───────── ℹ Using NeuroLibre base image {self.rees.binder_image_name}', 'yellow')
133144
else:
134-
self.cprint(f' └───────── ℹ This image was built from REES-compliant {self.rees.gh_user_repo_name} repository at the commit above','yellow')
145+
log_and_print(f' └───────── ℹ This image was built from REES-compliant {self.rees.gh_user_repo_name} repository at the commit above', 'yellow')
135146
except Exception as e:
136147
logging.error(f'Could not spawn a JH: \n {e}')
148+
output_logs.append(f'Error: {e}') # Collecting error output
149+
150+
return output_logs # Return collected logs and cprints
137151

138152
def delete_stopped_containers(self):
139153
"""

myst_libre/tools/myst_client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,7 @@ def build(self, *args, user=None, group=None):
157157
str: Command output or None if failed.
158158
"""
159159
os.chdir(self.build_dir)
160-
#self.cprint(f"--> Self env vars {self.env_vars}", "green")
161160
stdout_log, stderr_log = self.run_command(*args, env_vars=self.env_vars, user=user, group=group)
162-
#self.cprint(f"🐞 Command output: {stdout_log}", "light_grey")
163161
if stderr_log is not None:
164162
stdout_log += stderr_log
165163
return stdout_log

0 commit comments

Comments
 (0)