@@ -22,9 +22,8 @@ class Python(_environment._Environment):
22
22
23
23
Parameters
24
24
----------
25
- requirements : list of str, optional
26
- List of PyPI package names. If not provided, all packages currently installed through
27
- pip will be captured.
25
+ requirements : list of str
26
+ List of PyPI package names.
28
27
constraints : list of str, optional
29
28
List of PyPI package names with version specifiers. If not provided, nothing will be
30
29
captured.
@@ -38,21 +37,22 @@ class Python(_environment._Environment):
38
37
.. code-block:: python
39
38
40
39
from verta.environment import Python
41
- env1 = Python(requirements=Python.read_pip_file("../requirements.txt"))
42
- env2 = Python(
40
+ env1 = Python(requirements=Python.read_pip_environment())
41
+ env2 = Python(requirements=Python.read_pip_file("../requirements.txt"))
42
+ env3 = Python(
43
43
requirements=["tensorflow"],
44
44
env_vars=["CUDA_VISIBLE_DEVICES"],
45
45
)
46
46
47
47
"""
48
- def __init__ (self , requirements = None , constraints = None , env_vars = None , _autocapture = True ):
48
+ def __init__ (self , requirements , constraints = None , env_vars = None , _autocapture = True ):
49
49
super (Python , self ).__init__ (env_vars , _autocapture )
50
50
51
51
if _autocapture :
52
52
self ._capture_python_version ()
53
- if requirements is not None or _autocapture :
53
+ if requirements or _autocapture :
54
54
self ._capture_requirements (requirements )
55
- if constraints is not None :
55
+ if constraints :
56
56
self ._capture_constraints (constraints )
57
57
58
58
def __repr__ (self ):
@@ -105,7 +105,7 @@ def __repr__(self):
105
105
106
106
@classmethod
107
107
def _from_proto (cls , blob_msg ):
108
- obj = cls (_autocapture = False )
108
+ obj = cls (requirements = [], _autocapture = False )
109
109
obj ._msg .CopyFrom (blob_msg .environment )
110
110
111
111
return obj
@@ -175,11 +175,8 @@ def _capture_python_version(self):
175
175
self ._msg .python .version .patch = sys .version_info .micro
176
176
177
177
def _capture_requirements (self , requirements ):
178
- if requirements is None :
179
- # TODO: support conda
180
- req_specs = self .read_pip_environment ()
181
- elif (isinstance (requirements , list )
182
- and all (isinstance (req , six .string_types ) for req in requirements )):
178
+ if (isinstance (requirements , list )
179
+ and all (isinstance (req , six .string_types ) for req in requirements )):
183
180
req_specs = copy .copy (requirements )
184
181
_pip_requirements_utils .process_requirements (req_specs )
185
182
else :
0 commit comments