Skip to content

Commit

Permalink
bug: skip requirement comparison for pip reqs that is not a package
Browse files Browse the repository at this point in the history
  • Loading branch information
khorshuheng committed Apr 8, 2024
1 parent 1b8e3f5 commit 2d89f9b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
17 changes: 11 additions & 6 deletions python/sdk/merlin/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -51,11 +51,16 @@ def process_conda_env(
for additional_merlin_req in additional_merlin_reqs:
exist = False
for pip_req in pip_reqs:
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():
exist = True
break
# 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
try:
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():
exist = True
break
except InvalidRequirement:
pass

if not exist:
pip_reqs.insert(0, additional_merlin_req)
Expand Down
6 changes: 6 additions & 0 deletions python/sdk/test/requirements/non_package_reqs_in.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
- python=3.10.*
- pip:
- --extra-index-url=http://artifactory.com
- --trusted-host=artifactory.com
- scikit-learn==1.4.0
7 changes: 7 additions & 0 deletions python/sdk/test/requirements/non_package_reqs_out.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dependencies:
- python=3.10.*
- pip:
- --extra-index-url=http://artifactory.com
- --trusted-host=artifactory.com
- scikit-learn==1.4.0
- merlin-pyfunc-server<0.42.0
5 changes: 5 additions & 0 deletions python/sdk/test/requirements_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 2d89f9b

Please sign in to comment.