Skip to content

Commit

Permalink
[Runtimes] Fix requirements parsing in with_requirements (#894)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hedingber committed Apr 29, 2021
1 parent c731ee0 commit 65744d2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mlrun/runtimes/base.py
Expand Up @@ -792,7 +792,7 @@ def with_requirements(self, requirements: Union[str, List[str]]):
"""
if isinstance(requirements, str):
with open(requirements, "r") as fp:
requirements = fp.readlines()
requirements = fp.read().splitlines()
commands = self.spec.build.commands or []
commands.append("python -m pip install " + " ".join(requirements))
self.spec.build.commands = commands
Expand Down
2 changes: 2 additions & 0 deletions tests/api/runtimes/assets/requirements.txt
@@ -0,0 +1,2 @@
faker
python-dotenv
1 change: 1 addition & 0 deletions tests/api/runtimes/base.py
Expand Up @@ -34,6 +34,7 @@ def setup_method(self, method):
self.artifact_path = "/tmp"
self.function_name_label = "mlrun/name"
self.code_filename = str(self.assets_path / "sample_function.py")
self.requirements_file = str(self.assets_path / "requirements.txt")

self.vault_secrets = ["secret1", "secret2", "AWS_KEY"]
self.vault_secret_value = "secret123!@"
Expand Down
12 changes: 12 additions & 0 deletions tests/api/runtimes/test_kubejob.py
@@ -1,5 +1,6 @@
import os

import deepdiff
import pytest
from fastapi.testclient import TestClient
from sqlalchemy.orm import Session
Expand Down Expand Up @@ -241,3 +242,14 @@ def test_set_label(self, db: Session, client: TestClient):
runtime = self._generate_runtime()
self._execute_run(runtime, runspec=task)
self._assert_pod_creation_config(expected_labels=labels)

def test_with_requirements(self, db: Session, client: TestClient):
runtime = self._generate_runtime()
runtime.with_requirements(self.requirements_file)
expected_commands = ["python -m pip install faker python-dotenv"]
assert (
deepdiff.DeepDiff(
expected_commands, runtime.spec.build.commands, ignore_order=True,
)
== {}
)

0 comments on commit 65744d2

Please sign in to comment.