2
2
from __future__ import absolute_import , division , print_function
3
3
4
4
import atexit
5
+ import json
6
+ import os
5
7
import sys
6
8
import time
7
9
8
10
from polystores .stores .manager import StoreManager
9
11
10
12
from polyaxon_client import PolyaxonClient , settings
11
13
from polyaxon_client .exceptions import PolyaxonClientException
14
+ from polyaxon_client .tracking .in_cluster import ensure_in_custer
12
15
from polyaxon_client .tracking .paths import get_outputs_path
13
16
from polyaxon_client .tracking .utils .project import get_project_info
14
17
@@ -28,6 +31,9 @@ def __init__(self,
28
31
29
32
if not settings .IN_CLUSTER and project is None :
30
33
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' ]
31
37
32
38
self .last_status = None
33
39
self .client = client or PolyaxonClient ()
@@ -52,6 +58,29 @@ def __init__(self,
52
58
if outputs_store is None and settings .IN_CLUSTER and self .REQUIRES_OUTPUTS :
53
59
self .set_outputs_store (outputs_path = get_outputs_path (), set_env_vars = True )
54
60
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
+
55
84
def get_data (self ):
56
85
raise NotImplementedError
57
86
0 commit comments