diff --git a/python/sdk/merlin/requirements.py b/python/sdk/merlin/requirements.py index a4849f6f1..328e9a064 100644 --- a/python/sdk/merlin/requirements.py +++ b/python/sdk/merlin/requirements.py @@ -5,7 +5,7 @@ from typing import Any, List, Optional import yaml -from packaging.requirements import Requirement +from packaging.requirements import Requirement, InvalidRequirement _CONSTRAINTS_FILE_NAME = "constraints.txt" @@ -51,6 +51,11 @@ def process_conda_env( for additional_merlin_req in additional_merlin_reqs: exist = False for pip_req in pip_reqs: + # Skip requirement comparison for pip reqs that is not a package, which can happen if the user specifies + # repository or trusted host as part of the pip file + if pip_req.strip().startswith("--"): + continue + pip_req_obj = Requirement(pip_req) additional_merlin_req_obj = Requirement(additional_merlin_req) if pip_req_obj.name.lower() == additional_merlin_req_obj.name.lower(): diff --git a/python/sdk/test/requirements/non_package_reqs_in.yaml b/python/sdk/test/requirements/non_package_reqs_in.yaml new file mode 100644 index 000000000..56d14156b --- /dev/null +++ b/python/sdk/test/requirements/non_package_reqs_in.yaml @@ -0,0 +1,6 @@ +dependencies: + - python=3.10.* + - pip: + - --extra-index-url=http://artifactory.com + - --trusted-host=artifactory.com + - scikit-learn==1.4.0 diff --git a/python/sdk/test/requirements/non_package_reqs_out.yaml b/python/sdk/test/requirements/non_package_reqs_out.yaml new file mode 100644 index 000000000..ff10b4a6a --- /dev/null +++ b/python/sdk/test/requirements/non_package_reqs_out.yaml @@ -0,0 +1,7 @@ +dependencies: + - python=3.10.* + - pip: + - merlin-pyfunc-server<0.42.0 + - --extra-index-url=http://artifactory.com + - --trusted-host=artifactory.com + - scikit-learn==1.4.0 diff --git a/python/sdk/test/requirements_test.py b/python/sdk/test/requirements_test.py index 9805d5c66..837ca1154 100644 --- a/python/sdk/test/requirements_test.py +++ b/python/sdk/test/requirements_test.py @@ -27,6 +27,11 @@ "test/requirements/pyfunc_server_without_version_out.yaml", ["merlin-pyfunc-server<0.42.0"], ), + ( + "test/requirements/non_package_reqs_in.yaml", + "test/requirements/non_package_reqs_out.yaml", + ["merlin-pyfunc-server<0.42.0"], + ), ( "test/requirements/other_reqs_in.yaml", "test/requirements/other_reqs_out.yaml",