Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Try except block for conda/source activate #94

Merged
merged 3 commits into from
Jul 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions jupyter_forward/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,23 @@ def start(self):
)

def _launch_jupyter(self):

console.rule(
'[bold green]Running jupyter sanity checks (ensuring `jupyter` is in `$PATH`)',
characters='*',
)
check_jupyter_status = 'sh -c "command -v jupyter"'
conda_activate_cmd = 'source activate'
if self.conda_env:
check_jupyter_status = f'source activate {self.conda_env} && sh -c "command -v jupyter"'
console.rule('[bold green]Running jupyter sanity checks', characters='*')
self.run_command(command=check_jupyter_status)
try:
self.run_command(f'{conda_activate_cmd} {self.conda_env} && {check_jupyter_status}')
except SystemExit:
console.print(f'`{conda_activate_cmd}` failed. Trying `conda activate`...')
self.run_command(f'conda activate {self.conda_env} && {check_jupyter_status}')
conda_activate_cmd = 'conda activate'

else:
self.run_command(check_jupyter_status)
console.rule(
f'[bold green] Checking $TMPDIR and $HOME on {self.session.host}', characters='*'
)
Expand Down Expand Up @@ -186,7 +198,7 @@ def _launch_jupyter(self):
command = f'{command} --notebook-dir={self.notebook_dir}'
command = f'{command} >& {self.log_file}'
if self.conda_env:
command = f'source activate {self.conda_env} && {command}'
command = f'{conda_activate_cmd} {self.conda_env} && {command}'

if self.launch_command:
console.rule('[bold green]Preparing Batch Job script', characters='*')
Expand Down Expand Up @@ -268,9 +280,7 @@ def open_browser(port: int = None, token: str = None, url: str = None):
def is_port_available(port):
socket_for_port_check = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
status = socket_for_port_check.connect_ex(('localhost', int(port)))
if status == 0: # Port is in use
return False
return True
return status != 0


def parse_stdout(stdout: str):
Expand Down