def test_creation_and_hydration(self): path = random_str(random_int(10, 50)) is_dir = random_int(10, 2500) % 2 == 0 size_in_bytes = random_int(1, 10000) fi1 = FileInfo(path, is_dir, size_in_bytes) self._check(fi1, path, is_dir, size_in_bytes) as_dict = {"path": path, "is_dir": is_dir, "file_size": size_in_bytes} self.assertEqual(dict(fi1), as_dict) proto = fi1.to_proto() fi2 = FileInfo.from_proto(proto) self._check(fi2, path, is_dir, size_in_bytes) fi3 = FileInfo.from_dictionary(as_dict) self._check(fi3, path, is_dir, size_in_bytes)
def _list_artifacts_mlflow_artifacts(): """ A request handler for `GET /mlflow-artifacts/artifacts?path=<value>` to list artifacts in `path` (a relative path from the root artifact directory). """ request_message = _get_request_message(ListArtifactsMlflowArtifacts()) path = request_message.path if request_message.HasField("path") else None artifact_repo = _get_artifact_repo_mlflow_artifacts() files = [] for file_info in artifact_repo.list_artifacts(path): basename = posixpath.basename(file_info.path) new_file_info = FileInfo(basename, file_info.is_dir, file_info.file_size) files.append(new_file_info.to_proto()) response_message = ListArtifacts.Response() response_message.files.extend(files) response = Response(mimetype="application/json") response.set_data(message_to_json(response_message)) return response