20
20
from hopsworks import command , util
21
21
from hopsworks .core import environment_api , library_api
22
22
from hopsworks .engine import environment_engine
23
+ from typing import Optional
23
24
24
25
25
26
class Environment :
26
27
def __init__ (
27
28
self ,
28
- python_version ,
29
- python_conflicts ,
30
- pip_search_enabled ,
29
+ name = None ,
30
+ description = None ,
31
+ python_version = None ,
32
+ python_conflicts = None ,
33
+ pip_search_enabled = None ,
31
34
conflicts = None ,
32
35
conda_channel = None ,
33
36
libraries = None ,
@@ -38,6 +41,8 @@ def __init__(
38
41
project_name = None ,
39
42
** kwargs ,
40
43
):
44
+ self ._name = name
45
+ self ._description = description
41
46
self ._python_version = python_version
42
47
self ._python_conflicts = python_conflicts
43
48
self ._pip_search_enabled = pip_search_enabled
@@ -77,7 +82,17 @@ def python_version(self):
77
82
"""Python version of the environment"""
78
83
return self ._python_version
79
84
80
- def install_wheel (self , path , await_installation = True ):
85
+ @property
86
+ def name (self ):
87
+ """Name of the environment"""
88
+ return self ._name
89
+
90
+ @property
91
+ def description (self ):
92
+ """Description of the environment"""
93
+ return self ._description
94
+
95
+ def install_wheel (self , path , await_installation : Optional [bool ] = True ):
81
96
"""Install a python library packaged in a wheel file
82
97
83
98
```python
@@ -92,7 +107,8 @@ def install_wheel(self, path, await_installation=True):
92
107
93
108
# Install
94
109
env_api = project.get_environment_api()
95
- env = env_api.get_environment()
110
+ env = env_api.get_environment("my_custom_environment")
111
+
96
112
env.install_wheel(whl_path)
97
113
98
114
```
@@ -103,7 +119,7 @@ def install_wheel(self, path, await_installation=True):
103
119
"""
104
120
105
121
# Wait for any ongoing environment operations
106
- self ._environment_engine .await_environment_command ()
122
+ self ._environment_engine .await_environment_command (self . name )
107
123
108
124
library_name = os .path .basename (path )
109
125
@@ -116,15 +132,15 @@ def install_wheel(self, path, await_installation=True):
116
132
}
117
133
118
134
library_rest = self ._library_api .install (
119
- library_name , self .python_version , library_spec
135
+ library_name , self .name , library_spec
120
136
)
121
137
122
138
if await_installation :
123
- return self ._environment_engine .await_library_command (library_name )
139
+ return self ._environment_engine .await_library_command (self . name , library_name )
124
140
125
141
return library_rest
126
142
127
- def install_requirements (self , path , await_installation = True ):
143
+ def install_requirements (self , path , await_installation : Optional [ bool ] = True ):
128
144
"""Install libraries specified in a requirements.txt file
129
145
130
146
```python
@@ -139,7 +155,9 @@ def install_requirements(self, path, await_installation=True):
139
155
140
156
# Install
141
157
env_api = project.get_environment_api()
142
- env = env_api.get_environment()
158
+ env = env_api.get_environment("my_custom_environment")
159
+
160
+
143
161
env.install_requirements(requirements_path)
144
162
145
163
```
@@ -150,7 +168,7 @@ def install_requirements(self, path, await_installation=True):
150
168
"""
151
169
152
170
# Wait for any ongoing environment operations
153
- self ._environment_engine .await_environment_command ()
171
+ self ._environment_engine .await_environment_command (self . name )
154
172
155
173
library_name = os .path .basename (path )
156
174
@@ -163,11 +181,11 @@ def install_requirements(self, path, await_installation=True):
163
181
}
164
182
165
183
library_rest = self ._library_api .install (
166
- library_name , self .python_version , library_spec
184
+ library_name , self .name , library_spec
167
185
)
168
186
169
187
if await_installation :
170
- return self ._environment_engine .await_library_command (library_name )
188
+ return self ._environment_engine .await_library_command (self . name , library_name )
171
189
172
190
return library_rest
173
191
@@ -178,7 +196,7 @@ def delete(self):
178
196
# Raises
179
197
`RestAPIError`.
180
198
"""
181
- self ._environment_api ._delete (self .python_version )
199
+ self ._environment_api ._delete (self .name )
182
200
183
201
def __repr__ (self ):
184
- return f"Environment({ self ._python_version !r} )"
202
+ return f"Environment({ self .name !r} )"
0 commit comments