22from __future__ import absolute_import , division , print_function
33
44import atexit
5+ import json
6+ import os
57import sys
68import time
79
810from polystores .stores .manager import StoreManager
911
1012from polyaxon_client import PolyaxonClient , settings
1113from polyaxon_client .exceptions import PolyaxonClientException
14+ from polyaxon_client .tracking .in_cluster import ensure_in_custer
1215from polyaxon_client .tracking .paths import get_outputs_path
1316from polyaxon_client .tracking .utils .project import get_project_info
1417
@@ -28,6 +31,9 @@ def __init__(self,
2831
2932 if not settings .IN_CLUSTER and project is None :
3033 raise PolyaxonClientException ('Please provide a valid project.' )
34+ elif self .is_notebook_job :
35+ job_info = self .get_notebook_job_info ()
36+ project = job_info ['project_name' ]
3137
3238 self .last_status = None
3339 self .client = client or PolyaxonClient ()
@@ -52,6 +58,29 @@ def __init__(self,
5258 if outputs_store is None and settings .IN_CLUSTER and self .REQUIRES_OUTPUTS :
5359 self .set_outputs_store (outputs_path = get_outputs_path (), set_env_vars = True )
5460
61+ def get_notebook_job_info (self ):
62+ if settings .NO_OP :
63+ return None
64+
65+ ensure_in_custer ()
66+
67+ info = os .getenv ('POLYAXON_NOTEBOOK_INFO' , None )
68+ try :
69+ return json .loads (info ) if info else None
70+ except (ValueError , TypeError ):
71+ print ('Could get experiment info, '
72+ 'please make sure this is running inside a polyaxon job.' )
73+ return None
74+
75+ @property
76+ def is_notebook_job (self ):
77+ if settings .NO_OP :
78+ return None
79+
80+ ensure_in_custer ()
81+
82+ return 'POLYAXON_NOTEBOOK_INFO' in os .environ
83+
5584 def get_data (self ):
5685 raise NotImplementedError
5786
0 commit comments