From 24464b7c1019f7a7b3149ecb80a379c5f82337a0 Mon Sep 17 00:00:00 2001 From: Victor Sonck Date: Tue, 14 Dec 2021 19:49:34 +0100 Subject: [PATCH] Add better input handling for clearml-init in colab (#515) --- clearml/cli/config/__main__.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/clearml/cli/config/__main__.py b/clearml/cli/config/__main__.py index 634abcda..65cff178 100644 --- a/clearml/cli/config/__main__.py +++ b/clearml/cli/config/__main__.py @@ -67,10 +67,19 @@ def main(): print(description, end='') sentinel = '' parse_input = '' - for line in iter(input, sentinel): - parse_input += line+'\n' - if line.rstrip() == '}': - break + # COLAB_GPU will always be available, even when running on CPU + if os.environ.get('COLAB_GPU'): + # When running from a colab instance and calling clearml-init + # colab will squish the api credentials into a single line + # The regex splits this single line based on 2 spaces or more + import re + api_input = input() + parse_input = '\n'.join(re.split(r" {2,}", api_input)) + else: + for line in iter(input, sentinel): + parse_input += line+'\n' + if line.rstrip() == '}': + break credentials = None api_server = None web_server = None