MCPcopy Index your code
hub / github.com/tensorflow/datasets / _to_tmp

Method _to_tmp

tensorflow_datasets/testing/test_utils.py:153–177  ·  view source on GitHub ↗

Normalize the path by returning `tmp_path / p`.

(self, p, *, with_state: bool = False)

Source from the content-addressed store, hash-verified

151 # TODO(epot): recursively record all.
152
153 def _to_tmp(self, p, *, with_state: bool = False):
154 """Normalize the path by returning `tmp_path / p`."""
155 assert self._tmp_dir, 'Temp directory uninitialized.'
156 # If `p` was a `epath.Path`, it doesn't matter the value of `is_gcs`
157 # as returned values will be normalized anyway.
158 p_str = os.fspath(p)
159 state = _PathState(
160 is_gcs=p_str.startswith('gs://'),
161 is_abs=p_str.startswith('/'),
162 )
163 if state.is_gcs:
164 p = os.fspath(p).replace('gs://', '/big' + 'store/', 1)
165 p = pathlib.Path(p)
166 if p.anchor:
167 p = pathlib.Path(*p.parts[1:]) # Strip leading `/`
168 assert not p.is_absolute()
169 out_p = self._tmp_dir / p
170
171 # Propagate `is_gcs`, so results are consistents:
172 # * tf.io.gfile.glob('gs://')
173 # * tf.io.gfile.glob('/big' + 'store/')
174 if with_state:
175 return out_p, state
176 else:
177 return out_p
178
179 def _to_abs(self, p, *, state: _PathState):
180 """Normalize the output to strip the `tmp_path`."""

Callers 7

add_fileMethod · 0.95
read_fileMethod · 0.95
_mock_openMethod · 0.95
_mock_fnMethod · 0.95
_mock_fn_2_argsMethod · 0.95
_mock_globMethod · 0.95
_mock_walkMethod · 0.95

Calls 2

_PathStateClass · 0.85
replaceMethod · 0.45

Tested by

no test coverage detected