Normalize the path by returning `tmp_path / p`.
(self, p, *, with_state: bool = False)
| 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`.""" |
no test coverage detected