Skip to content

Commit 0633e35

Browse files
authored
Revert "IncludeFile now returns the included file in the client (#607)" (#637)
This reverts commit 0575f8d.
1 parent 74bb0d7 commit 0633e35

File tree

5 files changed

+41
-89
lines changed

5 files changed

+41
-89
lines changed

metaflow/client/core.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
MetaflowNamespaceMismatch,\
1212
MetaflowInternalError
1313

14-
from metaflow.includefile import IncludedFile
1514
from metaflow.metaflow_config import DEFAULT_METADATA
1615
from metaflow.plugins import ENVIRONMENTS, METADATA_PROVIDERS
1716
from metaflow.unbounded_foreach import CONTROL_TASK_TAG
@@ -712,8 +711,6 @@ def data(self):
712711
sha = self._object['sha']
713712
with filecache.get_data(ds_type, self.path_components[0], sha) as f:
714713
obj = pickle.load(f)
715-
if isinstance(obj, IncludedFile):
716-
return obj.decode(self.id)
717714
return obj
718715

719716
# TODO add

metaflow/includefile.py

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -165,27 +165,6 @@ def put(self, key, obj, overwrite=True):
165165
DATACLIENTS = {'local': Local,
166166
's3': S3}
167167

168-
class IncludedFile(object):
169-
# Thin wrapper to indicate to the MF client that this object is special
170-
# and should be handled as an IncludedFile when returning it (ie: fetching
171-
# the actual content)
172-
173-
def __init__(self, descriptor):
174-
self._descriptor = json.dumps(descriptor)
175-
176-
@property
177-
def descriptor(self):
178-
return self._descriptor
179-
180-
def decode(self, name, var_type='Artifact'):
181-
ok, file_type, err = LocalFile.is_file_handled(self._descriptor)
182-
if not ok:
183-
raise MetaflowException("%s '%s' could not be loaded: %s" % (var_type, name, err))
184-
if file_type is None or isinstance(file_type, LocalFile):
185-
raise MetaflowException("%s '%s' was not properly converted" % (var_type, name))
186-
return file_type.load(self._descriptor)
187-
188-
189168
class LocalFile():
190169
def __init__(self, is_text, encoding, path):
191170
self._is_text = is_text
@@ -194,16 +173,7 @@ def __init__(self, is_text, encoding, path):
194173

195174
@classmethod
196175
def is_file_handled(cls, path):
197-
# This returns a tuple:
198-
# - True/False indicating whether the file is handled
199-
# - None if we need to create a handler for the file, a LocalFile if
200-
# we already know what to do with the file or a Uploader if the file
201-
# is already present remotely (either starting with s3:// or local://)
202-
# - An error message if file is not handled
203176
if path:
204-
if isinstance(path, IncludedFile):
205-
path = path.descriptor
206-
207177
decoded_value = Uploader.decode_value(to_unicode(path))
208178
if decoded_value['type'] == 'self':
209179
return True, LocalFile(
@@ -325,10 +295,15 @@ def __init__(
325295
name, required=required, help=help,
326296
type=FilePathClass(is_text, encoding), **kwargs)
327297

328-
def load_parameter(self, v):
329-
if v is None:
330-
return v
331-
return v.decode(self.name, var_type='Parameter')
298+
def load_parameter(self, val):
299+
if val is None:
300+
return val
301+
ok, file_type, err = LocalFile.is_file_handled(val)
302+
if not ok:
303+
raise MetaflowException("Parameter '%s' could not be loaded: %s" % (self.name, err))
304+
if file_type is None or isinstance(file_type, LocalFile):
305+
raise MetaflowException("Parameter '%s' was not properly converted" % self.name)
306+
return file_type.load(val)
332307

333308

334309
class Uploader():
@@ -341,11 +316,11 @@ def __init__(self, client_class):
341316
@staticmethod
342317
def encode_url(url_type, url, **kwargs):
343318
# Avoid encoding twice (default -> URL -> _convert method of FilePath for example)
344-
if isinstance(url, IncludedFile):
319+
if url is None or len(url) == 0 or url[0] == '{':
345320
return url
346321
return_value = {'type': url_type, 'url': url}
347322
return_value.update(kwargs)
348-
return IncludedFile(return_value)
323+
return json.dumps(return_value)
349324

350325
@staticmethod
351326
def decode_value(value):

test/core/metaflow_test/cli_check.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import json
55
from tempfile import NamedTemporaryFile
66

7-
from metaflow.includefile import IncludedFile
87
from metaflow.util import is_stringish
98

109
from . import MetaflowCheck, AssertArtifactFailed, AssertLogFailed, truncate
@@ -40,8 +39,6 @@ def assert_artifact(self, step, name, value, fields=None):
4039
for field, v in fields.items():
4140
if is_stringish(artifact):
4241
data = json.loads(artifact)
43-
elif isinstance(artifact, IncludedFile):
44-
data = json.loads(artifact.descriptor)
4542
else:
4643
data = artifact
4744
if not isinstance(data, dict):
@@ -95,4 +92,4 @@ def get_log(self, step, logtype):
9592
'logs',
9693
'--%s' % logtype,
9794
'%s/%s' % (self.run_id, step)]
98-
return self.run_cli(cmd, capture_output=True).decode('utf-8')
95+
return self.run_cli(cmd, capture_output=True).decode('utf-8')

test/core/metaflow_test/metadata_check.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
32
from metaflow.util import is_stringish
43

54
from . import MetaflowCheck, AssertArtifactFailed, AssertLogFailed, assert_equals, assert_exception, truncate

test/core/tests/basic_include.py

Lines changed: 29 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -41,49 +41,33 @@ def step_all(self):
4141
pass
4242

4343
def check_results(self, flow, checker):
44-
run = checker.get_run()
45-
if run is None:
46-
# CliChecker does not return a run object; we check to make sure
47-
# the returned value is the blob describing the artifact
48-
# (this may be improved in the future)
49-
for step in flow:
50-
checker.assert_artifact(
51-
step.name,
52-
'myfile_txt',
53-
None,
54-
fields={'type': 'uploader-v1',
55-
'is_text': True,
56-
'encoding': None})
57-
checker.assert_artifact(
58-
step.name,
59-
'myfile_utf8',
60-
None,
61-
fields={'type': 'uploader-v1',
62-
'is_text': True,
63-
'encoding': 'utf8'})
64-
checker.assert_artifact(
65-
step.name,
66-
'myfile_binary',
67-
None,
68-
fields={'type': 'uploader-v1',
69-
'is_text': False,
70-
'encoding': None})
71-
checker.assert_artifact(
72-
step.name,
73-
'myfile_overriden',
74-
None,
75-
fields={'type': 'uploader-v1',
76-
'is_text': True,
77-
'encoding': None})
78-
else:
79-
# In the case of the client, we check the value.
80-
for step in flow:
81-
checker.assert_artifact(step.name, 'myfile_txt',
82-
"Regular Text File")
83-
checker.assert_artifact(step.name, 'myfile_utf8',
84-
u"UTF Text File \u5e74")
85-
checker.assert_artifact(step.name, 'myfile_binary',
86-
u"UTF Text File \u5e74".encode(encoding='utf8'))
87-
checker.assert_artifact(step.name, 'myfile_overriden',
88-
"Override Text File")
44+
for step in flow:
45+
checker.assert_artifact(
46+
step.name,
47+
'myfile_txt',
48+
None,
49+
fields={'type': 'uploader-v1',
50+
'is_text': True,
51+
'encoding': None})
52+
checker.assert_artifact(
53+
step.name,
54+
'myfile_utf8',
55+
None,
56+
fields={'type': 'uploader-v1',
57+
'is_text': True,
58+
'encoding': 'utf8'})
59+
checker.assert_artifact(
60+
step.name,
61+
'myfile_binary',
62+
None,
63+
fields={'type': 'uploader-v1',
64+
'is_text': False,
65+
'encoding': None})
66+
checker.assert_artifact(
67+
step.name,
68+
'myfile_overriden',
69+
None,
70+
fields={'type': 'uploader-v1',
71+
'is_text': True,
72+
'encoding': None})
8973

0 commit comments

Comments
 (0)