Skip to content

Commit 830e50a

Browse files
ttapjindaseldondev
authored andcommitted
add pip dependency only if not already exist
1 parent a737ae5 commit 830e50a

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

servers/mlflowserver/mlflowserver/conda_env_create.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import argparse
88
import json
99
import yaml
10+
import re
1011
import tempfile
1112
from subprocess import run
1213
from seldon_core.microservice import PARAMETERS_ENV_NAME, parse_parameters
@@ -78,7 +79,16 @@ def inject_base_reqs(env_file_path):
7879
for dep in conda_env["dependencies"]:
7980
if isinstance(dep, dict) and "pip" in dep:
8081
pip_exists = True
81-
dep["pip"].append(f"-r {BASE_REQS_PATH}")
82+
r = re.compile("=|>|<| ")
83+
package_list = [r.split(p)[0] for p in dep["pip"]]
84+
with open(BASE_REQS_PATH) as f:
85+
for line in f:
86+
line = line.rstrip()
87+
if not line or line.startswith("#"):
88+
continue
89+
package_name = r.split(line)[0]
90+
if package_name not in package_list:
91+
dep["pip"].append(line)
8292
break
8393
if not pip_exists:
8494
new_entry = {"pip": [f"-r {BASE_REQS_PATH}"]}

0 commit comments

Comments
 (0)